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EV4Y2VwdGlvbi4gKE9mZnNldCAzYyBpbiBVUE0gUkFNKQoJICovCgkweDdGRkZGQzA3LCAvKiBsYXN0ICovCgkJICAgIDB4RkZGRkZDRkYsIDB4RkZGRkZDRkYsIDB4RkZGRkZDRkYsCiNlbmRpZgp9OwoKLyoKICogQ2hlY2sgQm9hcmQgSWRlbnRpdHk6CiAqCiAqLwoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCkYqIEZ1bmN0aW9uOiAgICAgaW50IGNoZWNrYm9hcmQgKHZvaWQpIFAqQSpaKgogKgpQKiBQYXJhbWV0ZXJzOiAgIG5vbmUKUCoKUCogUmV0dXJudmFsdWU6ICBpbnQgLSAwIGlzIGFsd2F5cyByZXR1cm5lZAogKgpaKiBJbnRlbnRpb246ICAgIFRoaXMgZnVuY3Rpb24gaXMgdGhlIGNoZWNrYm9hcmQoKSBtZXRob2QgaW1wbGVtZW50YXRpb24KWiogICAgICAgICAgICAgICBmb3IgdGhlIGx3bW9uIGJvYXJkLiAgT25seSBhIHN0YW5kYXJkIG1lc3NhZ2UgaXMgcHJpbnRlZC4KICoKRCogRGVzaWduOiAgICAgICB3ZEBkZW54LmRlCkMqIENvZGluZzogICAgICAgd2RAZGVueC5kZQpWKiBWZXJpZmljYXRpb246IGR6dUBkZW54LmRlCiAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KaW50IGNoZWNrYm9hcmQgKHZvaWQpCnsKCXB1dHMgKCJCb2FyZDogTElDQ09OIEtvbnNvbGUgTENEM1xuIik7CglyZXR1cm4gKDApOwp9CgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKRiogRnVuY3Rpb246ICAgICBsb25nIGludCBpbml0ZHJhbSAoaW50IGJvYXJkX3R5cGUpIFAqQSpaKgogKgpQKiBQYXJhbWV0ZXJzOiAgIGludCBib2FyZF90eXBlClAqICAgICAgICAgICAgICAgIC0gVXN1YWxseSB0eXBlIG9mIHRoZSBib2FyZCAtIGlnbm9yZWQgaGVyZS4KUCoKUCogUmV0dXJudmFsdWU6ICBsb25nIGludApQKiAgICAgICAgICAgICAgICAtIFNpemUgb2YgaW5pdGlhbGl6ZWQgbWVtb3J5CiAqCloqIEludGVudGlvbjogICAgVGhpcyBmdW5jdGlvbiBpcyB0aGUgaW5pdGRyYW0oKSBtZXRob2QgaW1wbGVtZW50YXRpb24KWiogICAgICAgICAgICAgICBmb3IgdGhlIGx3bW9uIGJvYXJkLgpaKiAgICAgICAgICAgICAgIFRoZSBtZW1vcnkgY29udHJvbGxlciBpcyBpbml0aWFsaXplZCB0byBhY2Nlc3MgdGhlCloqICAgICAgICAgICAgICAgRFJBTS4KICoKRCogRGVzaWduOiAgICAgICB3ZEBkZW54LmRlCkMqIENvZGluZzogICAgICAgd2RAZGVueC5kZQpWKiBWZXJpZmljYXRpb246IGR6dUBkZW54LmRlCiAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KbG9uZyBpbnQgaW5pdGRyYW0gKGludCBib2FyZF90eXBlKQp7Cgl2b2xhdGlsZSBpbW1hcF90ICppbW1yID0gKGltbWFwX3QgKikgQ0ZHX0lNTVI7Cgl2b2xhdGlsZSBtZW1jdGw4eHhfdCAqbWVtY3RsID0gJmltbXItPmltX21lbWN0bDsKCWxvbmcgaW50IHNpemVfYjA7Cglsb25nIGludCBzaXplOCwgc2l6ZTk7CglpbnQgaTsKCgkvKgoJICogQ29uZmlndXJlIFVQTUEgZm9yIFNEUkFNCgkgKi8KCXVwbWNvbmZpZyAoVVBNQSwgKHVpbnQgKilzZHJhbV90YWJsZSwgc2l6ZW9mKHNkcmFtX3RhYmxlKS9zaXplb2YodWludCkpOwoKCW1lbWN0bC0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IHNpemU5OwoJCW1lbWN0bC0+bWVtY19tYW1yID0gQ0ZHX01BTVJfOUNPTCB8IE1BTVJfUFRBRTsKCQl1ZGVsYXkgKDUwMCk7Cgl9IGVsc2UgewkJCS8qIGJhY2sgdG8gOCBjb2x1bW5zICAgICAgICAgICAgKi8KCQlzaXplX2IwID0gc2l6ZTg7CgkJbWVtY3RsLT5tZW1jX21hbXIgPSBDRkdfTUFNUl84Q09MIHwgTUFNUl9QVEFFOwoJCXVkZWxheSAoNTAwKTsKCX0KCgkvKgoJICogRmluYWwgbWFwcGluZzoKCSAqLwoKCW1lbWN0bC0+bWVtY19vcjMgPSAoKC1zaXplX2IwKSAmIDB4RkZGRjAwMDApIHwKCQkJT1JfQ1NOVF9TQU0gfCBPUl9HNUxTIHwgU0RSQU1fVElNSU5HOwoJbWVtY3RsLT5tZW1jX2JyMyA9IChDRkdfU0RSQU1fQkFTRSAmIEJSX0JBX01TSykgfCBCUl9NU19VUE1BIHwgQlJfVjsKCXVkZWxheSAoMTAwMCk7CgoJcmV0dXJuIChzaXplX2IwKTsKfQoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCkYqIEZ1bmN0aW9uOiAgICAgc3RhdGljIGxvbmcgaW50IGRyYW1fc2l6ZSAobG9uZyBpbnQgbWFtcl92YWx1ZSwKRiogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsb25nIGludCAqYmFzZSwKRiogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsb25nIGludCBtYXhzaXplKSBQKkEqWioKICoKUCogUGFyYW1ldGVyczogICBsb25nIGludCBtYW1yX3ZhbHVlClAqICAgICAgICAgICAgICAgIC0gVmFsdWUgZm9yIE1BTVIgZm9yIHRoZSB0ZXN0ClAqICAgICAgICAgICAgICAgbG9uZyBpbnQgKmJhc2UKUCogICAgICAgICAgICAgICAgLSBCYXNlIGFkZ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Y3RsID0gJmltbXItPmltX21lbWN0bDsKCgltZW1jdGwtPm1lbWNfbWFtciA9IG1hbXJfdmFsdWU7CgoJcmV0dXJuIChnZXRfcmFtX3NpemUoYmFzZSwgbWF4c2l6ZSkpOwp9CgovKiAtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tICovCgojaWZuZGVmCVBCX0VORVRfVEVOQQojIGRlZmluZSBQQl9FTkVUX1RFTkEJKCh1aW50KTB4MDAwMDIwMDApCS8qIFBCIDE4ICovCiNlbmRpZgoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCkYqIEZ1bmN0aW9uOiAgICAgaW50IGJvYXJkX2Vhcmx5X2luaXRfZiAodm9pZCkgUCpBKloqCiAqClAqIFBhcmFtZXRlcnM6ICAgbm9uZQpQKgpQKiBSZXR1cm52YWx1ZTogIGludApQKiAgICAgICAgICAgICAgICAtIDAgaXMgYWx3YXlzIHJldHVybmVkLgogKgpaKiBJbnRlbnRpb246ICAgIFRoaXMgZnVuY3Rpb24gaXMgdGhlIGJvYXJkX2Vhcmx5X2luaXRfZigpIG1ldGhvZCBpbXBsZW1lbnRhdGlvbgpaKiAgICAgICAgICAgICAgIGZvciB0aGUgbHdtb24gYm9hcmQuCloqICAgICAgICAgICAgICAgRGlzYWJsZSBFdGhlcm5ldCBURU5BIG9uIFBvcnQgQi4KICoKRCogRGVzaWduOiAgICAgICB3ZEBkZW54LmRlCkMqIENvZGluZzogICAgICAgd2RAZGVueC5kZQpWKiBWZXJpZmljYXRpb246IGR6dUBkZW54LmRlCiAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KaW50IGJvYXJkX2Vhcmx5X2luaXRfZiAodm9pZCkKewoJdm9sYX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CQkvKiBjb25zaXN0ZW50IHN0YXRlLCBkb25lICovCgkJCWJyZWFrOwoJCX0KCQkvKiByZW1lYmVyIGxhc3Qgc3RhdGUsIGRlbGF5LCBhbmQgcmV0cnkgKi8KCQltZW1jcHkgKHRtcF9kYXRhLCBrYmRfZGF0YSwgS0VZQkRfREFUQUxFTik7CgkJdWRlbGF5ICg1MDAwKTsKCX0KfQoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCkYqIEZ1bmN0aW9uOiAgICAgaW50IG1pc2NfaW5pdF9yICh2b2lkKSBQKkEqWioKICoKUCogUGFyYW1ldGVyczogICBub25lClAqClAqIFJldHVybnZhbHVlOiAgaW50ClAqICAgICAgICAgICAgICAgIC0gMCBpcyBhbHdheXMgcmV0dXJuZWQsIGV2ZW4gaW4gdGhlIGNhc2Ugb2YgYSBrZXlib2FyZApQKiAgICAgICAgICAgICAgICAgICAgZXJyb3IuCiAqCloqIEludGVudGlvbjogICAgVGhpcyBmdW5jdGlvbiBpcyB0aGUgbWlzY19pbml0X3IoKSBtZXRob2QgaW1wbGVtZW50YXRpb24KWiogICAgICAgICAgICAgICBmb3IgdGhlIGx3bW9uIGJvYXJkLgpaKiAgICAgICAgICAgICAgIFRoZSBrZXlib2FyZCBjb250cm9sbGVyIGlzIGluaXRpYWxpemVkIGFuZCB0aGUgcmVzdWx0CloqICAgICAgICAgICAgICAgb2YgYSByZWFkIGNvcGllZCB0byB0aGUgZW52aXJvbm1lbnQgdmFyaWFibGUgImtleWJkIi4KWiogICAgICAgICAgICAgICBJZiBLRVlCRF9TRVRfREVCVUdNT0RFIGlzIGRlZmluZWQsIGEgY2hlY2sgaXMgbWFkZSBmb3IKWiogICAgICAgICAgICAgICB0aGlzIGtleSwgYW5kIGlmIGZvdW5kIGRpc3BsYXkgdG8gdGhlIExDRCB3aWxsIGJlIGVuYWJsZWQuCloqICAgICAgICAgICAgICAgVGhlIG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VybiAwOwp9CgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKRiogRnVuY3Rpb246ICAgICBzdGF0aWMgdWNoYXIgKmtleV9tYXRjaCAodWNoYXIgKmtiZF9kYXRhKSBQKkEqWioKICoKUCogUGFyYW1ldGVyczogICB1Y2hhciAqa2JkX2RhdGEKUCogICAgICAgICAgICAgICAgLSBUaGUga2V5cyB0byBtYXRjaCBhZ2FpbnN0IG91ciBtYWdpYyBkZWZpbml0aW9ucwpQKgpQKiBSZXR1cm52YWx1ZTogIHVjaGFyICoKUCogICAgICAgICAgICAgICAgLSAhPSBOVUxMOiBQb2ludGVyIHRvIHRoZSBjb3JyZXNwb25kaW5nIGNvbW1hbmQocykKUCogICAgICAgICAgICAgICAgICAgICBOVUxMOiBObyBtYWdpYyBpcyBhYm91dCB0byBoYXBwZW4KICoKWiogSW50ZW50aW9uOiAgICBDaGVjayBpZiBwcmVzc2VkIGtleShzKSBtYXRjaCBtYWdpYyBzZXF1ZW5jZSwKWiogICAgICAgICAgICAgICBhbmQgcmV0dXJuIHRoZSBjb21tYW5kIHN0cmluZyBhc3NvY2lhdGVkIHdpdGggdGhhdCBrZXkocykuCloqCloqICAgICAgICAgICAgICAgSWYgbm8ga2V5IHByZXNzIHdhcyBkZWNvZGVkLCBOVUxMIGlzIHJldHVybmVkLgpaKgpaKiAgICAgICAgICAgICAgIE5vdGU6IHRoZSBmaXJzdCBjaGFyYWN0ZXIgb2YgdGhlIGFyZ3VtZW50IHdpbGwgYmUKWiogICAgICAgICAgICAgICAgICAgICBvdmVyd3JpdHRlbiB3aXRoIHRoZSAibWFnaWMgY2hhcmN0ZXIgY29kZSIgb2YgdGhlCloqICAgICAgICAgICAgICAgICAgICAgZGVjb2RlZCBrZXkocyksIG9yICdcMCcuCloqCloqICAgICAgICAgICAgICAgTm90ZTogdGhlIHN0cmluZyBwb2ludHMgdG8gc3RhdGljIGVudmlyb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iBDT05GSUdfUFJFQk9PVCAqLwoKLyotLS0tLS0tLS0tLS0tLS1Cb2FyZCBTcGVjaWFsIENvbW1hbmRzOiBQSUMgcmVhZC93cml0ZSAtLS0tLS0tLS0tLS0tLS0qLwoKI2lmIChDT05GSUdfQ09NTUFORFMgJiBDRkdfQ01EX0JTUCkKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCkYqIEZ1bmN0aW9uOiAgICAgaW50IGRvX3BpYyAoY21kX3RibF90ICpjbWR0cCwgaW50IGZsYWcsCkYqICAgICAgICAgICAgICAgICAgICAgICAgICAgaW50IGFyZ2MsIGNoYXIgKmFyZ3ZbXSkgUCpBKloqCiAqClAqIFBhcmFtZXRlcnM6ICAgY21kX3RibF90ICpjbWR0cApQKiAgICAgICAgICAgICAgICAtIFBvaW50ZXIgdG8gb3VyIGNvbW1hbmQgdGFibGUgZW50cnkKUCogICAgICAgICAgICAgICBpbnQgZmxhZwpQKiAgICAgICAgICAgICAgICAtIElmIHRoZSBDTURfRkxBR19SRVBFQVQgYml0IGlzIHNldCwgdGhlbiB0aGlzIGNhbGwgaXMKUCogICAgICAgICAgICAgICAgICBhIHJlcGV0aXRpb24KUCogICAgICAgICAgICAgICBpbnQgYXJnYwpQKiAgICAgICAgICAgICAgICAtIEFyZ3VtZW50IGNvdW50ClAqICAgICAgICAgICAgICAgY2hhciAqYXJndltdClAqICAgICAgICAgICAgICAgIC0gQXJyYXkgb2YgdGhlIGFjdHVhbCBhcmd1bWVudHMKUCoKUCogUmV0dXJudmFsdWU6ICBpbnQKUCogICAgICAgICAgICAgICAgLSAwICBUaGUgY29tbWFuZCB3YXMgaGFuZGxlZCBzdWNjZXNzZnVsbHkKUCogICAgICAgICAgICAgICAgICAxICBBbiBlcnJvciBvY2N1cnJlZAogKgpaKiBJbnRlbnRpb246ICAgIEltcGxlbWVudCB0aGUgInBpYyBbcmVhZHx3cml0ZV0iIGN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UMgd3JpdGU6IHJlZyAlMDJ4IHZhbCAweCUwMng6ICUwMnggPT4gIiwKCQkJCXJlZywgdmFsLCBwaWNfcmVhZCAocmVnKSk7CgkJcGljX3dyaXRlIChyZWcsIHZhbCk7CgkJcHJpbnRmICgiJTAyeFxuXG4iLCBwaWNfcmVhZCAocmVnKSk7CgkJcmV0dXJuIDA7CglkZWZhdWx0OgoJCWJyZWFrOwoJfQoJcHJpbnRmICgiVXNhZ2U6XG4lc1xuIiwgY21kdHAtPnVzYWdlKTsKCXJldHVybiAxOwp9ClVfQk9PVF9DTUQoCglwaWMsCTQsCTEsCWRvX3BpYywKCSJwaWMgICAgIC0gcmVhZCBhbmQgd3JpdGUgUElDIHJlZ2lzdGVyc1xuIiwKCSJyZWFkICByZWcgICAgICAtIHJlYWQgUElDIHJlZ2lzdGVyIGByZWcnXG4iCgkicGljIHdyaXRlIHJlZyB2YWwgIC0gd3JpdGUgdmFsdWUgYHZhbCcgdG8gUElDIHJlZ2lzdGVyIGByZWcnXG4iCik7CgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKRiogRnVuY3Rpb246ICAgICBpbnQgZG9fa2JkIChjbWRfdGJsX3QgKmNtZHRwLCBpbnQgZmxhZywKRiogICAgICAgICAgICAgICAgICAgICAgICAgICBpbnQgYXJnYywgY2hhciAqYXJndltdKSBQKkEqWioKICoKUCogUGFyYW1ldGVyczogICBjbWRfdGJsX3QgKmNtZHRwClAqICAgICAgICAgICAgICAgIC0gUG9pbnRlciB0byBvdXIgY29tbWFuZCB0YWJsZSBlbnRyeQpQKiAgICAgICAgICAgICAgIGludCBmbGFnClAqICAgICAgICAgICAgICAgIC0gSWYgdGhlIENNRF9GTEFHX1JFUEVBVCBiaXQgaXMgc2V0LCB0aGVuIHRoaXMgY2FsbCBpcwpQKiAgICAgICAgICAgICAgICAgIGEgcmVwZXRpdGlvbgpQKiAgICAgICAgICAgICAgIGludCBhcmdjClAqICAgICAgICAgICAgICAgIC0gQXJndW1lbnQgY291bnQKUCogICAgICAgICAgICAgICBjaGFyICphcmd2W10KUCogICAgICAgICAgICAgICAgLSBBcnJheSBvZiB0aGUgYWN0dWFsIGFyZ3VtZW50cwpQKgpQKiBSZXR1cm52YWx1ZTogIGludApQKiAgICAgICAgICAgICAgICAtIDAgaXMgYWx3YXlzIHJldHVybmVkLgogKgpaKiBJbnRlbnRpb246ICAgIEltcGxlbWVudCB0aGUgImtiZCIgY29tbWFuZC4KWiogICAgICAgICAgICAgICBUaGUga2V5Ym9hcmQgc3RhdHVzIGlzIHJlYWQuICBUaGUgcmVzdWx0IGlzIHByaW50ZWQgb24KWiogICAgICAgICAgICAgICB0aGUgY29uc29sZSBhbmQgd3JpdHRlbiBpbnRvIHRoZSAia2V5YmQiIGVudmlyb25tZW50CloqICAgICAgICAgICAgICAgdmFyaWFibGUuCiAqCkQqIERlc2lnbjogICAgICAgd2RAZGVueC5kZQpDKiBDb2Rpbmc6ICAgICAgIHdkQGRlbnguZGUKViogVmVyaWZpY2F0aW9uOiBkenVAZGVueC5kZQogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCmludCBkb19rYmQgKGNtZF90YmxfdCAqY21kdHAsIGludCBmbGFnLCBpbnQgYXJnYywgY2hhciAqYXJndltdKQp7Cgl1Y2hhciBrYmRfZGF0YVtLRVlCRF9EQVRBTEVOXTsKCXVjaGFyIGtleWJkX2VudlsyICogS0VZQkRfREFUQUxFTiArIDFdOwoJdWNoYXIgdmFsOwoJaW50IGk7CgojaWYgMCAvKiBEb25lIGluIGtiZF9pbml0ICovCglpMmNfaW5pdCAoQ0ZHX0kyQ19TUEVFRCwgQ0ZHX0kyQ19TTEFWRSk7CiNlbmRpZgoKCS8qIFJlYWQga2V5cyAqLwoJdmFsID0gS0VZQkRfQ01EX1JFQURfS0VZUzsKCWkyY193cml0ZSAoa2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pdGlvbgpQKiAgICAgICAgICAgICAgIGludCBhcmdjClAqICAgICAgICAgICAgICAgIC0gQXJndW1lbnQgY291bnQKUCogICAgICAgICAgICAgICBjaGFyICphcmd2W10KUCogICAgICAgICAgICAgICAgLSBBcnJheSBvZiB0aGUgYWN0dWFsIGFyZ3VtZW50cwpQKgpQKiBSZXR1cm52YWx1ZTogIGludApQKiAgICAgICAgICAgICAgICAtIDAgIFRoZSBjb21tYW5kIHdhcyBoYW5kbGVkIHN1Y2Nlc3NmdWxseQpQKiAgICAgICAgICAgICAgICAgIDEgIEFuIGVycm9yIG9jY3VycmVkCiAqCloqIEludGVudGlvbjogICAgSW1wbGVtZW50IHRoZSAibHNiIFtvbnxvZmZdIiBjb21tYW5kcy4KWiogICAgICAgICAgICAgICBUaGUgbHNiIGlzIHN3aXRjaGVkIGFjY29yZGluZyB0byB0aGUgZmlyc3QgcGFyYW1ldGVyIGJ5CloqICAgICAgICAgICAgICAgYnkgc2lnbmFsaW5nIHRoZSBQSUMgSS9PIGV4cGFuZGVyLgpaKiAgICAgICAgICAgICAgIENhbGxlZCB3aXRoIG5vIGFyZ3VtZW50cywgdGhlIGN1cnJlbnQgc2V0dGluZyBpcwpaKiAgICAgICAgICAgICAgIHByaW50ZWQuCiAqCkQqIERlc2lnbjogICAgICAgd2RAZGVueC5kZQpDKiBDb2Rpbmc6ICAgICAgIHdkQGRlbnguZGUKViogVmVyaWZpY2F0aW9uOiBkenVAZGVueC5kZQogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCmludCBkb19sc2IgKGNtZF90YmxfdCAqY21kdHAsIGludCBmbGFnLCBpbnQgYXJnYywgY2hhciAqYXJndltdKQp7Cgl1Y2hhciB2YWw7CglpbW1hcF90ICppbW1yID0gKGltbWFwX3QgKikgQ0ZHX0lNTVI7CgoJc3dpdGNoIChhcmdjKSB7CgljYXNlIDE6CQkJCQkvKiBsc2IgLSBw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Igc3dpdGNoXG4iLAoJIm9uICAtIHN3aXRjaCBMU0Igb25cbiIKCSJsc2Igb2ZmIC0gc3dpdGNoIExTQiBvZmZcbiIKCSJsc2IgICAgIC0gcHJpbnQgY3VycmVudCBzZXR0aW5nXG4iCik7CgojZW5kaWYgLyogQ0ZHX0NNRF9CU1AgKi8KCi8qLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0gVXRpbGl0aWVzIC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tKi8KLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCkYqIEZ1bmN0aW9uOiAgICAgdWNoYXIgcGljX3JlYWQgKHVjaGFyIHJlZykgUCpBKloqCiAqClAqIFBhcmFtZXRlcnM6ICAgdWNoYXIgcmVnClAqICAgICAgICAgICAgICAgIC0gUmVnaXN0ZXIgdG8gcmVhZApQKgpQKiBSZXR1cm52YWx1ZTogIHVjaGFyClAqICAgICAgICAgICAgICAgIC0gVmFsdWUgcmVhZCBmcm9tIHJlZ2lzdGVyCiAqCloqIEludGVudGlvbjogICAgUmVhZCBhIHJlZ2lzdGVyIGZyb20gdGhlIFBJQyBJL08gZXhwYW5kZXIuCiAqCkQqIERlc2lnbjogICAgICAgd2RAZGVueC5kZQpDKiBDb2Rpbmc6ICAgICAgIHdkQGRlbnguZGUKViogVmVyaWZpY2F0aW9uOiBkenVAZGVueC5kZQogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCnVjaGFyIHBpY19yZWFkICh1Y2hhciByZWcpCnsKCXJldHVybiAoaTJjX3JlZ19yZWFkIChDRkdfSTJDX1BJQ0lPX0FERFIsIHJlZykpOwp9CgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKRiogRnVuY3Rpb246ICAgICB2b2lkIHBpY193cml0ZSAodWNoYXIgcmVnLCB1Y2hhciB2YWwpIFAqQSpaKgogKgpQKiBQYXJhbWV0ZXJzOiAgIHVjaGFyIHJlZwpQKiAgICAgICAgICAgICAgICAtIFJlZ2lzdGVyIHRvIHJlYWQKUCogICAgICAgICAgICAgICB1Y2hhciB2YWwKUCogICAgICAgICAgICAgICAgLSBWYWx1ZSB0byB3cml0ZQpQKgpQKiBSZXR1cm52YWx1ZTogIG5vbmUKICoKWiogSW50ZW50aW9uOiAgICBXcml0ZSB0byBhIHJlZ2lzdGVyIG9uIHRoZSBQSUMgSS9PIGV4cGFuZGVyLgogKgpEKiBEZXNpZ246ICAgICAgIHdkQGRlbnguZGUKQyogQ29kaW5nOiAgICAgICB3ZEBkZW54LmRlClYqIFZlcmlmaWNhdGlvbjogZHp1QGRlbnguZGUKICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwp2b2lkIHBpY193cml0ZSAodWNoYXIgcmVnLCB1Y2hhciB2YWwpCnsKCWkyY19yZWdfd3JpdGUgKENGR19JMkNfUElDSU9fQUREUiwgcmVnLCB2YWwpOwp9CgovKi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0gQm9hcmQgQ29udHJvbCBGdW5jdGlvbnMgLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSovCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgpGKiBGdW5jdGlvbjogICAgIHZvaWQgYm9hcmRfcG93ZXJvZmYgKHZvaWQpIFAqQSpaKgogKgpQKiBQYXJhbWV0ZXJzOiAgIG5vbmUKUCoKUCogUmV0dXJudmFsdWU6ICBub25lCiAqCloqIEludGVudGlvbjogICAgVHVybiBvZmYgdGhlIGJhdHRlcnkgcG93ZXIgYW5kIGxvb3AgZW5kbGVzcywgc28gdGhpcwpaKiA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