LyoKJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgIEREREQgICAgICAgSiAgViAgIFYgIFUgICBVICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgRCAgIEQgICAgICBKICBWICAgViAgVSAgIFUgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICBEICAgRCAgICAgIEogIFYgICBWICBVICAgVSAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgIEQgICBEICBKICAgSiAgIFYgViAgIFUgICBVICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgRERERCAgICBKSkogICAgIFYgICAgIFVVVSAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFJlYWQgRGpWdSBJbWFnZXMuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgU29mdHdhcmUgRGVzaWduICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIEpvaG4gQ3Jpc3R5ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIEp1bHkgMTk5MiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgQ29weXJpZ2h0IDE5OTktMjAxMiBJbWFnZU1hZ2ljayBTdHVkaW8gTExDLCBhIG5vbi1wcm9maXQgb3JnYW5pemF0aW9uICAgICAgJQolICBkZWRpY2F0ZWQgdG8gbWFraW5nIHNvZnR3YXJlIGltYWdpbmcgc29sdXRpb25zIGZyZWVseSBhdmFpbGFibGUuICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgWW91IG1heSBub3QgdXNlIHRoaXMgZmlsZSBleGNlcHQgaW4gY29tcGxpYW5jZSB3aXRoIHRoZSBMaWNlbnNlLiAgWW91IG1heSAgJQolICBvYnRhaW4gYSBjb3B5IG9mIHRoZSBMaWNlbnNlIGF0ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICBodHRwOi8vd3d3LmltYWdlbWFnaWNrLm9yZy9zY3JpcHQvbGljZW5zZS5waHAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgIFVubGVzcyByZXF1aXJlZCBieSBhcHBsaWNhYmxlIGxhdyBvciBhZ3JlZWQgdG8gaW4gd3JpdGluZywgc29mdHdhcmUgICAgICAgICUKJSAgZGlzdHJpYnV0ZWQgdW5kZXIgdGhlIExpY2Vuc2UgaXMgZGlzdHJpYnV0ZWQgb24gYW4gIkFTIElTIiBCQVNJUywgICAgICAgICAgJQolICBXSVRIT1VUIFdBUlJBTlRJRVMgT1IgQ09ORElUSU9OUyBPRiBBTlkgS0lORCwgZWl0aGVyIGV4cHJlc3Mgb3IgaW1wbGllZC4gICAlCiUgIFNlZSB0aGUgTGljZW5zZSBmb3IgdGhlIHNwZWNpZmljIGxhbmd1YWdlIGdvdmVybmluZyBwZXJtaXNzaW9ucyBhbmQgICAgICAgICUKJSAgbGltaXRhdGlvbnMgdW5kZXIgdGhlIExpY2Vuc2UuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUKJQolCiovCgwKLyoKICBJbmNsdWRlIGRlY2xhcmF0aW9ucy4KKi8KI2luY2x1ZGUgIk1hZ2lja0NvcmUvc3R1ZGlvLmgiCiNpbmNsdWRlICJNYWdpY2tDb3JlL2Jsb2IuaCIKI2luY2x1ZGUgIk1hZ2lja0Nvc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gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgIEkgcyBEIEogViBVICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlCiUKJSAgSXNESlZVKCkgcmV0dXJucyBNYWdpY2tUcnVlIGlmIHRoZSBpbWFnZSBmb3JtYXQgdHlwZSwgaWRlbnRpZmllZCBieSB0aGUKJSAgbWFnaWNrIHN0cmluZywgaXMgREpWVS4KJQolICBUaGUgZm9ybWF0IG9mIHRoZSBJc0RKVlUgbWV0aG9kIGlzOgolCiUgICAgICBNYWdpY2tCb29sZWFuVHlwZSBJc0RKVlUoY29uc3QgdW5zaWduZWQgY2hhciAqbWFnaWNrLGNvbnN0IHNpemVfdCBsZW5ndGgpCiUKJSAgQSBkZXNjcmlwdGlvbiBvZiBlYWNoIHBhcmFtZXRlciBmb2xsb3dzOgolCiUgICAgbyBtYWdpY2s6IGNvbXBhcmUgaW1hZ2UgZm9ybWF0IHBhdHRlcm4gYWdhaW5zdCB0aGVzZSBieXRlcy4KJQolICAgIG8gbGVuZ3RoOiBTcGVjaWZpZXMgdGhlIGxlbmd0aCBvZiB0aGUgbWFnaWNrIHN0cmluZy4KJQoqLwpzdGF0aWMgTWFnaWNrQm9vbGVhblR5cGUgSXNESlZVKGNvbnN0IHVuc2lnbmVkIGNoYXIgKm1hZ2ljayxjb25zdCBzaXplX3QgbGVuZ3RoKQp7CiAgaWYgKGxlbmd0aCA8IDgpCiAgICByZXR1cm4oTWFnaWNrRmFsc2UpOwogIGlmIChtZW1jbXAobWFnaWNrLCJBVCZURk9STSIsOCkgPT0gMCkKICAgIHJldHVybihNYWdpY2tUcnVlKTsKICByZXR1cm4oTWFnaWNrRmFsc2UpOwp9CgwKI2lmIGRlZmluZWQoTUFHSUNLQ09SRV9ESlZVX0RFTEVHQVRFKQovKgolJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICBSIGUgYSBkIEQgSiBWIFUgSSBtIGEgZyBlICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC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xOwoKICAgICAgICBkZGp2dV9yZWN0X3QgcmVjdDsKICAgICAgICByZWN0LnggPSB4OwogICAgICAgIHJlY3QueSA9IHk7CiAgICAgICAgcmVjdC53ID0gKHVuc2lnbmVkIGludCkgdzsgICAgICAgICAgICAgLyogLzEwICovCiAgICAgICAgcmVjdC5oID0gKHVuc2lnbmVkIGludCkgaDsgICAgICAgICAgICAgLyogLzEwICovCgogICAgICAgIGltYWdlID0gbGMtPmltYWdlOwogICAgICAgIHR5cGUgPSBkZGp2dV9wYWdlX2dldF90eXBlKGxjLT5wYWdlKTsKCiAgICAgICAgLyogc3RyaWRlIG9mIHRoaXMgdGVtcG9yYXJ5IGJ1ZmZlcjogKi8KICAgICAgICBzdHJpZGUgPSAodHlwZSA9PSBEREpWVV9QQUdFVFlQRV9CSVRPTkFMKT8KICAgICAgICAgICAgICAgIChpbWFnZS0+Y29sdW1ucyArIDcpLzggOiBpbWFnZS0+Y29sdW1ucyAqMzsKCiAgICAgICAgcSA9ICh1bnNpZ25lZCBjaGFyICopIEFjcXVpcmVRdWFudHVtTWVtb3J5KGltYWdlLT5yb3dzLHN0cmlkZSk7CiAgICAgICAgaWYgKHEgPT0gKHVuc2lnbmVkIGNoYXIgKikgTlVMTCkKICAgICAgICAgIHJldHVybjsKCiAgICAgICAgZm9ybWF0ID0gZGRqdnVfZm9ybWF0X2NyZWF0ZSgKICAgICAgICAgICAgICAgICh0eXBlID09IERESlZVX1BBR0VUWVBFX0JJVE9OQUwpP0RESlZVX0ZPUk1BVF9MU0JUT01TQiA6IERESlZVX0ZPUk1BVF9SR0IyNCwKICAgICAgICAgICAgICAgIC8qIERESlZVX0ZPUk1BVF9SR0IyNAogICAgICAgICAgICAgICAgICogRERKVlVfRk9STUFUX1JHQk1BU0szMiovCiAgICAgICAgICAgICAgICAvKiBEREpWVV9GT1JNQVRfUkdCTUFTSzMyICovCiAgICAgICAgICAgICAgICAwLCBOVUxMKTsKCiNpZiAwCiAgICAgICAgLyogZml4bWU6ICBUaHJvd1JlYWRlckV4Y2VwdGlvbiBpcyBhIG1hY3JvLCB3aGljaCB1c2VzICBgZXhjZXB0aW9uJyB2YXJpYWJsZSAqLwogICAgICAgIGlmIChmb3JtYXQgPT0gTlVMTCkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgYWJvcnQoKTsKICAgICAgICAgICAgICAgICAgICAgICAgLyogVGhyb3dSZWFkZXJFeGNlcHRpb24oUmVzb3VyY2VMaW1pdEVycm9yLCJNZW1vcnlBbGxvY2F0aW9uRmFpbGVkIik7ICovCiAgICAgICAgICAgICAgICB9CgojZW5kaWYKICAgICAgICBkZGp2dV9mb3JtYXRfc2V0X3Jvd19vcmRlcihmb3JtYXQsIDEpOwogICAgICAgIGRkanZ1X2Zvcm1hdF9zZXRfeV9kaXJlY3Rpb24oZm9ybWF0LCAxKTsKCiAgICAgICAgcmV0ID0gZGRqdnVfcGFnZV9yZW5kZXIocGFnZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgRERKVlVfUkVOREVSX0NPTE9SLCAvKiBkZGp2dV9yZW5kZXJfbW9kZV90ICovCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICZyZWN0LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAmcmVjdCwgICAgIC8qIG1tYzogPz8gKi8KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZm9ybWF0LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdHJpZGUsIC8qID8/ICovCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChjaGFyKilxKTsKICAgICAgICAodm9pZCkgcmV0OwogICAgICAgIGRkanZ1X2Zvcm1hdF9yZWxlYXNlKGZvcm1hdCk7CgoKICAgICAgICBpZiAodHlwZSA9PSBEREpWVV9QQUdFVFlQRV9CSVRPTkFMKSB7CiAgICAgICAgICAgICAgICAvKiAgKi8KI2lmIERFQlVHCiAgICAgICAgICAgICAgICBwcmludGYoIiVzOiBleHBhbmRpbmcgQklUT05BTCBwYWdlL2ltYWdlXG4iLCBfX0ZVTkNUSU9OX18pOwojZW5kaWYKICAgICAgICAgICAgICAgIHNpemVfdCBiaXQsIGJ5dGU7CgogICAgICAgICAgICAgICAgZm9yICh5PTA7IHkgPCAoc3NpemVfdCkgaW1hZ2UtPnJvd3M7IHkrKykKICAgICAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFF1YW50dW0gKiBvID0gUXVldWVBdXRoZW50aWNQaXhlbHMoaW1hZ2UsMCx5LGltYWdlLT5jb2x1bW5zLDEsZXhjZXB0aW9uKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobyA9PSAoUXVhbnR1bSAqKSBOVUxMKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYml0PTA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYnl0ZT0wOwoKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvKiBmaXhtZTogIHRoZSBub24tYWxpZ25lZCwgbGFzdCA9PDcgYml0cyAhIHRoYXQncyBvayEhISovCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZm9yICh4PSAwOyB4IDwgKHNzaXplX3QpIGltYWdlLT5jb2x1bW5zOyB4KyspCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChiaXQgPT0gMCkgYnl0ZT0gKHNpemVfdCkgcVsoeSAqIHN0cmlkZSkgKyAoeCAvIDgpXTsKCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFNldFBpeGVsSW5kZXgoaW1hZ2UsKFF1YW50dW0pICgoKGJ5dGUgJiAweDAxKSAhPSAwKSA/IDB4MDAgOiAweDAxKSxvKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYml0Kys7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChiaXQgPT0gOCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBiaXQ9MDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYnl0ZT4+PTE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG8rPUdldFBpeGVsQ2hhbm5lbHMoaW1hZ2UpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChTeW5jQXV0aGVudGljUGl4ZWxzKGltYWdlLGV4Y2VwdGlvbikgPT0gTWFnaWNrRmFsc2UpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKCFpbWFnZS0+cGluZykKICAgICAgICAgICAgICAgICAgU3luY0ltYWdlKGltYWdlLGV4Y2VwdGlvbik7CiAgICAgICAgfSBlbHNlIHsKI2lmIERFQlVHCiAgICAgICAgICAgICAgICBwcmludGYoIiVzOiBleHBhbmRpbmcgUEhPVE8gcGFnZS9pbWFnZVxuIiwgX19GVU5DVElPTl9fKTsKI2VuZGlmCiAgICAgICAgICAgICAgICAvKiBub3cgdHJhbnNmZXIgbGluZS13aXNlOiAqLwogICAgICAgICAgICAgICAgc3NpemVfdCBpOwojaWYgMAogICAgICAgICAgICAgICAgLyogb2xkOiAqLwogICAgICAgICAgICAgICAgY2hhciogcjsKI2Vsc2UKICAgICAgICAgICAgICAgIHJlZ2lzdGVyIFF1YW50dW0gKnI7CiAgICAgICAgICAgICAgICB1bnNpZ25lZCBjaGFyICpzOwojZW5kaWYKICAgICAgICAgICAgICAgIHM9cTsKICAgICAgICAgICAgICAgIGZvciAoaSA9IDA7aTwgKHNzaXplX3QpIGltYWdlLT5yb3dzOyBpKyspCiAgICAgICAgICAgICAgICAgICAgICAgIHsKI2lmIERFQlVHCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoaSAlIDEwMDAgPT0gMCkgcHJpbnRmKCIlZFxuIixpKTsKI2VuZGlmCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByID0gUXVldWVBdXRoZW50aWNQaXhlbHMoaW1hZ2UsMCxpLGltYWdlLT5jb2x1bW5zLDEsZXhjZXB0aW9uKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChyID09IChRdWFudHVtICopIE5VTEwpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICBmb3IgKHg9MDsgeCA8IChzc2l6ZV90KSBpbWFnZS0+Y29sdW1uczsgeCsrKQogICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgU2V0UGl4ZWxSZWQoaW1hZ2UsU2NhbGVDaGFyVG9RdWFudHVtKCpzKyspLHIpOwogICAgICAgICAgICAgICAgICAgIFNldFBpeGVsR3JlZW4oaW1hZ2UsU2NhbGVDaGFyVG9RdWFudHVtKCpzKyspLHIpOwogICAgICAgICAgICAgICAgICAgIFNldFBpeGVsQmx1ZShpbWFnZSxTY2FsZUNoYXJUb1F1YW50dW0oKnMrKykscik7CiAgICAgICAgICAgICAgICAgICAgcis9R2V0UGl4ZWxDaGFubmVscyhpbWFnZSk7CiAgICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFN5bmNBdXRoZW50aWNQaXhlbHMoaW1hZ2UsZXhjZXB0aW9uKTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBxPSh1bnNpZ25lZCBjaGFyICopIFJlbGlucXVpc2hNYWdpY2tNZW1vcnkocSk7Cn0KCgojaWYgZGVmaW5lZChNQUdJQ0tDT1JFX0RKVlVfREVMRUdBVEUpCgojaWYgMApzdGF0aWMgaW50CmdldF9wYWdlX2xpbmUoTG9hZENvbnRleHQgKmxjLCBpbnQgcm93LCBRdWFudHVtSW5mbyogcXVhbnR1bV9pbmZvKQp7CiAgZGRqdnVfZm9ybWF0X3QKICAgICpmb3JtYXQ7CgogIGludAogICAgcmV0OwoKICBzaXplX3QKICAgIHN0cmlkZTsKCiAgdW5zaWduZWQgY2hhcgogICAgKnE7CgogICAgICAgIGRkanZ1X3JlY3RfdCByZWN0LCBwYWdlcmVjdDsKICAgICAgICByZWN0LnggPSAwOwogICAgICAgIHJlY3QueSA9IHJvdzsKICAgICAgICByZWN0LncgPSBsYy0+aW1hZ2UtPmNvbHVtbnM7ICAgICAgICAgICAgIC8qIC8xMCAqLwogICAgICAgIHJlY3QuaCA9IDE7ICAgICAgICAgICAgIC8qIC8xMCAqLwoKICAgICAgICBwYWdlcmVjdC54ID0gMDsKICAgICAgICBwYWdlcmVjdC55ID0gMDsKICAgICAgICBwYWdlcmVjdC53ID0gbGMtPmltYWdlLT5jb2x1bW5zOwogICAgICAgIHBhZ2VyZWN0LmggPSBsYy0+aW1hZ2UtPnJvd3M7CgoKICAgICAgICBmb3JtYXQgPSBkZGp2dV9mb3JtYXRfY3JlYXRlKAojaWYgUkdCCiAgICAgICAgICAgICAgICBEREpWVV9GT1JNQVRfUkdCMjQKI2Vsc2UKICAgICAgICAgICAgICAgIERESlZVX0ZPUk1BVF9HUkVZOAojZW5kaWYKICAgICAgICAgICAgICAgICwKICAgICAgICAgICAgICAgIDAsIE5VTEwpOwogICAgICAgIGRkanZ1X2Zvcm1hdF9zZXRfcm93X29yZGVyKGZvcm1hdCwgMSk7CiAgICAgICAgZGRqdnVfZm9ybWF0X3NldF95X2RpcmVjdGlvbihmb3JtYXQsIDEpOwoKICAgICAgICBzdHJpZGU9MTsKI2lmIFJHQgogICAgICAgIHN0cmlkZT0zOwojZW5kaWYKICAgICAgICBxID0gKHVuc2lnbmVkIGNoYXIgKikgQWNxdWlyZVF1YW50dW1NZW1vcnkobGMtPmltYWdlLT5jb2x1bW5zLHN0cmlkZSk7CgogICAgICAgIHJldCA9IGRkanZ1X3BhZ2VfcmVuZGVyKGxjLT5wYWdlLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBEREpWVV9SRU5ERVJfQ09MT1IsIC8qIGRkanZ1X3JlbmRlcl9tb2RlX3QgKi8KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJnBhZ2VyZWN0LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAmcmVjdCwgICAgIC8qIG1tYzogPz8gKi8KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZm9ybWF0LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwYWdlcmVjdC53ICogMywgLyogPz8gKi8KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKGNoYXIqKXEpOwoKICAgICAgICBJbXBvcnRRdWFudHVtUGl4ZWxzKGxjLT5pbWFnZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgIChDYWNoZVZpZXcgKikgTlVMTCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHF1YW50dW1faW5mbywKI2lmIFJHQgogICAgICAgICAgICAgICAgICAgICAgICAgICAgUkdCUXVhbnR1bQojZWxzZQogICAgICAgICAgICAgICAgICAgICAgICAgICAgR3JheVF1YW50dW0KI2VuZGlmCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAscSwmbGMtPmltYWdlLT5leGNlcHRpb24pOwogICAgICAgIHE9KHVuc2lnbmVkIGNoYXIgKikgUmVsaW5xdWlzaE1hZ2lja01lbW9yeShxKTsKICAgICAgICBkZGp2dV9mb3JtYXRfcmVsZWFzZShmb3JtYXQpOwogICAgICAgIHJldHVybiByZXQ7Cn0KI2VuZGlmCiNlbmRpZgoKLyoKJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgUiBlIGEgZCBPIG4gZSBEIEogViBVIEkgbSBhIGcgZSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUKJQolICBSZWFkT25lREpWVUltYWdlKCkgcmVhZHMgYSBQb3J0YWJsZSBOZXR3b3JrIEdyYXBoaWNzIChESlZVKSBpbWFnZSBmaWxlCiUgIChtaW51cyB0aGUgOC1ieXRlIHNpZ25hdHVyZSkgIGFuZCByZXR1cm5zIGl0LiAgSXQgYWxsb2NhdGVzIHRoZSBtZW1vcnkKJSAgbm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2dnaW5nOwogIGludCB0YWc7CgogICAgICAgIC8qIHNvLCB3ZSBrbm93IHRoYXQgdGhlIHBhZ2UgaXMgdGhlcmUhIEdldCBpdHMgZGltZW5zaW9uLCBhbmQgICovCgogICAgICAgIC8qIFJlYWQgb25lIERKVlUgaW1hZ2UgKi8KICAgICAgICBpbWFnZSA9IGxjLT5pbWFnZTsKCiAgICAgICAgLyogcmVnaXN0ZXIgUXVhbnR1bSAqcTsgKi8KCiAgICAgICAgbG9nZ2luZz1Mb2dNYWdpY2tFdmVudChDb2RlckV2ZW50LEdldE1hZ2lja01vZHVsZSgpLCAiICBlbnRlciBSZWFkT25lREpWVUltYWdlKCkiKTsKICAgICAgICAodm9pZCkgbG9nZ2luZzsKCiNpZiBERUJVRwogICAgICAgIHByaW50ZigiPT09PSAgTG9hZGluZyB0aGUgcGFnZSAlZFxuIiwgcGFnZW51bSk7CiNlbmRpZgogICAgICAgIGxjLT5wYWdlID0gZGRqdnVfcGFnZV9jcmVhdGVfYnlfcGFnZW5vKGxjLT5kb2N1bWVudCwgcGFnZW51bSk7IC8qICAwPyAqLwoKICAgICAgICAvKiBwdW1wIGRhdGEgdW50aWxsIHRoZSBwYWdlIGlzIHJlYWR5IGZvciByZW5kZXJpbmcuICovCiAgICAgICAgdGFnPSgtMSk7CiAgICAgICAgZG8gewogICAgICAgICAgICAgICAgd2hpbGUgKChtZXNzYWdlID0gZGRqdnVfbWVzc2FnZV9wZWVrKGxjLT5jb250ZXh0KSkpCiAgICAgICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0YWc9cHJvY2Vzc19tZXNzYWdlKG1lc3NhZ2UpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0YWcgPT0gMCkgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZGRqdnVfbWVzc2FnZV9wb3AobGMtPmNvbnRleHQpOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAvKiBmaXhtZTogbWF5YmUgZXhpdD8gKi8KICAgICAgICAgICAgICAgIC8qIGlmIChsYy0+ZXJyb3IpIGJyZWFrOyAqLwoKICAgICAgICAgICAgICAgIG1lc3NhZ2UgPSBwdW1wX2RhdGFfdW50aWxfbWVzc2FnZShsYyxpbWFnZSk7CiAgICAgICAgICAgICAgICBpZiAobWVzc2FnZSkKICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRhZz1wcm9jZXNzX21lc3NhZ2UobWVzc2FnZSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHRhZyA9PSAwKSBicmVhazsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkZGp2dV9tZXNzYWdlX3BvcChsYy0+Y29udGV4dCk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKChtZXNzYWdlID0gZGRqdnVfbWVzc2FnZV9wZWVrKGxjLT5jb250ZXh0KSkpOwogICAgICAgIH0gd2hpbGUgKCFkZGp2dV9wYWdlX2RlY29kaW5nX2RvbmUobGMtPnBhZ2UpKTsKCiAgICAgICAgZGRqdnVfZG9jdW1lbnRfZ2V0X3BhZ2VpbmZvKGxjLT5kb2N1bWVudCwgcGFnZW51bSwgJmluZm8pOwoKICAgICAgICBpbWFnZS0+cmVzb2x1dGlvbi54ID0gKGZsb2F0KSBpbmZvLmRwaTsKICAgICAgICBpbWFnZS0+cmVzb2x1dGlvbi55ID0oZmxvYXQpIGluZm8uZHBpOwogICAgICAgIGlmIChpbWFnZV9pbmZvLT5kZW5zaXR5ICE9IChjaGFyICopIE5VTEwpCiAgICAgICAgICB7CiAgICAgICAgICAgIGludAogICAgICAgICAgICAgIGZsYWdzOwoKICAgICAgICAgICAgR2VvbWV0cnlJbmZvCiAgICAgICAgICAgICAgZ2VvbWV0cnlfaW5mbzsKCiAgICAgICAgICAgIC8qCiAgICAgICAgICAgICA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ogICAgICAgIHByaW50Zigibm93IGZpbGxpbmcgJS4yMGcgeCAlLjIwZ1xuIiwoZG91YmxlKSBpbWFnZS0+Y29sdW1ucywoZG91YmxlKQogICAgICAgICAgaW1hZ2UtPnJvd3MpOwojZW5kaWYKCgojaWYgMSAgICAgICAgICAgICAgICAgICAgICAgICAgIC8qIHBlcl9saW5lICovCgogICAgICAgIC8qIHEgPSBRdWV1ZUF1dGhlbnRpY1BpeGVscyhpbWFnZSwwLDAsaW1hZ2UtPmNvbHVtbnMsaW1hZ2UtPnJvd3MpOyAqLwogICAgICAgIGdldF9wYWdlX2ltYWdlKGxjLCBsYy0+cGFnZSwgMCwgMCwgaW5mby53aWR0aCwgaW5mby5oZWlnaHQsIGltYWdlX2luZm8sCiAgICAgICAgICBleGNlcHRpb24pOwojZWxzZQogICAgICAgIGludCBpOwogICAgICAgIGZvciAoaSA9IDA7aTwgaW1hZ2UtPnJvd3M7IGkrKykKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgcHJpbnRmKCIlZFxuIixpKTsKICAgICAgICAgICAgICAgICAgICAgICAgcSA9IFF1ZXVlQXV0aGVudGljUGl4ZWxzKGltYWdlLDAsaSxpbWFnZS0+Y29sdW1ucywxKTsKICAgICAgICAgICAgICAgICAgICAgICAgZ2V0X3BhZ2VfbGluZShsYywgaSwgcXVhbnR1bV9pbmZvKTsKICAgICAgICAgICAgICAgICAgICAgICAgU3luY0F1dGhlbnRpY1BpeGVscyhpbWFnZSk7CiAgICAgICAgICAgICAgICB9CgojZW5kaWYgLyogcGVyX2xpbmUgKi8KCgojaWYgREVCVUcKICAgICAgICBwcmludGYoIkVORDogZmluaXNoZWQgZmlsbGluZyAlLjIwZyB4ICUuMjBnXG4iLChkb3VibGUpIGltYWdlLT5jb2x1bW5zLAogICAgICAgICAgKGRvdWJsZSkgaW1hZ2UtPnJvd3MpOwojZW5kaWYKCiAgICAgICAgaWYgKCFpbWFnZS0+cGluZykKICAgICAgICAgIFN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ICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgIFIgZSBnIGkgcyB0IGUgciBEIEogViBVIEkgbSBhIGcgZSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlCiUKJSAgUmVnaXN0ZXJESlZVSW1hZ2UoKSBhZGRzIGF0dHJpYnV0ZXMgZm9yIHRoZSBESlZVIGltYWdlIGZvcm1hdCB0bwolICB0aGUgbGlzdCBvZiBzdXBwb3J0ZWQgZm9ybWF0cy4gIFRoZSBhdHRyaWJ1dGVzIGluY2x1ZGUgdGhlIGltYWdlIGZvcm1hdAolICB0YWcsIGEgbWV0aG9kIHRvIHJlYWQgYW5kL29yIHdyaXRlIHRoZSBmb3JtYXQsIHdoZXRoZXIgdGhlIGZvcm1hdAolICBzdXBwb3J0cyB0aGUgc2F2aW5nIG9mIG1vcmUgdGhhbiBvbmUgZnJhbWUgdG8gdGhlIHNhbWUgZmlsZSBvciBibG9iLAolICB3aGV0aGVyIHRoZSBmb3JtYXQgc3VwcG9ydHMgbmF0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W1hZ2VIYW5kbGVyICopIFJlYWRESlZVSW1hZ2U7CiNlbmRpZgogIGVudHJ5LT5yYXc9TWFnaWNrVHJ1ZTsKICBlbnRyeS0+bWFnaWNrPShJc0ltYWdlRm9ybWF0SGFuZGxlciAqKSBJc0RKVlU7CiAgZW50cnktPmFkam9pbj1NYWdpY2tGYWxzZTsKICBlbnRyeS0+dGhyZWFkX3N1cHBvcnQ9TWFnaWNrVHJ1ZTsKICBlbnRyeS0+ZGVzY3JpcHRpb249QWNxdWlyZVN0cmluZygiROlq4CB2dSIpOwogIGVudHJ5LT5tb2R1bGU9QWNxdWlyZVN0cmluZygiREpWVSIpOwogIGlmICgqdmVyc2lvbiAhPSAnXDAnKQogICAgZW50cnktPnZlcnNpb249QWNxdWlyZVN0cmluZyh2ZXJzaW9uKTsKICBlbnRyeS0+bm90ZT1BY3F1aXJlU3RyaW5nKERKVlVOb3RlKTsKICAodm9pZCkgUmVnaXN0ZXJNYWdpY2tJbmZvKGVudHJ5KTsKICByZXR1cm4oTWFnaWNrSW1hZ2VDb2RlclNpZ25hdHVyZSk7Cn0KDAovKgolJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICBVIG4gciBlIGcgaSBzIHQgZSByIEQgSiBWIFUgSSBtIGEgZyBlICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJQolCiUgIFVucmVnaXN0ZXJESlZVSW1hZ2UoKSByZW1vdmVzIGZvcm1hdCByZWdpc3RyYXRpb25zIG1hZGUgYnkgdGhlCiUgIERKVlUgbW9kdWxlIGZyb20gdGhlIGxpc3Qgb2Ygc3VwcG9ydGVkIGZvcm1hdHMuCiUKJSAgVGhlIGZvcm1hdCBvZiB0aGUgVW5yZWdpc3RlckRKVlVJbWFnZSBtZXRob2QgaXM6CiUKJSAgICAgIFVucmVnaXN0ZXJESlZVSW1hZ2Uodm9pZCkKJQoqLwpNb2R1bGVFeHBvcnQgdm9pZCBVbnJlZ2lzdGVyREpWVUltYWdlKHZvaWQpCnsKICAodm9pZCkgVW5yZWdpc3Rlck1hZ2lja0luZm8oIkRKVlUiKTsKfQo=