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vYyhyZXQtPmdsX3BhdGh2LCBuYl9wYXRocyAqIDIgKiBzaXplb2YoY2hhciAqKSk7CiAgICAgICAgICAgIGlmICh0bXAgPT0gTlVMTCkKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICByZXQtPmdsX3BhdGh2ID0gdG1wOwogICAgICAgICAgICBuYl9wYXRocyAqPSAyOwoJfQoJc3RybmNweShkaXJlY3RvcnkgKyBsZW4sIEZpbmRGaWxlRGF0YS5jRmlsZU5hbWUsIDQ5OSAtIGxlbik7CglyZXQtPmdsX3BhdGh2W3JldC0+Z2xfcGF0aGNdID0gc3RyZHVwKGRpcmVjdG9yeSk7CiAgICAgICAgaWYgKHJldC0+Z2xfcGF0aHZbcmV0LT5nbF9wYXRoY10gPT0gTlVMTCkKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgcmV0LT5nbF9wYXRoYysrOwogICAgfQogICAgcmV0LT5nbF9wYXRodltyZXQtPmdsX3BhdGhjXSA9IE5VTEw7Cgpkb25lOgogICAgRmluZENsb3NlKGhGaW5kKTsKICAgIHJldHVybigwKTsKfQogCgoKc3RhdGljIHZvaWQgZ2xvYmZyZWUoZ2xvYl90ICpwZ2xvYikgewogICAgdW5zaWduZWQgaW50IGk7CiAgICBpZiAocGdsb2IgPT0gTlVMTCkKICAgICAgICByZXR1cm47CiAgICAKICAgIGZvciAoaSA9IDA7aSA8IHBnbG9iLT5nbF9wYXRoYztpKyspIHsKICAgICAgICAgaWYgKHBnbG9iLT5nbF9wYXRodltpXSAhPSBOVUxMKQogICAgICAgICAgICAgZnJlZShwZ2xvYi0+Z2xfcGF0aHZbaV0pOwogICAgfQp9CiNkZWZpbmUgdnNucHJpbnRmIF92c25wcmludGYKI2RlZmluZSBzbnByaW50ZiBfc25wcmludGYKI2Vsc2UKI2luY2x1ZGUgPGdsb2IuaD4KI2VuZGlmCgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq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R5IHdpdGggdGhlIGxlZ2FjeSBlcnJvciBoYW5kbGluZwogICAgICovCiAgICBpZiAoY3R4dCAhPSBOVUxMKSB7CiAgICAgICAgaW5wdXQgPSBjdHh0LT5pbnB1dDsKICAgICAgICBpZiAoKGlucHV0ICE9IE5VTEwpICYmIChpbnB1dC0+ZmlsZW5hbWUgPT0gTlVMTCkgJiYKICAgICAgICAgICAgKGN0eHQtPmlucHV0TnIgPiAxKSkgewogICAgICAgICAgICBjdXIgPSBpbnB1dDsKICAgICAgICAgICAgaW5wdXQgPSBjdHh0LT5pbnB1dFRhYltjdHh0LT5pbnB1dE5yIC0gMl07CiAgICAgICAgfQogICAgICAgIGlmIChpbnB1dCAhPSBOVUxMKSB7CiAgICAgICAgICAgIGlmIChpbnB1dC0+ZmlsZW5hbWUpCiAgICAgICAgICAgICAgICBjaGFubmVsKGRhdGEsICIlczolZDogIiwgaW5wdXQtPmZpbGVuYW1lLCBpbnB1dC0+bGluZSk7CiAgICAgICAgICAgIGVsc2UgaWYgKChsaW5lICE9IDApICYmIChkb21haW4gPT0gWE1MX0ZST01fUEFSU0VSKSkKICAgICAgICAgICAgICAgIGNoYW5uZWwoZGF0YSwgIkVudGl0eTogbGluZSAlZDogIiwgaW5wdXQtPmxpbmUpOwogICAgICAgIH0KICAgIH0gZWxzZSB7CiAgICAgICAgaWYgKGZpbGUgIT0gTlVMTCkKICAgICAgICAgICAgY2hhbm5lbChkYXRhLCAiJXM6JWQ6ICIsIGZpbGUsIGxpbmUpOwogICAgICAgIGVsc2UgaWYgKChsaW5lICE9IDApICYmIChkb21haW4gPT0gWE1MX0ZST01fUEFSU0VSKSkKICAgICAgICAgICAgY2hhbm5lbChkYXRhLCAiRW50aXR5OiBsaW5lICVkOiAiLCBsaW5lKTsKICAgIH0KICAgIGlmIChuYW1lICE9IE5VTEwpIHsKICAgICAgICBjaGFubmVsKGRhdGEsICJlbGVtZW50ICVzOiAiLCBuYW1lKTsKICAgIH0KICAgIGlmIChjb2RlID09IFhNTF9FUlJfT0spCiAgICAgICAgcmV0dXJuOwogICAgc3dpdGNoIChkb21haW4pIHsKICAgICAgICBjYXNlIFhNTF9GUk9NX1BBUlNFUjoKICAgICAgICAgICAgY2hhbm5lbChkYXRhLCAicGFyc2VyICIpOwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIFhNTF9GUk9NX05BTUVTUEFDRToKICAgICAgICAgICAgY2hhbm5lbChkYXRhLCAibmFtZXNwYWNlICIpOwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIFhNTF9GUk9NX0RURDoKICAgICAgICBjYXNlIFhNTF9GUk9NX1ZBTElEOgogICAgICAgICAgICBjaGFubmVsKGRhdGEsICJ2YWxpZGl0eSAiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBYTUxfRlJPTV9IVE1MOgogICAgICAgICAgICBjaGFubmVsKGRhdGEsICJIVE1MIHBhcnNlciAiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBYTUxfRlJPTV9NRU1PUlk6CiAgICAgICAgICAgIGNoYW5uZWwoZGF0YSwgIm1lbW9yeSAiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBYTUxfRlJPTV9PVVRQVVQ6CiAgICAgICAgICAgIGNoYW5uZWwoZGF0YSwgIm91dHB1dCAiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBYTUxfRlJPTV9JTzoKICAgICAgICAgICAgY2hhbm5lbChkYXRhLCAiSS9PICIpOwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIFhNTF9GUk9NX1hJTkNMVURFOgogICAgICAgICAgICBjaGFubmVsKGRhdGEsICJYSW5jbHVkZSAiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBYTUxfRlJPTV9YUEFUSDoKICAgICAgICAgICAgY2hhbm5lbChkYXRhLCAiWFBhdGggIik7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgWE1MX0ZST01fWFBPSU5URVI6CiAgICAgICAgICAgIGNoYW5uZWwoZGF0YSwgInBhcnNlciAiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBYTUxfRlJPTV9SRUdFWFA6CiAgICAgICAgICAgIGNoYW5uZWwoZGF0YSwgInJlZ2V4cCAiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBYTUxfRlJPTV9NT0RVTEU6CiAgICAgICAgICAgIGNoYW5uZWwoZGF0YSwgIm1vZHVsZSAiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBYTUxfRlJPTV9TQ0hFTUFTVjoKICAgICAgICAgICAgY2hhbm5lbChkYXRhLCAiU2NoZW1hcyB2YWxpZGl0eSAiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBYTUxfRlJPTV9TQ0hFTUFTUDoKICAgICAgICAgICAgY2hhbm5lbChkYXRhLCAiU2NoZW1hcyBwYXJzZXIgIik7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgWE1MX0ZST01fUkVMQVhOR1A6CiAgICAgICAgICAgIGNoYW5uZWwoZGF0YSwgIlJlbGF4LU5HIHBhcnNlciAiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBYTUxfRlJPTV9SRUxBWE5HVjoKICAgICAgICAgICAgY2hhbm5lbChkYXRhLCAiUmVsYXgtTkcgdmFsaWRpdHkgIik7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgWE1MX0ZST01fQ0FUQUxPRzoKICAgICAgICAgICAgY2hhbm5lbChkYXRhLCAiQ2F0YWxvZyAiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBYTUxfRlJPTV9DMTROOgogICAgICAgICAgICBjaGFubmVsKGRhdGEsICJDMTROICIpOwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIFhNTF9GUk9NX1hTTFQ6CiAgICAgICAgICAgIGNoYW5uZWwoZGF0YSwgIlhTTFQgIik7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgIGJyZWFrOwogICAgfQogICAgaWYgKGNvZGUgPT0gWE1MX0VSUl9PSykKICAgICAgICByZXR1cm47CiAgICBzd2l0Y2ggKGxldmVsKSB7CiAgICAgICAgY2FzZSBYTUxfRVJSX05PTkU6CiAgICAgICAgICAgIGNoYW5uZWwoZGF0YSwgIjogIik7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgWE1MX0VSUl9XQVJOSU5HOgogICAgICAgICAgICBjaGFubmVsKGRhdGEsICJ3YXJuaW5nIDogIik7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgWE1MX0VSUl9FUlJPUjoKICAgICAgICAgICAgY2hhbm5lbChkYXRhLCAiZXJyb3IgOiAiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBYTUxfRVJSX0ZBVEFMOgogICAgICAgICAgICBjaGFubmVsKGRhdGEsICJlcnJvciA6ICIpOwogICAgICAgICAgICBicmVhazsKICAgIH0KICAgIGlmIChjb2RlID09IFhNTF9FUlJfT0spCiAgICAgICAgcmV0dXJuOwogICAgaWYgKHN0ciAhPSBOVUxMKSB7CiAgICAgICAgaW50IGxlbjsKCWxlbiA9IHhtbFN0cmxlbigoY29uc3QgeG1sQ2hhciAqKXN0cik7CglpZiAoKGxlbiA+IDApICYmIChzdHJbbGVuIC0gMV0gIT0gJ1xuJykpCgkgICAgY2hhbm5lbChkYXRhLCAiJXNcbiIsIHN0cik7CgllbHNlCgkgICAgY2hhbm5lbChkYXRhLCAiJXMiLCBzdHIpOwogICAgfSBlbHNlIHsKICAgICAgICBjaGFubmVsKGRhdGEsICIlc1xuIiwgIm91dCBvZiBtZW1vcnkgZXJyb3IiKTsKICAgIH0KICAgIGlmIChjb2RlID09IFhNTF9FUlJfT0spCiAgICA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YW1lLCAmaW5mbykgPCAwKSAKCXJldHVybigtMSk7CiAgICBiYXNlID0gbWFsbG9jKGluZm8uc3Rfc2l6ZSArIDEpOwogICAgaWYgKGJhc2UgPT0gTlVMTCkKCXJldHVybigtMSk7CiAgICBpZiAoKGZkID0gb3BlbihmaWxlbmFtZSwgUkRfRkxBR1MpKSA8IDApIHsKICAgICAgICBmcmVlKGJhc2UpOwoJcmV0dXJuKC0xKTsKICAgIH0KICAgIHdoaWxlICgocmVzID0gcmVhZChmZCwgJmJhc2Vbc2l6XSwgaW5mby5zdF9zaXplIC0gc2l6KSkgPiAwKSB7CiAgICAgICAgc2l6ICs9IHJlczsKICAgIH0KICAgIGNsb3NlKGZkKTsKI2lmICFkZWZpbmVkKF9XSU4zMikKICAgIGlmIChzaXogIT0gaW5mby5zdF9zaXplKSB7CiAgICAgICAgZnJlZShiYXNlKTsKCXJldHVybigtMSk7CiAgICB9CiNlbmRpZgogICAgYmFzZVtzaXpdID0gMDsKICAgICptZW0gPSBiYXNlOwogICAgKnNpemUgPSBzaXo7CiAgICByZXR1cm4oMCk7Cn0KCnN0YXRpYyBpbnQgdW5sb2FkTWVtKGNvbnN0IGNoYXIgKm1lbSkgewogICAgZnJlZSgoY2hhciAqKW1lbSk7CiAgICByZXR1cm4oMCk7Cn0KCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKICoJCQkJCQkJCQkqCiAqCQlUZXN0cyBpbXBsZW1lbnRhdGlvbnMJCQkJCSoKICoJCQkJCQkJCQkqCiAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCiAqCQkJCQkJCQkJKgogKgkJUGFyc2UgdG8gU0FYIGJhc2VkIHRlc3R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ICVzIGZhaWxlZFxuIiwgZmlsZW5hbWUpOwoJICAgIHJldHVybigtMSk7Cgl9CiAgICB9IGVsc2UgaWYgKG9wdGlvbnMgJiBYTUxfUEFSU0VfRFREVkFMSUQpIHsKICAgICAgICBpZiAodGVzdEVycm9yc1NpemUgIT0gMCkKCSAgICBmcHJpbnRmKHN0ZGVyciwgIlZhbGlkYXRpb24gZm9yICVzIGZhaWxlZFxuIiwgZmlsZW5hbWUpOwogICAgfQoKICAgIHJldHVybigwKTsKfQoKI2lmZGVmIExJQlhNTF9SRUFERVJfRU5BQkxFRAovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCiAqCQkJCQkJCQkJKgogKgkJUmVhZGVyIGJhc2VkIHRlc3RzCQkJCQkqCiAqCQkJCQkJCQkJKgogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwoKc3RhdGljIHZvaWQgcHJvY2Vzc05vZGUoRklMRSAqb3V0LCB4bWxUZXh0UmVhZGVyUHRyIHJlYWRlcikgewogICAgY29uc3QgeG1sQ2hhciAqbmFtZSwgKnZhbHVlOwogICAgaW50IHR5cGUsIGVtcHR5OwoKICAgIHR5cGUgPSB4bWxUZXh0UmVhZGVyTm9kZVR5cGUocmVhZGVyKTsKICAgIGVtcHR5ID0geG1sVGV4dFJlYWRlcklzRW1wdHlFbGVtZW50KHJlYWRlcik7CgogICAgbmFtZSA9IHhtbFRleHRSZWFkZXJDb25zdE5hbWUocmVhZGVyKTsKICAgIGlmIChuYW1lID09IE5VTEwpCgluYW1lID0gQkFEX0NBU1QgIi0tIjsKCiAgICB2YWx1ZSA9IHhtbFRleHRSZWFkZXJDb25zdFZhbHVlKHJlYWRlcik7CgogICAgCiAgICBmcHJpbnRmKG91dCwgIiVkICVkICVzICVkICVkIiwgCgkgICAgeG1sVGV4dFJlYWRlckRlcHR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KCSAgICBmcHJpbnRmKHN0ZGVyciwgIlJlc3VsdCBmb3IgJXMgZmFpbGVkXG4iLCBmaWxlbmFtZSk7CgkgICAgcmVzID0gMTsKCX0KICAgIH0KCiAgICB1bmxpbmsodGVtcCk7CiAgICBmcmVlKHRlbXApOwogICAgeG1sRnJlZURvYyh4cGF0aERvY3VtZW50KTsKCiAgICBpZiAoZXJyICE9IE5VTEwpIHsKCXJldCA9IGNvbXBhcmVGaWxlTWVtKGVyciwgdGVzdEVycm9ycywgdGVzdEVycm9yc1NpemUpOwoJaWYgKHJldCAhPSAwKSB7CgkgICAgZnByaW50ZihzdGRlcnIsICJFcnJvciBmb3IgJXMgZmFpbGVkXG4iLCBmaWxlbmFtZSk7CgkgICAgcmVzID0gMTsKCX0KICAgIH0KICAgIHJldHVybihyZXMpOwp9CgojZW5kaWYgLyogTElCWE1MX0RFQlVHX0VOQUJMRUQgKi8KI2VuZGlmIC8qIFhQQVRIICovCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKICoJCQkJCQkJCQkqCiAqCQkJVVJJIGJhc2VkIHRlc3RzCQkJCQkqCiAqCQkJCQkJCQkJKgogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwoKc3RhdGljIHZvaWQKaGFuZGxlVVJJKGNvbnN0IGNoYXIgKnN0ciwgY29uc3QgY2hhciAqYmFzZSwgRklMRSAqbykgewogICAgaW50IHJldDsKICAgIHhtbFVSSVB0ciB1cmk7CiAgICB4bWxDaGFyICpyZXMgPSBOVUxMLCAqcGFyc2VkID0gTlVMTDsKCiAgICB1cmkgPSB4bWxDcmVhdGVVUkkoKTsKCiAgICBpZiAoYmFzZSA9PSBOVUxMKSB7CglyZXQgPSB4bWxQYXJzZVVSSVJlZmVyZW5jZSh1cmksIHN0cik7CglpZiAocmV0ICE9IDApCgkgICA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KCX0gZWxzZSBpZiAocGFyc2VkICE9IDEpIHsKCSAgICBmcHJpbnRmKHN0ZGVyciwgImZhaWxlZCB0aGUgcGFyc2luZyB0ZXN0IGZvciAlcyIsCgkgICAgICAgICAgICB1cmlwX3Rlc3RVUkxzW3VyaXBfY3VycmVudF0pOwoJICAgIGZhaWx1cmVzKys7Cgl9CgluYl90ZXN0cysrOwogICAgfQoKICAgIHhtbFBvcElucHV0Q2FsbGJhY2tzKCk7CiAgICByZXR1cm4oZmFpbHVyZXMpOwp9CgojaWZkZWYgTElCWE1MX1NDSEVNQVNfRU5BQkxFRAovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCiAqCQkJCQkJCQkJKgogKgkJCVNjaGVtYXMgdGVzdHMJCQkJCSoKICoJCQkJCQkJCQkqCiAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCnN0YXRpYyBpbnQKc2NoZW1hc09uZVRlc3QoY29uc3QgY2hhciAqc2NoLAogICAgICAgICAgICAgICBjb25zdCBjaGFyICpmaWxlbmFtZSwKICAgICAgICAgICAgICAgY29uc3QgY2hhciAqcmVzdWx0LAoJICAgICAgIGNvbnN0IGNoYXIgKmVyciwKCSAgICAgICBpbnQgb3B0aW9ucywKCSAgICAgICB4bWxTY2hlbWFQdHIgc2NoZW1hcykgewogICAgeG1sRG9jUHRyIGRvYzsKICAgIHhtbFNjaGVtYVZhbGlkQ3R4dFB0ciBjdHh0OwogICAgaW50IHJldCA9IDA7CiAgICBjaGFyICp0ZW1wOwogICAgRklMRSAqc2NoZW1hc091dHB1dDsKCiAgICBkb2MgPSB4bWxSZWFkRmlsZShmaWxlbmFtZSwgTlVMTCwgb3B0aW9ucyk7CiAgICBpZiAoZG9jID09IE5VTEwpIHsKICAgICAgICBmcHJpbnRmKHN0ZGVyciwgImZhaWxlZCB0byBwY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VzdHMJCQkJCSoKICoJCQkJCQkJCQkqCiAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCnN0YXRpYyBpbnQKcm5nT25lVGVzdChjb25zdCBjaGFyICpzY2gsCiAgICAgICAgICAgICAgIGNvbnN0IGNoYXIgKmZpbGVuYW1lLAogICAgICAgICAgICAgICBjb25zdCBjaGFyICpyZXN1bHQsCgkgICAgICAgY29uc3QgY2hhciAqZXJyLAoJICAgICAgIGludCBvcHRpb25zLAoJICAgICAgIHhtbFJlbGF4TkdQdHIgc2NoZW1hcykgewogICAgeG1sRG9jUHRyIGRvYzsKICAgIHhtbFJlbGF4TkdWYWxpZEN0eHRQdHIgY3R4dDsKICAgIGludCByZXQgPSAwOwogICAgY2hhciAqdGVtcDsKICAgIEZJTEUgKnNjaGVtYXNPdXRwdXQ7CgogICAgZG9jID0geG1sUmVhZEZpbGUoZmlsZW5hbWUsIE5VTEwsIG9wdGlvbnMpOwogICAgaWYgKGRvYyA9PSBOVUxMKSB7CiAgICAgICAgZnByaW50ZihzdGRlcnIsICJmYWlsZWQgdG8gcGFyc2UgaW5zdGFuY2UgJXMgZm9yICVzXG4iLCBmaWxlbmFtZSwgc2NoKTsKCXJldHVybigtMSk7CiAgICB9CgogICAgdGVtcCA9IHJlc3VsdEZpbGVuYW1lKHJlc3VsdCwgIiIsICIucmVzIik7CiAgICBpZiAodGVtcCA9PSBOVUxMKSB7CiAgICAgICAgZnByaW50ZihzdGRlcnIsICJPdXQgb2YgbWVtb3J5XG4iKTsKICAgICAgICBmYXRhbEVycm9yKCk7CiAgICB9CiAgICBzY2hlbWFzT3V0cHV0ID0gZm9wZW4odGVtcCwgIndiIik7CiAgICBpZiAoc2NoZW1hc091dHB1dCA9PSBOVUxMKSB7CglmcHJpbnRmKHN0ZGVyciwgImZhaWxlZCB0byBvcGVuIG91dHB1dCBmaWxlICVzXG4iLCB0ZW1wKTsKCXhtbE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XRob3V0Q29tbWVudFRlc3QoY29uc3QgY2hhciAqZmlsZW5hbWUsCiAgICAgICAgICAgICAgICAgICAgY29uc3QgY2hhciAqcmVzdWwgQVRUUklCVVRFX1VOVVNFRCwKCQkgICAgY29uc3QgY2hhciAqZXJyIEFUVFJJQlVURV9VTlVTRUQsCgkJICAgIGludCBvcHRpb25zIEFUVFJJQlVURV9VTlVTRUQpIHsKICAgIHJldHVybihjMTRuQ29tbW9uVGVzdChmaWxlbmFtZSwgMCwgMCwgIndpdGhvdXQtY29tbWVudHMiKSk7Cn0Kc3RhdGljIGludApjMTRuRXhjV2l0aG91dENvbW1lbnRUZXN0KGNvbnN0IGNoYXIgKmZpbGVuYW1lLAogICAgICAgICAgICAgICAgICAgIGNvbnN0IGNoYXIgKnJlc3VsIEFUVFJJQlVURV9VTlVTRUQsCgkJICAgIGNvbnN0IGNoYXIgKmVyciBBVFRSSUJVVEVfVU5VU0VELAoJCSAgICBpbnQgb3B0aW9ucyBBVFRSSUJVVEVfVU5VU0VEKSB7CiAgICByZXR1cm4oYzE0bkNvbW1vblRlc3QoZmlsZW5hbWUsIDAsIDEsICJleGMtd2l0aG91dC1jb21tZW50cyIpKTsKfQojZW5kaWYKI2lmIGRlZmluZWQoTElCWE1MX1RIUkVBRF9FTkFCTEVEKSAmJiBkZWZpbmVkKExJQlhNTF9DQVRBTE9HX0VOQUJMRUQpICYmIGRlZmluZWQgKExJQlhNTF9TQVgxX0VOQUJMRUQpCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKICoJCQkJCQkJCQkqCiAqCQkJQ2F0YWxvZyBhbmQgdGhyZWFkcyB0ZXN0CQkJKgogKgkJCQkJCQkJCSoKICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KCi8qCiAqIG1vc3RseSBhIGN1dCBhbmQgcGFzdGU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gICAgICAgICAgb2theSA9IDA7CiAgICAgICAgfQogICAgICAgIGlmICh4bWxHZW5lcmljRXJyb3JDb250ZXh0ICE9IHN0ZGVycikgewogICAgICAgICAgICBwcmludGYoInhtbEdlbmVyaWNFcnJvckNvbnRleHQgb3ZlcnJpZGUgZmFpbGVkXG4iKTsKICAgICAgICAgICAgb2theSA9IDA7CiAgICAgICAgfQogICAgfQogICAgaWYgKG9rYXkgPT0gMCkKICAgICAgICByZXR1cm4gKCh2b2lkICopIEZhaWxlZCk7CiAgICByZXR1cm4gKCh2b2lkICopIE9rYXkpOwp9CgojaWYgZGVmaW5lZChsaW51eCkgfHwgZGVmaW5lZChzb2xhcmlzKQoKI2luY2x1ZGUgPHB0aHJlYWQuaD4KCnN0YXRpYyBwdGhyZWFkX3QgdGlkW01BWF9BUkdDXTsKCnN0YXRpYyBpbnQKdGVzdFRocmVhZCh2b2lkKQp7CiAgICB1bnNpZ25lZCBpbnQgaSwgcmVwZWF0OwogICAgdW5zaWduZWQgaW50IG51bV90aHJlYWRzID0gc2l6ZW9mKHRlc3RmaWxlcykgLyBzaXplb2YodGVzdGZpbGVzWzBdKTsKICAgIHZvaWQgKnJlc3VsdHNbTUFYX0FSR0NdOwogICAgaW50IHJldDsKICAgIGludCByZXMgPSAwOwogICAgCiAgICB4bWxJbml0UGFyc2VyKCk7CgogICAgZm9yIChyZXBlYXQgPSAwOyByZXBlYXQgPCA1MDA7IHJlcGVhdCsrKSB7CiAgICAgICAgeG1sTG9hZENhdGFsb2coY2F0YWxvZyk7CiAgICAgICAgbmJfdGVzdHMrKzsKCiAgICAgICAgZm9yIChpID0gMDsgaSA8IG51bV90aHJlYWRzOyBpKyspIHsKICAgICAgICAgICAgcmVzdWx0c1tpXSA9IE5VTEw7CiAgICAgICAgICAgIHRpZFtpXSA9IChwdGhyZWFkX3QpIC0gMTsKICAgICAgICB9CgogICAgICAgIGZvciAoaSA9IDA7IGkgPCBudW1fdGhyZWFkczsgaSsrKSB7CiAgICAgICAgICAgIHJldCA9IHB0aHJlYWRfY3JlYXRlKCZ0aWRbaV0sIDAsIHRocmVhZF9zcGVjaWZpY19kYXRhLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAodm9pZCAqKSB0ZXN0ZmlsZXNbaV0pOwogICAgICAgICAgICBpZiAocmV0ICE9IDApIHsKICAgICAgICAgICAgICAgIGZwcmludGYoc3RkZXJyLCAicHRocmVhZF9jcmVhdGUgZmFpbGVkXG4iKTsKICAgICAgICAgICAgICAgIHJldHVybiAoMSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZm9yIChpID0gMDsgaSA8IG51bV90aHJlYWRzOyBpKyspIHsKICAgICAgICAgICAgcmV0ID0gcHRocmVhZF9qb2luKHRpZFtpXSwgJnJlc3VsdHNbaV0pOwogICAgICAgICAgICBpZiAocmV0ICE9IDApIHsKICAgICAgICAgICAgICAgIGZwcmludGYoc3RkZXJyLCAicHRocmVhZF9qb2luIGZhaWxlZFxuIik7CiAgICAgICAgICAgICAgICByZXR1cm4gKDEpOwogICAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICB4bWxDYXRhbG9nQ2xlYW51cCgpOwogICAgICAgIGZvciAoaSA9IDA7IGkgPCBudW1fdGhyZWFkczsgaSsrKQogICAgICAgICAgICBpZiAocmVzdWx0c1tpXSAhPSAodm9pZCAqKSBPa2F5KSB7CiAgICAgICAgICAgICAgICBmcHJpbnRmKHN0ZGVyciwgIlRocmVhZCAlZCBoYW5kbGluZyAlcyBmYWlsZWRcbiIsCiAgICAgICAgICAgICAgICAgICAgICAgIGksIHRlc3RmaWxlc1tpXSk7CiAgICAgICAgICAgICAgICByZXMgPSAxOwogICAgICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gKHJlcyk7Cn0KCiNlbGlmIGRlZmluZWQgV0lOMzIKI2luY2x1ZGUgPHdpbmRvd3MuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKI2RlZmluZSBURVNUX1JFUEVBVF9DT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gICAgICAgICAgICAgICAgICAgICAgJnVzZWxlc3MpOwogICAgICAgICAgICBpZiAodGlkW2ldID09IE5VTEwpIHsKICAgICAgICAgICAgICAgIGZwcmludGYoc3RkZXJyLCAiQ3JlYXRlVGhyZWFkIGZhaWxlZFxuIik7CiAgICAgICAgICAgICAgICByZXR1cm4oMSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIGlmIChXYWl0Rm9yTXVsdGlwbGVPYmplY3RzKG51bV90aHJlYWRzLCB0aWQsIFRSVUUsIElORklOSVRFKSA9PQogICAgICAgICAgICBXQUlUX0ZBSUxFRCkgewogICAgICAgICAgICBmcHJpbnRmKHN0ZGVyciwgIldhaXRGb3JNdWx0aXBsZU9iamVjdHMgZmFpbGVkXG4iKTsKCSAgICByZXR1cm4oMSk7Cgl9CgogICAgICAgIGZvciAoaSA9IDA7IGkgPCBudW1fdGhyZWFkczsgaSsrKSB7CiAgICAgICAgICAgIHJldCA9IEdldEV4aXRDb2RlVGhyZWFkKHRpZFtpXSwgJnJlc3VsdHNbaV0pOwogICAgICAgICAgICBpZiAocmV0ID09IDApIHsKICAgICAgICAgICAgICAgIGZwcmludGYoc3RkZXJyLCAiR2V0RXhpdENvZGVUaHJlYWQgZmFpbGVkXG4iKTsKICAgICAgICAgICAgICAgIHJldHVybigxKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBDbG9zZUhhbmRsZSh0aWRbaV0pOwogICAgICAgIH0KCiAgICAgICAgeG1sQ2F0YWxvZ0NsZWFudXAoKTsKICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbnVtX3RocmVhZHM7IGkrKykgewogICAgICAgICAgICBpZiAocmVzdWx0c1tpXSAhPSAoRFdPUkQpIE9rYXkpIHsKICAgICAgICAgICAgICAgIGZwcmludGYoc3RkZXJyLCAiVGhyZWFkICVkIGhhbmRsaW5nICVzIGZhaWxlZFxuIiwKCQkgICAgICAgIGksIHRlc3RmaWxlc1tpXSk7CgkgICAgICAgIHJlcyA9IDE7CgkgICAgfQogICAgICAgIH0KICAgIH0KCiAgICByZXR1cm4gKHJlcyk7Cn0KCiNlbGlmIGRlZmluZWQgX19CRU9TX18KI2luY2x1ZGUgPE9TLmg+CgpzdGF0aWMgdGhyZWFkX2lkIHRpZFtNQVhfQVJHQ107CgpzdGF0aWMgaW50CnRlc3RUaHJlYWQodm9pZCkKewogICAgdW5zaWduZWQgaW50IGksIHJlcGVhdDsKICAgIHVuc2lnbmVkIGludCBudW1fdGhyZWFkcyA9IHNpemVvZih0ZXN0ZmlsZXMpIC8gc2l6ZW9mKHRlc3RmaWxlc1swXSk7CiAgICB2b2lkICpyZXN1bHRzW01BWF9BUkdDXTsKICAgIHN0YXR1c190IHJldDsKICAgIGludCByZXMgPSAwOwoKICAgIHhtbEluaXRQYXJzZXIoKTsKICAgIGZvciAocmVwZWF0ID0gMDsgcmVwZWF0IDwgNTAwOyByZXBlYXQrKykgewogICAgICAgIHhtbExvYWRDYXRhbG9nKGNhdGFsb2cpOwogICAgICAgIGZvciAoaSA9IDA7IGkgPCBudW1fdGhyZWFkczsgaSsrKSB7CiAgICAgICAgICAgIHJlc3VsdHNbaV0gPSBOVUxMOwogICAgICAgICAgICB0aWRbaV0gPSAodGhyZWFkX2lkKSAtIDE7CiAgICAgICAgfQogICAgICAgIGZvciAoaSA9IDA7IGkgPCBudW1fdGhyZWFkczsgaSsrKSB7CiAgICAgICAgICAgIHRpZFtpXSA9CiAgICAgICAgICAgICAgICBzcGF3bl90aHJlYWQodGhyZWFkX3NwZWNpZmljX2RhdGEsICJ4bWxUZXN0VGhyZWFkIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICBCX05PUk1BTF9QUklPUklUWSwgKHZvaWQgKikgdGVzdGZpbGVzW2ldKTsKICAgICAgICAgICAgaWYgKHRpZFtpXSA8IEJfT0spIHsKICAgICAgICAgICAgICAgIGZwcmludGYoc3RkZXJyLCAiYmVvc190aHJlYWRfY3JlYXRlIGZhaWxlZFxuIik7CiAgICAgICAgICAgICAgICByZXR1cm4gKDEpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHByaW50ZigiYmVvc190aHJlYWRfY3JlYXRlICVkIC0+ICVkXG4iLCBpLCB0aWRbaV0pOwogICAgICAgIH0KICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbnVtX3RocmVhZHM7IGkrKykgewogICAgICAgICAgICByZXQgPSB3YWl0X2Zvcl90aHJlYWQodGlkW2ldLCAmcmVzdWx0c1tpXSk7CiAgICAgICAgICAgIHByaW50ZigiYmVvc190aHJlYWRfd2FpdCAlZCAtPiAlZFxuIiwgaSwgcmV0KTsKICAgICAgICAgICAgaWYgKHJldCAhPSBCX09LKSB7CiAgICAgICAgICAgICAgICBmcHJpbnRmKHN0ZGVyciwgImJlb3NfdGhyZWFkX3dhaXQgZmFpbGVkXG4iKTsKICAgICAgICAgICAgICAgIHJldHVybiAoMSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIHhtbENhdGFsb2dDbGVhbnVwKCk7CiAgICAgICAgcmV0ID0gQl9PSzsKICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbnVtX3RocmVhZHM7IGkrKykKICAgICAgICAgICAgaWYgKHJlc3VsdHNbaV0gIT0gKHZvaWQgKikgT2theSkgewogICAgICAgICAgICAgICAgcHJpbnRmKCJUaHJlYWQgJWQgaGFuZGxpbmcgJXMgZmFpbGVkXG4iLCBpLCB0ZXN0ZmlsZXNbaV0pOwogICAgICAgICAgICAgICAgcmV0ID0gQl9FUlJPUjsKICAgICAgICAgICAgfQogICAgfQogICAgaWYgKHJldCAhPSBCX09LKQogICAgICAgIHJldHVybigxKTsKICAgIHJldHVybiAoMCk7Cn0KI2Vsc2UKc3RhdGljIGludAp0ZXN0VGhyZWFkKHZvaWQpCnsKICAgIGZwcmludGYoc3RkZXJyLAogICAgICAgICAgICAiU3BlY2lmaWMgcGxhdGZvcm0gdGhyZWFkIHN1cHBvcnQgbm90IGRldGVjdGVkXG4iKTsKICAgIHJ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