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kKCSAqLwoJMHg3RkZGRkMwNywgLyogbGFzdCAqLwoJCSAgICAweEZGRkZGQ0ZGLCAweEZGRkZGQ0ZGLCAweEZGRkZGQ0ZGLAojZW5kaWYKfTsKCi8qCiAqIENoZWNrIEJvYXJkIElkZW50aXR5OgogKgogKi8KCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgpGKiBGdW5jdGlvbjogICAgIGludCBjaGVja2JvYXJkICh2b2lkKSBQKkEqWioKICoKUCogUGFyYW1ldGVyczogICBub25lClAqClAqIFJldHVybnZhbHVlOiAgaW50IC0gMCBpcyBhbHdheXMgcmV0dXJuZWQKICoKWiogSW50ZW50aW9uOiAgICBUaGlzIGZ1bmN0aW9uIGlzIHRoZSBjaGVja2JvYXJkKCkgbWV0aG9kIGltcGxlbWVudGF0aW9uCloqICAgICAgICAgICAgICAgZm9yIHRoZSBsd21vbiBib2FyZC4gIE9ubHkgYSBzdGFuZGFyZCBtZXNzYWdlIGlzIHByaW50ZWQuCiAqCkQqIERlc2lnbjogICAgICAgd2RAZGVueC5kZQpDKiBDb2Rpbmc6ICAgICAgIHdkQGRlbnguZGUKViogVmVyaWZpY2F0aW9uOiBkenVAZGVueC5kZQogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCmludCBjaGVja2JvYXJkICh2b2lkKQp7CglwdXRzICgiQm9hcmQ6IExJQ0NPTiBLb25zb2xlIExDRDJcbiIpOwoJcmV0dXJuICgwKTsKfQoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCkYqIEZ1bmN0aW9uOiAgICAgbG9uZyBpbnQgaW5pdGRyYW0gKGludCBib2FyZF90eXBlKSBQKkEqWioKICoKUCogUGFyYW1ldGVyczogICBpbnQgYm9hcmRfdHlwZQpQKiAgICAgICAgICAgICAgICAtIFVzdWFsbHkgdHlwZSBvZiB0aGUgYm9hcmQgLSBpZ25vcmVkIGhlcmUuClAqClAqIFJldHVybnZhbHVlOiAgbG9uZyBpbnQKUCogICAgICAgICAgICAgICAgLSBTaXplIG9mIGluaXRpYWxpemVkIG1lbW9yeQogKgpaKiBJbnRlbnRpb246ICAgIFRoaXMgZnVuY3Rpb24gaXMgdGhlIGluaXRkcmFtKCkgbWV0aG9kIGltcGxlbWVudGF0aW9uCloqICAgICAgICAgICAgICAgZm9yIHRoZSBsd21vbiBib2FyZC4KWiogICAgICAgICAgICAgICBUaGUgbWVtb3J5IGNvbnRyb2xsZXIgaXMgaW5pdGlhbGl6ZWQgdG8gYWNjZXNzIHRoZQpaKiAgICAgICAgICAgICAgIERSQU0uCiAqCkQqIERlc2lnbjogICAgICAgd2RAZGVueC5kZQpDKiBDb2Rpbmc6ICAgICAgIHdkQGRlbnguZGUKViogVmVyaWZpY2F0aW9uOiBkenVAZGVueC5kZQogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCmxvbmcgaW50IGluaXRkcmFtIChpbnQgYm9hcmRfdHlwZSkKewoJdm9sYXRpbGUgaW1tYXBfdCAqaW1tciA9IChpbW1hcF90ICopIENGR19JTU1SOwoJdm9sYXRpbGUgbWVtY3RsOHh4X3QgKm1lbWN0bCA9ICZpbW1yLT5pbV9tZW1jdGw7Cglsb25nIGludCBzaXplX2IwOwoJbG9uZyBpbnQgc2l6ZTgsIHNpemU5OwoJaW50IGk7CgoJLyoKCSAqIENvbmZpZ3VyZSBVUE1BIGZvciBTRFJBTQoJICovCgl1cG1jb25maWcgKFVQTUEsICh1aW50ICopc2RyYW1fdGFibGUsIHNpemVvZihzZHJhbV90YWJsZSkvc2l6ZW9mKHVpbnQpKTsKCgltZW1jdGwtPm1lbWNfbXB0cHIgPSBDRkdfTVBUUFI7CgoJLyogYnVyc3QgbGV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gICAgIGxvbmcgaW50IG1heHNpemUKUCogICAgICAgICAgICAgICAgLSBNYXhpbXVtIHNpemUgdG8gdGVzdCBmb3IKUCoKUCogUmV0dXJudmFsdWU6ICBsb25nIGludApQKiAgICAgICAgICAgICAgICAtIFNpemUgb2YgcHJvYmVkIG1lbW9yeQogKgpaKiBJbnRlbnRpb246ICAgIENoZWNrIG1lbW9yeSByYW5nZSBmb3IgdmFsaWQgUkFNLiBBIHNpbXBsZSBtZW1vcnkgdGVzdApaKiAgICAgICAgICAgICAgIGRldGVybWluZXMgdGhlIGFjdHVhbGx5IGF2YWlsYWJsZSBSQU0gc2l6ZSBiZXR3ZWVuCloqICAgICAgICAgICAgICAgYWRkcmVzc2VzIGBiYXNlJyBhbmQgYGJhc2UgKyBtYXhzaXplJy4gU29tZSAobm90IGFsbCkKWiogICAgICAgICAgICAgICBoYXJkd2FyZSBlcnJvcnMgYXJlIGRldGVjdGVkOgpaKiAgICAgICAgICAgICAgICAtIHNob3J0IGJldHdlZW4gYWRkcmVzcyBsaW5lcwpaKiAgICAgICAgICAgICAgICAtIHNob3J0IGJldHdlZW4gZGF0YSBsaW5lcwogKgpEKiBEZXNpZ246ICAgICAgIHdkQGRlbnguZGUKQyogQ29kaW5nOiAgICAgICB3ZEBkZW54LmRlClYqIFZlcmlmaWNhdGlvbjogZHp1QGRlbnguZGUKICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwpzdGF0aWMgbG9uZyBpbnQgZHJhbV9zaXplIChsb25nIGludCBtYW1yX3ZhbHVlLCBsb25nIGludCAqYmFzZSwgbG9uZyBpbnQgbWF4c2l6ZSkKewoJdm9sYXRpbGUgaW1tYXBfdCAqaW1tciA9IChpbW1hcF90ICopIENGR19JTU1SOwoJdm9sYXRpbGUgbWVtY3RsOHh4X3QgKm1lbWN0bCA9ICZpbW1yLT5pbV9tZW1jdGw7Cgl2b2xhdGlsZSBsb25nIGlud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DAwMDIwMDApCS8qIFBCIDE4ICovCiNlbmRpZgoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCkYqIEZ1bmN0aW9uOiAgICAgaW50IGJvYXJkX3ByZV9pbml0ICh2b2lkKSBQKkEqWioKICoKUCogUGFyYW1ldGVyczogICBub25lClAqClAqIFJldHVybnZhbHVlOiAgaW50ClAqICAgICAgICAgICAgICAgIC0gMCBpcyBhbHdheXMgcmV0dXJuZWQuCiAqCloqIEludGVudGlvbjogICAgVGhpcyBmdW5jdGlvbiBpcyB0aGUgYm9hcmRfcHJlX2luaXQoKSBtZXRob2QgaW1wbGVtZW50YXRpb24KWiogICAgICAgICAgICAgICBmb3IgdGhlIGx3bW9uIGJvYXJkLgpaKiAgICAgICAgICAgICAgIERpc2FibGUgRXRoZXJuZXQgVEVOQSBvbiBQb3J0IEIuCiAqCkQqIERlc2lnbjogICAgICAgd2RAZGVueC5kZQpDKiBDb2Rpbmc6ICAgICAgIHdkQGRlbnguZGUKViogVmVyaWZpY2F0aW9uOiBkenVAZGVueC5kZQogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCmludCBib2FyZF9wcmVfaW5pdCAodm9pZCkKewoJdm9sYXRpbGUgaW1tYXBfdCAqaW1tciA9IChpbW1hcF90ICopIENGR19JTU1SOwoKCS8qIERpc2FibGUgRXRoZXJuZXQgVEVOQSBvbiBQb3J0IEIKCSAqIE5lY2Vzc2FyeSBiZWNhdXNlIG9mIHB1bGwgdXAgaW4gQ09NMyBwb3J0LgoJICoKCSAqIFRoaXMgaXMganVzdCBhIHByZWxpbWluYXJ5IGZpeCwgaW50ZW5kZWQgdG8gdHVybiBvZmYgVEVOQQoJICogYXMgc29vbiBhcyBwb3NzaWJsZSB0byBhdm9pZCBub2lzZSBvbiB0aGUgbmV0d29yay4gT25jZQoJICogSbJDIGlzIHJ1bm5pbmcgd2Ugd2lsbCBtYWtlIHN1cmUgdGhlIGludGVyZmFjZSBpcwoJICogY29ycmVjdGx5IGluaXRpYWxpemVkLgoJICovCglpbW1yLT5pbV9jcG0uY3BfcGJwYXIgJj0gflBCX0VORVRfVEVOQTsKCWltbXItPmltX2NwbS5jcF9wYm9kciAmPSB+UEJfRU5FVF9URU5BOwoJaW1tci0+aW1fY3BtLmNwX3BiZGF0ICY9IH5QQl9FTkVUX1RFTkE7CS8qIHNldCB0byAwID0gZGlzYWJsZWQgKi8KCWltbXItPmltX2NwbS5jcF9wYmRpciB8PSBQQl9FTkVUX1RFTkE7CgoJcmV0dXJuICgwKTsKfQoKLyogLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSAqLwoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCkYqIEZ1bmN0aW9uOiAgICAgdm9pZCByZXNldF9waHkgKHZvaWQpIFAqQSpaKgogKgpQKiBQYXJhbWV0ZXJzOiAgIG5vbmUKUCoKUCogUmV0dXJudmFsdWU6ICBub25lCiAqCloqIEludGVudGlvbjogICAgUmVzZXQgdGhlIFBIWS4gIEluIHRoZSBsd21vbiBjYXNlIHdlIGRvIHRoaXMgYnkgdGhlCloqICAgICAgICAgICAgICAgc2lnbmFsaW5nIHRoZSBQSUMgSS9PIGV4cGFuZGVyLgogKgpEKiBEZXNpZ246ICAgICAgIHdkQGRlbnguZGUKQyogQ29kaW5nOiAgICAgICB3ZEBkZW54LmRlClYqIFZlcmlmaWNhdGlvbjogZHp1QGRlbnguZGUKICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwp2b2lkIHJlc2V0X3BoeSAodm9pZCkKewoJdWNo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bnRpb246ICAgIFRoaXMgZnVuY3Rpb24gaXMgdGhlIG1pc2NfaW5pdF9yKCkgbWV0aG9kIGltcGxlbWVudGF0aW9uCloqICAgICAgICAgICAgICAgZm9yIHRoZSBsd21vbiBib2FyZC4KWiogICAgICAgICAgICAgICBUaGUga2V5Ym9hcmQgY29udHJvbGxlciBpcyBpbml0aWFsaXplZCBhbmQgdGhlIHJlc3VsdApaKiAgICAgICAgICAgICAgIG9mIGEgcmVhZCBjb3BpZWQgdG8gdGhlIGVudmlyb25tZW50IHZhcmlhYmxlICJrZXliZCIuCloqICAgICAgICAgICAgICAgSWYgS0VZQkRfU0VUX0RFQlVHTU9ERSBpcyBkZWZpbmVkLCBhIGNoZWNrIGlzIG1hZGUgZm9yCloqICAgICAgICAgICAgICAgdGhpcyBrZXksIGFuZCBpZiBmb3VuZCBkaXNwbGF5IHRvIHRoZSBMQ0Qgd2lsbCBiZSBlbmFibGVkLgpaKiAgICAgICAgICAgICAgIFRoZSBrZXlzIGluICJrZXliZCIgYXJlIGNoZWNrZWQgYWdhaW5zdCB0aGUgbWFnaWMKWiogICAgICAgICAgICAgICBrZXljb21tYW5kcyBkZWZpbmVkIGluIHRoZSBlbnZpcm9ubWVudC4KWiogICAgICAgICAgICAgICBTZWUgYWxzbyBrZXlfbWF0Y2goKS4KICoKRCogRGVzaWduOiAgICAgICB3ZEBkZW54LmRlCkMqIENvZGluZzogICAgICAgd2RAZGVueC5kZQpWKiBWZXJpZmljYXRpb246IGR6dUBkZW54LmRlCiAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KaW50IG1pc2NfaW5pdF9yICh2b2lkKQp7CglERUNMQVJFX0dMT0JBTF9EQVRBX1BUUjsKCgl1Y2hhciBrYmRfZGF0YVtLRVlCRF9EQVRBTEVOXTsKCXVjaGFyIGtleWJkX2VudlsyICogS0VZQkRfREFUQUxFTiArIDFdOwoJdWNoYXIga2JkX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dGNoIG1hZ2ljIHNlcXVlbmNlLApaKiAgICAgICAgICAgICAgIGFuZCByZXR1cm4gdGhlIGNvbW1hbmQgc3RyaW5nIGFzc29jaWF0ZWQgd2l0aCB0aGF0IGtleShzKS4KWioKWiogICAgICAgICAgICAgICBJZiBubyBrZXkgcHJlc3Mgd2FzIGRlY29kZWQsIE5VTEwgaXMgcmV0dXJuZWQuCloqCloqICAgICAgICAgICAgICAgTm90ZTogdGhlIGZpcnN0IGNoYXJhY3RlciBvZiB0aGUgYXJndW1lbnQgd2lsbCBiZQpaKiAgICAgICAgICAgICAgICAgICAgIG92ZXJ3cml0dGVuIHdpdGggdGhlICJtYWdpYyBjaGFyY3RlciBjb2RlIiBvZiB0aGUKWiogICAgICAgICAgICAgICAgICAgICBkZWNvZGVkIGtleShzKSwgb3IgJ1wwJy4KWioKWiogICAgICAgICAgICAgICBOb3RlOiB0aGUgc3RyaW5nIHBvaW50cyB0byBzdGF0aWMgZW52aXJvbm1lbnQgZGF0YQpaKiAgICAgICAgICAgICAgICAgICAgIGFuZCBtdXN0IGJlIHNhdmVkIGJlZm9yZSB5b3UgY2FsbCBhbnkgZnVuY3Rpb24gdGhhdApaKiAgICAgICAgICAgICAgICAgICAgIG1vZGlmaWVzIHRoZSBlbnZpcm9ubWVudC4KICoKRCogRGVzaWduOiAgICAgICB3ZEBkZW54LmRlCkMqIENvZGluZzogICAgICAgd2RAZGVueC5kZQpWKiBWZXJpZmljYXRpb246IGR6dUBkZW54LmRlCiAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8Kc3RhdGljIHVjaGFyICprZXlfbWF0Y2ggKHVjaGFyICprYmRfZGF0YSkKewoJdWNoYXIgbWFnaWNbc2l6ZW9mIChrYmRfbWFnaWNfcHJlZml4KSArIDFdOwoJdWNoYXIgKnN1ZmZpeDsKCXVjaGFyICprYmRfbWFnaWNfa2V5czsKCgkvKgoJICogVGhlIGZ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kX25hbWVbc2l6ZW9mIChrYmRfY29tbWFuZF9wcmVmaXgpICsgMV07CgkJCWNoYXIgKmNtZDsKCgkJCXNwcmludGYgKGNtZF9uYW1lLCAiJXMlYyIsIGtiZF9jb21tYW5kX3ByZWZpeCwgKnN1ZmZpeCk7CgoJCQljbWQgPSBnZXRlbnYgKGNtZF9uYW1lKTsKI2lmIDAKCQkJcHJpbnRmICgiIyMjIFNldCBQUkVCT09UIHRvICQoJXMpOiBcIiVzXCJcbiIsCgkJCQkJY21kX25hbWUsIGNtZCA/IGNtZCA6ICI8PE5VTEw+PiIpOwojZW5kaWYKCQkJKmtiZF9kYXRhID0gKnN1ZmZpeDsKCQkJcmV0dXJuIChjbWQpOwoJCX0KCX0KI2lmIDAKCXByaW50ZiAoIiMjIyBEZWxldGUgUFJFQk9PVFxuIik7CiNlbmRpZgoJKmtiZF9kYXRhID0gJ1wwJzsKCXJldHVybiAoTlVMTCk7Cn0KI2VuZGlmIC8qIENPTkZJR19QUkVCT09UICovCgovKi0tLS0tLS0tLS0tLS0tLUJvYXJkIFNwZWNpYWwgQ29tbWFuZHM6IFBJQyByZWFkL3dyaXRlIC0tLS0tLS0tLS0tLS0tLSovCgojaWYgKENPTkZJR19DT01NQU5EUyAmIENGR19DTURfQlNQKQovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKRiogRnVuY3Rpb246ICAgICBpbnQgZG9fcGljIChjbWRfdGJsX3QgKmNtZHRwLCBpbnQgZmxhZywKRiogICAgICAgICAgICAgICAgICAgICAgICAgICBpbnQgYXJnYywgY2hhciAqYXJndltdKSBQKkEqWioKICoKUCogUGFyYW1ldGVyczogICBjbWRfdGJsX3QgKmNtZHRwClAqICAgICAgICAgICAgICAgIC0gUG9pbnRlciB0byBvdXIgY29tbWFuZCB0YWJsZSBlbnRyeQpQKiAgICAgICAgICAgICAgIGludCBmbGFnClAqICAgICAgICAgICAgICAgIC0gSWYgdGhlIENNRF9GTEFHX1JFUEVBVCBiaXQgaXMgc2V0LCB0aGVuIHRoaXMgY2FsbCBpcwpQKiAgICAgICAgICAgICAgICAgIGEgcmVwZXRpdGlvbgpQKiAgICAgICAgICAgICAgIGludCBhcmdjClAqICAgICAgICAgICAgICAgIC0gQXJndW1lbnQgY291bnQKUCogICAgICAgICAgICAgICBjaGFyICphcmd2W10KUCogICAgICAgICAgICAgICAgLSBBcnJheSBvZiB0aGUgYWN0dWFsIGFyZ3VtZW50cwpQKgpQKiBSZXR1cm52YWx1ZTogIGludApQKiAgICAgICAgICAgICAgICAtIDAgIFRoZSBjb21tYW5kIHdhcyBoYW5kbGVkIHN1Y2Nlc3NmdWxseQpQKiAgICAgICAgICAgICAgICAgIDEgIEFuIGVycm9yIG9jY3VycmVkCiAqCloqIEludGVudGlvbjogICAgSW1wbGVtZW50IHRoZSAicGljIFtyZWFkfHdyaXRlXSIgY29tbWFuZHMuCloqICAgICAgICAgICAgICAgVGhlIHJlYWQgc3ViY29tbWFuZCB0YWtlcyBvbmUgYXJndW1lbnQsIHRoZSByZWdpc3RlciwKWiogICAgICAgICAgICAgICB3aGVyZWFzIHRoZSB3cml0ZSBjb21tYW5kIHRha2VzIHR3bywgdGhlIHJlZ2lzdGVyIGFuZApaKiAgICAgICAgICAgICAgIHRoZSBuZXcgdmFsdWUuCiAqCkQqIERlc2lnbjogICAgICAgd2RAZGVueC5kZQpDKiBDb2Rpbmc6ICAgICAgIHdkQGRlbnguZGUKViogVmVyaWZpY2F0aW9uOiBkenVAZGVueC5kZQogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCmludCBkb19waWMgKGNtZF90YmxfdCAqY21kdHAsIGludCBmbGFnLCBpbnQgYXJnYywgY2hhciAqYXJndltdKQp7Cgl1Y2hhciByZWcsIHZhbDsKCglzd2l0Y2ggKGFyZ2MpIHsKCWNhc2UgMzoJCQkJCS8qI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ioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgpGKiBGdW5jdGlvbjogICAgIGludCBkb19rYmQgKGNtZF90YmxfdCAqY21kdHAsIGludCBmbGFnLApGKiAgICAgICAgICAgICAgICAgICAgICAgICAgIGludCBhcmdjLCBjaGFyICphcmd2W10pIFAqQSpaKgogKgpQKiBQYXJhbWV0ZXJzOiAgIGNtZF90YmxfdCAqY21kdHAKUCogICAgICAgICAgICAgICAgLSBQb2ludGVyIHRvIG91ciBjb21tYW5kIHRhYmxlIGVudHJ5ClAqICAgICAgICAgICAgICAgaW50IGZsYWcKUCogICAgICAgICAgICAgICAgLSBJZiB0aGUgQ01EX0ZMQUdfUkVQRUFUIGJpdCBpcyBzZXQsIHRoZW4gdGhpcyBjYWxsIGlzClAqICAgICAgICAgICAgICAgICAgYSByZXBldGl0aW9uClAqICAgICAgICAgICAgICAgaW50IGFyZ2MKUCogICAgICAgICAgICAgICAgLSBBcmd1bWVudCBjb3VudApQKiAgICAgICAgICAgICAgIGNoYXIgKmFyZ3ZbXQpQKiAgICAgICAgICAgICAgICAtIEFycmF5IG9mIHRoZSBhY3R1YWwgYXJndW1lbnRzClAqClAqIFJldHVybnZhbHVlOiAgaW50ClAqICAgICAgICAgICAgICAgIC0gMCBpcyBhbHdheXMgcmV0dXJuZWQuCiAqCloqIEludGVudGlvbjogICAgSW1wbGVtZW50IHRoZSAia2JkIiBjb21tYW5kLgpaKiAgICAgICAgICAgICAgIFRoZSBrZXlib2FyZCBzdGF0dXMgaXMgcmVhZC4gIFRoZSByZXN1bHQgaXMgcHJpbnRlZCBvbgpaKiAgICAgICAgICAgICAgIHRoZSBjb25zb2xlIGFuZCB3cml0dGVuIGludG8gdGhlICJrZXliZCIgZW52aXJvbm1lbnQKWiogICAgICAgICAgICAgICB2YXJpYWJsZS4KICoKRCogRGVzaWduOiAgICAgICB3ZEBkZW54LmRlCkMqIENvZGluZzogICAgICA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AwOAkJLyogUEMuMTIgKi8KCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgpGKiBGdW5jdGlvbjogICAgIGludCBkb19sc2IgKGNtZF90YmxfdCAqY21kdHAsIGludCBmbGFnLApGKiAgICAgICAgICAgICAgICAgICAgICAgICAgIGludCBhcmdjLCBjaGFyICphcmd2W10pIFAqQSpaKgogKgpQKiBQYXJhbWV0ZXJzOiAgIGNtZF90YmxfdCAqY21kdHAKUCogICAgICAgICAgICAgICAgLSBQb2ludGVyIHRvIG91ciBjb21tYW5kIHRhYmxlIGVudHJ5ClAqICAgICAgICAgICAgICAgaW50IGZsYWcKUCogICAgICAgICAgICAgICAgLSBJZiB0aGUgQ01EX0ZMQUdfUkVQRUFUIGJpdCBpcyBzZXQsIHRoZW4gdGhpcyBjYWxsIGlzClAqICAgICAgICAgICAgICAgICAgYSByZXBldGl0aW9uClAqICAgICAgICAgICAgICAgaW50IGFyZ2MKUCogICAgICAgICAgICAgICAgLSBBcmd1bWVudCBjb3VudApQKiAgICAgICAgICAgICAgIGNoYXIgKmFyZ3ZbXQpQKiAgICAgICAgICAgICAgICAtIEFycmF5IG9mIHRoZSBhY3R1YWwgYXJndW1lbnRzClAqClAqIFJldHVybnZhbHVlOiAgaW50ClAqICAgICAgICAgICAgICAgIC0gMCAgVGhlIGNvbW1hbmQgd2FzIGhhbmRsZWQgc3VjY2Vzc2Z1bGx5ClAqICAgICAgICAgICAgICAgICAgMSAgQW4gZXJyb3Igb2NjdXJyZWQKICoKWiogSW50ZW50aW9uOiAgICBJbXBsZW1lbnQgdGhlICJsc2IgW29ufG9mZl0iIGNvbW1hbmRzLgpaKiAgICAgICAgICAgICAgIFRoZSBsc2IgaXMgc3dpdGNoZWQgYWNjb3JkaW5nIHRvIHRoZSBmaXJzdCBwYXJhbWV0ZXIgYnkKWiogICAgICAgICAgICAgICBieSBzaWduYWxpbmcgdGhlIFBJQyB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ZSByZWFkIGZyb20gcmVnaXN0ZXIKICoKWiogSW50ZW50aW9uOiAgICBSZWFkIGEgcmVnaXN0ZXIgZnJvbSB0aGUgUElDIEkvTyBleHBhbmRlci4KICoKRCogRGVzaWduOiAgICAgICB3ZEBkZW54LmRlCkMqIENvZGluZzogICAgICAgd2RAZGVueC5kZQpWKiBWZXJpZmljYXRpb246IGR6dUBkZW54LmRlCiAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KdWNoYXIgcGljX3JlYWQgKHVjaGFyIHJlZykKewoJcmV0dXJuIChpMmNfcmVnX3JlYWQgKENGR19JMkNfUElDSU9fQUREUiwgcmVnKSk7Cn0KCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgpGKiBGdW5jdGlvbjogICAgIHZvaWQgcGljX3dyaXRlICh1Y2hhciByZWcsIHVjaGFyIHZhbCkgUCpBKloqCiAqClAqIFBhcmFtZXRlcnM6ICAgdWNoYXIgcmVnClAqICAgICAgICAgICAgICAgIC0gUmVnaXN0ZXIgdG8gcmVhZApQKiAgICAgICAgICAgICAgIHVjaGFyIHZhbApQKiAgICAgICAgICAgICAgICAtIFZhbHVlIHRvIHdyaXRlClAqClAqIFJldHVybnZhbHVlOiAgbm9uZQogKgpaKiBJbnRlbnRpb246ICAgIFdyaXRlIHRvIGEgcmVnaXN0ZXIgb24gdGhlIFBJQyBJL08gZXhwYW5kZXIuCiAqCkQqIERlc2lnbjogICAgICAgd2RAZGVueC5kZQpDKiBDb2Rpbmc6ICAgICAgIHdkQGRlbnguZGUKViogVmVyaWZpY2F0aW9uOiBkenVAZGVueC5kZQogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCnZvaWQgcGljX3dyaXRlICh1Y2hhciByZWcsIHVjaGFy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