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gICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIEkyQ19TTUJVU19CWVRFOgogICAgICAgICAgICAgICAgaWYgKHJlYWRfd3JpdGUgPT0gSTJDX1NNQlVTX1JFQUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgY3NyX291dDMyKChWX1NNQl9BRERSKGFkZHIpIHwgVl9TTUJfVFRfUkQxQllURSksCgkJCQkgIFNNQl9DU1IoYWRhcCwgUl9TTUJfU1RBUlQpKTsKICAgICAgICAgICAgICAgICAgICAgICAgZGF0YV9ieXRlcyA9IDE7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBjc3Jfb3V0MzIoVl9TTUJfQ01EKGNvbW1hbmQpLCBTTUJfQ1NSKGFkYXAsIFJfU01CX0NNRCkpOwogICAgICAgICAgICAgICAgICAgICAgICBjc3Jfb3V0MzIoKFZfU01CX0FERFIoYWRkcikgfCBWX1NNQl9UVF9XUjFCWVRFKSwKCQkJCSAgU01CX0NTUihhZGFwLCBSX1NNQl9TVEFSVCkpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBJMkNfU01CVVNfQllURV9EQVRBOgogICAgICAgICAgICAgICAgY3NyX291dDMyKFZfU01CX0NNRChjb21tYW5kKSwgU01CX0NTUihhZGFwLCBSX1NNQl9DTUQpKTsKICAgICAgICAgICAgICAgIGlmIChyZWFkX3dyaXRlID09IEkyQ19TTUJVU19SRUFEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGNzcl9vdXQzMigoVl9TTUJfQUREUihhZGRyKSB8IFZfU01CX1RUX0NNRF9SRDFCWVRFKSwKCQkJCSAgU01CX0NTUihhZGFwLCBSX1NNQl9TVEFSVCkpOwogICAgICAgICAgICAgICAgICAgICAgICBkYXRhX2J5dGVzID0gMTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGNzcl9vdXQzMihWX1NNQl9MQihkYXRhLT5ieXRlKSwgU01CX0NTUihhZGFwLCBSX1NNQl9EQVRBKSk7CiAgICAgICAgICAgICAgICAgICAgICAgIGNzcl9vdXQzMigoVl9TTUJfQUREUihhZGRyKSB8IFZfU01CX1RUX1dSMkJZVEUpLAoJCQkJICBTTUJfQ1NSKGFkYXAsIFJfU01CX1NUQVJUKSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIEkyQ19TTUJVU19XT1JEX0RBVEE6CiAgICAgICAgICAgICAgICBjc3Jfb3V0MzIoVl9TTUJfQ01EKGNvbW1hbmQpLCBTTUJfQ1NSKGFkYXAsIFJfU01CX0NNRCkpOwogICAgICAgICAgICAgICAgaWYgKHJlYWRfd3JpdGUgPT0gSTJDX1NNQlVTX1JFQUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgY3NyX291dDMyKChWX1NNQl9BRERSKGFkZHIpIHwgVl9TTUJfVFRfQ01EX1JEMkJZVEUpLAoJCQkJICBTTUJfQ1NSKGFkYXAsIFJfU01CX1NUQVJUKSk7CiAgICAgICAgICAgICAgICAgICAgICAgIGRhdGFfYnl0ZXMgPSAyOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgY3NyX291dDMyKFZfU01CX0xCKGRhdGEtPndvcmQgJiAweGZmKSwgU01CX0NTUihhZGFwLCBSX1NNQl9EQVRBKSk7CiAgICAgICAgICAgICAgICAgICAgICAgIGNzcl9vdXQzMihWX1NNQl9NQihkYXRhLT53b3JkID4+IDgpLCBTTUJfQ1NSKGFkYXAsIFJfU01CX0RBVEEpKTsKICAgICAgICAgICAgICAgICAgICAgICAgY3NyX291dDMyKChWX1NNQl9BRERSKGFkZHIpIHwgVl9TTUJfVFRfV1IyQllURSksCgkJCQkgIFNNQl9DU1IoYWRhcCwgUl9TTUJfU1RBUlQpKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgI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