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ICAgTS4gTG9od2Fzc2VyCiAgIGNvbnRlbnRzL2Rlc2NyaXB0aW9uOiBwbnMuYwoKKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwoKI2luY2x1ZGUgImFhY2VuY19wbnMuaCIKI2luY2x1ZGUgInBzeV9kYXRhLmgiCiNpbmNsdWRlICJwbnNwYXJhbS5oIgojaW5jbHVkZSAibm9pc2VkZXQuaCIKI2luY2x1ZGUgImJpdF9jbnQuaCIKI2luY2x1ZGUgImludGVyZmFjZS5oIgoKCi8qIG1pbkNvcnJlbGF0aW9uRW5lcmd5ID0gKDEuMGUtMTBmKV4yIH4gMl4tNjcgPSAyXi00NyAqIDJeLTIwICovCnN0YXRpYyBjb25zdCBGSVhQX0RCTCBtaW5Db3JyZWxhdGlvbkVuZXJneSA9IEZMMkZYQ09OU1RfREJMKDAuMCk7IC8qIEZMMkZYQ09OU1RfREJMKChmbG9hdClGREtwb3coMi4wLC00NykpOyAqLwovKiBub2lzZUNvcnJlbGF0aW9uVGhyZXNoID0gMC42XjIgKi8Kc3RhdGljIGNvbnN0IEZJWFBfREJMIG5vaXNlQ29ycmVsYXRpb25UaHJlc2ggPSBGTDJGWENPTlNUX0RCTCgwLjM2KTsKCnN0YXRpYyB2b2lkIEZES2FhY0VuY19GREthYWNFbmNfbm9pc2VEZXRlY3Rpb24oIFBOU19DT05GSUcgICpwbnNDb25mLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgUE5TX0RBVEEgICAgKnBuc0RhdGEsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBJTlQgICBzZmJBY3RpdmUsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBJTlQgICAqc2ZiT2Zmc2V0LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgSU5UICAgICAgICAgIHRuc09yZGVyLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgSU5UICAgICAgICAgdG5zUHJlZGljdGlvbkdhaW4sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBJTlQgICAgICAgICB0bnNBY3RpdmUsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBGSVhQX0RCTCAgICAqbWRjdFNwZWN0cnVtLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgSU5UICAgICAgICAgKnNmYk1heFNjYWxlU3BlYywKICAgICAgICAgICAgICAgICAgICAgICAgICAgIEZJWFBfU0dMICAgICpzZmJ0b25hbGl0eSApOwoKc3RhdGljIHZvaWQgRkRLYWFjRW5jX0NhbGNOb2lzZU5yZ3MoIGNvbnN0IElOVCAgIHNmYkFjdGl2ZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgSU5UICAgICAgICAgKnBuc0ZsYWcsCiAgICAgICAgICAgICAgICAgICAgICAgICAgIEZJWFBfREJMICAgICpzZmJFbmVyZ3lMZERhdGEsCiAgICAgICAgICAgICAgICAgICAgICAgICAgIElOVCAgICAgICAgICpub2lzZU5yZyApOwoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCgogICAgZnVuY3Rpb25uYW1lOiBpbml0UG5zQ29uZmlndXJhdGlvbgogICAgZGVzY3JpcHRpb246ICBmaWxsIHBuc0NvbmYgd2l0aCBwbnMgcGFyYW1ldGVycwogICAgcmV0dXJuczogICAgICBlcnJvciBzdGF0dXMKICAgIGlucHV0OiAgICAgICAgUE5TIENvbmZpZyBzdHJ1Y3QgKG1vZGlmaWVkKQogICAgICAgICAgICAgICAgICBiaXRyYXRlLCBzYW1wbGVyYXRlLCB1c2VQbnMsCiAgICAgICAgICAgICAgICAgIG51bWJlciBvZiBzZmIncywgcG9pbnRlciB0byBzZmIgb2Zmc2V0CiAgICBvdXRwdXQ6ICAgICAgIGVycm9yIGNvZGUKCioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwoKQUFDX0VOQ09ERVJfRVJST1IgRkRLYWFjRW5jX0luaXRQbnNDb25maWd1cmF0aW9uKFBOU19DT05GSUcgKnBuc0NvbmYsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBJTlQgICAgICAgICBiaXRSYXRlLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgSU5UICAgICAgICAgc2FtcGxlUmF0ZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIElOVCAgICAgICAgIHVzZVBucywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIElOVCAgICAgICAgIHNmYkNudCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IElOVCAgKnNmYk9mZnNldCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IElOVCAgIG51bUNoYW4sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBJTlQgICBpc0xDKQp7CiAgQUFDX0VOQ09ERVJfRVJST1IgRXJyb3JTdGF0dXM7CgogIC8qIGluaXQgbm9pc2UgZGV0ZWN0aW9uICovCiAgRXJyb3JTdGF0dXMgPSBGREthYWNFbmNfR2V0UG5zUGFyYW0oJnBuc0NvbmYtPm5wLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJpdFJhdGUsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2FtcGxlUmF0ZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzZmJDbnQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2ZiT2Zmc2V0LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICZ1c2VQbnMsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbnVtQ2hhbiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpc0xDKTsKICBpZiAoRXJyb3JTdGF0dXMgIT0gQUFDX0VOQ19PSykKICAgIHJldHVybiBFcnJvclN0YXR1czsKCiAgcG5zQ29uZi0+bWluQ29ycmVsYXRpb25FbmVyZ3kgPSBtaW5Db3JyZWxhdGlvbkVuZXJneTsKICBwbnNDb25mLT5ub2lzZUNvcnJlbGF0aW9uVGhyZXNoID0gbm9pc2VDb3JyZWxhdGlvblRocmVzaDsKCiAgcG5zQ29uZi0+dXNlUG5zID0gdXNlUG5zOwoKICByZXR1cm4gQUFDX0VOQ19PSzsKfQoKCgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKCiAgICBmdW5jdGlvbm5hbWU6IEZES2FhY0VuY19QbnNEZXRlY3QKICAgIGRlc2NyaXB0aW9uOiAgZG8gZGVjaXNpb24sIGlmIFBOUyBzaGFsbCB1c2VkIG9yIG5vdAogICAgcmV0dXJuczoKICAgIGlucHV0OiAgICAgICAgcG5zIGNvbmZpZyBzdHJ1Y3R1cmUKICAgICAgICAgICAgICAgICAgcG5zIGRhdGEgc3RydWN0dXJlIChtb2RpZmllZCksCiAgICAgICAgICAgICAgICAgIGxhc3RXaW5kb3dTZXF1ZW5jZSAobG9uZyBvciBzaG9ydCBibG9ja3MpCiAgICAgICAgICAgICAgICAgIHNmYkFjdGl2ZQogICAgICAgICAgICAgICAgICBwb2ludGVyIHRvIFNmYiBFbmVyZ3ksIFRocmVzaG9sZCwgT2Zmc2V0CiAgICAgICAgICAgICAgICAgIHBvaW50ZXIgdG8gbWRjdCBTcGVjdHJ1bQogICAgICAgICAgICAgICAgICBsZW5ndGggb2YgZWFjaCBncm91cAogICAgICAgICAgICAgICAgICBwb2ludGVyIHRvIHRvbmFsaXR5IGNhbGN1bGF0ZWQgaW4gY2hhb3NtZWFzdXJlCiAgICAgICAgICAgICAgICAgIHRucyBvcmRlciBhbmQgcHJlZGljdGlvbiBnYWluCiAgICAgICAgICAgICAgICAgIGNhbGN1bGF0ZWQgbm9pc2VOcmcgYXQgYWN0aXZlIFBOUwogICAgb3V0cHV0OiAgICAgICBwbnNGbGFnIGluIHBucyBkYXRhIHN0cnVjdHVyZQoKKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCnZvaWQgRkRLYWFjRW5jX1Buc0RldGVjdChQTlNfQ09ORklHICAqcG5zQ29uZiwKICAgICAgICAgICAgICAgICAgICAgICAgIFBOU19EQVRBICAgICpwbnNEYXRhLAogICAgICAgICAgICAgICAgICAgICAgICAgY29uc3QgSU5UICAgIGxhc3RXaW5kb3dTZXF1ZW5jZSwKICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IElOVCAgICBzZmJBY3RpdmUsCiAgICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBJTlQgICAgbWF4U2ZiUGVyR3JvdXAsCiAgICAgICAgICAgICAgICAgICAgICAgICBGSVhQX0RCTCAgICAqc2ZiVGhyZXNob2xkTGREYXRhLAogICAgICAgICAgICAgICAgICAgICAgICAgY29uc3QgSU5UICAgKnNmYk9mZnNldCwKICAgICAgICAgICAgICAgICAgICAgICAgIEZJWFBfREJMICAgICptZGN0U3BlY3RydW0sCiAgICAgICAgICAgICAgICAgICAgICAgICBJTlQgICAgICAgICAqc2ZiTWF4U2NhbGVTcGVjLAogICAgICAgICAgICAgICAgICAgICAgICAgRklYUF9TR0wgICAgKnNmYnRvbmFsaXR5LAogICAgICAgICAgICAgICAgICAgICAgICAgSU5UICAgICAgICAgIHRuc09yZGVyLAogICAgICAgICAgICAgICAgICAgICAgICAgSU5UICAgICAgICAgIHRuc1ByZWRpY3Rpb25HYWluLAogICAgICAgICAgICAgICAgICAgICAgICAgSU5UICAgICAgICAgIHRuc0FjdGl2ZSwKICAgICAgICAgICAgICAgICAgICAgICAgIEZJWFBfREJMICAgICpzZmJFbmVyZ3lMZERhdGEsCiAgICAgICAgICAgICAgICAgICAgICAgICBJTlQgICAgICAgICAqbm9pc2VOcmcgKQoKewogIGludCBzZmI7CiAgaW50IHN0YXJ0Tm9pc2VTZmI7CgogIGlmIChwbnNDb25mLT5ucC5kZXRlY3Rpb25BbGdvcml0aG1GbGFncyAmIElTX0xPV19DT01MRVhJVFkpIHsKICAgIGlmICggKCFwbnNDb25mLT51c2VQbnMpIHx8ICAgICAgICAgICAgICAvKiBwbnMgZW5hYmxlZD8gKi8KICAgICAgICAgICAobGFzdFdpbmRvd1NlcXVlbmNlID09IFNIT1JUX1dJTkRPVykgKSAvKiBjdXJyZW50bHkgb25seSBsb25nIGJsb2NrcyAqLwogICAgewogICAgICBGREttZW1jbGVhcihwbnNEYXRhLT5wbnNGbGFnLCBNQVhfR1JPVVBFRF9TRkIqc2l6ZW9mKElOVCkpOyAvKiBjbGVhciBhbGwgcG5zRmxhZ3MgKi8KICAgICAgZm9yIChzZmI9MDsgc2ZiPE1BWF9HUk9VUEVEX1NGQjsgc2ZiKyspIHsKICAgICAgICAgIG5vaXNlTnJnW3NmYl0gPSBOT19OT0lTRV9QTlM7ICAgICAgICAgICAgICAgICAgICAgICAgICAgLyogY2xlYXIgbnJnJ3Mgb2YgcHJldmlvdXMgZnJhbWUgKi8KICAgICAgfQogICAgICByZXR1cm47CiAgICB9CiAgfQogIGVsc2UgewogICAgaWYoIXBuc0NvbmYtPnVzZVBucykKICAgICAgcmV0dXJuOwoKICAgIC8qIFBOUyBvbmx5IGZvciBsb25nIFdpbmRvd3MgKi8KICAgIGlmIChwbnNDb25mLT5ucC5kZXRlY3Rpb25BbGdvcml0aG1GbGFncyAmIEpVU1RfTE9OR19XSU5ET1cpIHsKICAgICAgaWYobGFzdFdpbmRvd1NlcXVlbmNlICE9IExPTkdfV0lORE9XKSB7CiAgICAgICAgZm9yIChzZmIgPSAwOyBzZmIgPCBzZmJBY3RpdmU7IHNmYisrKSB7CiAgICAgICAgICBwbnNEYXRhLT5wbnNGbGFnW3NmYl0gPSAwOyAgICAvKiBjbGVhciBhbGwgcG5zRmxhZ3MgKi8KICAgICAgICB9CiAgICAgICAgcmV0dXJuOwogICAgICB9CiAgICB9CiAgfQogIC8qCiAgICBjYWxsIG5vaXNlIGRldGVjdGlvbgogICovCiAgRkRLYWFjRW5jX0ZES2FhY0VuY19ub2lzZURldGVjdGlvbiggcG5zQ29uZiwKICAgICAgICAgICAgICAgICAgcG5zRGF0YSwKICAgICAgICAgICAgICAgICAgc2ZiQWN0aXZlLAogICAgICAgICAgICAgICAgICBzZmJPZmZzZXQsCiAgICAgICAgICAgICAgICAgIHRuc09yZGVyLAogICAgICAgICAgICAgICAgICB0bnNQcmVkaWN0aW9uR2FpbiwKICAgICAgICAgICAgICAgICAgdG5zQWN0aXZlLAogICAgICAgICAgICAgICAgICBtZGN0U3BlY3RydW0sCiAgICAgICAgICAgICAgICAgIHNmYk1heFNjYWxlU3BlYywKICAgICAgICAgICAgICAgICAgc2ZidG9uYWxpdHkgKTsKCiAgLyogc2V0IHN0YXJ0Tm9pc2VTZmIgKGxvbmcpICovCiAgc3RhcnROb2lzZVNmYiA9IHBuc0NvbmYtPm5wLnN0YXJ0U2ZiOwoKICAvKiBTZXQgbm9pc2Ugc3Vic3RpdHV0aW9uIHN0YXR1cyAqLwogIGZvcihzZmIgPSAwOyBzZmIgPCBzZmJBY3RpdmU7IHNmYisrKSB7CgogICAgLyogTm8gUE5TIGJlbG93IHN0YXJ0Tm9pc2VTZmIgKi8KICAgIGlmKHNmYiA8IHN0YXJ0Tm9pc2VTZmIpewogICAgICBwbnNEYXRhLT5wbnNGbGFnW3NmYl0gPSAwOwogICAgICBjb250aW51ZTsKICAgIH0KCiAgICAvKgogICAgICBkbyBub2lzZSBzdWJzdGl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ZU5yZ3MoIHNmYkFjdGl2ZSwKICAgICAgICAgICAgICAgICBwbnNEYXRhLT5wbnNGbGFnLAogICAgICAgICAgICAgICAgIHNmYkVuZXJneUxkRGF0YSwKICAgICAgICAgICAgICAgICBub2lzZU5yZyApOwp9CgoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCgogICAgZnVuY3Rpb25uYW1lOkZES2FhY0VuY19GREthYWNFbmNfbm9pc2VEZXRlY3Rpb24KICAgIGRlc2NyaXB0aW9uOiB3cmFwcGVyIGZvciBub2lzZWRldC5jCiAgICByZXR1cm5zOgogICAgaW5wdXQ6ICAgICAgIHBucyBjb25maWcgc3RydWN0dXJlCiAgICAgICAgICAgICAgICAgcG5zIGRhdGEgc3RydWN0dXJlIChtb2RpZmllZCksCiAgICAgICAgICAgICAgICAgc2ZiQWN0aXZlCiAgICAgICAgICAgICAgICAgdG5zIG9yZGVyIGFuZCBwcmVkaWN0aW9uIGdhaW4KICAgICAgICAgICAgICAgICBwb2ludGVyIHRvIG1kY3QgU3BlY3RydW1hbmQgU2ZiIEVuZXJneQogICAgICAgICAgICAgICAgIHBvaW50ZXIgdG8gU2ZiIHRvbmFsaXR5CiAgICBvdXRwdXQ6ICAgICAgbm9pc2VGdXp6eU1lYXN1cmUgaW4gc3RydWN0dXJlIHBuc0RhdGEKICAgICAgICAgICAgICAgICBmbGFncyB0b25hbCAvIG5vbnRvbmFsCgoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8Kc3RhdGljIHZvaWQgRkRLYWFjRW5jX0ZES2FhY0VuY19ub2lzZURldGVjdGlvbiggUE5TX0NPTkZJRyAgKnBuc0NvbmYsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBQTlNfREFUQSAgICAqcG5zRGF0YSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IElOVCAgIHNmYkFjdGl2ZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IElOVCAgICpzZmJPZmZzZXQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpbnQgICAgICAgICAgdG5zT3JkZXIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBJTlQgICAgICAgICB0bnNQcmVkaWN0aW9uR2FpbiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgIElOVCAgICAgICAgIHRuc0FjdGl2ZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgIEZJWFBfREJMICAgICptZGN0U3BlY3RydW0sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBJTlQgICAgICAgICAqc2ZiTWF4U2NhbGVTcGVjLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgRklYUF9TR0wgICAgKnNmYnRvbmFsaXR5ICkKewogICAgSU5UIGNvbmRpdGlvbiA9IFRSVUU7CiAgICBpZiAoICEocG5zQ29uZi0+bnAuZGV0ZWN0aW9uQWxnb3JpdGhtRmxhZ3MgJiBJU19MT1dfQ09NTEVYSVRZKSApIHsKICAgICAgY29uZGl0aW9uID0gKHRuc09yZGVyID4gMyk7CiAgICB9CiAgICAvKgogICAgbm8gUE5TIGlmIGhlYXZ5IFROUyBhY3Rpdml0eQogICAgY2xlYXIgcG5zRGF0YS0+bm9pc2VGdXp6eU1lYXN1cmUKICAgICovCiAgICBpZigocG5zQ29uZi0+bnAuZGV0ZWN0aW9uQWxnb3JpdGhtRmxhZ3MgJiBVU0VfVE5TX0dBSU5fVEhSKSAmJgogICAgICAodG5zUHJlZGljdGlvbkdhaW4gPj0gcG5zQ29uZi0+bnAudG5zR2FpblRocmVzaG9sZCkgJiYgY29uZGl0aW9uICYmCiAgICAgICEoKHBuc0NvbmYtPm5wLmRldGVjdGlvbkFsZ29yaXRobUZsYWdzICYgVVNFX1ROU19QTlMpICYmICh0bnNQcmVkaWN0aW9uR2FpbiA+PSBwbnNDb25mLT5ucC50bnNQTlNHYWluVGhyZXNob2xkKSAmJiAodG5zQWN0aXZlKSkgKQogICAgewogICAgICAgIC8qIGNsZWFyIGFsbCBub2lzZUZ1enp5TWVhc3VyZSAqLwogICAgICAgIEZES21lbWNsZWFyKHBuc0RhdGEtPm5vaXNlRnV6enlNZWFzdXJlLCBzZmJBY3RpdmUqc2l6ZW9mKEZJWFBfU0dMKSk7CiAgICB9CiAgICBlbHNlCiAgICB7CiAgICAgICAgLyoKICAgICAgICBjYWxsIG5vaXNlIGRldGVjdGlvbiwgb3V0cHV0IGluIHBuc0RhdGEtPm5vaXNlRnV6enlNZWFzdXJlLAogICAgICAgIHVzZSByZWFsIG1kY3Qgc3BlY3RyYWwgZGF0YQogICAgICAgICovCiAgICAgICAgRkRLYWFjRW5jX25vaXNlRGV0ZWN0KCBtZGN0U3BlY3RydW0sCiAgICAgICAgICAgIHNmYk1heFNjYWxlU3BlYywKICAgICAgICAgICAgc2ZiQWN0aXZlLAogICAgICAgICAgICBzZmJPZmZzZXQsCiAgICAgICAgICAgIHBuc0RhdGEtPm5vaXNlRnV6enlNZWFzdXJlLAogICAgICAgICAgICAmcG5zQ29uZi0+bnAsCiAgICAgICAgICAgIHNmYnRvbmFsaXR5KTsKICAgIH0KfQoKCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgoKICAgIGZ1bmN0aW9ubmFtZTpGREthYWNFbmNfQ2FsY05vaXNlTnJncwogICAgZGVzY3JpcHRpb246IENhbGN1bGF0ZSB0aGUgTm9pc2VOcmcncwogICAgcmV0dXJuczoKICAgIGlucHV0OiAgICAgICBzZmJBY3RpdmUKICAgICAgICAgICAgICAgICBpZiBwbnNGbGFnIGNhbGN1bGF0ZSBOb2lzZU5yZwogICAgICAgICAgICAgICAgIHBvaW50ZXIgdG8gc2ZiRW5lcmd5IGFuZCBncm91cExlbgogICAgICAgICAgICAgICAgIHBvaW50ZXIgdG8gbm9pc2VOcmcgKG1vZGlmaWVkKQogICAgb3V0cHV0OiAgICAgIG5vaXNlTnJnJ3MgaW4gcG5zRmxhZ2VkIHNmYidzCgoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KCnN0YXRpYyB2b2lkIEZES2FhY0VuY19DYWxjTm9pc2VOcmdzKCBjb25zdCBJTlQgICAgc2ZiQWN0aXZlLAogICAgICAgICAgICAgICAgICAgICAgICAgICBJTlQgICAgICAgICAqUkVTVFJJQ1QgcG5zRmxhZywKICAgICAgICAgICAgICAgICAgICAgICAgICAgRklYUF9EQkwgICAgKlJFU1RSSUNUIHNmYkVuZXJneUxkRGF0YSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgSU5UICAgICAgICAgKlJFU1RSSUNUIG5vaXNlTnJnICkKewogIGludCBzZmI7CiAgSU5UIHRtcCA9ICgtTE9HX05PUk1fUENNKTw8MjsKCiAgZm9yKHNmYiA9IDA7IHNmYiA8IHNmYkFjdGl2ZTsgc2ZiKyspIHsKICAgIGlmKHBuc0ZsYWdbc2ZiXSkgewogICAgICBJTlQgbnJnID0gKC1zZmJFbmVyZ3lMZERhdGFbc2ZiXStGTDJGWENPTlNUX0RCTCgwLjVmLzY0LjBmKSk+PihERlJBQ1RfQklUUy0xLTcpOwogICAgICBub2lzZU5yZ1tzZmJdID0gdG1wIC0gbnJnOwogICAgfQogIH0KfQoKCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgoKICAgIGZ1bmN0aW9ubmFtZTpGREthYWNFbmNfQ29kZVBuc0NoYW5uZWwKICAgIGRlc2NyaXB0aW9uOiBFeGVjdXRlIHBucyBkZWNpc3Npb24KICAgIHJldHVybnM6CiAgICBpbnB1dDogICAgICAgc2ZiQWN0aXZlCiAgICAgICAgICAgICAgICAgcG5zIGNvbmZpZyBzdHJ1Y3R1cmUKICAgICAgICAgICAgICAgICB1c2UgUE5TIGlmIHBuc0ZsYWcKICAgICAgICAgICAgICAgICBwb2ludGVyIHRvIFNmYiBFbmVyZ3ksIG5vaXNlTnJnLCBUaHJlc2hvbGQKICAgIG91dHB1dDogICAgICBzZXQgc2ZiVGhyZXNob2xkIGhpZ2ggdG8gY29kZSBwZSB3aXRoIDAsCiAgICAgICAgICAgICAgICAgbm9pc2VOcmcgbWFya3MgZmxhZyBmb3IgcG5zIGNvZGluZwoKKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCgp2b2lkIEZES2FhY0VuY19Db2RlUG5zQ2hhbm5lbChjb25zdCBJTlQgICAgIHNmYkFjdGl2ZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgUE5TX0NPTkZJRyAgICAqcG5zQ29uZiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgSU5UICAgICAgICAgICAqUkVTVFJJQ1QgcG5zRmxhZywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgRklYUF9EQkwgICAgICAqUkVTVFJJQ1Qgc2ZiRW5lcmd5TGREYXRhLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBJTlQgICAgICAgICAgICpSRVNUUklDVCBub2lzZU5yZywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgRklYUF9EQkwgICAgICAqUkVTVFJJQ1Qgc2ZiVGhyZXNob2xkTGREYXRhKQp7CiAgSU5UIHNmYjsKICBJTlQgbGFzdGlOb2lzZUVuZXJneSA9IDA7CiAgSU5UIGZpcnN0UE5TYmFuZCA9IDE7IC8qIFRSVUUgZm9yIGZpcnN0IFBOUy1jb2RlZCBiYW5kICovCgogIC8qIG5vIFBOUyAqLwogIGlmKCFwbnNDb25mLT51c2VQbnMpIHsKICAgIGZvcihzZmIgPSAwOyBzZmIgPCBzZmJBY3Rpd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ub2lzZU5yZ1tzZmJdOwogICAgfQogICAgZWxzZSB7CiAgICAgIC8qIG5vIFBOUyBjb2RpbmcgKi8KICAgICAgbm9pc2VOcmdbc2ZiXSA9IE5PX05PSVNFX1BOUzsKICAgIH0KICB9Cn0KCgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKCiAgICBmdW5jdGlvbm5hbWU6RkRLYWFjRW5jX1ByZVByb2Nlc3NQbnNDaGFubmVsUGFpcgogICAgZGVzY3JpcHRpb246IENhbGN1bGF0ZSB0aGUgY29ycmVsYXRpb24gb2Ygbm9pc2UgaW4gYSBjaGFubmVsIHBhaXIKCiAgICByZXR1cm5zOgogICAgaW5wdXQ6ICAgICAgIHNmYkFjdGl2ZQogICAgICAgICAgICAgICAgIHBvaW50ZXIgdG8gc2ZiIGVuZXJnaWVzIGxlZnQsIHJpZ2h0IGFuZCBtaWQgY2hhbm5lbAogICAgICAgICAgICAgICAgIHBucyBjb25maWcgc3RydWN0dXJlCiAgICAgICAgICAgICAgICAgcG5zIGRhdGEgc3RydWN0dXJlIGxlZnQgYW5kIHJpZ2h0IChtb2RpZmllZCkKCiAgICBvdXRwdXQ6ICAgICAgbm9pc2VFbmVyZ3lDb3JyZWxhdGlvbiBpbiBwbnMgZGF0YSBzdHJ1Y3R1cmUKCioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwoKdm9pZCBGREthYWNFbmNfUHJlUHJvY2Vzc1Buc0NoYW5uZWxQYWlyKGNvbnN0IElOVCAgIHNmYkFjdGl2ZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIEZJWFBfREJMICAgKlJFU1RSSUNUIHNmYkVuZXJneUxlZnQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBGSVhQX0RCTCAgICpSRVNUUklDVCBzZmJFbmVyZ3lSaWdodCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIEZJWFBfREJMICAgKlJFU1RSSUNUIHNmYkVuZXJneUxlZnRMRCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIEZJWFBfREJMICAgKlJFU1RSSUNUIHNmYkVuZXJneVJpZ2h0TEQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBGSVhQX0RCTCAgICpSRVNUUklDVCBzZmJFbmVyZ3lNaWQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBQTlNfQ09ORklHICpSRVNUUklDVCBwbnNDb25mLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgUE5TX0RBVEEgICAqcG5zRGF0YUxlZnQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBQTlNfREFUQSAgICpwbnNEYXRhUmlnaHQpCnsKICBJTlQgc2ZiOwogIEZJWFBfREJMIGNjZjsKCiAgaWYoIXBuc0NvbmYtPnVzZVBucykKICAgIHJldHVybjsKCiAgRklYUF9EQkwgKlJFU1RSSUNUIHBOb2lzZUVuZXJneUNvcnJlbGF0aW9uTCA9IHBuc0RhdGFMZWZ0LT5ub2lzZUVuZXJneUNvcnJlbGF0aW9uOwogIEZJWFBfREJMICpSRVNUUklDVCBwTm9pc2VFbmVyZ3lDb3JyZWxhdGlvblIgPSBwbnNEYXRhUmlnaHQtPm5vaXNlRW5lcmd5Q29ycmVsYXRpb247CgogIGZvcihzZmI9MDtzZmI8IHNmYkFjdGl2ZTtzZmIrKykgewogICAgRklYUF9EQkwgcXVvdCA9IChzZmJFbmVyZ3lMZWZ0TERbc2ZiXT4+MSkgKyAoc2ZiRW5lcmd5UmlnaHRMRFtzZmJdPj4xKTsKCiAgICBpZihxdW90IDwgRkwyRlhDT05TVF9EQkwoLTMyLjBmLyhmbG9hdClMRF9EQVRBX1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ogICAgaW5wdXQ6ICAgICAgIHNmYkFjdGl2ZQogICAgICAgICAgICAgICAgIHBucyBjb25maWcgc3RydWN0dXJlCiAgICAgICAgICAgICAgICAgcG5zIGRhdGEgc3RydWN0dXJlIGxlZnQgYW5kIHJpZ2h0IChtb2RpZmllZCkKICAgICAgICAgICAgICAgICBwb2ludGVyIHRvIG1zTWFzaywgZmxhZ3MgY29ycmVsYXRpb24gYnkgcG5zIGNvZGluZyAobW9kaWZpZWQpCiAgICAgICAgICAgICAgICAgRGlnZXN0IG9mIE1TIGNvZGluZwogICAgb3V0cHV0OiAgICAgIHBuc0ZsYWcgaW4gcG5zIGRhdGEgc3RydWN0dXJlLAogICAgICAgICAgICAgICAgIG1zRmxhZyBpbiBtc01hc2sgKGZsYWdzIGNvcnJlbGF0aW9uKQoKKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCgp2b2lkIEZES2FhY0VuY19Qb3N0UHJvY2Vzc1Buc0NoYW5uZWxQYWlyKGNvbnN0IElOVCAgIHNmYkFjdGl2ZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBQTlNfQ09ORklHICAqcG5zQ29uZiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBQTlNfREFUQSAgICAqcG5zRGF0YUxlZnQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgUE5TX0RBVEEgICAgKnBuc0RhdGFSaWdodCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBJTlQgICAgICAgICAqUkVTVFJJQ1QgbXNNYXNrLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIElOVCAgICAgICAgICptc0RpZ2VzdCApCnsKICBJTlQgc2ZiOwoKICBpZighcG5zQ29uZi0+dXNlUG5zKQogICAgcmV0dXJuOwoKICBmb3Ioc2ZiPTA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