Ci8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgoqICNpbmNsdWRlx/gKKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCiNpbmNsdWRlICA8c3RkaW8uaD4KI2luY2x1ZGUgIDxzdGRsaWIuaD4KI2luY2x1ZGUgIDxzaWduYWwuaD4KI2luY2x1ZGUgIDxzeXMvdGltZS5oPgojaW5jbHVkZSAgPHN5c2xvZy5oPgojaW5jbHVkZSAgPGZjbnRsLmg+CiNpbmNsdWRlICA8cHRocmVhZC5oPgojaW5jbHVkZSAgPHN0ZGxpYi5oPgojaW5jbHVkZSAgPHN0cmluZy5oPgojaW5jbHVkZSAgPGVycm5vLmg+CiNpbmNsdWRlICA8c3lzL3R5cGVzLmg+CiNpbmNsdWRlICA8c3lzL3ByY3RsLmg+CiNpbmNsdWRlICA8dW5pc3RkLmg+CiNpbmNsdWRlICA8bGludXgvcnRjLmg+CiNpbmNsdWRlICA8dGltZS5oPgojaW5jbHVkZSAgPHN5cy9pcGMuaD4KI2luY2x1ZGUgIDxzeXMvbXNnLmg+CiNpbmNsdWRlICAic29mdGFwX2FwaS5oIgojaW5jbHVkZSAgIm1lc3NhZ2UuaCIKI2luY2x1ZGUgICJydGNfdGltZXIuaCIKCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgoqIMr9vt294bm5tqjS5cf4CioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKKiDN4rK/seTBv8n5w/fH+AoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCioguuq2qNLlx/gKKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCmludCBydGNfdGltZXJfYWRkKFVMT05HIHVsU2VjLCBSVENfSUQgIHJ0Y19pZCwgaW50IHNyY19pZCkvL2FkZF9ydGNfdGltZXIKewoJaW50IHJldCA9IC0xOwoJaW50IGRhdGFfbGVuID0gMDsKCVJUQ19EQVRBX0JVRiAgYnVmID0gezB9OwoJY2hhciBydGNfY3B1WzE2XSA9IHswfTsKCWNoYXIgcnRjX2NwX3JlYWR5WzhdID0gezB9OwoKCS8vvOC/2NPQxMTQqdOm08PJ6NbDwcu2zMqxvOS1xHJ0YwoJaWYgKHVsU2VjIDwgNTkpCgkJc2xvZyhNSVNDX1BSSU5ULCBTTE9HX0VSUiwgICAicnRjIHRpbWUgaXMgJWQsIGxlc3MgdGhhbiA2MC4gc3JjOjB4JXgsIGlkOjB4JXggXG4iLCB1bFNlYywgc3JjX2lkLCBydGNfaWQpOwoKCWJ1Zi5zcmNNb2R1bGUgPSBzcmNfaWQ7CglidWYubW9kdWxlID0gcnRjX2lkOwoJYnVmLnVsU2VjID0gdWxTZWM7CglidWYud2FrZXVwID0gMDsKCWJ1Zi5pc191dGMgPSAwOwoJZGF0YV9sZW4gPSBzaXplb2YoUlRDX0RBVEFfQlVGKTsKCWJ1Zi50aW1lX3ZhbCA9IHRpbWUoMCk7CglidWYuY3B1ID0gUlRDX0NQVV9BUDsKCglyZXQgPSBpcGNfc2VuZF9tZXNzYWdlKHNyY19pZCw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