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VyKTsKfQoKbW9kdWxlX2luaXQoaW50ZWxmYl9pbml0KTsKbW9kdWxlX2V4aXQoaW50ZWxmYl9leGl0KTsKCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKICogICAgICAgICAgICAgICAgICAgICBtdHJyIHN1cHBvcnQgZnVuY3Rpb25zICAgICAgICAgICAgICAgICAgKgogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwoKI2lmZGVmIENPTkZJR19NVFJSCnN0YXRpYyBpbmxpbmUgdm9pZCBfX2RldmluaXQgc2V0X210cnIoc3RydWN0IGludGVsZmJfaW5mbyAqZGluZm8pCnsKCWRpbmZvLT5tdHJyX3JlZyA9IG10cnJfYWRkKGRpbmZvLT5hcGVydHVyZS5waHlzaWNhbCwKCQkJCSAgIGRpbmZvLT5hcGVydHVyZS5zaXplLCBNVFJSX1RZUEVfV1JDT01CLCAxKTsKCWlmIChkaW5mby0+bXRycl9yZWcgPCAwKSB7CgkJRVJSX01TRygidW5hYmxlIHRvIHNldCBNVFJSXG4iKTsKCQlyZXR1cm47Cgl9CglkaW5mby0+aGFzX210cnIgPSAxOwp9CnN0YXRpYyBpbmxpbmUgdm9pZCB1bnNldF9tdHJyKHN0cnVjdCBpbnRlbGZiX2luZm8gKmRpbmZvKQp7CiAgCWlmIChkaW5mby0+aGFzX210cnIpCiAgCQltdHJyX2RlbChkaW5mby0+bXRycl9yZWcsIGRpbmZvLT5hcGVydHVyZS5waHlzaWNhbCwKCQkJIGRpbmZvLT5hcGVydHVyZS5zaXplKTsKfQojZWxzZQojZGVmaW5lIHNldF9tdHJyKHgpIFdSTl9NU0coIk1UUlIgaXMgZGlzYWJsZWQgaW4gdGhlIGtlcm5lbFxuIikKCiNkZWZpbmUgdW5zZXRfbXRycih4KSBkbyB7IH0gd2hpbGUgKDApCiNlbmRpZiAvKiBDT05GSUdfTVRSU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fcGNpX3VucmVnaXN0ZXIoc3RydWN0IHBjaV9kZXYgKnBkZXYpCnsKCXN0cnVjdCBpbnRlbGZiX2luZm8gKmRpbmZvID0gcGNpX2dldF9kcnZkYXRhKHBkZXYpOwoKCURCR19NU0coImludGVsZmJfcGNpX3VucmVnaXN0ZXJcbiIpOwoKCWlmICghZGluZm8pCgkJcmV0dXJuOwoKCWNsZWFudXAoZGluZm8pOwoKCXBjaV9zZXRfZHJ2ZGF0YShwZGV2LCBOVUxMKTsKfQoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgogKiAgICAgICAgICAgICAgICAgICAgICAgaGVscGVyIGZ1bmN0aW9ucyAgICAgICAgICAgICAgICAgICAgICAqCiAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCgppbnQgX19pbmxpbmVfXwppbnRlbGZiX3Zhcl90b19kZXB0aChjb25zdCBzdHJ1Y3QgZmJfdmFyX3NjcmVlbmluZm8gKnZhcikKewoJREJHX01TRygiaW50ZWxmYl92YXJfdG9fZGVwdGg6IGJwcDogJWQsIGdyZWVuLmxlbmd0aCBpcyAlZFxuIiwKCQl2YXItPmJpdHNfcGVyX3BpeGVsLCB2YXItPmdyZWVuLmxlbmd0aCk7CgoJc3dpdGNoICh2YXItPmJpdHNfcGVyX3BpeGVsKSB7CgljYXNlIDE2OgoJCXJldHVybiAodmFyLT5ncmVlbi5sZW5ndGggPT0gNikgPyAxNiA6IDE1OwoJY2FzZSAzMjoKCQlyZXR1cm4gMjQ7CglkZWZhdWx0OgoJCXJldHVybiB2YXItPmJpdHNfcGVyX3BpeGVsOwoJfQp9CgoKc3RhdGljIF9faW5saW5lX18gaW50CnZhcl90b19yZWZyZXNoKGNvbnN0IHN0cnVjdCBmYl92YXJfc2NyZWVuaW5mbyAqdmFyKQp7CglpbnQgeHRvdCA9IHZhci0+eHJlcyArIHZhci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