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SB8IENPTkZJUk0sIE5VTEwpOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIGNhc2UgKDMpOgogICAgICAgICAgICAgICAgICAgICAgICBsMV9tc2coY3MsIEhXX0RFQUNUSVZBVEUgfCBJTkRJQ0FUSU9OLCBOVUxMKTsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICBjYXNlICg0KToKICAgICAgICAgICAgICAgICAgICAgICAgbDFfbXNnKGNzLCBIV19QT1dFUlVQIHwgQ09ORklSTSwgTlVMTCk7CiAgICAgICAgICAgICAgICAgICAgICAgIEFtZDc5MzBfcGhfY29tbWFuZChjcywgMHg1MCwgIkhXX0VOQUJMRSBSRVFVRVNUIik7CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgY2FzZSAoNSk6CgkJCWwxX21zZyhjcywgSFdfUlNZTkMgfCBJTkRJQ0FUSU9OLCBOVUxMKTsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICBjYXNlICg2KToKCQkJbDFfbXNnKGNzLCBIV19JTkZPNF9QOCB8IElORElDQVRJT04sIE5VTEwpOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIGNhc2UgKDcpOiAvKiBpbml0LCBDYXJkIHN0YXJ0cyBpbiBGNyAqLwoJCQlsMV9tc2coY3MsIEhXX1JTWU5DIHwgSU5ESUNBVElPTiwgTlVMTCk7CgkJCWwxX21zZyhjcywgSFdfSU5GTzRfUDggfCBJTkRJQ0FUSU9OLCBOVUxMKTsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICBjYXNlICg4KToKICAgICAgICAgICAgICAgICAgICAgICAgbDFfbXNnKGNzLCBIV19QT1dFUlVQIHwgQ09ORklSTSwgTlVMTCk7CiAgICAgICAgICAgICAgICAgICAgICAgIC8qIGZhbGwgdGhyb3VnaCAqLwogICAgICAgICAgICAgICAgY2FzZSAoOSk6CiAgICAgICAgICAgICAgICAgICAgICAgIEFtZDc5MzBfcGhfY29tbWFuZChjcywgMHg0MCwgIkhXX0VOQUJMRSBSRVEgY2xlYXJlZCBpZiBzZXQiKTsKCQkJbDFfbXNnKGNzLCBIV19SU1lOQyB8IElORElDQVRJT04sIE5VTEwpOwoJCQlsMV9tc2coY3MsIEhXX0lORk8yIHwgSU5ESUNBVElPTiwgTlVMTCk7CgkJCWwxX21zZyhjcywgSFdfSU5GTzRfUDggfCBJTkRJQ0FUSU9OLCBOVUxMKTsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICBjYXNlICgxMCk6CiAgICAgICAgICAgICAgICAgICAgICAgIEFtZDc5MzBfcGhfY29tbWFuZChjcywgMHg0MCwgIlQzIGV4cGlyZWQsIEhXX0VOQUJMRSBSRVEgY2xlYXJlZCIpOwogICAgICAgICAgICAgICAgICAgICAgICBjcy0+ZGMuYW1kNzkzMC5vbGRfc3RhdGUgPSAzOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIGNhc2UgKDExKToKCQkJbDFfbXNnKGNzLCBIV19JTkZPMiB8IElORElDQVRJT04sIE5VTEwpOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKCQlkZWZhdWx0OgoJCQlicmVhazsKCX0KfQoKCgpzdGF0aWMgdm9pZApBbWQ3OTMwX2JoKHN0cnVjdCBJc2RuQ2FyZFN0YXRlICpjcykKewoKICAgICAgICBzdHJ1Y3QgUFN0YWNrICpzdHB0cjsKCglpZiAoIWNzKQoJCXJldHVybjsKCWlmICh0ZXN0X2FuZF9jbGVhcl9iaXQoRF9DTEVBUkJVU1ksICZjcy0+ZXZlbnQpKSB7CiAgICAgICAgICAgICAgICBpZiAoY3MtPmRlYnVnKQoJCQlkZWJ1Z2wxKGNzLCAiQW1kNzkzMDogYmgsIEQtQ2hhbm5lb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gICAgICAgICAgIGlmICgoY3MtPnJjdmlkeCkgPiAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmICghKHNrYiA9IGFsbG9jX3NrYihjcy0+cmN2aWR4LCBHRlBfQVRPTUlDKSkpCgkJCQkJCQlwcmludGsoS0VSTl9XQVJOSU5HICJIaVNheDogQW1kNzkzMDogZW1wdHlfRGZpZm8sIEQgcmVjZWl2ZSBvdXQgb2YgbWVtb3J5IVxuIik7CgkJCQkJCWVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8qIERlYnVnZ2luZyAqLwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChjcy0+ZGVidWcgJiBMMV9ERUJfSVNBQ19GSUZPKSB7CgkJCQkJCQkJY2hhciAqdCA9IGNzLT5kbG9nOwoKCQkJCQkJCQl0ICs9IHNwcmludGYodCwgIkFtZDc5MzA6IGVtcHR5X0RmaWZvIGNudDogJWQgfCIsIGNzLT5yY3ZpZHgpOwoJCQkJCQkJCVF1aWNrSGV4KHQsIGNzLT5yY3ZidWYsIGNzLT5yY3ZpZHgpOwoJCQkJCQkJCWRlYnVnbDEoY3MsIGNzLT5kbG9nKTsKCQkJCQkJCX0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvKiBtb3ZlcyByZWNlaXZlZCBkYXRhIGluIHNrLWJ1ZmZlciAqLwoJCQkJCQkJbWVtY3B5KHNrYl9wdXQoc2tiLCBjcy0+cmN2aWR4KSwgY3MtPnJjdmJ1ZiwgY3MtPnJjdmlkeCk7CgkJCQkJCQlza2JfcXVldWVfdGFpbCgmY3MtPnJxLCBza2IpOwoJCQkJCQl9CgkJCQkJfQoKCQkJCX0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvKiB0aHJvdyBkYW1hZ2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gIkFtZDc5MzA6IGludGVycnVwdDogZW1wdHkgRC1GSUZPIik7CiAgICAgICAgICAgICAgICBBbWQ3OTMwX2VtcHR5X0RmaWZvKGNzLCAwKTsKCX0KCgogICAgICAgIC8qIEQtRnJhbWUgdHJhbnNtaXQgY29tcGxldGUgKi8KCWlmIChkc3IxICYgNjQpIHsKCQlpZiAoY3MtPmRlYnVnICYgTDFfREVCX0lTQUMpIHsKCQkJZGVidWdsMShjcywgIkFtZDc5MzA6IGludGVycnVwdDogdHJhbnNtaXQgcGFja2V0IHJlYWR5Iik7CiAgICAgICAgCX0KCQkvKiBBTUQgaW50ZXJydXB0cyBvZmYgKi8KICAgICAgICAgICAgICAgIEFtZElycU9mZihjcyk7CgogICAgICAgICAgICAgICAgaWYgKHRlc3RfYW5kX2NsZWFyX2JpdChGTEdfREJVU1lfVElNRVIsICZjcy0+SFdfRmxhZ3MpKQoJCQlkZWxfdGltZXIoJmNzLT5kYnVzeXRpbWVyKTsKCQlpZiAodGVzdF9hbmRfY2xlYXJfYml0KEZMR19MMV9EQlVTWSwgJmNzLT5IV19GbGFncykpCgkJCXNjaGVkdWxlX2V2ZW50KGNzLCBEX0NMRUFSQlVTWSk7CgogICAgICAgICAgICAgICAgaWYgKGNzLT50eF9za2IpIHsKICAgICAgICAJCWlmIChjcy0+ZGVidWcgJiBMMV9ERUJfSVNBQykKCSAgICAgICAgCQlkZWJ1Z2wxKGNzLCAiQW1kNzkzMDogaW50ZXJydXB0OiBUWC1QYWNrZXQgcmVhZHksIGZyZWVpbmcgc2tiIik7CiAgICAgICAgICAgICAgICAgICAgICAgIGRldl9rZnJlZV9za2JfaXJxKGNzLT50eF9za2IpOwoJCQljcy0+dHhfY250ID0gMDsKICAgICAgICAgICAgICAgICAgICAgICAgY3MtPmRjLmFtZDc5MzAudHhfeG10bGVuPTA7CgkJCWNzLT50eF9za2IgPSBOVUxMOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKChjcy0+dHhfc2ti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