LyoqDQogKiBAZmlsZSBmbGFnc19hcGkuYw0KICogQGJyaWVmIGZsYWdzt9bH+L3Tv9rKtc/WDQogKg0KICogQ29weXJpZ2h0IChDKSAyMDIzIFNhbmVjaGlwcyBUZWNobm9sb2d5IENvLiwgTHRkLg0KICogQGF1dGhvciANCiAqIA0KICogVGhpcyBwcm9ncmFtIGlzIGZyZWUgc29mdHdhcmU7IHlvdSBjYW4gcmVkaXN0cmlidXRlIGl0IGFuZC9vciBtb2RpZnkNCiAqIGl0IHVuZGVyIHRoZSB0ZXJtcyBvZiB0aGUgR05VIEdlbmVyYWwgUHVibGljIExpY2Vuc2UgdmVyc2lvbiAyIGFzDQogKiBwdWJsaXNoZWQgYnkgdGhlIEZyZWUgU29mdHdhcmUgRm91bmRhdGlvbi4go6ix2NGho7pHUEx2MiBMaWNlbmNlo6kNCiAqDQogKi8NCg0KDQovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKg0KICogICAgICAgICAgICAgICAgICAgICAgICAgICBJbmNsdWRlIGhlYWRlciBmaWxlcyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICoNCiAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovDQojaW5jbHVkZSA8c3RkaW8uaD4NCiNpbmNsdWRlIDxzdGRsaWIuaD4NCiNpbmNsdWRlIDx1bmlzdGQuaD4NCiNpbmNsdWRlIDxzdHJpbmcuaD4NCiNpbmNsdWRlIDxlcnJuby5oPg0KI2luY2x1ZGUgPHN5cy9pb2N0bC5oPg0KI2luY2x1ZGUgPHN5cy9zdGF0Lmg+DQojaW5jbHVkZSA8ZmNudGwuaD4NCiNpbmNsdWRlIDxtdGQvbXRkLWFiaS5oPg0KDQojaW5jbHVkZSAicHViX2ZsYWdzLmgiDQoNCiNpbmNsdWRlICJmbGFnc19sb2cuaCINCiNpbmNsdWRlICJmbGFnc19hcGkuaCINCg0KDQovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKg0KICogICAgICAgICAgICAgICAgICAgICAgICAgICAgIE1hY3JvIGRlZmluaXRpb25zICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICoNCiAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovDQojZGVmaW5lIE1BWF9QQVRIX0xFTiAoMjU2KQ0KDQojZGVmaW5lIFBBUlRJVElPTl9OQU1FX0ZMQUdTICJmbGFncyINCg0KI2RlZmluZSBGTEFHU19JTklUX1ZBTElEX0JMT0NLU19OVU0JKDgpDQoNCiNkZWZpbmUgR09PRF9CTE9DSyAoMCkNCiNkZWZpbmUgQkFEX0JMT0NLICgxKQ0KDQojZGVmaW5lIEZJTEVfUEFUSF9QUk9DX0NNRExJTkUgIi9wcm9jL2NtZGxpbmUiDQoNCiNkZWZpbmUgUFJPQ19DTURMSU5FX1NZU1RFTV9BX0ZMQUcgICAic3lzdGVtPXN5c3RlbV9hIg0KI2RlZmluZSBQUk9DX0NNRExJTkVfU1lTVEVNX0JfRkxBRyAgICJzeXN0ZW09c3lzdGVtX2IiDQoNCiNkZWZpbmUgU1lTVEVNX0lOREVYX1VOS05PV04gKC0xKQ0KI2RlZmluZSBTWVNURU1fSU5ERVhfMSAoMSkNCiNkZWZpbmUgU1lTVEVNX0lOREVYXzIgKDIpDQoNCiNkZWZpbmUgQ1JDX0xFX0JJVFMgNjQNCiNkZWZpbmUgQ1JDMzJfUE9MWV9MRSAweGVkYjg4MzIwDQojZGVmaW5lIExFX1RBQkxFX1JPV1MgKENSQ19MRV9CSVRTLzgpDQojZGVmaW5lIExFX1RBQkxFX1NJWkUgMjU2DQoNCg0KLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioNCiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICBUeXBlIGRlZmluaXRpb25zICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAqDQogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLw0KdHlwZWRlZiBzdHJ1Y3QNCnsNCiAgICB1bnNpZ25lZCBpbnQgbXRkX3RvdGFsc2l6ZTsJCQkJLy8gbXRkIGRldmljZSB0b3RhbCBzaXplDQogICAgdW5zaWduZWQgaW50IG10ZF9wYWdlcGVyYmxvY2s7CQkJLy8gbXRkIGRldmljZSBwYWdlIHBlciBibG9jaw0KICAgIHVuc2lnbmVkIGludCBtdGRfYmxvY2tzaXplOwkJCQkvLyBtdGQgZGV2aWNlIGJsb2NrIHNpemUNCiAgICB1bnNpZ25lZCBpbnQgbXRkX3BhZ2VzaXplOwkJCQkvLyBtdGQgZGV2aWNlIHBhZ2Ugc2l6ZQ0KICAgIHVuc2lnbmVkIGludCBtdGRfb29ic2l6ZTsJCQkJLy8gbXRkIGRldmljZSBvb2Igc2l6ZQ0KICAgIGludCBwYXJ0aV9maWxlX2Rlc2M7CQkJCQkvLyBwYXJ0aXRpb24gdXBkYXRlIGZpbGUgZGVzY3JpcHRpb24NCn0gcGFydGl0aW9uX210ZF9pbmZvX3Q7DQoNCg0KdHlwZWRlZiBlbnVtDQp7DQogICAgREVWSUNFX01URCA9IDAsDQogICAgREVWSUNFX1pGVEwgPSAxLA0KICAgIERFVklDRV9NVERfQkxPQ0ssDQp9IGRldmljZV90eXBlX3Q7DQoNCg0KLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioNCiAqCQkJCQkJICAgTG9jYWwgdmFyaWFibGUgZGVmaW5pdGlvbnMJCQkJCQkgICAqDQogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLw0KDQoNCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqDQogKgkJCQkJCSAgR2xvYmFsIHZhcmlhYmxlIGRlZmluaXRpb25zCQkJCQkJICAgKg0KICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8NCnN0YXRpYyB1bnNpZ25lZCBpbnQgY3JjMzJ0YWJsZV9sZVtMRV9UQUJMRV9ST1dTXVsyNTZdOw0KDQoNCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqDQogKiAJCQkJCSAgIExvY2FsIGZ1bmN0aW9uIGRlY2xhcmF0aW9ucwkJCQkJCQkgICAqDQogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLw0Kc3RhdGljIHZvaWQgY3JjMzJpbml0X2xlX2dlbmVyaWMoY29uc3QgdW5zaWduZWQgaW50IHBvbHlub21pYWwsIHVuc2lnbmVkIGludCAoKnRhYilbMjU2XSk7DQpzdGF0aWMgdW5zaWduZWQgaW50IGNyYzMyX2JvZHkodW5zaWduZWQgaW50IGNyYywgdW5zaWduZWQgY2hhciBjb25zdCAqYnVmLCBzaXplX3QgbGVuLCBjb25zdCB1bnNpZ25lZCBpbnQgKCp0YWIpWzI1Nl0pOw0Kc3RhdGljIHVuc2lnbmVkIGludCBjcmMzMl9sZV9nZW5lcmljKHVuc2lnbmVkIGludCBjcmMsIHVuc2lnbmVkIGNoYXIgY29uc3QgKnAsIHNpemVfdCBsZW4sIGNvbnN0IHVuc2lnbmVkIGludCAoKnRhYilbMjU2XSk7DQoNCnN0YXRpYyBpbnQgbXRkX2dldChjb25zdCBjaGFyICppX3BhcnRpX25hbWUsIGRldmljZV90eXBlX3QgZGV2aWNlX3R5cGUsIGNoYXIgKm9fbXRkX3BhdGgsIHVuc2lnbmVkIGludCBvX210ZF9wYXRoX2xlbik7DQpzdGF0aWMgaW50IHdyaXRlX2ZsYWdzX2luZm8ocGFydGl0aW9uX210ZF9pbmZvX3QgKnBfbXRkX2luZm8sIGludCBpbmRleCwgdW5zaWduZWQgY2hhciAqY29udGVudCwgaW50IGxlbik7DQoNCnN0YXRpYyBpbnQgZ2V0X2ZsYWdzX2luZm8oVF9GTEFHU19JTkZPICpwX21haW4sIGludCAqcF9tYWluX2luZGV4LCBUX0ZMQUdTX0lORk8gKnBfYmFja3VwLCBpbnQgKnBfYmFja3VwX2luZGV4KTsNCnN0YXRpYyBpbnQgc2V0X2ZsYWdzX2luZm8oVF9GTEFHU19JTkZPICpwX2ZsYWdzX2luZm8sIGludCAqcF9tYWluX2luZGV4LCBpbnQgKnBfYmFja3VwX2luZGV4KTsNCg0Kc3RhdGljIHZvaWQgY29weV9mbGFnc19pbmZvKFRfRkxBR1NfSU5GTyAqZHN0LCBUX0ZMQUdTX0lORk8gKnNyYyk7DQoNCnN0YXRpYyBpbnQgZ2V0X2N1cnJlbnRfc3lzdGVtKCk7DQoNCg0KLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioNCiAqIAkJCQkJIExvY2FsIGZ1bmN0aW9uIGltcGxlbWVudGF0aW9ucyAJCQkJCQkgICAqDQogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLw0Kc3RhdGljIHZvaWQgY3JjMzJpbml0X2xlX2dlbmVyaWMoY29uc3QgdW5zaWduZWQga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ICBtZW1zZXQoYnVmLCAwLCBzaXplb2YoYnVmKSk7DQogICAgICAgIGxpbmVfc3RyID0gZmdldHMoYnVmLCBzaXplb2YoYnVmKSAtIDEsIGZwX210ZCk7DQoNCiAgICAgICAgaWYgKE5VTEwgPT0gbGluZV9zdHIpDQogICAgICAgIHsNCiAgICAgICAgICAgIGZsYWdzX2VycigiZ2V0IGluZm8gZnJvbSBtdGQgZXJyb3I6ICVzIiwgc3RyZXJyb3IoZXJybm8pKTsNCiAgICAgICAgICAgIGZjbG9zZShmcF9tdGQpOw0KICAgICAgICAgICAgcmV0dXJuIC0xOw0KICAgICAgICB9DQogICAgICAgIC8vIG10ZDU6IDAwMTAwMDAwIDAwMDIwMDAwICJmb3RhZmxhZyINCiAgICAgICAgbWF0Y2hlcyA9IHNzY2FuZihidWYsICJtdGQlZDogJXggJXggXCIlNjNbXlwiXSIsDQogICAgICAgICAgICAgICAgICAgICAgICAgJm10ZG51bSwgJm10ZHNpemUsICZtdGRlcmFzZXNpemUsIG10ZG5hbWUpOw0KICAgICAgICBtdGRuYW1lWzYzXSA9ICdcMCc7DQoNCiAgICAgICAgaWYgKChtYXRjaGVzID09IDQpICYmIChzdHJjbXAobXRkbmFtZSwgaV9wYXJ0aV9uYW1lKSA9PSAwKSkNCiAgICAgICAgew0KICAgICAgICAgICAgbWVtc2V0KG9fbXRkX3BhdGgsIDAsIG9fbXRkX3BhdGhfbGVuKTsNCiAgICAgICAgICAgIGlmIChkZXZpY2VfdHlwZSA9PSBERVZJQ0VfTVREX0JMT0NLKQ0KICAgICAgICAgICAgew0KICAgICAgICAgICAgICAgIHNucHJpbnRmKG9fbXRkX3BhdGgsIG9fbXRkX3BhdGhfbGVuLCAiL2Rldi9tdGRibG9jayVkIiwgbXRkbnVtKTsNCiAgICAgICAgICAgIH0NCiAgICAgICAgICAgIGVsc2UgaWYgKGRldmljZV90eXBlID09IERFVklDRV9NVEQpDQogICAgICAgICAgICB7DQogICAgICAgICAgICAgICAgc25wcmludGYob19tdGRfcGF0aCwgb19tdGRfcGF0aF9sZW4sICIvZGV2L210ZCVkIiwgbXRkbnVtKTsNCiAgICAgICAgICAgIH0NCiAgICAgICAgICAgIGVsc2UgaWYgKGRldmljZV90eXBlID09IERFVklDRV9aRlRMKQ0KICAgICAgICAgICAgew0KICAgICAgICAgICAgICAgIHNucHJpbnRmKG9fbXRkX3BhdGgsIG9fbXRkX3BhdGhfbGVuLCAiL2Rldi96ZnRsJWQiLCBtdGRudW0pOw0KICAgICAgICAgICAgfQ0KICAgICAgICAgICAgZWxzZQ0KICAgICAgICAgICAgew0KICAgICAgICAgICAgICAgIGZsYWdzX2VycigidW5rbm93biBkZXZpY2UgdHlwZSAlZCIsIGRldmljZV90eXBlKTsNCiAgICAgICAgICAgICAgICBmY2xvc2UoZnBfbXRkKTsNCiAgICAgICAgICAgICAgICByZXR1cm4gLTE7DQogICAgICAgICAgICB9DQogICAgICAgICAgICAvLyBwcmludGYoIltsaWJtdGRdOiBvX210ZF9wYXRoPVslc11cbiIsIG9fbXRkX3BhdGgpOw0KICAgICAgICAgICAgYnJlYWs7DQogICAgICAgIH0NCiAgICB9DQogICAgZmNsb3NlKGZwX210ZCk7DQogICAgcmV0dXJuIDA7DQp9DQoNCg0Kc3RhdGljIGludCB3cml0ZV9mbGFnc19pbmZvKHBhcnRpdGlvbl9tdGRfaW5mb190ICpwX210ZF9pbmZvLCBpbnQgaW5kZXgsIHVuc2lnbmVkIGNoYXIgKmNvbnRlbnQsIGludCBsZW4pDQp7DQogICAgc3RydWN0IGVyYXNlX2luZm9fdXNlciBlcmFzZV9pbmZvOw0KICAgIGludCB3cml0ZV9sZW4gPSAwOw0KICAgIGxvbmcgbG9uZyAgb2ZmcyA9IDA7DQoNCiAgICBlcmFzZV9pbmZvLnN0YXJ0ID0gaW5kZXggKiBwX210ZF9pbmZvLT5tdGRfYmxvY2tzaXplOw0KICAgIGVyYXNlX2luZm8ubGVuZ3RoID0gcF9tdGRfaW5mby0+bXRkX2Js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gIHsNCiAgICAgICAgICAgIGJsb2NrX2ZsYWcgPSBHT09EX0JMT0NLOw0KICAgICAgICB9DQogICAgICAgIGVsc2UNCiAgICAgICAgew0KICAgICAgICAgICAgZmxhZ3NfZXJyKCJmbGFncyBibG9jayBbJWRdIGlzIGJhZCwgZXJybm89JWQsIHN0cmVycm9yPVslc10iLCBpbmRleCwgZXJybm8sIHN0cmVycm9yKGVycm5vKSk7DQogICAgICAgICAgICBibG9ja19mbGFnID0gIEJBRF9CTE9DSzsNCiAgICAgICAgfQ0KDQogICAgICAgIGlmIChibG9ja19mbGFnID09IEdPT0RfQkxPQ0spDQogICAgICAgIHsNCiAgICAgICAgICAgIGlmIChsc2VlayhtdGRfaW5mby5wYXJ0aV9maWxlX2Rlc2MsIGluZGV4ICogbXRkX2luZm8ubXRkX2Jsb2Nrc2l6ZSwgU0VFS19TRVQpIDwgMCkNCiAgICAgICAgICAgIHsNCiAgICAgICAgICAgICAgICBmbGFnc19lcnIoImxzZWVrIGVycm9yLCBlcnJubz0lZCwgc3RyZXJyb3I9WyVzXSIsIGVycm5vLCBzdHJlcnJvcihlcnJubykpOw0KICAgICAgICAgICAgICAgIGdvdG8gZXJyb3JfY2xvc2U7DQogICAgICAgICAgICB9DQoNCiAgICAgICAgICAgIGlmIChnb29kX2luZGV4ID09IDApDQogICAgICAgICAgICB7DQogICAgICAgICAgICAgICAgcmVhZF9sZW4gPSByZWFkKG10ZF9pbmZvLnBhcnRpX2ZpbGVfZGVzYywgKHVuc2lnbmVkIGNoYXIqKXBfbWFpbiwgc2l6ZW9mKFRfRkxBR1NfSU5GTykpOw0KICAgICAgICAgICAgICAgICpwX21haW5faW5kZXggPSBpbmRleDsNCiAgICAgICAgICAgIH0NCiAgICAgICAgICAgIGVsc2UgaWYgKGdvb2RfaW5kZXggPT0gMSkNCiAgICAgICAgICAgIHsNCiAgICAgICAgICAgICAgICByZWFkX2xlbiA9IHJlYWQobXRkX2luZm8ucGFydGlfZmlsZV9kZXNjLCAod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8ubXRkX2Jsb2Nrc2l6ZSk7DQogICAgICAgIGlmIChyZXQgPT0gMCkNCiAgICAgICAgew0KICAgICAgICAgICAgLy8g0LSzybmmo6zNy7P2o6yyorj80MK12tK7v+nOu9bDDQogICAgICAgICAgICBmbGFnc19sb2coIm1haW4gZmxhZ3MgbG9jYXRpb246IFslZF0tPlslZF0iLCBtYWluX2luZGV4LCBpbmRleCk7DQogICAgICAgICAgICBtYWluX2luZGV4ID0gaW5kZXg7DQogICAgICAgICAgICBicmVhazsNCiAgICAgICAgfQ0KICAgICAgICBlbHNlIGlmIChyZXQgPT0gQkFEX0JMT0NLKQ0KICAgICAgICB7DQogICAgICAgICAgICAvLyDT9rW9u7W/6aOsz/K688z40ru/6Q0KICAgICAgICAgICAgZmxhZ3NfbG9nKCJmbGFncyBibG9jayBpbmRleCBbJWRdIGlzIGJhZCIsIGluZGV4KTsNCiAgICAgICAgICAgIGNvbnRpbnVlOw0KICAgICAgICB9DQogICAgICAgIGVsc2UNCiAgICAgICAgew0KICAgICAgICAgICAgZmxhZ3NfZXJyKCJ3cml0ZSBtYWluIGZsYWdzIGZhaWwiKTsNCiAgICAgICAgICAgIG1haW5faW5kZXggPSAtMTsNCiAgICAgICAgICAgIGJyZWFrOw0KICAgICAgICB9DQogICAgfQ0KDQogICAgZmxhZ3NfbG9nKCJiZWdpbiB0byB3cml0ZSBiYWNrdXAgZmxhZ3MiKTsNCg0KICAgIGZvciAoaW5kZXggPSAwOyBpbmRleCA8IGJsb2NrX251bTsgaW5kZXgrKykNCiAgICB7DQogICAgICAgIGlmIChpbmRleCA9PSBtYWluX2luZGV4KQ0KICAgICAgICB7DQogICAgICAgICAgICBjb250aW51ZTsNCiAgICAgICAgfQ0KDQogICAgICAgIGZsYWdzX2xvZygid3JpdGUgYmFja3VwIHRvIFslZF0gYmxvY2siLCBpbmRleCk7DQogICAgICAgIHJldCA9IHdyaXRlX2ZsYWdzX2luZm8oJm10ZF9pbmZvLCBpbmRleCwgcmVhbF93cml0ZV9jb250ZW50LCBtdGRfaW5mby5tdGRfYmxvY2tzaXplKTsNCiAgICAgICAgaWYgKHJldCA9PSAwKQ0KICAgICAgICB7DQogICAgICAgICAgICAvLyDQtLPJuaajrM3Ls/ajrLKiuPzQwrXa0ru/6c671sMNCiAgICAgICAgICAgIGZsYWdzX2xvZygiYmFja3VwIGZsYWdzIGxvY2F0aW9uOiBbJWRdLT5bJWRdIiwgYmFja19pbmRleCwgaW5kZXgpOw0KICAgICAgICAgICAgYmFja19pbmRleCA9IGluZGV4Ow0KICAgICAgICAgICAgYnJlYWs7DQogICAgICAgIH0NCiAgICAgICAgZWxzZSBpZiAocmV0ID09IEJBRF9CTE9DSykNCiAgICAgICAgew0KICAgICAgICAgICAgLy8g0/a1vbu1v+mjrM/yuvPM+NK7v+kNCiAgICAgICAgICAgIGNvbnRpbnVlOw0KICAgICAgICB9DQogICAgICAgIGVsc2UNCiAgICAgICAgew0KICAgICAgICAgICAgZmxhZ3NfZXJyKCJ3cml0ZSBiYWNrdXAgZmxhZ3MgZmFpbCIpOw0KICAgICAgICAgICAgYmFja19pbmRleCA9IC0xOw0KICAgICAgICAgICAgYnJlYWs7DQogICAgICAgIH0NCiAgICB9DQoNCiAgICBpZiAobWFpbl9pbmRleCA9PSAtMSAmJiBiYWNrX2luZGV4ID09IC0xKQ0KICAgIHsNCiAgICAgICAgZ290byBlcnJvcjsNCiAgICB9DQogICAgZWxzZQ0KICAgIHsNCiAgICAgICAgcmV0ID0gMDsNCiAgICAgICAgZ290byBlbmQ7DQogICAgfQ0KDQplcnJvcjoNCiAgICByZXQgPSAtMTsNCg0KZW5kOg0KICAgIGNsb3NlKGZkX2RzdCk7DQoJDQoJaWYoTlVMTCAhPSByZWFsX3dyaXRlX2NvbnRlbnQpDQoJew0KCQlmcmVlKHJlYWxfd3JpdGVfY29udGVudCk7DQoJCXJlYWxfd3JpdGVfY29udGVudCA9IE5VTEw7DQoJfQ0KCQ0KICAgIHJldHVybiByZXQ7DQp9DQ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kOw0KICAgICAgICB9DQoNCiAgICAgICAgcHJpbnRmKCJidWZmOiVzIiwgYnVmKTsNCg0KICAgICAgICBwYXJhID0gc3RydG9rKGJ1ZiwgIiAiKTsNCiAgICAgICAgd2hpbGUgKHBhcmEpDQogICAgICAgIHsNCiAgICAgICAgICAgIHByaW50ZigicGFyYTolcyIsIHBhcmEpOw0KICAgICAgICAgICAgaWYgKHN0cm5jbXAocGFyYSwgUFJPQ19DTURMSU5FX1NZU1RFTV9BX0ZMQUcsIHN0cmxlbihQUk9DX0NNRExJTkVfU1lTVEVNX0FfRkxBRykpID09IDApDQogICAgICAgICAgICB7DQogICAgICAgICAgICAgICAgY3VycmVudF9zeXN0ZW0gPSBTWVNURU1fSU5ERVhfMTsNCiAgICAgICAgICAgICAgICBnb3RvIGVuZDsNCiAgICAgICAgICAgIH0NCiAgICAgICAgICAgIGVsc2UgaWYgKHN0cm5jbXAocGFyYSwgUFJPQ19DTURMSU5FX1NZU1RFTV9CX0ZMQUcsIHN0cmxlbihQUk9DX0NNRExJTkVfU1lTVEVNX0JfRkxBRykpID09IDApDQogICAgICAgICAgICB7DQogICAgICAgICAgICAgICAgY3VycmVudF9zeXN0ZW0gPSBTWVNURU1fSU5ERVhfMjsNCiAgICAgICAgICAgICAgICBnb3RvIGVuZDsNCiAgICAgICAgICAgIH0NCiAgICAgICAgICAgIGVsc2UNCiAgICAgICAgICAgIHsNCiAgICAgICAgICAgICAgICAvLzoNCiAgICAgICAgICAgIH0NCiAgICAgICAgICAgIHBhcmEgPSBzdHJ0b2soTlVMTCwgIiAiKTsNCiAgICAgICAgfQ0KICAgIH0NCg0KZW5kOg0KICAgIGlmIChmZF9jbWQpDQogICAgew0KICAgICAgICBmY2xvc2UoZmRfY21kKTsNCiAgICB9DQoJDQogICAgcmV0dXJuIGN1cnJlbnRfc3lzdGVtOw0KfQ0KDQoNCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqK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