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8sIF9OT1RfVVNFRF8sIF9OT1RfVVNFRF8sIF9OT1RfVVNFRF8sCgkvKgoJICogRXhjZXB0aW9uLiAoT2Zmc2V0IDNjIGluIFVQTSBSQU0pCgkgKi8KCTB4N0ZGRkZDMDcsIC8qIGxhc3QgKi8KCQkgICAgMHhGRkZGRkNGRiwgMHhGRkZGRkNGRiwgMHhGRkZGRkNGRiwKI2VuZGlmCn07CgovKgogKiBDaGVjayBCb2FyZCBJZGVudGl0eToKICoKICovCgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKRiogRnVuY3Rpb246ICAgICBpbnQgY2hlY2tib2FyZCAodm9pZCkgUCpBKloqCiAqClAqIFBhcmFtZXRlcnM6ICAgbm9uZQpQKgpQKiBSZXR1cm52YWx1ZTogIGludCAtIDAgaXMgYWx3YXlzIHJldHVybmVkCiAqCloqIEludGVudGlvbjogICAgVGhpcyBmdW5jdGlvbiBpcyB0aGUgY2hlY2tib2FyZCgpIG1ldGhvZCBpbXBsZW1lbnRhdGlvbgpaKiAgICAgICAgICAgICAgIGZvciB0aGUgbHdtb24gYm9hcmQuICBPbmx5IGEgc3RhbmRhcmQgbWVzc2FnZSBpcyBwcmludGVkLgogKgpEKiBEZXNpZ246ICAgICAgIHdkQGRlbnguZGUKQyogQ29kaW5nOiAgICAgICB3ZEBkZW54LmRlClYqIFZlcmlmaWNhdGlvbjogZHp1QGRlbnguZGUKICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwppbnQgY2hlY2tib2FyZCAodm9pZCkKewoJcHV0cyAoIkJvYXJkOiBMSUNDT04gS29uc29sZSBMQ0QzXG4iKTsKCXJldHVybiAoMCk7Cn0KCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgpGKiBGdW5jdG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paKgogKgpQKiBQYXJhbWV0ZXJzOiAgIGxvbmcgaW50IG1hbXJfdmFsdWUKUCogICAgICAgICAgICAgICAgLSBWYWx1ZSBmb3IgTUFNUiBmb3IgdGhlIHRlc3QKUCogICAgICAgICAgICAgICBsb25nIGludCAqYmFzZQpQKiAgICAgICAgICAgICAgICAtIEJhc2UgYWRkcmVzcyBmb3IgdGhlIHRlc3QKUCogICAgICAgICAgICAgICBsb25nIGludCBtYXhzaXplClAqICAgICAgICAgICAgICAgIC0gTWF4aW11bSBzaXplIHRvIHRlc3QgZm9yClAqClAqIFJldHVybnZhbHVlOiAgbG9uZyBpbnQKUCogICAgICAgICAgICAgICAgLSBTaXplIG9mIHByb2JlZCBtZW1vcnkKICoKWiogSW50ZW50aW9uOiAgICBDaGVjayBtZW1vcnkgcmFuZ2UgZm9yIHZhbGlkIFJBTS4gQSBzaW1wbGUgbWVtb3J5IHRlc3QKWiogICAgICAgICAgICAgICBkZXRlcm1pbmVzIHRoZSBhY3R1YWxseSBhdmFpbGFibGUgUkFNIHNpemUgYmV0d2VlbgpaKiAgICAgICAgICAgICAgIGFkZHJlc3NlcyBgYmFzZScgYW5kIGBiYXNlICsgbWF4c2l6ZScuIFNvbWUgKG5vdCBhbGwpCloqICAgICAgICAgICAgICAgaGFyZHdhcmUgZXJyb3JzIGFyZSBkZXRlY3RlZDoKWiogICAgICAgICAgICAgICAgLSBzaG9ydCBiZXR3ZWVuIGFkZHJlc3MgbGluZXMKWiogICAgICAgICAgICAgICAgLSBzaG9ydCBiZXR3ZWVuIGRhdGEgbGluZXMKICoKRCogRGVzaWduOiAgICAgICB3ZEBkZW54LmRlCkMqIENvZGluZzogICAgICAgd2RAZGVueC5kZQpWKiBWZXJpZmljYXRpb246IGR6dUBkZW54LmRlCiAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8Kc3RhdGljIGxvbmcgaW50IGRyYW1fc2l6ZSA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DAsIDAsIGtiZF9kYXRhLCBLRVlCRF9EQVRBTEVOKTsKCgkJaWYgKG1lbWNtcChrYmRfZGF0YSwgdG1wX2RhdGEsIEtFWUJEX0RBVEFMRU4pID09IDApIHsKCQkJLyogY29uc2lzdGVudCBzdGF0ZSwgZG9uZSAqLwoJCQlicmVhazsKCQl9CgkJLyogcmVtZWJlciBsYXN0IHN0YXRlLCBkZWxheSwgYW5kIHJldHJ5ICovCgkJbWVtY3B5ICh0bXBfZGF0YSwga2JkX2RhdGEsIEtFWUJEX0RBVEFMRU4pOwoJCXVkZWxheSAoNTAwMCk7Cgl9Cn0KCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgpGKiBGdW5jdGlvbjogICAgIGludCBtaXNjX2luaXRfciAodm9pZCkgUCpBKloqCiAqClAqIFBhcmFtZXRlcnM6ICAgbm9uZQpQKgpQKiBSZXR1cm52YWx1ZTogIGludApQKiAgICAgICAgICAgICAgICAtIDAgaXMgYWx3YXlzIHJldHVybmVkLCBldmVuIGluIHRoZSBjYXNlIG9mIGEga2V5Ym9hcmQKUCogICAgICAgICAgICAgICAgICAgIGVycm9yLgogKgpaKiBJbnRlbnRpb246ICAgIFRoaXMgZnVuY3Rpb24gaXMgdGhlIG1pc2NfaW5pdF9yKCkgbWV0aG9kIGltcGxlbWVudGF0aW9uCloqICAgICAgICAgICAgICAgZm9yIHRoZSBsd21vbiBib2FyZC4KWiogICAgICAgICAgICAgICBUaGUga2V5Ym9hcmQgY29udHJvbGxlciBpcyBpbml0aWFsaXplZCBhbmQgdGhlIHJlc3VsdApaKiAgICAgICAgICAgICAgIG9mIGEgcmVhZCBjb3BpZWQgdG8gdGhlIGVudmlyb25tZW50IHZhcmlhYmxlICJrZXliZCIuCloqICAgICAgICAgICAgICAgSWYgS0VZQkRfU0VUX0RFQlVHTU9ERSBpcyBkZWZpbmVkLCBhIGNoZWNrIGlzIG1hZGUgZm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rKSwKCQlnZC0+cmFtX3NpemUgPj4gMjAsCgkJZ2QtPmJkLT5iaV9mbGFzaHNpemUgPj4gMjAgKTsKI2VuZGlmIC8qIENPTkZJR19MQ0RfSU5GT19CRUxPV19MT0dPICovCn0KI2VuZGlmIC8qIENPTkZJR19MQ0RfSU5GTyAqLwoKLyotLS0tLS0tLS0tLS0tLS1Cb2FyZCBTcGVjaWFsIENvbW1hbmRzOiBQSUMgcmVhZC93cml0ZSAtLS0tLS0tLS0tLS0tLS0qLwoKI2lmIGRlZmluZWQoQ09ORklHX0NNRF9CU1ApCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgpGKiBGdW5jdGlvbjogICAgIGludCBkb19waWMgKGNtZF90YmxfdCAqY21kdHAsIGludCBmbGFnLApGKiAgICAgICAgICAgICAgICAgICAgICAgICAgIGludCBhcmdjLCBjaGFyICphcmd2W10pIFAqQSpaKgogKgpQKiBQYXJhbWV0ZXJzOiAgIGNtZF90YmxfdCAqY21kdHAKUCogICAgICAgICAgICAgICAgLSBQb2ludGVyIHRvIG91ciBjb21tYW5kIHRhYmxlIGVudHJ5ClAqICAgICAgICAgICAgICAgaW50IGZsYWcKUCogICAgICAgICAgICAgICAgLSBJZiB0aGUgQ01EX0ZMQUdfUkVQRUFUIGJpdCBpcyBzZXQsIHRoZW4gdGhpcyBjYWxsIGlzClAqICAgICAgICAgICAgICAgICAgYSByZXBldGl0aW9uClAqICAgICAgICAgICAgICAgaW50IGFyZ2MKUCogICAgICAgICAgICAgICAgLSBBcmd1bWVudCBjb3VudApQKiAgICAgICAgICAgICAgIGNoYXIgKmFyZ3ZbXQpQKiAgICAgICAgICAgICAgICAtIEFycmF5IG9mIHRoZSBhY3R1YWwgYXJndW1lbnRzClAqClAqIFJldHVybnZhbHVlOiAgaW50ClAqICAgICAgICAgICAgICAgIC0gMCAgVGhlIGNvbW1hbmQgd2FzIGhhbmRsZWQgc3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ICAgICAgICAtIElmIHRoZSBDTURfRkxBR19SRVBFQVQgYml0IGlzIHNldCwgdGhlbiB0aGlzIGNhbGwgaXMKUCogICAgICAgICAgICAgICAgICBhIHJlcGV0aXRpb24KUCogICAgICAgICAgICAgICBpbnQgYXJnYwpQKiAgICAgICAgICAgICAgICAtIEFyZ3VtZW50IGNvdW50ClAqICAgICAgICAgICAgICAgY2hhciAqYXJndltdClAqICAgICAgICAgICAgICAgIC0gQXJyYXkgb2YgdGhlIGFjdHVhbCBhcmd1bWVudHMKUCoKUCogUmV0dXJudmFsdWU6ICBpbnQKUCogICAgICAgICAgICAgICAgLSAwIGlzIGFsd2F5cyByZXR1cm5lZC4KICoKWiogSW50ZW50aW9uOiAgICBJbXBsZW1lbnQgdGhlICJrYmQiIGNvbW1hbmQuCloqICAgICAgICAgICAgICAgVGhlIGtleWJvYXJkIHN0YXR1cyBpcyByZWFkLiAgVGhlIHJlc3VsdCBpcyBwcmludGVkIG9uCloqICAgICAgICAgICAgICAgdGhlIGNvbnNvbGUgYW5kIHdyaXR0ZW4gaW50byB0aGUgImtleWJkIiBlbnZpcm9ubWVudApaKiAgICAgICAgICAgICAgIHZhcmlhYmxlLgogKgpEKiBEZXNpZ246ICAgICAgIHdkQGRlbnguZGUKQyogQ29kaW5nOiAgICAgICB3ZEBkZW54LmRlClYqIFZlcmlmaWNhdGlvbjogZHp1QGRlbnguZGUKICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwppbnQgZG9fa2JkIChjbWRfdGJsX3QgKmNtZHRwLCBpbnQgZmxhZywgaW50IGFyZ2MsIGNoYXIgKmFyZ3ZbXSkKewoJdWNoYXIga2JkX2RhdGFbS0VZQkRfREFUQUxFTl07CgljaGFyIGtleWJkX2VudlsyICogS0VZQkRfREFUQUxFTiArIDFdOwoJdWNoYXIgdmFsOwoJaW50IGk7CgojaWYgMCAvKiBEb25lIGluIGtiZF9pbml0ICovCglpMmNfaW5pdCAoQ09ORklHX1NZU19JMkNfU1BFRUQsIENPTkZJR19TWVNfSTJDX1NMQVZFKTsKI2VuZGlmCgoJLyogUmVhZCBrZXlzICovCgl2YWwgPSBLRVlCRF9DTURfUkVBRF9LRVlTOwoJaTJjX3dyaXRlIChrYmRfYWRkciwgMCwgMCwgJnZhbCwgMSk7CglpMmNfcmVhZCAoa2JkX2FkZHIsIDAsIDAsIGtiZF9kYXRhLCBLRVlCRF9EQVRBTEVOKTsKCglwdXRzICgiS2V5czoiKTsKCWZvciAoaSA9IDA7IGkgPCBLRVlCRF9EQVRBTEVOOyArK2kpIHsKCQlzcHJpbnRmIChrZXliZF9lbnYgKyBpICsgaSwgIiUwMlgiLCBrYmRfZGF0YVtpXSk7CgkJcHJpbnRmICgiICUwMngiLCBrYmRfZGF0YVtpXSk7Cgl9CglwdXRjICgnXG4nKTsKCXNldGVudiAoImtleWJkIiwga2V5YmRfZW52KTsKCXJldHVybiAwOwp9CgpVX0JPT1RfQ01EKAoJa2JkLAkxLAkxLAlkb19rYmQsCgkia2JkICAgICAtIHJlYWQga2V5Ym9hcmQgc3RhdHVzXG4iLAoJTlVMTAopOwoKLyogUmVhZCBhbmQgc2V0IExTQiBzd2l0Y2ggKi8KI2RlZmluZSBDT05GSUdfU1lTX1BDX1RYRDFfRU5BCQkweDAwMDgJCS8qIFBDLjEyICovCgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKRiogRnVuY3Rpb246ICAgICBpbnQgZG9fbHNiIChjbWRfdGJsX3QgKmNtZHRwLCBpbnQgZmxhZywKRiogICAgICAgICAgICAgICAgICAgICAgICAgICBpbnQgYXJnYywgY2hhciAqYXJndltdKSBQKkEqWioKICoKUCogUGFyYW1ldGVyczogICBjbWRfdGJsX3QgKmNtZHRwClAqICAgICAgICAgICAgICAgIC0gUG9pbnRlciB0byBvdXIgY29tbWFuZCB0YWJsZSBlbnRyeQpQKiAgICAgICAgICAgICAgIGludCBmbGFnClAqICAgICAgICAgICAgICAgIC0gSWYgdGhlIENNRF9GTEFHX1JFUEVBVCBiaXQgaXMgc2V0LCB0aGVuIHRoaXMgY2FsbCBpcwpQKiAgICAgICAgICAgICAgICAgIGEgcmVwZXRpdGlvbgpQKiAgICAgICAgICAgICAgIGludCBhcmdjClAqICAgICAgICAgICAgICAgIC0gQXJndW1lbnQgY291bnQKUCogICAgICAgICAgICAgICBjaGFyICphcmd2W10KUCogICAgICAgICAgICAgICAgLSBBcnJheSBvZiB0aGUgYWN0dWFsIGFyZ3VtZW50cwpQKgpQKiBSZXR1cm52YWx1ZTogIGludApQKiAgICAgICAgICAgICAgICAtIDAgIFRoZSBjb21tYW5kIHdhcyBoYW5kbGVkIHN1Y2Nlc3NmdWxseQpQKiAgICAgICAgICAgICAgICAgIDEgIEFuIGVycm9yIG9jY3VycmVkCiAqCloqIEludGVudGlvbjogICAgSW1wbGVtZW50IHRoZSAibHNiIFtvbnxvZmZdIiBjb21tYW5kcy4KWiogICAgICAgICAgICAgICBUaGUgbHNiIGlzIHN3aXRjaGVkIGFjY29yZGluZyB0byB0aGUgZmlyc3QgcGFyYW1ldGVyIGJ5CloqICAgICAgICAgICAgICAgYnkgc2lnbmFsaW5nIHRoZSBQSUMgSS9PIGV4cGFuZGVyLgpaKiAgICAgICAgICAgICAgIENhbGxlZCB3aXRoIG5vIGFyZ3VtZW50cywgdGhlIGN1cnJlbnQgc2V0dGluZyBpcwpaKiAgICAgICAgICAgICAgIHByaW50ZWQuCiAqCkQqIERlc2lnbjogICAgICAgd2RAZGVueC5kZQpDKiBDb2Rpbmc6ICAgICAgIHdkQGRlbnguZGUKViogVmVyaWZpY2F0aW9uOiBkenVAZGVueC5kZQogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCmludCBkb19sc2IgKGNtZF90YmxfdCAqY21kdHAsIGludC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y2hhciBwaWNfcmVhZCAodWNoYXIgcmVnKQp7CglyZXR1cm4gKGkyY19yZWdfcmVhZCAoQ09ORklHX1NZU19JMkNfUElDSU9fQUREUiwgcmVnKSk7Cn0KCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgpGKiBGdW5jdGlvbjogICAgIHZvaWQgcGljX3dyaXRlICh1Y2hhciByZWcsIHVjaGFyIHZhbCkgUCpBKloqCiAqClAqIFBhcmFtZXRlcnM6ICAgdWNoYXIgcmVnClAqICAgICAgICAgICAgICAgIC0gUmVnaXN0ZXIgdG8gcmVhZApQKiAgICAgICAgICAgICAgIHVjaGFyIHZhbApQKiAgICAgICAgICAgICAgICAtIFZhbHVlIHRvIHdyaXRlClAqClAqIFJldHVybnZhbHVlOiAgbm9uZQogKgpaKiBJbnRlbnRpb246ICAgIFdyaXRlIHRvIGEgcmVnaXN0ZXIgb24gdGhlIFBJQyBJL08gZXhwYW5kZXIuCiAqCkQqIERlc2lnbjogICAgICAgd2RAZGVueC5kZQpDKiBDb2Rpbmc6ICAgICAgIHdkQGRlbnguZGUKViogVmVyaWZpY2F0aW9uOiBkenVAZGVueC5kZQogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCnZvaWQgcGljX3dyaXRlICh1Y2hhciByZWcsIHVjaGFyIHZhbCkKewoJaTJjX3JlZ193cml0ZSAoQ09ORklHX1NZU19JMkNfUElDSU9fQUREUiwgcmVnLCB2YWwpOwp9CgovKi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0gQm9hcmQgQ29udHJvbCBGdW5jdGlvbnMgLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSovCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgpGKiBGdW5jdGlvbjogICAgIHZva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