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Y3R4dCAhPSBOVUxMKSB7CiAgICAgICAgaW5wdXQgPSBjdHh0LT5pbnB1dDsKICAgICAgICBpZiAoKGlucHV0ICE9IE5VTEwpICYmIChpbnB1dC0+ZmlsZW5hbWUgPT0gTlVMTCkgJiYKICAgICAgICAgICAgKGN0eHQtPmlucHV0TnIgPiAxKSkgewogICAgICAgICAgICBjdXIgPSBpbnB1dDsKICAgICAgICAgICAgaW5wdXQgPSBjdHh0LT5pbnB1dFRhYltjdHh0LT5pbnB1dE5yIC0gMl07CiAgICAgICAgfQogICAgICAgIGlmIChpbnB1dCAhPSBOVUxMKSB7CiAgICAgICAgICAgIGlmIChpbnB1dC0+ZmlsZW5hbWUpCiAgICAgICAgICAgICAgICBjaGFubmVsKGRhdGEsICIlczolZDogIiwgaW5wdXQtPmZpbGVuYW1lLCBpbnB1dC0+bGluZSk7CiAgICAgICAgICAgIGVsc2UgaWYgKChsaW5lICE9IDApICYmIChkb21haW4gPT0gWE1MX0ZST01fUEFSU0VSKSkKICAgICAgICAgICAgICAgIGNoYW5uZWwoZGF0YSwgIkVudGl0eTogbGluZSAlZDogIiwgaW5wdXQtPmxpbmUpOwogICAgICAgIH0KICAgIH0gZWxzZSB7CiAgICAgICAgaWYgKGZpbGUgIT0gTlVMTCkKICAgICAgICAgICAgY2hhbm5lbChkYXRhLCAiJXM6JWQ6ICIsIGZpbGUsIGxpbmUpOwogICAgICAgIGVsc2UgaWYgKChsaW5lICE9IDApICYmIChkb21haW4gPT0gWE1MX0ZST01fUEFSU0VSKSkKICAgICAgICAgICAgY2hhbm5lbChkYXRhLCAiRW50aXR5OiBsaW5lICVkOiAiLCBsaW5lKTsKICAgIH0KICAgIGlmIChuYW1lICE9IE5VTEwpIHsKICAgICAgICBjaGFubmVsKGRhdGEsICJlbGVtZW50ICVzOiAiLCBuYW1lKTsKICAgIH0KICAgIGlmIChjb2RlID09IFhNTF9FUlJfT0spCiAgICAgICAgcmV0dXJuOwogICAgc3dpdGNoIChkb21haW4pIHsKICAgICAgICBjYXNlIFhNTF9GUk9NX1BBUlNFUjoKICAgICAgICAgICAgY2hhbm5lbChkYXRhLCAicGFyc2VyICIpOwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIFhNTF9GUk9NX05BTUVTUEFDRToKICAgICAgICAgICAgY2hhbm5lbChkYXRhLCAibmFtZXNwYWNlICIpOwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIFhNTF9GUk9NX0RURDoKICAgICAgICBjYXNlIFhNTF9GUk9NX1ZBTElEOgogICAgICAgICAgICBjaGFubmVsKGRhdGEsICJ2YWxpZGl0eSAiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBYTUxfRlJPTV9IVE1MOgogICAgICAgICAgICBjaGFubmVsKGRhdGEsICJIVE1MIHBhcnNlciAiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBYTUxfRlJPTV9NRU1PUlk6CiAgICAgICAgICAgIGNoYW5uZWwoZGF0YSwgIm1lbW9yeSAiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBYTUxfRlJPTV9PVVRQVVQ6CiAgICAgICAgICAgIGNoYW5uZWwoZGF0YSwgIm91dHB1dCAiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBYTUxfRlJPTV9JTzoKICAgICAgICAgICAgY2hhbm5lbChkYXRhLCAiSS9PICIpOwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIFhNTF9GUk9NX1hJTkNMVURFOgogICAgICAgICAgICBjaGFubmVsKGRhdGEsICJYSW5jbHVkZSAiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBYTUxfRlJPTV9YUEFUSDoKICAgICAgICAgICAgY2hhbm5lbChkYXRhLCAiWFBhdGggIik7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgWE1MX0ZST01fWFBPSU5URVI6CiAgICAgICAgICAgIGNoYW5uZWwoZGF0YSwgInBhcnNlciAiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBYTUxfRlJPTV9SRUdFWFA6CiAgICAgICAgICAgIGNoYW5uZWwoZGF0YSwgInJlZ2V4cCAiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBYTUxfRlJPTV9NT0RVTEU6CiAgICAgICAgICAgIGNoYW5uZWwoZGF0YSwgIm1vZHVsZSAiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBYTUxfRlJPTV9TQ0hFTUFTVjoKICAgICAgICAgICAgY2hhbm5lbChkYXRhLCAiU2NoZW1hcyB2YWxpZGl0eSAiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBYTUxfRlJPTV9TQ0hFTUFTUDoKICAgICAgICAgICAgY2hhbm5lbChkYXRhLCAiU2NoZW1hcyBwYXJzZXIgIik7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgWE1MX0ZST01fUkVMQVhOR1A6CiAgICAgICAgICAgIGNoYW5uZWwoZGF0YSwgIlJlbGF4LU5HIHBhcnNlciAiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBYTUxfRlJPTV9SRUxBWE5HVjoKICAgICAgICAgICAgY2hhbm5lbChkYXRhLCAiUmVsYXgtTkcgdmFsaWRpdHkgIik7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgWE1MX0ZST01fQ0FUQUxPRzoKICAgICAgICAgICAgY2hhbm5lbChkYXRhLCAiQ2F0YWxvZyAiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBYTUxfRlJPTV9DMTROOgogICAgICAgICAgICBjaGFubmVsKGRhdGEsICJDMTROICIpOwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIFhNTF9GUk9NX1hTTFQ6CiAgICAgICAgICAgIGNoYW5uZWwoZGF0YSwgIlhTTFQgIik7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgIGJyZWFrOwogICAgfQogICAgaWYgKGNvZGUgPT0gWE1MX0VSUl9PSykKICAgICAgICByZXR1cm47CiAgICBzd2l0Y2ggKGxldmVsKSB7CiAgICAgICAgY2FzZSBYTUxfRVJSX05PTkU6CiAgICAgICAgICAgIGNoYW5uZWwoZGF0YSwgIjogIik7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgWE1MX0VSUl9XQVJOSU5HOgogICAgICAgICAgICBjaGFubmVsKGRhdGEsICJ3YXJuaW5nIDogIik7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgWE1MX0VSUl9FUlJPUjoKICAgICAgICAgICAgY2hhbm5lbChkYXRhLCAiZXJyb3IgOiAiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBYTUxfRVJSX0ZBVEFMOgogICAgICAgICAgICBjaGFubmVsKGRhdGEsICJlcnJvciA6ICIpOwogICAgICAgICAgICBicmVhazsKICAgIH0KICAgIGlmIChjb2RlID09IFhNTF9FUlJfT0spCiAgICAgICAgcmV0dXJuOwogICAgaWYgKHN0ciAhPSBOVUxMKSB7CiAgICAgICAgaW50IGxlbjsKCWxlbiA9IHhtbFN0cmxlbigoY29uc3QgeG1sQ2hhciAqKXN0cik7CglpZiAoKGxlbiA+IDApICYmIChzdHJbbGVuIC0gMV0gIT0gJ1xuJykpCgkgICAgY2hhbm5lbChkYXRhLCAiJXNcbiIsIHN0cik7CgllbHNlCgkgICAgY2hhbm5lbChkYXRhLCAiJXMiLCBzdHIpOwogICAgfSBlbHNlIHsKICAgICAgICBjaGFubmVsKGRhdGEsICIlc1xuIiwgIm91dCBvZiBtZW1vcnkgZXJyb3IiKTsKICAgIH0KICAgIGlmIChjb2RlID09IFhNTF9FUlJfT0spCiAgICAgICAgcmV0dXJuOwoKICAgIGlmIChjdHh0ICE9IE5VTEwpIHsKICAgICAgICB4bWxQ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gewogICAgaW50IGZkLCByZXM7CiAgICBzdHJ1Y3Qgc3RhdCBpbmZvOwogICAgY2hhciAqYmFzZTsKICAgIGludCBzaXogPSAwOwogICAgaWYgKHN0YXQoZmlsZW5hbWUsICZpbmZvKSA8IDApCglyZXR1cm4oLTEpOwogICAgYmFzZSA9IG1hbGxvYyhpbmZvLnN0X3NpemUgKyAxKTsKICAgIGlmIChiYXNlID09IE5VTEwpCglyZXR1cm4oLTEpOwogICAgaWYgKChmZCA9IG9wZW4oZmlsZW5hbWUsIFJEX0ZMQUdTKSkgPCAwKSB7CiAgICAgICAgZnJlZShiYXNlKTsKCXJldHVybigtMSk7CiAgICB9CiAgICB3aGlsZSAoKHJlcyA9IHJlYWQoZmQsICZiYXNlW3Npel0sIGluZm8uc3Rfc2l6ZSAtIHNpeikpID4gMCkgewogICAgICAgIHNpeiArPSByZXM7CiAgICB9CiAgICBjbG9zZShmZCk7CiNpZiAhZGVmaW5lZChfV0lOMzIpCiAgICBpZiAoc2l6ICE9IGluZm8uc3Rfc2l6ZSkgewogICAgICAgIGZyZWUoYmFzZSk7CglyZXR1cm4oLTEpOwogICAgfQojZW5kaWYKICAgIGJhc2Vbc2l6XSA9IDA7CiAgICAqbWVtID0gYmFzZTsKICAgICpzaXplID0gc2l6OwogICAgcmV0dXJuKDApOwp9CgpzdGF0aWMgaW50IHVubG9hZE1lbShjb25zdCBjaGFyICptZW0pIHsKICAgIGZyZWUoKGNoYXIgKiltZW0pOwogICAgcmV0dXJuKDApOwp9CgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCiAqCQkJCQkJCQkJKgogKgkJVGVzdHMgaW1wbGVtZW50YXRpb25zCQkJCQkqCiAqCQkJCQkJCQkJKgogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgogKgkJCQkJCQkJCSoKICoJCVBhcnNlIHRvIFNBWCBiYXNlZCB0ZXN0cwkJCQkqCiAqCQkJCQkJCQkJKgogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwoKc3RhdGljIEZJTEUgKlNBWGRlYnVnID0gTlVMTDsKCi8qCiAqIGVtcHR5IFNBWCBibG9jawogKi8Kc3RhdGljIHhtbFNBWEhhbmRsZXIgZW1wdHlTQVhIYW5kbGVyU3RydWN0ID0gewogICAgTlVMTCwgLyogaW50ZXJuYWxTdWJzZXQgKi8KICAgIE5VTEwsIC8qIGlzU3RhbmRhbG9uZSAqLwogICAgTlVMTCwgLyogaGFzSW50ZXJuYWxTdWJzZXQgKi8KICAgIE5VTEwsIC8qIGhhc0V4dGVybmFsU3Vic2V0ICovCiAgICBOVUxMLCAvKiByZXNvbHZlRW50aXR5ICovCiAgICBOVUxMLCAvKiBnZXRFbnRpdHkgKi8KICAgIE5VTEwsIC8qIGVudGl0eURlY2wgKi8KICAgIE5VTEwsIC8qIG5vdGF0aW9uRGVjbCAqLwogICAgTlVMTCwgLyogYXR0cmlidXRlRGVjbCAqLwogICAgTlVMTCwgLyogZWxlbWVudERlY2wgKi8KICAgIE5VTEwsIC8qIHVucGFyc2VkRW50aXR5RGVjbCAqLwogICAgTlVMTCwgLyogc2V0RG9jdW1lbnRMb2NhdG9yICovCiAgICBOVUxMLCAvKiBzdGFydERvY3VtZW50ICovCiAgICBOVUxMLCAvKiBlbmREb2N1bWVudCAqLwogICAgTlVMTCwgLyogc3RhcnRFbGVtZW50ICovCiAgICBOVUxMLCAvKiBlbmRFbGVtZW50ICovCiAgICBOVUxMLCAvKiByZWZlcmVuY2UgKi8KICAgIE5VTEwsIC8qIGNoYXJhY3RlcnMgKi8KICAgIE5VTEwsIC8qIGlnbm9yYW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gcmVhZGVyOwogICAgaW50IHJldDsKICAgIGNvbnN0IGNoYXIgKmJhc2U7CiAgICBpbnQgc2l6ZTsKCiAgICAvKgogICAgICogbG9hZCBhbmQgcGFyc2UgdGhlIG1lbW9yeQogICAgICovCiAgICBpZiAobG9hZE1lbShmaWxlbmFtZSwgJmJhc2UsICZzaXplKSAhPSAwKSB7CiAgICAgICAgZnByaW50ZihzdGRlcnIsICJGYWlsZWQgdG8gbG9hZCAlc1xuIiwgZmlsZW5hbWUpOwoJcmV0dXJuKC0xKTsKICAgIH0KICAgIHJlYWRlciA9IHhtbFJlYWRlckZvck1lbW9yeShiYXNlLCBzaXplLCBmaWxlbmFtZSwgTlVMTCwgb3B0aW9ucyk7CiAgICByZXQgPSBzdHJlYW1Qcm9jZXNzVGVzdChmaWxlbmFtZSwgcmVzdWx0LCBlcnIsIHJlYWRlciwgTlVMTCk7CiAgICBmcmVlKChjaGFyICopYmFzZSk7CiAgICB4bWxGcmVlVGV4dFJlYWRlcihyZWFkZXIpOwogICAgcmV0dXJuKHJldCk7Cn0KI2VuZGlmCgojaWZkZWYgTElCWE1MX1hQQVRIX0VOQUJMRUQKI2lmZGVmIExJQlhNTF9ERUJVR19FTkFCTEVECi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKICoJCQkJCQkJCQkqCiAqCQlYUGF0aCBhbmQgWFBvaW50ZXIgYmFzZWQgdGVzdHMJCQkJKgogKgkJCQkJCQkJCSoKICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KCnN0YXRpYyBGSUxFICp4cGF0aE91dHB1dDsKc3RhdGljIHhtbERvY1B0ciB4cGF0aERvY3VtZW50OwoKc3RhdGljIHZvaWQKdGVzdFhQYXRoKGNvbnN0IGNoYXIgKnN0ciwgaW50IHhwdHIsIGludCBleHByKSB7CiAgICB4bWxYU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gkgICAgZXJyWzQ5OV0gPSAwOwoJfSBlbHNlIHsKCSAgICBmcHJpbnRmKHN0ZGVyciwgImRvbid0IGtub3cgaG93IHRvIHByb2Nlc3MgJXNcbiIsIGluc3RhbmNlKTsKCSAgICBjb250aW51ZTsKCX0KCWlmIChzY2hlbWFzID09IE5VTEwpIHsKCX0gZWxzZSB7CgkgICAgbmJfdGVzdHMrKzsKCSAgICByZXQgPSBzY2hlbWFzT25lVGVzdChmaWxlbmFtZSwgaW5zdGFuY2UsIHJlc3VsdCwgZXJyLAoJICAgICAgICAgICAgICAgICAgICAgICAgIG9wdGlvbnMsIHNjaGVtYXMpOwoJICAgIGlmIChyZXQgIT0gMCkKCQlyZXMgPSByZXQ7Cgl9CiAgICB9CiAgICBnbG9iZnJlZSgmZ2xvYmJ1Zik7CiAgICB4bWxTY2hlbWFGcmVlKHNjaGVtYXMpOwoKICAgIHJldHVybihyZXMpOwp9CgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCiAqCQkJCQkJCQkJKgogKgkJCVNjaGVtYXMgdGVzdHMJCQkJCSoKICoJCQkJCQkJCQkqCiAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCnN0YXRpYyBpbnQKcm5nT25lVGVzdChjb25zdCBjaGFyICpzY2gsCiAgICAgICAgICAgICAgIGNvbnN0IGNoYXIgKmZpbGVuYW1lLAogICAgICAgICAgICAgICBjb25zdCBjaGFyICpyZXN1bHQsCgkgICAgICAgY29uc3QgY2hhciAqZXJyLAoJICAgICAgIGludCBvcHRpb25zLAoJICAgICAgIHhtbFJlbGF4TkdQdHIgc2NoZW1hcykgewogICAgeG1sRG9jUHRyIGRvYzsKICAgIHhtbFJlbGF4TkdWYWxpZEN0eHRQdHIgY3R4dDsKICAgIGludCByZXQgPSAwOwogICAgY2hhciAqdGVtcDsKICA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gKi8KCiNlbmRpZgoKI2lmZGVmIExJQlhNTF9QQVRURVJOX0VOQUJMRUQKI2lmZGVmIExJQlhNTF9SRUFERVJfRU5BQkxFRAovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCiAqCQkJCQkJCQkJKgogKgkJCVBhdHRlcm5zIHRlc3RzCQkJCQkqCiAqCQkJCQkJCQkJKgogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwpzdGF0aWMgdm9pZCBwYXR0ZXJuTm9kZShGSUxFICpvdXQsIHhtbFRleHRSZWFkZXJQdHIgcmVhZGVyLAogICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBjaGFyICpwYXR0ZXJuLCB4bWxQYXR0ZXJuUHRyIHBhdHRlcm5jLAoJCQl4bWxTdHJlYW1DdHh0UHRyIHBhdHN0cmVhbSkgewogICAgeG1sQ2hhciAqcGF0aCA9IE5VTEw7CiAgICBpbnQgbWF0Y2ggPSAtMTsKICAgIGludCB0eXBlLCBlbXB0eTsKCiAgICB0eXBlID0geG1sVGV4dFJlYWRlck5vZGVUeXBlKHJlYWRlcik7CiAgICBlbXB0eSA9IHhtbFRleHRSZWFkZXJJc0VtcHR5RWxlbWVudChyZWFkZXIpOwoKICAgIGlmICh0eXBlID09IFhNTF9SRUFERVJfVFlQRV9FTEVNRU5UKSB7CgkvKiBkbyB0aGUgY2hlY2sgb25seSBvbiBlbGVtZW50IHN0YXJ0ICovCgltYXRjaCA9IHhtbFBhdHRlcm5NYXRjaChwYXR0ZXJuYywgeG1sVGV4dFJlYWRlckN1cnJlbnROb2RlKHJlYWRlcikpOwoKCWlmIChtYXRjaCkgewoJICAgIHBhdGggPSB4bWxHZXROb2RlUGF0aCh4bWxUZXh0UmVhZGVyQ3VycmVudE5vZGUocmVhZGVyKSk7CgkgICAgZnByaW50ZihvdXQsICJO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l0aG91dENvbW1lbnRUZXN0KGNvbnN0IGNoYXIgKmZpbGVuYW1lLAogICAgICAgICAgICAgICAgICAgIGNvbnN0IGNoYXIgKnJlc3VsIEFUVFJJQlVURV9VTlVTRUQsCgkJICAgIGNvbnN0IGNoYXIgKmVyciBBVFRSSUJVVEVfVU5VU0VELAoJCSAgICBpbnQgb3B0aW9ucyBBVFRSSUJVVEVfVU5VU0VEKSB7CiAgICByZXR1cm4oYzE0bkNvbW1vblRlc3QoZmlsZW5hbWUsIDAsIFhNTF9DMTROX0VYQ0xVU0lWRV8xXzAsICJleGMtd2l0aG91dC1jb21tZW50cyIpKTsKfQpzdGF0aWMgaW50CmMxNG4xMVdpdGhvdXRDb21tZW50VGVzdChjb25zdCBjaGFyICpmaWxlbmFtZSwKICAgICAgICAgICAgICAgICAgICBjb25zdCBjaGFyICpyZXN1bCBBVFRSSUJVVEVfVU5VU0VELAoJCSAgICBjb25zdCBjaGFyICplcnIgQVRUUklCVVRFX1VOVVNFRCwKCQkgICAgaW50IG9wdGlvbnMgQVRUUklCVVRFX1VOVVNFRCkgewogICAgcmV0dXJuKGMxNG5Db21tb25UZXN0KGZpbGVuYW1lLCAwLCBYTUxfQzE0Tl8xXzEsICIxLTEtd2l0aG91dC1jb21tZW50cyIpKTsKfQojZW5kaWYKI2lmIGRlZmluZWQoTElCWE1MX1RIUkVBRF9FTkFCTEVEKSAmJiBkZWZpbmVkKExJQlhNTF9DQVRBTE9HX0VOQUJMRUQpICYmIGRlZmluZWQgKExJQlhNTF9TQVgxX0VOQUJMRUQpCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKICoJCQkJCQkJCQkqCiAqCQkJQ2F0YWxvZyBhbmQgdGhyZWFkcyB0ZXN0CQkJKgogKgkJCQkJCQkJCSoKICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqK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ZWZhdWx0VmFsdWUgb3ZlcnJpZGUgZmFpbGVkXG4iKTsKICAgICAgICAgICAgb2theSA9IDA7CiAgICAgICAgfQogICAgICAgIGlmICh4bWxHZW5lcmljRXJyb3JDb250ZXh0ICE9IHN0ZGVycikgewogICAgICAgICAgICBwcmludGYoInhtbEdlbmVyaWNFcnJvckNvbnRleHQgb3ZlcnJpZGUgZmFpbGVkXG4iKTsKICAgICAgICAgICAgb2theSA9IDA7CiAgICAgICAgfQogICAgfQogICAgaWYgKG9rYXkgPT0gMCkKICAgICAgICByZXR1cm4gKCh2b2lkICopIEZhaWxlZCk7CiAgICByZXR1cm4gKCh2b2lkICopIE9rYXkpOwp9CgojaWYgZGVmaW5lZChsaW51eCkgfHwgZGVmaW5lZChfX3N1bikgfHwgZGVmaW5lZChfX0FQUExFX0NDX18pCgojaW5jbHVkZSA8cHRocmVhZC5oPgoKc3RhdGljIHB0aHJlYWRfdCB0aWRbTUFYX0FSR0NdOwoKc3RhdGljIGludAp0ZXN0VGhyZWFkKHZvaWQpCnsKICAgIHVuc2lnbmVkIGludCBpLCByZXBlYXQ7CiAgICB1bnNpZ25lZCBpbnQgbnVtX3RocmVhZHMgPSBzaXplb2YodGVzdGZpbGVzKSAvIHNpemVvZih0ZXN0ZmlsZXNbMF0pOwogICAgdm9pZCAqcmVzdWx0c1tNQVhfQVJHQ107CiAgICBpbnQgcmV0OwogICAgaW50IHJlcyA9IDA7CgogICAgeG1sSW5pdFBhcnNlcigpOwoKICAgIGZvciAocmVwZWF0ID0gMDsgcmVwZWF0IDwgNTAwOyByZXBlYXQrKykgewogICAgICAgIHhtbExvYWRDYXRhbG9nKGNhdGFsb2cpOwogICAgICAgIG5iX3Rlc3RzKys7CgogICAgICAgIGZvciAoaSA9IDA7IGkgPCBudW1fdGhyZWFkczsgaSsrKSB7CiAgICAgICAgICAgIHJlc3VsdHNbaV0gPSBOVUxMOwogICAgICAgICAgICB0aWRbaV0gPSAocHRocmVhZF90KSAtIDE7CiAgICAgICAgfQoKICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbnVtX3RocmVhZHM7IGkrKykgewogICAgICAgICAgICByZXQgPSBwdGhyZWFkX2NyZWF0ZSgmdGlkW2ldLCAwLCB0aHJlYWRfc3BlY2lmaWNfZGF0YSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKHZvaWQgKikgdGVzdGZpbGVzW2ldKTsKICAgICAgICAgICAgaWYgKHJldCAhPSAwKSB7CiAgICAgICAgICAgICAgICBmcHJpbnRmKHN0ZGVyciwgInB0aHJlYWRfY3JlYXRlIGZhaWxlZFxuIik7CiAgICAgICAgICAgICAgICByZXR1cm4gKDEpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGZvciAoaSA9IDA7IGkgPCBudW1fdGhyZWFkczsgaSsrKSB7CiAgICAgICAgICAgIHJldCA9IHB0aHJlYWRfam9pbih0aWRbaV0sICZyZXN1bHRzW2ldKTsKICAgICAgICAgICAgaWYgKHJldCAhPSAwKSB7CiAgICAgICAgICAgICAgICBmcHJpbnRmKHN0ZGVyciwgInB0aHJlYWRfam9pbiBmYWlsZWRcbiIpOwogICAgICAgICAgICAgICAgcmV0dXJuICgxKTsKICAgICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgeG1sQ2F0YWxvZ0NsZWFudXAoKTsKICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbnVtX3RocmVhZHM7IGkrKykKICAgICAgICAgICAgaWYgKHJlc3VsdHNbaV0gIT0gKHZvaWQgKikgT2theSkgewogICAgICAgICAgICAgICAgZnByaW50ZihzdGRlcnIsICJUaHJlYWQgJWQgaGFuZGxpbmcgJXMgZmFpbGVkXG4iLAogICAgICAgICAgICAgICAgICAgICAgICBpLCB0ZXN0ZmlsZXNbaV0pOwogICAgICAgICAgICAgICAgcmVzID0gMTsKICAgICAgICAgICAgfQogICAgfQogICAgcmV0dXJuIChyZXMpOwp9CgojZWxpZiBkZWZpbmVkIFdJTjMyCiNpbmNsdW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BlY2lmaWNfZGF0YSwKCQkJCSAgKHZvaWQgKikgdGVzdGZpbGVzW2ldLCAwLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJnVzZWxlc3MpOwogICAgICAgICAgICBpZiAodGlkW2ldID09IE5VTEwpIHsKICAgICAgICAgICAgICAgIGZwcmludGYoc3RkZXJyLCAiQ3JlYXRlVGhyZWFkIGZhaWxlZFxuIik7CiAgICAgICAgICAgICAgICByZXR1cm4oMSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIGlmIChXYWl0Rm9yTXVsdGlwbGVPYmplY3RzKG51bV90aHJlYWRzLCB0aWQsIFRSVUUsIElORklOSVRFKSA9PQogICAgICAgICAgICBXQUlUX0ZBSUxFRCkgewogICAgICAgICAgICBmcHJpbnRmKHN0ZGVyciwgIldhaXRGb3JNdWx0aXBsZU9iamVjdHMgZmFpbGVkXG4iKTsKCSAgICByZXR1cm4oMSk7Cgl9CgogICAgICAgIGZvciAoaSA9IDA7IGkgPCBudW1fdGhyZWFkczsgaSsrKSB7CiAgICAgICAgICAgIHJldCA9IEdldEV4aXRDb2RlVGhyZWFkKHRpZFtpXSwgJnJlc3VsdHNbaV0pOwogICAgICAgICAgICBpZiAocmV0ID09IDApIHsKICAgICAgICAgICAgICAgIGZwcmludGYoc3RkZXJyLCAiR2V0RXhpdENvZGVUaHJlYWQgZmFpbGVkXG4iKTsKICAgICAgICAgICAgICAgIHJldHVybigxKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBDbG9zZUhhbmRsZSh0aWRbaV0pOwogICAgICAgIH0KCiAgICAgICAgeG1sQ2F0YWxvZ0NsZWFudXAoKTsKICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbnVtX3RocmVhZHM7IGkrKykgewogICAgICAgICAgICBpZiAocmVzdWx0c1tpXSAhPSAoRFdPUkQpIE9rYXkpIHsKICAgICAgICAgICAgICAgIGZwcmludGYoc3RkZXJyLCAiVGhyZWFkICVkIGhhbmRsaW5nICVzIGZhaWxlZFxuIiwKCQkgICAgICAgIGksIHRlc3RmaWxlc1tpXSk7CgkgICAgICAgIHJlcyA9IDE7CgkgICAgfQogICAgICAgIH0KICAgIH0KCiAgICByZXR1cm4gKHJlcyk7Cn0KCiNlbGlmIGRlZmluZWQgX19CRU9TX18KI2luY2x1ZGUgPE9TLmg+CgpzdGF0aWMgdGhyZWFkX2lkIHRpZFtNQVhfQVJHQ107CgpzdGF0aWMgaW50CnRlc3RUaHJlYWQodm9pZCkKewogICAgdW5zaWduZWQgaW50IGksIHJlcGVhdDsKICAgIHVuc2lnbmVkIGludCBudW1fdGhyZWFkcyA9IHNpemVvZih0ZXN0ZmlsZXMpIC8gc2l6ZW9mKHRlc3RmaWxlc1swXSk7CiAgICB2b2lkICpyZXN1bHRzW01BWF9BUkdDXTsKICAgIHN0YXR1c190IHJldDsKICAgIGludCByZXMgPSAwOwoKICAgIHhtbEluaXRQYXJzZXIoKTsKICAgIGZvciAocmVwZWF0ID0gMDsgcmVwZWF0IDwgNTAwOyByZXBlYXQrKykgewogICAgICAgIHhtbExvYWRDYXRhbG9nKGNhdGFsb2cpOwogICAgICAgIGZvciAoaSA9IDA7IGkgPCBudW1fdGhyZWFkczsgaSsrKSB7CiAgICAgICAgICAgIHJlc3VsdHNbaV0gPSBOVUxMOwogICAgICAgICAgICB0aWRbaV0gPSAodGhyZWFkX2lkKSAtIDE7CiAgICAgICAgfQogICAgICAgIGZvciAoaSA9IDA7IGkgPCBudW1fdGhyZWFkczsgaSsrKSB7CiAgICAgICAgICAgIHRpZFtpXSA9CiAgICAgICAgICAgICAgICBzcGF3bl90aHJlYWQodGhyZWFkX3NwZWNpZmljX2RhdGEsICJ4bWxUZXN0VGhyZWFkIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICBCX05PUk1BTF9QUklPUklUWSwgKHZvaWQgKikgdGVzdGZpbGVzW2ldKTsKICAgICAgICAgICAgaWYgKHRpZFtpXSA8IEJfT0spIHsKICAgICAgICAgICAgICAgIGZwcmludGYoc3RkZXJyLCAiYmVvc190aHJlYWRfY3JlYXRlIGZhaWxlZFxuIik7CiAgICAgICAgICAgICAgICByZXR1cm4gKDEpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHByaW50ZigiYmVvc190aHJlYWRfY3JlYXRlICVkIC0+ICVkXG4iLCBpLCB0aWRbaV0pOwogICAgICAgIH0KICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbnVtX3RocmVhZHM7IGkrKykgewogICAgICAgICAgICByZXQgPSB3YWl0X2Zvcl90aHJlYWQodGlkW2ldLCAmcmVzdWx0c1tpXSk7CiAgICAgICAgICAgIHByaW50ZigiYmVvc190aHJlYWRfd2FpdCAlZCAtPiAlZFxuIiwgaSwgcmV0KTsKICAgICAgICAgICAgaWYgKHJldCAhPSBCX09LKSB7CiAgICAgICAgICAgICAgICBmcHJpbnRmKHN0ZGVyciwgImJlb3NfdGhyZWFkX3dhaXQgZmFpbGVkXG4iKTsKICAgICAgICAgICAgICAgIHJldHVybiAoMSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIHhtbENhdGFsb2dDbGVhbnVwKCk7CiAgICAgICAgcmV0ID0gQl9PSzsKICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbnVtX3RocmVhZHM7IGkrKykKICAgICAgICAgICAgaWYgKHJlc3VsdHNbaV0gIT0gKHZvaWQgKikgT2theSkgewogICAgICAgICAgICAgICAgcHJpbnRmKCJUaHJlYWQgJWQgaGFuZGxpbmcgJXMgZmFpbGVkXG4iLCBpLCB0ZXN0ZmlsZXNbaV0pOwogICAgICAgICAgICAgICAgcmV0ID0gQl9FUlJPUjsKICAgICAgICAgICAgfQogICAgfQogICAgaWYgKHJldCAhPSBCX09LKQogICAgICAgIHJldHVybigxKTsKICAgIHJldHVybiAoMCk7Cn0KI2Vsc2UKc3RhdGljIGludAp0ZXN0VGhyZWFkKHZvaWQpCnsKICAgIGZwcmludGYoc3RkZXJyLAogICAgICAgICAgICAiU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