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ApIHsKCQlFUlJfTVNHKCJ1bmFibGUgdG8gc2V0IE1UUlJcbiIpOwoJCXJldHVybjsKCX0KCWRpbmZvLT5oYXNfbXRyciA9IDE7Cn0Kc3RhdGljIGlubGluZSB2b2lkIHVuc2V0X210cnIoc3RydWN0IGludGVsZmJfaW5mbyAqZGluZm8pCnsKICAJaWYgKGRpbmZvLT5oYXNfbXRycikKICAJCW10cnJfZGVsKGRpbmZvLT5tdHJyX3JlZywgZGluZm8tPmFwZXJ0dXJlLnBoeXNpY2FsLAoJCQkgZGluZm8tPmFwZXJ0dXJlLnNpemUpOwp9CiNlbHNlCiNkZWZpbmUgc2V0X210cnIoeCkgV1JOX01TRygiTVRSUiBpcyBkaXNhYmxlZCBpbiB0aGUga2VybmVsXG4iKQoKI2RlZmluZSB1bnNldF9tdHJyKHgpIGRvIHsgfSB3aGlsZSAoMCkKI2VuZGlmIC8qIENPTkZJR19NVFJSICovCgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCiAqICAgICAgICAgICAgICAgICAgICAgICAgZHJpdmVyIGluaXQgLyBjbGVhbnVwICAgICAgICAgICAgICAgICoKICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KCnN0YXRpYyB2b2lkCmNsZWFudXAoc3RydWN0IGludGVsZmJfaW5mbyAqZGluZm8pCnsKCURCR19NU0coImNsZWFudXBcbiIpOwoKCWlmICghZGluZm8pCgkJcmV0dXJuOwoKCWZiX2RlYWxsb2NfY21hcCgmZGluZm8tPmluZm8tPmNtYXApOwoJa2ZyZWUoZGluZm8tPmluZm8tPnBpeG1hcC5hZGRyKTsKCglpZiAoZGluZm8tPnJlZ2lzdGVyZWQpCgkJdW5yZWdpc3Rlcl9mcmFtZWJ1ZmZlcihkaW5mby0+aW5mbyk7CgoJdW5zZXRfbXRycihkaW5mbyk7CgoJaWYgKGRpbmZvLT5mYm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