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BVF9NT0RFX1NPQ0tfMSA9IDAsCisgICAgQVRfTU9ERV9TT0NLXzIsCisgICAgQVRfTU9ERV9ERVZfMSwKKyAgICBBVF9NT0RFX0RFVl8yCit9IGF0X21vZGVfZW51bTsKKworc3RhdGljIGludCBlcG9sbF9mZCA9IC0xOworc3RhdGljIHN0cnVjdCBlcG9sbF9ldmVudCBlcG9sbF9ldmVudHNbMjBdOworc3RhdGljIGludCBhdF9mZCA9IC0xOworc3RhdGljIGF0X21vZGVfZW51bSBhdF9tb2RlID0gQVRfTU9ERV9TT0NLXzE7CisKK3N0YXRpYyBjaGFyICphdF9yc3BfY29tcGxldGVfdGFnW10gPSB7CisgICAgICAgICJPSyIsCisgICAgICAgICJFUlJPUiIsCisgICAgICAgICJDT05ORUNUIiwKKwkJIitDTVMgRVJST1I6IiwKKwkJIitDTUUgRVJST1I6IiwKKwkJIk5PIEFOU1dFUiIsCisJCSJOTyBESUFMVE9ORSIsCisJCU5VTEx9OworCisvLyNpZmRlZiBBVF9UWVBFX1NPQ0tFVAorI2RlZmluZSBURU1QX0ZBSUxVUkVfUkVUUlkoZXhwKSAoeyAgICAgICAgIFwKKyAgICB0eXBlb2YgKGV4cCkgX3JjOyAgICAgICAgICAgICAgICAgICAgICBcCisgICAgZG8geyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAorICAgICAgICBfcmMgPSAoZXhwKTsgICAgICAgICAgICAgICAgICAgICAgIFwKKyAgICB9IHdoaWxlIChfcmMgPT0gLTEgJiYgZXJybm8gPT0gRUlOVFIpOyBcCisgICAgX3JjOyB9KQorLy8jZW5kaWYKKworc3RhdGljIHZvaWQgYXRfZXBvbGxfY2hhbmdlKGludCBpc19hZGQsaW50IGZkKQoreworICAgIHN0cnVjdCBlcG9sbF9ldmVudCBldjsKKyAgICBtZW1zZXQoJmV2LDB4MCxzaXplb2Yoc3RydWN0IGVwb2xsX2V2ZW50KSk7CisgICAgZXYuZGF0YS5mZCA9IGZkOworICAgIGV2LmV2ZW50cyA9IEVQT0xMSU4gfCBFUE9MTEVUOworICAgIGlmKGlzX2FkZCkKKyAgICB7CisgICAgICAgIGVwb2xsX2N0bChlcG9sbF9mZCxFUE9MTF9DVExfQURELGZkLCZldik7CisgICAgfQorICAgIGVsc2UKKyAgICB7CisgICAgICAgIGVwb2xsX2N0bChlcG9sbF9mZCxFUE9MTF9DVExfREVMLGZkLCZldik7CisgICAgfQorfQorCitzdGF0aWMgaW50IGF0X3NldF9mZF9ub2Jsb2NrKGludCBmZCkKK3sKKyAgICAvLyBTZXQgT19OT05CTE9DSworICAgIGludCBmbGFncyA9IGZjbnRsKGZkLCBGX0dFVEZMLCAwKTsKKyAgICBpZiAoZmxhZ3MgPCAwKSB7CisgICAgICAgIExPR0UoIkdldCBmbGFncyBlcnJvcjolc1xuIiwgc3RyZXJyb3IoZXJybm8pKTsKKyAgICAgICAgcmV0dXJuIC0xOworICAgIH0KKyAgICBmbGFncyB8PSBPX05PTkJMT0NLOworICAgIGlmIChmY250bChmZCwgRl9TRVRGTCwgZmxhZ3MpIDwgMCkgeworICAgICAgICBMT0dFKCJTZXQgZmxhZ3MgZXJyb3I6JXNcbiIsIHN0cmVycm9yKGVycm5vKSk7CisgICAgICAgIHJldHVybiAtMTsKKyAgICB9CisKKyAgICByZXR1cm4gMDsKK30KKworLy8jaWZkZWYgQVRfVFlQRV9TT0NLRVQKK2ludCBvcGVuU29ja2V0KGNvbnN0IGNoYXIqIHNvY2tuYW1lKQoreworCWludCBzb2NrID0gc29ja2V0KEFGX1VOSVgsIFNPQ0tfU1RSRUFNLCAwKTsKKwlpZiAoc29jayA8IDApIHsKKwkJTE9HRSgiRXJyb3IgY3JlYXRlIHNvY2tldDogJXNcbiIsIHN0cmVycm9yKGVycm5vKSk7CisJCXJldHVybiAtMTsKKwl9CisJc3RydWN0IHNvY2thZGRyX3VuIGFkZHI7CisJbWVtc2V0KCZhZGRyLCAwLCBzaXplb2YoYWRkcikpOworCWFkZHIuc3VuX2ZhbW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ld3RpbywgQjExNTIwMCk7CisJCQljZnNldGlzcGVlZCgmbmV3dGlvLCBCMTE1MjAwKTsKKwkJCWJyZWFrOworCX0KKworCWlmICh0Y3NldGF0dHIoZmQsIFRDU0FOT1csICZuZXd0aW8pIDwgMCkgeworCQlwcmludGYoIkNhbid0IHNldCBwb3J0IHNldHRpbmdcbiIpOworCQlyZXR1cm4gLTE7CisJfQorCS8qIEJsb2NraW5nIGJlaGF2aW9yICovCisJZmNudGwoZmQsIEZfU0VURkwsIDApOworI2VuZGlmCisKKyAgICByZXR1cm4gZmQ7Cit9CisKKworc3RhdGljIHZvaWQgc2lnbmFsX3Byb2Nlc3MoaW50IHNpZ25hbF9udW0pIHsKKyAgICBpZihhdF9mZCA+IDApIHsKKyAgICAgICAgY2xvc2UoYXRfZmQpOworICAgIH0KKyNpZmRlZiBNQlRLX0xPRworICAgIExPR0QoIkV4aXQgYnkgc2lnIC0gJWRcbiIsIHNpZ25hbF9udW0pOworI2VuZGlmCisgICAgZXhpdCgwKTsKK30KKworc3RhdGljIHZvaWQqIHJlYWRfdGhyZWFkX3J1biggdm9pZCAqYXJnKQoreworICAgIC8vVU5VU0VEKGFyZyk7CisKKyAgICBjaGFyIGF0X3JzcFsxMDI0XTsKKyAgICBjaGFyICpwdHI7CisgICAgaW50IGluZGV4OworICAgIGludCBsZW47CisgICAgd2hpbGUoYXRfZmQgPiAwKSB7CisgICAgICAgIG1lbXNldChhdF9yc3AsIDB4MCwgMTAyNCk7CisgICAgICAgIGluZGV4ID0gMDsKKyAgICAgICAgbGVuID0gMDsKKyAgICAgICAgd2hpbGUoMSkgeworICAgICAgICAgICAgaWYoKGxlbiA9IHJlYWQoYXRfZmQsIGF0X3JzcCArIGluZGV4LCAxMDI0KSkgPiAwKSB7CisgICAgICAgICAgICAgICAgcHRyID0gYXRfcnNwOworICAgICAgICAgICAgICAgIHdoaWxlKCpwdHIgPT0gJ1xyJyB8fCAqcHRyID09ICdcbicpCisgICAgICAgICAgICAgICAgeworICAgICAgICAgICAgICAgICAgICBwdHIrKzsKKyAgICAgICAgICAgICAgICB9CisgICAgICAgICAgICAgICAgaWYoc3RybGVuKHB0cikgPiAwICYmIHB0cltzdHJsZW4ocHRyKSAtIDFdID09ICdcbicpIHsKKyAgICAgICAgICAgICAgICAgICAgcHJpbnRmKCI8JXNcbiIsIHB0cik7CisjaWZkZWYgTUJUS19MT0cKKyAgICAgICAgICAgICAgICAgICAgTE9HVigiUlNQOiVzIiwgcHRyKTsKKyNlbmRpZgorCisgICAgICAgICAgICAgICAgICAgIGJyZWFrOworICAgICAgICAgICAgICAgIH0gZWxzZSB7CisgICAgICAgICAgICAgICAgICAgIGluZGV4ICs9IGxlbjsKKyAgICAgICAgICAgICAgICB9CisgICAgICAgICAgICB9IGVsc2UgeworICAgICAgICAgICAgICAgIExPR0UoIlJlYWQgZXJyb3I6JWQiLGVycm5vKTsKKyAgICAgICAgICAgICAgICByZXR1cm4gTlVMTDsKKyAgICAgICAgICAgIH0KKyAgICAgICAgfQorICAgIH0KKworICAgIExPR0QoInJlYWRfdGhyZWFkX3J1bigpIGV4aXQuXG4iKTsKKyAgICByZXR1cm4gTlVMTDsKK30KKworc3RhdGljIGludCByZWFkX3RocmVhZF9zdGFydCgpCit7CisgICAgcHRocmVhZF90IHRpZDsKKyAgICBwdGhyZWFkX2F0dHJfdCBhdHRyOworICAgIHB0aHJlYWRfYXR0cl9pbml0ICgmYXR0cik7CisgICAgcHRocmVhZF9hdHRyX3NldGRldGFjaHN0YXRlKCZhdHRyLCBQVEhSRUFEX0NSRUFURV9ERVRBQ0hFRCk7CisgICAgaW50IHJldCA9IHB0aHJlYWRfY3JlYXRlKCZ0aWQsICZhdHRyLCByZWFkX3RocmVhZF9ydW4sICZhdHRyKTsKKyAgICBpZiAocmV0IDwgMCkKKyAgICB7CisgICAgICAgIExPR0UoInB0aHJlYWRfY3JlYXRlXG4iKTsKKyAgICAgICAgcmV0dXJuIC0xOworICAgIH0KKworICAgIHJldHVybiAwOworfQorCitzdGF0aWMgaW50IGF0X2NvbXBsZXRlKGNoYXIgKnJzcCkKK3sKKyNpZiAwCisgICAgY2hhciAqcHRyID0gYXRfcnNwX2NvbXBsZXRlX3RhZzsKKyAgICB3aGlsZShwdHIpIHsKKyAgICAgICAgTE9HRCgicHRyID0gJXMiLCBwdHIpOworICAgICAgICBpZihzdHJzdHIocnNwLCBwdHIpKSB7CisgICAgICAgICAgICBMT0dEKCIlcyAsICVzIiwgcnNwLCBwdHIpOworICAgICAgICAgICAgcmV0dXJuIDE7CisgICAgICAgIH0KKyAgICAgICAgcHRyKys7CisgICAgfQorI2Vsc2UKKyAgICBpbnQgaSA9IDA7CisgICAgd2hpbGUoYXRfcnNwX2NvbXBsZXRlX3RhZ1tpXSkgeworICAgICAgICBMT0dEKCJwdHIgPSAlcyIsIGF0X3JzcF9jb21wbGV0ZV90YWdbaV0pOworICAgICAgICBpZihzdHJzdHIocnNwLCBhdF9yc3BfY29tcGxldGVfdGFnW2ldKSkgeworICAgICAgICAgICAgTE9HRCgiJXMgLCAlcyIsIHJzcCwgYXRfcnNwX2NvbXBsZXRlX3RhZ1tpXSk7CisgICAgICAgICAgICByZXR1cm4gMTsKKyAgICAgICAgfQorICAgICAgICBpKys7CisgICAgfQorCisjZW5kaWYKKyAgICByZXR1cm4gMDsKK30KKworc3RhdGljIHZvaWQgYXRfcnNwX3JlYWQoKQoreworICAgIGNoYXIgYXRfcnNwWzEwMjRdOworICAgIGludCBsZW4gPSAwOworICAgIHdoaWxlKDEpIHsKKyAgICAgICAgbWVtc2V0KGF0X3JzcCwgMHgwLCAxMDI0KTsKKyAgICAgICAgaWYoKGxlbiA9IHJlYWQoYXRfZmQsIGF0X3JzcCwgMTAyNCkpID4gMCkgeworICAgICAgICAgICAgcHJpbnRmKCIlcyIsIGF0X3JzcCk7CisgICAgICAgICAgICBpZihhdF9jb21wbGV0ZShhdF9yc3ApKSB7CisgICAgICAgICAgICAgICAgYnJlYWs7CisgICAgICAgICAgICB9CisgICAgICAgIH0gZWxzZSB7CisgICAgICAgICAgICBwcmludGYoIlJlYWQgZXJyb3I6JWRcbiIsZXJybm8pOworICAgICAgICAgICAgYnJlYWs7CisgICAgICAgIH0KKyAgICB9Cit9CisKK3N0YXRpYyB2b2lkIGhlbHAoKQoreworICAgIHByaW50ZigiYXQgOiBFbnRlciBBVCBtb2RlKFNvY2tldCkuXG4iKTsKKyAgICBwcmludGYoImF0IDxhdF9jbWQ+OiBTZW5kIEFUIGNvbW1hbmQoU29ja2V0KS5cbiIpOworICAgIHByaW50ZigiYXQgPGRldj46IEVudGVyIEFUIG1vZGUoRGV2aWNlKS5cbiIpOworICAgIHByaW50ZigiYXQgPGRldj4gZWNobzogtK6/2sr9vt272M/UoaNcbiIpOworICAgIHByaW50ZigiYXQgPGRldj4gPGF0X2NtZD46IFNlbmQgQVQgY29tbWFuZChEZXZpY2UpLlxuIik7Cit9CisKK3N0YXRpYyB2b2lkIHNpZ19wcm9jZXNzKGludCBzaWcpCit7CisgICAgTE9HSSgiSSBnb3Qgc2lnbmFsICVkXG4iLCBzaWcpOworICAgIHN3aXRjaChzaWcpCisgICAgeworICAgICAgICBjYXNlIFNJR0lOVDogLy8gQ3RybCArIEMKKyAgICAgICAgeworICAgICAgICAgICAgTE9HSSgiRXhpdCBieSBTSUdJTlQuXG4iKTsKKyAgICAgICAgICAgIGV4aXQoMCk7CisgICAgICAgIH0KKyAgICAgICAgY2FzZSBTSUdRVUlUOiAvLyBDdHJsICsgXCAowODLxiBTSUdJTlQgo6y1q9KqsvrJ+mNvcmXOxLz+KQorICAgICAgICB7CisgICAgICAgICAgICBMT0dJKCJFeGl0IGJ5IFNJR1FVSVQuXG4iKTsKKyAgICAgICAgICAgIGV4aXQoMCk7CisgICAgICAgIH0KKyAgICAgICAgY2FzZSBTSUdURVJNOi8vIMSsyM9raWxsICAgKM2sIFNJR0tJTEwgo6y1qyBTSUdLSUxMILK7v8mytrvxKQorICAgICAgICB7CisgICAgICAgICAgICBMT0dJKCJFeGl0IGJ5IFNJR1RFUk0uXG4iKTsKKyAgICAgICAgICAgIGV4aXQoMCk7CisgICAgICAgIH0KKyAgICAgICAgY2FzZSBTSUdUU1RQOi8vIEN0cmwgKyBaICjNrCBTSUdTVE9QIKOstasgU0lHU1RPUCCyu7/Jsra78SkKKyAgICAgICAgeworICAgICAgICAgICAgTE9HSSgiRXhpdCBieSBTSUdUU1RQLlxuIik7CisgICAgICAgICAgICBleGl0KDApOworICAgICAgICB9CisgICAgICAgIGNhc2UgU0lHU0VHVjogLy8gyOe/1da41esKKyAgICAgICAgeworICAgICAgICAgICAgTE9HSSgiRXhpdCBieSBTSUdTRUdWLlxuIik7CisgICAgICAgICAgICBleGl0KDApOworICAgICAgICB9CisgICAgICAgIGRlZmF1bHQ6CisgICAgICAgIHsKKyAgICAgICAgICAgIExPR0koIlVua25vd24gc2lnOiVkXG4iLHNpZyk7CisgICAgICAgICAgICBicmVhazsKKyAgICAgICAgfQorICAgIH0KK30KKworaW50IG1haW4oaW50IGFyZ2MsIGNoYXIgKmFyZ3ZbXSkKK3sKKyAgICAvL1VOVVNFRChhcmdjKTsKKyAgICAvL1VOVVNFRChhcmd2KTsKKyAgICBzaWduYWwoU0lHSU5ULCBzaWdfcHJvY2Vzcyk7CisgICAgc2lnbmFsKFNJR1FVSVQsIHNpZ19wcm9jZXNzKTsKKyAgICBzaWduYWwoU0lHVEVSTSwgc2lnX3Byb2Nlc3MpOworICAgIC8vc2lnbmFsKFNJR1RTVFAsIHNpZ19wcm9jZXNzKTsKKyAgICAvL3NpZ25hbChTSUdTRUdWLCBzaWdfcHJvY2Vzcyk7CisKKyNpZmRlZiBNQlRLX0xPRworICAgIG1idGtfbG9nX2luaXQoInJhZGlvIiwgIk1CVEtfQVQiKTsKKyAgICBMT0dJKCJtYnRrX2F0IHN0YXJ0LiIpOworI2VuZGlmCisKKyAgICBzaWduYWwoU0lHS0lMTCwgc2lnbmFsX3Byb2Nlc3MpOworICAgIHNpZ25hbChTSUdJTlQsIHNpZ25hbF9wcm9jZXNzKTsKKyAgICBzaWduYWwoU0lHUVVJVCwgc2lnbmFsX3Byb2Nlc3MpOworICAgIHNpZ25hbChTSUdURVJNLCBzaWduYWxfcHJvY2Vzcyk7CisKKyAgICBjaGFyICphdF9jbWQgPSBOVUxMOworICAgIGJvb2wgZWNobyA9IEZBTFNFOworICAgIGlmKGFyZ2MgPT0gMSkgeworICAgICAgICBhdF9tb2RlID0gQVRfTU9ERV9TT0NLXzE7CisgICAgfSBlbHNlIGlmKGFyZ2MgPT0gMikgeworICAgICAgICBpZighc3RybmNhc2VjbXAoYXJndlsxXSwgImF0IiwgMikpIHsKKyAgICAgICAgICAgIGF0X21vZGUgPSBBVF9NT0RFX1NPQ0tfMjsKKyAgICAgICAgICAgIGF0X2NtZCA9IGFyZ3ZbMV07CisgICAgICAgIH0gZWxzZSBpZighc3RybmNhc2VjbXAoYXJndlsxXSwgIi9kZXYvIiwgNSkpIHsKKyAgICAgICAgICAgIGF0X21vZGUgPSBBVF9NT0RFX0RFVl8xOworICAgICAgICB9IGVsc2UgeworICAgICAgICAgICAgaGVscCgpOworICAgICAgICAgICAgcmV0dXJuIC0xOworICAgICAgICB9CisgICAgfSBlbHNlIGlmKGFyZ2MgPT0gMykgeworICAgICAgICBpZighc3RybmNhc2VjbXAoYXJndlsxXSwgIi9kZXYvIiwgNSkgJiYgKCFzdHJuY2FzZWNtcChhcmd2WzJdLCAiYXQiLCAyKSB8fCAhc3RybmNhc2VjbXAoYXJndlsyXSwgImVjaG8iLCA0KSkpIHsKKyAgICAgICAgICAgIGF0X21vZGUgPSBBVF9NT0RFX0RFVl8yOworICAgICAgICAgICAgaWYoIXN0cm5jYXNlY21wKGFyZ3ZbMl0sICJhdCIsIDIpKSB7CisgICAgICAgICAgICAgICAgYXRfY21kID0gYXJndlsyXTsKKyAgICAgICAgICAgIH0gZWxzZSB7CisgICAgICAgICAgICAgICAgZWNobyA9IFRSVUU7CisgICAgICAgICAgICB9CisgICAgICAgIH0gZWxzZSB7CisgICAgICAgICAgICBoZWxwKCk7CisgICAgICAgICAgICByZXR1cm4gLTE7CisgICAgICAgIH0KKyAgICB9IGVsc2UgeworICAgICAgICBoZWxwKCk7CisgICAgICAgIHJldHVybiAtMTsKKyAgICB9CisjaWYgMAorI2lmZGVmIEFUX1RZUEVfU09DS0VUCisgICAgYXRfZmQgPSBvcGVuU29ja2V0KCIvdG1wL2F0Y21kbWJ0ayIpOworI2Vsc2UKKwlhdF9mZCA9IGF0X29wZW4oYXJndlsxXSk7CisjZW5kaWYKKyAgICBpZihhdF9mZCA+IDApIHsKKyNpZmRlZiBBVF9UWVBFX1NPQ0tFVAorICAgICAgICBpZihhcmdjID4gMSkgeworICAgICAgICAgICAgY2hhciAqYXRfY21kID0gYXJndlsxXTsKKyNlbHNlCisJICAgIGlmKGFyZ2MgPiAyKSB7CisgICAgICAgICAgICBjaGFyICphdF9jbWQgPSBhcmd2WzJdOworI2VuZGlmCisjZW5kaWYKKworICAgIGlmKGF0X21vZGUgPT0gQVRfTU9ERV9TT0NLXzEgfHwgYXRfbW9kZSA9PSBBVF9NT0RFX1NPQ0tfMikgeworICAgICAgICBhdF9mZCA9IG9wZW5Tb2NrZXQoIi90bXAvYXRjbWRtYnRrIik7CisgICAgfSBlbHNlIHsKKyNpZiAwCisgICAgICAgIGF0X2ZkID0gYXRfb3Blbihhcmd2WzFdKTsKKyNlbHNlCisgICAgICAgIGlmKGVjaG8pIHsKKyAgICAgICAgICAgIGF0X2ZkID0gYWRiX3BvcnRfb3Blbihhcmd2WzFdLCAxMTUyMDApOworICAgICAgICB9IGVsc2UgeworICAgICAgICAgICAgYXRfZmQgPSBhdF9vcGVuKGFyZ3ZbMV0pOworICAgICAgICB9CisjZW5kaWYKKyAgICB9CisgICAgaWYoYXRfZmQgPiAwKSB7CisgICAgICAgIGlmKGF0X2NtZCAhPSBOVUxMKSB7CisgICAgICAgICAgICBjaGFyICpwdHIgPSBhdF9jbWQgKyBzdHJsZW4oYXRfY21kKSAtIDE7CisgICAgICAgICAgICB3aGlsZShwdHIgPj0gYXRfY21kICYmICgqcHRyID09ICdccicgfHwgKnB0ciA9PSAnXG4nKSkKKyAgICAgICAgICAgIHsKKyAgICAgICAgICAgICAgICAqcHRyLS0gPSAnXDAnOworICAgICAgICAgICAgfQorICAgICAgICAgICAgLy8gcHJpbnRmKCJBVDpbJWxkXSVzXG4iLCBzdHJsZW4oYXRfY21kKSwgYXRfY21kKTsKKyAgICAgICAgICAgIGlmKCFzdHJuY2FzZWNtcChhdF9jbWQsICJhdCIsIDIpKQorICAgICAgICAgICAgeworICAgICAgICAgICAgICAgICooKytwdHIpID0gJ1xyJzsKKyAgICAgICAgICAgICAgICAqKCsrcHRyKSA9ICdcbic7CisgICAgICAgICAgICAgICAgaWYod3JpdGUoYXRfZmQsIGF0X2NtZCwgc3RybGVuKGF0X2NtZCkpIDw9IDApIHsKKyAgICAgICAgICAgICAgICAgICAgcHJpbnRmKCJXcml0ZSBlcnJvcjolZFxuIiwgZXJybm8pOworICAgICAgICAgICAgICAgIH0gZWxzZSB7CisgICAgICAgICAgICAgICAgICAgIC8vIFJlYWQgcmVzcG9uc2UuCisgICAgICAgICAgICAgICAgICAgIGF0X3JzcF9yZWFkKCk7CisgICAgICAgICAgICAgICAgfQorICAgICAgICAgICAgfSBlbHNlIHsKKyAgICAgICAgICAgICAgICBwcmludGYoIkFUIGVycm9yIVxuIik7CisgICAgICAgICAgICB9CisgICAgICAgIH0gZWxzZSB7CisgICAgICAgICAgICBpZihlY2hvKSB7CisgICAgICAgICAgICAgICAgY2hhciByZWFkX2J1ZmZbMTAyNF07CisgICAgICAgICAgICAgICAgY2hhciB3cml0ZV9idWZmWzEwMjRdOworICAgICAgICAgICAgICAgIGludCBsZW47CisjaWYgMAorICAgICAgICAgICAgICAgIGZkX3NldCBmZHM7CisgICAgICAgICAgICAgICAgaW50IGZkY291bnQsIG5mZHMgPSAwOworICAgICAgICAgICAgICAgIHdoaWxlKDEpIHsKKyAgICAgICAgICAgICAgICAgICAgRkRfU0VUKGF0X2ZkLCAmZmRzKTsKKyAgICAgICAgCQkgICAgaWYoYXRfZmQgPiBuZmRzKQorICAgICAgICAJCQkgICAgbmZkcyA9IGF0X2ZkOworCisgICAgICAgICAgICAgICAgICAgIGZkY291bnQgPSBzZWxlY3QobmZkcyArIDEsICZmZHMsIE5VTEwsIE5VTEwsIE5VTEwpOworICAgICAgICAJCQlpZihmZGNvdW50IDwgMCkgLyogZXJyb3IgKi8KKyAgICAgICAgCQkJeworICAgICAgICAJCQkJcHJpbnRmKCJzZWxlY3QgcmV0dXJuZWQgJWQsIGVycm5vICVkLCBjb250aW51ZVxyIiwgZmRjb3VudCwgZXJybm8pOworICAgICAgICAJCQkJc2xlZXAoMSk7CisgICAgICAgIAkJCQljb250aW51ZTsKKyAgICAgICAgCQkJfQorCisgICAgICAgIAkJCWlmKEZEX0lTU0VUKGF0X2ZkLCAmZmRzKSkKKyAgICAgICAgCQkJeworICAgICAgICAgICAgICAgICAgICAgICAgRkRfQ0xSKGF0X2ZkLCAmZmRzKTsKKyAgICAgICAgICAgICAgICAgICAgICAgIG1lbXNldChyZWFkX2J1ZmYsIDB4MCwgMTAyNCk7CisgICAgICAgICAgICAgICAgICAgICAgICBpZigobGVuID0gcmVhZChhdF9mZCwgcmVhZF9idWZmLCAxMDI0KSkgPiAwKSB7CisgICAgICAgICAgICAgICAgICAgICAgICAgICAgbWVtc2V0KHdyaXRlX2J1ZmYsIDB4MCwgMTAyNCk7CisgICAgICAgICAgICAgICAgICAgICAgICAgICAgcHJpbnRmKCIlc1xuIiwgcmVhZF9idWZmKTsKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gPSBzbnByaW50Zih3cml0ZV9idWZmLCAxMDI0LCAiJXNcbiIsIHJlYWRfYnVmZik7CisgICAgICAgICAgICAgICAgICAgICAgICAgICAgd3JpdGUoYXRfZmQsIHdyaXRlX2J1ZmYsIGxlbik7CisgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgeworICAgICAgICAgICAgICAgICAgICAgICAgICAgIHByaW50ZigiUmVhZCBlcnJvcjolZFxuIixlcnJubyk7CisgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIE5VTEw7CisgICAgICAgICAgICAgICAgICAgICAgICB9CisgICAgICAgICAgICAgICAgICAgIH0KKyAgICAgICAgICAgICAgICB9CisjZWxzZQorICAgICAgICAgICAgICAgIHByaW50ZigiV2FpdHRpbmcgZGF0YSEhIVxuIik7CisgICAgICAgICAgICAgICAgd2hpbGUoMSkgeworICAgICAgICAgICAgICAgICAgICBtZW1zZXQocmVhZF9idWZmLCAweDAsIDEwMjQpOworICAgICAgICAgICAgICAgICAgICBpZigobGVuID0gcmVhZChhdF9mZCwgcmVhZF9idWZmLCAxMDI0KSkgPiAwKSB7CisgICAgICAgICAgICAgICAgICAgICAgICBtZW1zZXQod3JpdGVfYnVmZiwgMHgwLCAxMDI0KTsKKyAgICAgICAgICAgICAgICAgICAgICAgIHByaW50ZigiJXNcbiIsIHJlYWRfYnVmZik7CisgICAgICAgICAgICAgICAgICAgICAgICBsZW4gPSBzbnByaW50Zih3cml0ZV9idWZmLCAxMDI0LCAiJXNcbiIsIHJlYWRfYnVmZik7CisgICAgICAgICAgICAgICAgICAgICAgICB3cml0ZShhdF9mZCwgd3JpdGVfYnVmZiwgbGVuKTsKKyAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKKyAgICAgICAgICAgICAgICAgICAgICAgIHByaW50ZigiUmVhZCBlcnJvcjolZFxuIixlcnJubyk7CisgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gTlVMTDsKKyAgICAgICAgICAgICAgICAgICAgfQorICAgICAgICAgICAgICAgIH0KKyNlbmRpZgorICAgICAgICAgICAgfSBlbHNlIHsKKyAgICAgICAgICAgICAgICBzZXRidWYoc3Rkb3V0LCBOVUxMKTsKKyAgICAgICAgICAgICAgICByZWFkX3RocmVhZF9zdGFydCgpOworICAgICAgICAgICAgICAgIGNoYXIgYXRfY21kWzEwMF07CisgICAgICAgICAgICAgICAgLy9wcmludGYoIj4+Iik7CisgICAgICAgICAgICAgICAgd2hpbGUoMSkKKyAgICAgICAgICAgICAgICB7CisgICAgICAgICAgICAgICAgICAgIG1lbXNldChhdF9jbWQsIDB4MCwgMTAwKTsKKyAgICAgICAgICAgICAgICAgICAgaWYoZmdldHMoYXRfY21kLCAxMDAsIHN0ZGluKSkKKyAgICAgICAgICAgICAgICAgICAgeworICAgICAgICAgICAgICAgICAgICAgICAgY2hhciAqcHRyID0gYXRfY21kICsgc3RybGVuKGF0X2NtZCkgLSAxOworICAgICAgICAgICAgICAgICAgICAgICAgd2hpbGUocHRyID49IGF0X2NtZCAmJiAoKnB0ciA9PSAnXHInIHx8ICpwdHIgPT0gJ1xuJykpCisgICAgICAgICAgICAgICAgICAgICAgICB7CisgICAgICAgICAgICAgICAgICAgICAgICAgICAgKnB0ci0tID0gJ1wwJzsKKyAgICAgICAgICAgICAgICAgICAgICAgIH0KKyAgICAgICAgICAgICAgICAgICAgICAgIC8vIHByaW50ZigiQVQ6WyVsZF0lc1xuIiwgc3RybGVuKGF0X2NtZCksIGF0X2NtZCk7CisgICAgICAgICAgICAgICAgICAgICAgICBpZighc3RybmNhc2VjbXAoYXRfY21kLCAiYXQiLCAyKSkKKyAgICAgICAgICAgICAgICAgICAgICAgIHsKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAqKCsrcHRyKSA9ICdccic7CisgICAgICAgICAgICAgICAgICAgICAgICAgICAgKigrK3B0cikgPSAnXG4nOworICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmKHdyaXRlKGF0X2ZkLCBhdF9jbWQsIHN0cmxlbihhdF9jbWQpKSA8PSAwKSB7CisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIExPR0UoIldyaXRlIGVycm9yOiVkIixlcnJubyk7CisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOworICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KKyAgICAgICAgICAgICAgICAgICAgICAgICAgICBwcmludGYoIj4lcyIsYXRfY21kKTsKKyNpZmRlZiBNQlRLX0xPRworICAgICAgICAgICAgICAgICAgICAgICAgICAgIExPR1YoIkFUOiVzIixhdF9jbWQpOworI2VuZGlmCisgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYoIXN0cmNhc2VjbXAoYXRfY21kLCAicSIpKSB7CisgICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CisgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgeworICAgICAgICAgICAgICAgICAgICAgICAgICAgIHByaW50ZigiXG4iKTsKKyAgICAgICAgICAgICAgICAgICAgICAgIH0KKyAgICAgICAgICAgICAgICAgICAgfQorICAgICAgICAgICAgICAgIH0KKyAgICAgICAgICAgIH0KKyAgICAgICAgfQorCisgICAgICAgIGNsb3NlKGF0X2ZkKTsKKworI2lmZGVmIE1CVEtfTE9HCisgICAgICAgIExPR0QoIkVYSVQiKTsKKyNlbmRpZgorICAgIH0KKworICAgIHJldHVybiAwOworfQo=