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XRlKENBUF9FTkRQVFNFVFVQU1RBVCwgMCwgIDApOyAgIC8qIHdyaXRlcyBpdHMgY29udGVudCAqLwoKCS8qIGNsZWFyIGNvbXBsZXRlIHN0YXR1cyAqLwoJaHdfY3dyaXRlKENBUF9FTkRQVENPTVBMRVRFLCAgMCwgIDApOyAgIC8qIHdyaXRlcyBpdHMgY29udGVudCAqLwoKCS8qIHdhaXQgdW50aWwgYWxsIGJpdHMgY2xlYXJlZCAqLwoJd2hpbGUgKGh3X2NyZWFkKENBUF9FTkRQVFBSSU1FLCB+MCkpCgkJdWRlbGF5KDEwKTsgICAgICAgICAgICAgLyogbm90IFJUT1MgZnJpZW5kbHkgKi8KCgkvKiByZXNldCBhbGwgZW5kcG9pbnRzID8gKi8KCgkvKiByZXNldCBpbnRlcm5hbCBzdGF0dXMgYW5kIHdhaXQgZm9yIGZ1cnRoZXIgaW5zdHJ1Y3Rpb25zCgkgICBubyBuZWVkIHRvIHZlcmlmeSB0aGUgcG9ydCByZXNldCBzdGF0dXMgKEVTUyBkb2VzIGl0KSAqLwoKCXJldHVybiAwOwp9CgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCiAqIERCRyBibG9jawogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCi8qKgogKiBzaG93X2RldmljZTogcHJpbnRzIGluZm9ybWF0aW9uIGFib3V0IGRldmljZSBjYXBhYmlsaXRpZXMgYW5kIHN0YXR1cwogKgogKiBDaGVjayAiZGV2aWNlLmgiIGZvciBkZXRhaWxzCiAqLwpzdGF0aWMgc3NpemVfdCBzaG93X2RldmljZShzdHJ1Y3QgZGV2aWNlICpkZXYsIHN0cnVjdCBkZXZpY2VfYXR0cmlidXRlICphdHRyLAoJCQkgICBjaGFyICpidWYpCnsKCXN0cnVjdCBjaTEzeHh4ICp1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HVzICE9IE5VTEwpIHsKCQl1c2JfZXBfZnJlZV9yZXF1ZXN0KGdhZGdldC0+ZXAwLCBtRXAtPnN0YXR1cyk7CgkJbUVwLT5zdGF0dXMgPSBOVUxMOwoJfQoKCXJldHVybiAwOwp9CgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCiAqIElTUiBibG9jawogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCi8qKgogKiBpc3JfcmVzZXRfaGFuZGxlcjogVVNCIHJlc2V0IGludGVycnVwdCBoYW5kbGVyCiAqIEB1ZGM6IFVEQyBkZXZpY2UKICoKICogVGhpcyBmdW5jdGlvbiByZXNldHMgVVNCIGVuZ2luZSBhZnRlciBhIGJ1cyByZXNldCBvY2N1cnJlZAogKi8Kc3RhdGljIHZvaWQgaXNyX3Jlc2V0X2hhbmRsZXIoc3RydWN0IGNpMTN4eHggKnVkYykKX19yZWxlYXNlcyh1ZGMtPmxvY2spCl9fYWNxdWlyZXModWRjLT5sb2NrKQp7CglzdHJ1Y3QgY2kxM3h4eF9lcCAqbUVwID0gJnVkYy0+Y2kxM3h4eF9lcFswXTsKCWludCByZXR2YWw7CgoJdHJhY2UoIiVwIiwgdWRjKTsKCglpZiAodWRjID09IE5VTEwpIHsKCQllcnIoIkVJTlZBTCIpOwoJCXJldHVybjsKCX0KCglkYmdfZXZlbnQoMHhGRiwgIkJVUyBSU1QiLCAwKTsKCglzcGluX3VubG9jayh1ZGMtPmxvY2spOwoJcmV0dmFsID0gX2dhZGdldF9zdG9wX2FjdGl2aXR5KCZ1ZGMtPmdhZGdldCk7CglpZiAocmV0dmFsKQoJCWdvdG8gZG9uZTsKCglyZXR2YWwgPSBod191c2JfcmVzZXQoKTsKCWlmIChyZXR2YWwpCgkJZ290byBkb25lOwoKCXJldHZhbCA9IHVz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