LyoKJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgIFBQUFAgICBEREREICAgRkZGRkYgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgUCAgIFAgIEQgICBEICBGICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICBQUFBQICAgRCAgIEQgIEZGRiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgIFAgICAgICBEICAgRCAgRiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgUCAgICAgIEREREQgICBGICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgUmVhZC9Xcml0ZSBQb3J0YWJsZSBEb2N1bWVudCBGb3JtYXQgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgU29mdHdhcmUgRGVzaWduICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIEpvaG4gQ3Jpc3R5ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIEp1bHkgMTk5MiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgQ29weXJpZ2h0IDE5OTktMjAxMSBJbWFnZU1hZ2ljayBTdHVkaW8gTExDLCBhIG5vbi1wcm9maXQgb3JnYW5pemF0aW9uICAgICAgJQolICBkZWRpY2F0ZWQgdG8gbWFraW5nIHNvZnR3YXJlIGltYWdpbmcgc29sdXRpb25zIGZyZWVseSBhdmFpbGFibGUuICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgWW91IG1heSBub3QgdXNlIHRoaXMgZmlsZSBleGNlcHQgaW4gY29tcGxpYW5jZSB3aXRoIHRoZSBMaWNlbnNlLiAgWW91IG1heSAgJQolICBvYnRhaW4gYSBjb3B5IG9mIHRoZSBMaWNlbnNlIGF0ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICBodHRwOi8vd3d3LmltYWdlbWFnaWNrLm9yZy9zY3JpcHQvbGljZW5zZS5waHAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgIFVubGVzcyByZXF1aXJlZCBieSBhcHBsaWNhYmxlIGxhdyBvciBhZ3JlZWQgdG8gaW4gd3JpdGluZywgc29mdHdhcmUgICAgICAgICUKJSAgZGlzdHJpYnV0ZWQgdW5kZXIgdGhlIExpY2Vuc2UgaXMgZGlzdHJpYnV0ZWQgb24gYW4gIkFTIElTIiBCQVNJUywgICAgICAgICAgJQolICBXSVRIT1VUIFdBUlJBTlRJRVMgT1IgQ09ORElUSU9OUyBPRiBBTlkgS0lORCwgZWl0aGVyIGV4cHJlc3Mgb3IgaW1wbGllZC4gICAlCiUgIFNlZSB0aGUgTGljZW5zZSBmb3IgdGhlIHNwZWNpZmljIGxhbmd1YWdlIGdvdmVybmluZyBwZXJtaXNzaW9ucyBhbmQgICAgICAgICUKJSAgbGltaXRhdGlvbnMgdW5kZXIgdGhlIExpY2Vuc2UuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUKJQolCiovCgwKLyoKICBJbmNsdWRlIGRlY2xhcmF0aW9ucy4KKi8KI2luY2x1ZGUgIm1hZ2ljay9zdHVkaW8uaCIKI2luY2x1ZGUgIm1hZ2ljay9ibG9iLmgiCiNpbmNsdWRlICJtYWdpY2svYmxvYi1wcml2Y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zdHJpbmdfLmgiCiNpbmNsdWRlICJtYWdpY2svbW9kdWxlLmgiCiNpbmNsdWRlICJtYWdpY2svdHJhbnNmb3JtLmgiCiNpbmNsdWRlICJtYWdpY2svdXRpbGl0eS5oIgojaW5jbHVkZSAibWFnaWNrL21vZHVsZS5oIgoMCi8qCiAgRGVmaW5lIGRlY2xhcmF0aW9ucy4KKi8KI2lmIGRlZmluZWQoTUFHSUNLQ09SRV9USUZGX0RFTEVHQVRFKQojZGVmaW5lIENDSVRUUGFyYW0gICItMSIKI2Vsc2UKI2RlZmluZSBDQ0lUVFBhcmFtICAiMCIKI2VuZGlmCgwKLyoKICBGb3J3YXJkIGRlY2xhcmF0aW9ucy4KKi8Kc3RhdGljIE1hZ2lja0Jvb2xlYW5UeXBlCiAgV3JpdGVQREZJbWFnZShjb25zdCBJbWFnZUluZm8gKixJbWFnZSAqKTsKDAovKgolJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICBJIG4gdiBvIGsgZSBQIEQgRiBEIGUgbCBlIGcgYSB0IGUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA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0dXJuKE1hZ2lja0ZhbHNlKTsKICAgIH0KICByZXR1cm4oTWFnaWNrVHJ1ZSk7CiNlbHNlCiAgc3RhdHVzPVN5c3RlbUNvbW1hbmQoTWFnaWNrRmFsc2UsdmVyYm9zZSxjb21tYW5kLGV4Y2VwdGlvbik7CiAgcmV0dXJuKHN0YXR1cyA9PSAwID8gTWFnaWNrVHJ1ZSA6IE1hZ2lja0ZhbHNlKTsKI2VuZGlmCn0KDAovKgolJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICBJIHMgUCBEIEYgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJQolCiUg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ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgIFIgZSBhIGQgUCBEIEYgSSBtIGEgZyBlICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlCiUKJSAgUmVhZFBERkltYWdlKCkgcmVhZHMgYSBQb3J0YWJsZSBEb2N1bWVudCBGb3JtYXQgaW1hZ2UgZmlsZSBhbmQKJSAgcmV0dXJucyBpdC4gIEl0IGFsbG9jYXRlcyB0aGUgbWVtb3J5IG5lY2Vzc2FyeSBmb3IgdGhlIG5ldyBJbWFnZSBzdHJ1Y3R1cmUKJSAgYW5kIHJldHVybnMgYSBwb2ludGVyIHRvIHRoZSBuZXcgaW1hZ2UuCiUKJSAgVGhlIGZvcm1hdCBvZiB0aGUgUmVhZFBERkltYWdlIG1ldGhvZCBpczoKJQolICAgICAgSW1hZ2UgKlJlYWRQREZJbWFnZShjb25zdCBJbWFnZUluZm8gKmltYWdlX2luZm8sRXhjZXB0aW9uSW5mbyAqZXhjZXB0aW9uKQolCiUgIEEgZGVzY3JpcHRpb24gb2YgZWFjaCBwYXJhbWV0ZXI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dCkgc3NjYW5mKGNvbW1hbmQsIlJvdGF0ZSAlbGYiLCZhbmdsZSk7CiAgICAvKgogICAgICBJcyB0aGlzIGEgQ01ZSyBkb2N1bWVudD8KICAgICovCiAgICBpZiAoTG9jYWxlTkNvbXBhcmUoRGV2aWNlQ01ZSyxjb21tYW5kLHN0cmxlbihEZXZpY2VDTVlLKSkgPT0gMCkKICAgICAgY215az1NYWdpY2tUcnVlOwogICAgaWYgKExvY2FsZU5Db21wYXJlKFNwb3RDb2xvcixjb21tYW5kLHN0cmxlbihTcG90Q29sb3IpKSA9PSAwKQogICAgICB7CiAgICAgICAgY2hhcgogICAgICAgICAgbmFtZVtNYXhUZXh0RXh0ZW50XSwKICAgICAgICAgIHByb3BlcnR5W01heFRleHRFeHRlbnRdLAogICAgICAgICAgKnZhbHVlOwoKICAgICAgICByZWdpc3RlciBzc2l6ZV90CiAgICAgICAgICBpOwoKICAgICAgICAvKgogICAgICAgICAgTm90ZSBzcG90IG5hbWVzLgogICAgICAgICovCiAgICAgICAgKHZvaWQpIEZvcm1hdE1hZ2lja1N0cmluZyhwcm9wZXJ0eSxNYXhUZXh0RXh0ZW50LCJwZGY6U3BvdENvbG9yLSUuMjBnIiwKICAgICAgICAgIChkb3VibGUpIHNwb3Rjb2xvcisrKTsKICAgICAgICBpPTA7CiAgICAgICAgZm9yIChjPVJlYWRCbG9iQnl0ZShpbWFnZSk7IGMgIT0gRU9GOyBjPVJlYWRCbG9iQnl0ZShpbWFnZSkpCiAgICAgICAgewogICAgICAgICAgaWYgKChpc3NwYWNlKGMpICE9IDApIHx8IChjID09ICcvJykgfHwgKChpKzEpID09IE1heFRleHRFeHRlbnQpKQogICAgICAgICAgICBicmVhazsKICAgICAgICAgIG5hbWVbaSsrXT0oY2hhcikgYzsKICAgICAgICB9CiAgICAgICAgbmFtZVtpXT0nXDAnOwogICAgICAgIHZhbHVlPUFjcXVpcmVTdHJpbmcobmFtZSk7CiAgICAgICAgKHZvaWQpIFN1YnN0aXR1dGVTdHJpbmcoJnZhbHVlLCIjMjAiLCIgIik7CiAgICAgICAgKHZvaWQpIFNldEltYWdlUHJvcGVydHkoaW1hZ2UscHJvcGVydHksdmFsdWUpOwogICAgICAgIHZhbHVlPURlc3Ryb3lTdHJpbmcodmFsdWUpOwogICAgICAgIGNvbnRpbnVlOwogICAgICB9CiAgICBpZiAoTG9jYWxlTkNvbXBhcmUoUERGVmVyc2lvbixjb21tYW5kLHN0cmxlbihQREZWZXJzaW9uKSkgPT0gMCkKICAgICAgKHZvaWQpIFNldEltYWdlUHJvcGVydHkoaW1hZ2UsInBkZjpWZXJzaW9uIixjb21tYW5kKTsKICAgIGNvdW50PTA7CiAgICBpZiAoY3JvcGJveCAhPSBNYWdpY2tGYWxzZSkKICAgICAgewogICAgICAgIGlmIChMb2NhbGVOQ29tcGFyZShDcm9wQm94LGNvbW1hbmQsc3RybGVuKENyb3BCb3gpKSA9PSAwKQogICAgICAgICAgewogICAgICAgICAgICAvKgogICAgICAgICAgICAgIE5vdGUgcmVnaW9uIGRlZmluZWQgYnkgY3JvcCBib3guCiAgICAgICAgICAgICovCiAgICAgICAgICAgIGNvdW50PShzc2l6ZV90KSBzc2NhbmYoY29tbWFuZCwiQ3JvcEJveCBbJWxmICVsZiAlbGYgJWxmIiwKICAgICAgICAgICAgICAmYm91bmRzLngxLCZib3VuZHMueTEsJmJvdW5kcy54MiwmYm91bmRzLnkyKTsKICAgICAgICAgICAgaWYgKGNvdW50ICE9IDQpCiAgICAgICAgICAgICAgY291bnQ9KHNzaXplX3QpIHNzY2FuZihjb21tYW5kLCJDcm9wQm94WyVsZiAlbGYgJWxmICVsZiIsCiAgICAgICAgICAgICAgICAmYm91bmRzLngxLCZib3VuZHMueTEsJmJvdW5kcy54MiwmYm91bmRzLnkyKTsKICAgICAgICAgIH0KICAgICAgfQogICAgZWxzZQogICAgICBpZiAodHJpbWJveCAhPSBNYWdpY2tGYWxzZSkKICAgICAgICB7CiAgICAgICAgICBpZiAoTG9jYWxlTkNvbXBhcmUoVHJpbUJveCxjb21tYW5kLHN0cmxlbihUcmltQm94KSkgPT0gMCkKICAgICAgICAgICAgewogICAgICAgICAgICAgIC8qCiAgICAgICAgICAgICAgICBOb3RlIHJlZ2lvbiBkZWZpbmVkIGJ5IHRyaW0gYm94LgogICAgICAgICAgICAgICovCiAgICAgICAgICAgICAgY291bnQ9KHNzaXplX3QpIHNzY2FuZihjb21tYW5kLCJUcmltQm94IFslbGYgJWxmICVsZiAlbGYiLAogICAgICAgICAgICAgICAgJmJvdW5kcy54MSwmYm91bmRzLnkxLCZib3VuZHMueDIsJmJvdW5kcy55Mik7CiAgICAgICAgICAgICAgaWYgKGNvdW50ICE9IDQpCiAgICAgICAgICAgICAgICBjb3VudD0oc3NpemVfdCkgc3NjYW5mKGNvbW1hbmQsIlRyaW1Cb3hbJWxmICVsZiAlbGYgJWxmIiwKICAgICAgICAgICAgICAgICAgJmJvdW5kcy54MSwmYm91bmRzLnkxLCZib3VuZHMueDIsJmJvdW5kcy55Mik7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIGVsc2UKICAgICAgICBpZiAoTG9jYWxlTkNvbXBhcmUoTWVkaWFCb3gsY29tbWFuZCxzdHJsZW4oTWVkaWFCb3gpKSA9PSAwKQogICAgICAgICAgewogICAgICAgICAgICAvKgogICAgICAgICAgICAgIE5vdGUgcmVnaW9uIGRlZmluZWQgYnkgbWVkaWEgYm94LgogICAgICAgICAgICAqLwogICAgICAgICAgICBjb3VudD0oc3NpemVfdCkgc3NjYW5mKGNvbW1hbmQsIk1lZGlhQm94IFslbGYgJWxmICVsZiAlbGYiLAogICAgICAgICAgICAgICZib3VuZHMueDEsJmJvdW5kcy55MSwmYm91bmRzLngyLCZib3VuZHMueTIpOwogICAgICAgICAgICBpZiAoY291bnQgIT0gNCkKICAgICAgICAgICAgICBjb3VudD0oc3NpemVfdCkgc3NjYW5mKGNvbW1hbmQsIk1lZGlhQm94WyVsZiAlbGYgJWxmICVsZiIsCiAgICAgICAgICAgICAgICAmYm91bmRzLngxLCZib3VuZHMueTEsJmJvdW5kcy54MiwmYm91bmRzLnkyKTsKICAgICAgICAgIH0KICAgIGlmIChjb3VudCAhPSA0KQogICAgICBjb250aW51ZTsKICAgIGlmICgoKGJvdW5kcy54MiA+IGhpcmVzX2JvdW5kcy54MikgJiYgKGJvdW5kcy55MiA+IGhpcmVzX2JvdW5kcy55MikpIHx8CiAgICAgICAgKChoaXJlc19ib3VuZHMueDIgPT0gMC4wKSAmJiAoaGlyZXNfYm91bmRzLnkyID09IDAuMCkpKQogICAgICB7CiAgICAgICAgLyoKICAgICAgICAgIFNldCBQREYgcmVuZGVyIGdlb21ldHJ5LgogICAgICAgICovCiAgICAgICAgKHZvaWQpIEZvcm1hdE1hZ2lja1N0cmluZyhnZW9tZXRyeSxNYXhUZXh0RXh0ZW50LAogICAgICAgICAgIiVneCVnJSsuMTVnJSsuMTVnIixib3VuZHMueDItYm91bmRzLngxLGJvdW5kcy55Mi1ib3VuZHMueTEsCiAgICAgICAgICAgYm91bmRzLngxLGJvdW5kcy55MSk7CiAgICAgICAgKHZvaWQpIFNldEltYWdlUHJvcGVydHkoaW1hZ2UsInBkZjpIaVJlc0JvdW5kaW5nQm94IixnZW9tZXRyeSk7CiAgICAgICAgcGFnZS53aWR0aD0oc2l6ZV90KSBmbG9vcihib3VuZHMueDItYm91bmRzLngxKzAuNSk7CiAgICAgICAgcGFnZS5oZWlnaHQ9KHNpemVfdCkgZmxvb3IoYm91bmRzLnkyLWJvdW5kcy55MSswLjUpOwogICAgICAgIGhpcmVzX2JvdW5kcz1ib3VuZHM7CiAgICAgIH0KICB9CiAgKHZvaWQpIENsb3NlQmxvYihpbWFnZSk7CiAgaWYgKChmYWJzKGFuZ2xlKSA9PSA5MC4wKSB8fCAoZmFicyhhbmdsZSkgPT0gMjcwLjApKQogICAgewogICAgICBzaXplX3QKICAgICAgICBzd2FwOwoKICAgICAgc3dhcD1wYWdlLndpZHRoOwogICAgICBwYWdl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X2ltYWdlLT5wYWdlPXBhZ2U7CiAgICAodm9pZCkgQ2xvbmVJbWFnZVByb2ZpbGVzKHBkZl9pbWFnZSxpbWFnZSk7CiAgICAodm9pZCkgQ2xvbmVJbWFnZVByb3BlcnRpZXMocGRmX2ltYWdlLGltYWdlKTsKICAgIG5leHQ9U3luY05leHRJbWFnZUluTGlzdChwZGZfaW1hZ2UpOwogICAgaWYgKG5leHQgIT0gKEltYWdlICopIE5VTEwpCiAgICAgIHBkZl9pbWFnZT1uZXh0OwogIH0gd2hpbGUgKG5leHQgIT0gKEltYWdlICopIE5VTEwpOwogIGltYWdlPURlc3Ryb3lJbWFnZShpbWFnZSk7CiAgc2NlbmU9MDsKICBmb3IgKG5leHQ9R2V0Rmlyc3RJbWFnZUluTGlzdChwZGZfaW1hZ2UpOyBuZXh0ICE9IChJbWFnZSAqKSBOVUxMOyApCiAgewogICAgbmV4dC0+c2NlbmU9c2NlbmUrKzsKICAgIG5leHQ9R2V0TmV4dEltYWdlSW5MaXN0KG5leHQpOwogIH0KICByZXR1cm4oR2V0Rmlyc3RJbWFnZUluTGlzdChwZGZfaW1hZ2UpKTsKfQoMCi8qCiUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgIFIgZSBnIGkgcyB0IGUgciBQIEQgRiBJIG0gYSBnIGUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlCiUKJSAgUmVnaXN0ZXJQREZJbWFnZSgpIGFkZHMgcHJvcGVydGllcyBmb3IgdGhlIFBERiBpbWFnZSBmb3JtYXQgdG8KJSAgdGhlIGxpc3Qgb2Ygc3VwcG9ydGVkIGZvcm1hdHMuICBUaGUgcHJvcGVydGllcyBpbmNsdWRlIHRoZSBpbWFnZSBmb3JtYXQKJSAgdGFnLCBhIG1ldGhvZCB0byByZWFkIGFuZC9vciB3cml0ZSB0aGUgZm9ybWF0LCB3aGV0aGVyIHRoZSBmb3JtYXQKJSAgc3VwcG9ydHMgdGhlIHNhdmluZyBvZiBtb3JlIHRoYW4gb25lIGZyYW1lIHRvIHRoZSBzYW1lIGZpbGUgb3IgYmxvYiwKJSAgd2hldGhlciB0aGUgZm9ybWF0IHN1cHBvcnRzIG5hdGl2ZSBpbi1tZW1vcnkgSS9PLCBhbmQgYSBicmllZgolICBkZXNjcmlwdGlvbiBvZiB0aGUgZm9ybWF0LgolCiUgIFRoZSBmb3JtYXQgb2YgdGhlIFJlZ2lzdGVyUERGSW1hZ2UgbWV0aG9kIGlzOgolCiUgICAgICBzaXplX3QgUmVnaXN0ZXJQREZJbWFnZSh2b2lkKQolCiovCk1vZHVsZUV4cG9ydCBzaXplX3QgUmVnaXN0ZXJQREZJbWFnZSh2b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VhZF9zdXBwb3J0PUVuY29kZXJUaHJlYWRTdXBwb3J0OwogIGVudHJ5LT5kZXNjcmlwdGlvbj1Db25zdGFudFN0cmluZygiUG9ydGFibGUgRG9jdW1lbnQgQXJjaGl2ZSBGb3JtYXQiKTsKICBlbnRyeS0+bW9kdWxlPUNvbnN0YW50U3RyaW5nKCJQREYiKTsKICAodm9pZCkgUmVnaXN0ZXJNYWdpY2tJbmZvKGVudHJ5KTsKICByZXR1cm4oTWFnaWNrSW1hZ2VDb2RlclNpZ25hdHVyZSk7Cn0KDAovKgolJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICBVIG4gciBlIGcgaSBzIHQgZSByIFAgRCBGIEkgbSBhIGcgZSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJQolCiUgIFVucmVnaXN0ZXJQREZJbWFnZSgpIHJlbW92ZXMgZm9ybWF0IHJlZ2lzdHJhdGlvbnMgbWFkZSBieSB0aGUKJSAgUERGIG1vZHVsZSBmcm9tIHRoZSBsaXN0IG9mIHN1cHBvcnRlZCBmb3JtYXRzLgolCiUgIFRoZSBmb3JtYXQgb2YgdGhlIFVucmVnaXN0ZXJQREZJbWFnZSBtZXRob2QgaXM6CiUKJSAgICAgIFVucmVnaXN0ZXJQREZJbWFnZSh2b2lkKQolCiovCk1vZHVsZUV4cG9ydCB2b2lkIFVucmVnaXN0ZXJQREZJbWFnZSh2b2lkKQp7CiAgKHZvaWQpIFVucmVnaXN0ZXJNYWdpY2tJbmZvKCJBSSIpOwogICh2b2lkKSBVbnJlZ2lzdGVyTWFnaWNrSW5mbygiRVBERiIpOwogICh2b2lkKSBVbnJlZ2lzdGVyTWFnaWNrSW5mbygiUERGIik7CiAgKHZvaWQpIFVucmVnaXN0ZXJNYWdpY2tJbmZvKCJQREZBIik7Cn0KDAovKgolJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICBXIHIgaSB0IGUgUCBEIEYgSSBtIGEgZyBlICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJQolICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAlCiUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICUKJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJQolCiUgIFdyaXRlUERGSW1hZ2UoKSB3cml0ZXMgYW4gaW1hZ2UgaW4gdGhlIFBvcnRhYmxlIERvY3VtZW50IGltYWdlCiUgIGZvcm1hdC4KJQolICBUaGUgZm9ybWF0IG9mIHRoZSBXcml0ZVBERkltYWdlIG1ldGhvZCBpczoKJQolICAgICAgTWFnaWNrQm9vbGVhblR5cGUgV3JpdGVQREZJbWFnZShjb25zdCBJbWFnZUluZm8gKmltYWdlX2luZm8sSW1hZ2UgKmltYWdlKQolCiUgIEEgZGVzY3JpcHRpb24gb2YgZWFjaCBwYXJhbWV0ZXIgZm9sbG93cy4KJQolICAgIG8gaW1hZ2VfaW5mbzogdGhlIGltYWdlIGluZm8uCiUKJSAgICBvIGltYWdlOiAgVGhlIGltYWdlLgolCiovCgpzdGF0aWMgaW5saW5lIHNpemVfdCBNYWdpY2tNYXgoY29uc3Qgc2l6ZV90IHgsY29uc3Qgc2l6ZV90IHkpCnsKICBpZiAoeCA+IHkpCiAgICByZXR1cm4oeCk7CiAgcmV0dXJuKHkpOwp9CgpzdGF0aWMgaW5saW5lIHNpemVfdCBNYWdpY2tNaW4oY29uc3Qgc2l6ZV90IHgsY29uc3Qgc2l6ZV90IHkpCnsKICBpZiAoeCA8IHkpCiAgICByZXR1cm4oeCk7CiAgcmV0dXJuKHkpO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YKICAgICAgICAgKElzR3JheUltYWdlKGltYWdlLCZpbWFnZS0+ZXhjZXB0aW9uKSAhPSBNYWdpY2tGYWxzZSkpKQogICAgICB7CiAgICAgICAgc3dpdGNoIChjb21wcmVzc2lvbikKICAgICAgICB7CiAgICAgICAgICBjYXNlIEZheENvbXByZXNzaW9uOgogICAgICAgICAgY2FzZSBHcm91cDRDb21wcmVzc2lvbjoKICAgICAgICAgIHsKICAgICAgICAgICAgaWYgKExvY2FsZUNvbXBhcmUoQ0NJVFRQYXJhbSwiMCIpID09IDApCiAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgKHZvaWQpIEh1ZmZtYW5FbmNvZGVJbWFnZShpbWFnZV9pbmZvLGltYWdlLGltYWdlKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgKHZvaWQpIEh1ZmZtYW4yREVuY29kZUltYWdlKGltYWdlX2luZm8saW1hZ2UsaW1hZ2UpOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICAgIGNhc2UgSlBFR0NvbXByZXNzaW9uOgogICAgICAgICAgewogICAgICAgICAgICBzdGF0dXM9SW5qZWN0SW1hZ2VCbG9iKGltYWdlX2luZm8saW1hZ2UsaW1hZ2UsImpwZWciLAogICAgICAgICAgICAgICZpbWFnZS0+ZXhjZXB0aW9uKTsKICAgICAgICAgICAgaWYgKHN0YXR1cyA9PSBNYWdpY2tGYWxzZSkKICAgICAgICAgICAgICBUaHJvd1dyaXRlckV4Y2VwdGlvbihDb2RlckVycm9yLGltYWdlLT5leGNlcHRpb24ucmVhc29uKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgICBjYXNlIEpQRUcyMDAwQ29tcHJlc3Npb246CiAgICAgICAgICB7CiAgICAgICAgICAgIHN0YXR1cz1JbmplY3RJbWFnZUJsb2IoaW1hZ2VfaW5mbyxpbWFnZSxpbWFnZSwianAyIiwKICAgICAgICAgICAgICAmaW1hZ2UtPmV4Y2VwdGlvbik7CiAgICAgICAgICAgIGlmIChzdGF0dXMgPT0gTWFnaWNrRmFsc2UpCiAgICAgICAgICAgICAgVGhyb3dXcml0ZXJFeGNlcHRpb24oQ29kZXJFcnJvcixpbWFnZS0+ZXhjZXB0aW9uLnJlYXNvbik7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgY2FzZSBSTEVDb21wcmVzc2lvbjoKICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICB7CiAgICAgICAgICAgIC8qCiAgICAgICAgICAgICAgQWxsb2NhdGUgcGl4ZWwgYXJyYXkuCiAgICAgICAgICAgICovCiAgICAgICAgICAgIGxlbmd0aD0oc2l6ZV90KSBudW1iZXJfcGl4ZWxzOwogICAgICAgICAgICBwaXhlbHM9KHVuc2lnbmVkIGNoYXIgKikgQWNxdWlyZVF1YW50dW1NZW1vcnkobGVuZ3RoLAogICAgICAgICAgICAgIHNpemVvZigqcGl4ZWxzKSk7CiAgICAgICAgICAgIGlmIChwaXhlbHMgPT0gKHVuc2lnbmVkIGNoYXIgKikgTlVMTCkKICAgICAgICAgICAgICBUaHJvd1dyaXRlckV4Y2VwdGlvbihSZXNvdXJjZUxpbWl0RXJyb3IsIk1lbW9yeUFsbG9jYXRpb25GYWlsZWQiKTsKICAgICAgICAgICAgLyoKICAgICAgICAgICAgICBEdW1wIFJ1bmxlbmd0aCBlbmNvZGVkIHBpeGVscy4KICAgICAgICAgICAgKi8KICAgICAgICAgICAgcT1waXhlbHM7CiAgICAgICAgICAgIGZvciAoeT0wOyB5IDwgKHNzaXplX3QpIGltYWdlLT5yb3dzOyB5KyspCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICBwPUdldFZpcnR1YWxQaXhlbHMoaW1hZ2UsMCx5LGltYWdlLT5jb2x1bW5zLDEsCiAgICAgICAgICAgICAgICAmaW1hZ2UtPmV4Y2VwdGlvbik7CiAgICAgICAgICAgICAgaWYgKHAgPT0gKGNvbnN0IFBpeGVsUGFja2V0ICopIE5VTEwpCiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBmb3IgKHg9MDsgeCA8IChzc2l6ZV90KSBpbWFnZS0+Y29sdW1uczsgeCsrKQogICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICpxKys9U2NhbGVRdWFudHVtVG9DaGFyKFBpeGVsSW50ZW5zaXR5VG9RdWFudHVtKHApKTsKICAgICAgICAgICAgICAgIHArKzsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKGltYWdlLT5wcmV2aW91cyA9PSAoSW1hZ2UgKikgTlVMTCkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgc3RhdHVzPVNldEltYWdlUHJvZ3Jlc3MoaW1hZ2UsU2F2ZUltYWdlVGFnLChNYWdpY2tPZmZzZXRUeXBlKSB5LAogICAgICAgICAgICAgICAgaW1hZ2UtPnJvd3MpOwogICAgICAgICAgICAgICAgICBpZiAoc3RhdHVzID09IE1hZ2lja0ZhbHNlKQogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiNpZiBkZWZpbmVkKE1BR0lDS0NPUkVfWkxJQl9ERUxFR0FURSkKICAgICAgICAgICAgaWYgKGNvbXByZXNzaW9uID09IFppcENvbXByZXNzaW9uKQogICAgICAgICAgICAgIHN0YXR1cz1aTElCRW5jb2RlSW1hZ2UoaW1hZ2UsbGVuZ3RoLHBpeGVscyk7CiAgICAgICAgICAgIGVsc2UKI2VuZGlmCiAgICAgICAgICAgICAgaWYgKGNvbXByZXNzaW9uID09IExaV0NvbXByZXNzaW9uKQogICAgICAgICAgICAgICAgc3RhdHVzPUxaV0VuY29kZUltYWdlKGltYWdlLGxlbmd0aCxwaXhlbHMpOwogICAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgIHN0YXR1cz1QYWNrYml0c0VuY29kZUltYWdlKGltYWdlLGxlbmd0aCxwaXhlbHMpOwogICAgICAgICAgICBwaXhlbHM9KHVuc2lnbmVkIGNoYXIgKikgUmVsaW5xdWlzaE1hZ2lja01lbW9yeShwaXhlbHMpOwogICAgICAgICAgICBpZiAoc3RhdHVzID09IE1hZ2lja0ZhbHNlKQogICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICh2b2lkKSBDbG9zZUJsb2IoaW1hZ2UpOwogICAgICAgICAgICAgICAgcmV0dXJuKE1hZ2lja0ZhbHNlKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgY2FzZSBOb0NvbXByZXNzaW9uOgogICAgICAgICAgewogICAgICAgICAgICAvKgogICAgICAgICAgICAgIER1bXAgdW5jb21wcmVzc2VkIFBzZXVkb0NvbG9yIHBhY2tldHMuCiAgICAgICAgICAgICovCiAgICAgICAgICAgIEFzY2lpODVJbml0aWFsaXplKGltYWdlKTsKICAgICAgICAgICAgZm9yICh5PTA7IHkgPCAoc3NpemVfdCkgaW1hZ2UtPnJvd3M7IHkrKykKICAgICAgICAgICAgewogICAgICAgICAgICAgIHA9R2V0VmlydHVhbFBpeGVscyhpbWFnZSwwLHksaW1hZ2UtPmNvbHVtbnMsMSwKICAgICAgICAgICAgICAgICZpbWFnZS0+ZXhjZXB0aW9uKTsKICAgICAgICAgICAgICBpZiAocCA9PSAoY29uc3QgUGl4ZWxQYWNrZXQgKikgTlVMTCkKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGZvciAoeD0wOyB4IDwgKHNzaXplX3QpIGltYWdlLT5jb2x1bW5zOyB4KyspCiAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgQXNjaWk4NUVuY29kZShpbWFnZSwKICAgICAgICAgICAgICAgICAgU2NhbGVRdWFudHVtVG9DaGFyKFBpeGVsSW50ZW5zaXR5VG9RdWFudHVtKHApKSk7CiAgICAgICAgICAgICAgICBwKys7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChpbWFnZS0+cHJldmlvdXMgPT0gKEltYWdlICopIE5VTEwpCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgIHN0YXR1cz1TZXRJbWFnZVByb2dyZXNzKGltYWdlLFNhdmVJbWFnZVRhZywoTWFnaWNrT2Zmc2V0VHlwZSkgeSwKICAgICAgICAgICAgICAgIGltYWdlLT5yb3dzKTsKICAgICAgICAgICAgICAgICAgaWYgKHN0YXR1cyA9PSBNYWdpY2tGYWxzZSkKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBBc2NpaTg1Rmx1c2goaW1hZ2UpOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgIGVsc2UKICAgICAgaWYgKChpbWFnZS0+c3RvcmFnZV9jbGFzcyA9PSBEaXJlY3RDbGFzcykgfHwgKGltYWdlLT5jb2xvcnMgPiAyNTYpIHx8CiAgICAgICAgICAoY29tcHJlc3Npb24gPT0gSlBFR0NvbXByZXNzaW9uKSB8fAogICAgICAgICAgKGNvbXByZXNzaW9uID09IEpQRUcyMDAwQ29tcHJlc3Npb24pKQogICAgICAgIHN3aXRjaCAoY29tcHJlc3Npb24pCiAgICAgICAgewogICAgICAgICAgY2FzZSBKUEVHQ29tcHJlc3Npb246CiAgICAgICAgICB7CiAgICAgICAgICAgIHN0YXR1cz1JbmplY3RJbWFnZUJsb2IoaW1hZ2VfaW5mbyxpbWFnZSxpbWFnZSwianBlZyIsCiAgICAgICAgICAgICAgJmltYWdlLT5leGNlcHRpb24pOwogICAgICAgICAgICBpZiAoc3RhdHVzID09IE1hZ2lja0ZhbHNlKQogICAgICAgICAgICAgIFRocm93V3JpdGVyRXhjZXB0aW9uKENvZGVyRXJyb3IsaW1hZ2UtPmV4Y2VwdGlvbi5yZWFzb24pOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICAgIGNhc2UgSlBFRzIwMDBDb21wcmVzc2lvbjoKICAgICAgICAgIHsKICAgICAgICAgICAgc3RhdHVzPUluamVjdEltYWdlQmxvYihpbWFnZV9pbmZvLGltYWdlLGltYWdlLCJqcDIiLAogICAgICAgICAgICAgICZpbWFnZS0+ZXhjZXB0aW9uKTsKICAgICAgICAgICAgaWYgKHN0YXR1cyA9PSBNYWdpY2tGYWxzZSkKICAgICAgICAgICAgICBUaHJvd1dyaXRlckV4Y2VwdGlvbihDb2RlckVycm9yLGltYWdlLT5leGNlcHRpb24ucmVhc29uKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgICBjYXNlIFJMRUNvbXByZXNzaW9uOgogICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgIHsKICAgICAgICAgICAgLyoKICAgICAgICAgICAgICBBbGxvY2F0ZSBwaXhlbCBhcnJheS4KICAgICAgICAgICAgKi8KICAgICAgICAgICAgbGVuZ3RoPShzaXplX3QpIG51bWJlcl9waXhlbHM7CiAgICAgICAgICAgIHBpeGVscz0odW5zaWduZWQgY2hhciAqKSBBY3F1aXJlUXVhbnR1bU1lbW9yeShsZW5ndGgsCiAgICAgICAgICAgICAgNCpzaXplb2YoKnBpeGVscykpOwogICAgICAgICAgICBsZW5ndGgqPWltYWdlLT5jb2xvcnNwYWNlID09IENNWUtDb2xvcnNwYWNlID8gNFVMIDogM1VMOwogICAgICAgICAgICBpZiAocGl4ZWxzID09ICh1bnNpZ25lZCBjaGFyICopIE5VTEwpCiAgICAgICAgICAgICAgVGhyb3dXcml0ZXJFeGNlcHRpb24oUmVzb3VyY2VMaW1pdEVycm9yLCJNZW1vcnlBbGxvY2F0aW9uRmFpbGVkIik7CiAgICAgICAgICAgIC8qCiAgICAgICAgICAgICAgRHVtcCBydW5vZmZzZXQgZW5jb2RlZCBwaXhlbHMuCiAgICAgICAgICAgICovCiAgICAgICAgICAgIHE9cGl4ZWxzOwogICAgICAgICAgICBmb3IgKHk9MDsgeSA8IChzc2l6ZV90KSBpbWFnZS0+cm93czsgeSsrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgcD1HZXRWaXJ0dWFsUGl4ZWxzKGltYWdlLDAseSxpbWFnZS0+Y29sdW1ucywxLAogICAgICAgICAgICAgICAgJmltYWdlLT5leGNlcHRpb24pOwogICAgICAgICAgICAgIGlmIChwID09IChjb25zdCBQaXhlbFBhY2tldCAqKSBOVUxMKQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgaW5kZXhlcz1HZXRWaXJ0dWFsSW5kZXhRdWV1ZShpbWFnZSk7CiAgICAgICAgICAgICAgZm9yICh4PTA7IHggPCAoc3NpemVfdCkgaW1hZ2UtPmNvbHVtbnM7IHgrKykKICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAqcSsrPVNjYWxlUXVhbnR1bVRvQ2hhcihHZXRSZWRQaXhlbENvbXBvbmVudChwKSk7CiAgICAgICAgICAgICAgICAqcSsrPVNjYWxlUXVhbnR1bVRvQ2hhcihHZXRHcmVlblBpeGVsQ29tcG9uZW50KHApKTsKICAgICAgICAgICAgICAgICpxKys9U2NhbGVRdWFudHVtVG9DaGFyKEdldEJsdWVQaXhlbENvbXBvbmVudChwKSk7CiAgICAgICAgICAgICAgICBpZiAoaW1hZ2UtPmNvbG9yc3BhY2UgPT0gQ01ZS0NvbG9yc3BhY2UpCiAgICAgICAgICAgICAgICAgICpxKys9U2NhbGVRdWFudHVtVG9DaGFyKGluZGV4ZXNbeF0pOwogICAgICAgICAgICAgICAgcCsrOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAoaW1hZ2UtPnByZXZpb3VzID09IChJbWFnZSAqKSBOVUxMKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICBzdGF0dXM9U2V0SW1hZ2VQcm9ncmVzcyhpbWFnZSxTYXZlSW1hZ2VUYWcsKE1hZ2lja09mZnNldFR5cGUpIHksCiAgICAgICAgICAgICAgICBpbWFnZS0+cm93cyk7CiAgICAgICAgICAgICAgICAgIGlmIChzdGF0dXMgPT0gTWFnaWNrRmFsc2UpCiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KI2lmIGRlZmluZWQoTUFHSUNLQ09SRV9aTElCX0RFTEVHQVRFKQogICAgICAgICAgICBpZiAoY29tcHJlc3Npb24gPT0gWmlwQ29tcHJlc3Npb24pCiAgICAgICAgICAgICAgc3RhdHVzPVpMSUJFbmNvZGVJbWFnZShpbWFnZSxsZW5ndGgscGl4ZWxzKTsKICAgICAgICAgICAgZWxzZQojZW5kaWYKICAgICAgICAgICAgICBpZiAoY29tcHJlc3Npb24gPT0gTFpXQ29tcHJlc3Npb24pCiAgICAgICAgICAgICAgICBzdGF0dXM9TFpXRW5jb2RlSW1hZ2UoaW1hZ2UsbGVuZ3RoLHBpeGVscyk7CiAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgc3RhdHVzPVBhY2tiaXRzRW5jb2RlSW1hZ2UoaW1hZ2UsbGVuZ3RoLHBpeGVscyk7CiAgICAgICAgICAgIHBpeGVscz0odW5zaWduZWQgY2hhciAqKSBSZWxpbnF1aXNoTWFnaWNrTWVtb3J5KHBpeGVscyk7CiAgICAgICAgICAgIGlmIChzdGF0dXMgPT0gTWFnaWNrRmFsc2UpCiAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgKHZvaWQpIENsb3NlQmxvYihpbWFnZSk7CiAgICAgICAgICAgICAgICByZXR1cm4oTWFnaWNrRmFsc2UpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgICBjYXNlIE5vQ29tcHJlc3Npb246CiAgICAgICAgICB7CiAgICAgICAgICAgIC8qCiAgICAgICAgICAgICAgRHVtcCB1bmNvbXByZXNzZWQgRGlyZWN0Q29sb3IgcGFja2V0cy4KICAgICAgICAgICAgKi8KICAgICAgICAgICAgQXNjaWk4NUluaXRpYWxpemUoaW1hZ2UpOwogICAgICAgICAgICBmb3IgKHk9MDsgeSA8IChzc2l6ZV90KSBpbWFnZS0+cm93czsgeSsrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgcD1HZXRWaXJ0dWFsUGl4ZWxzKGltYWdlLDAseSxpbWFnZS0+Y29sdW1ucywxLAogICAgICAgICAgICAgICAgJmltYWdlLT5leGNlcHRpb24pOwogICAgICAgICAgICAgIGlmIChwID09IChjb25zdCBQaXhlbFBhY2tldCAqKSBOVUxMKQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgaW5kZXhlcz1HZXRWaXJ0dWFsSW5kZXhRdWV1ZShpbWFnZSk7CiAgICAgICAgICAgICAgZm9yICh4PTA7IHggPCAoc3NpemVfdCkgaW1hZ2UtPmNvbHVtbnM7IHgrKykKICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBBc2NpaTg1RW5jb2RlKGltYWdlLFNjYWxlUXVhbnR1bVRvQ2hhcihHZXRSZWRQaXhlbENvbXBvbmVudChwKSkpOwogICAgICAgICAgICAgICAgQXNjaWk4NUVuY29kZShpbWFnZSxTY2FsZVF1YW50dW1Ub0NoYXIoR2V0R3JlZW5QaXhlbENvbXBvbmVudChwKSkpOwogICAgICAgICAgICAgICAgQXNjaWk4NUVuY29kZShpbWFnZSxTY2FsZVF1YW50dW1Ub0NoYXIoR2V0Qmx1ZVBpeGVsQ29tcG9uZW50KHApKSk7CiAgICAgICAgICAgICAgICBpZiAoaW1hZ2UtPmNvbG9yc3BhY2UgPT0gQ01ZS0NvbG9yc3BhY2UpCiAgICAgICAgICAgICAgICAgIEFzY2lpODVFbmNvZGUoaW1hZ2UsU2NhbGVRdWFudHVtVG9DaGFyKGluZGV4ZXNbeF0pKTsKICAgICAgICAgICAgICAgIHArKzsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKGltYWdlLT5wcmV2aW91cyA9PSAoSW1hZ2UgKikgTlVMTCkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgc3RhdHVzPVNldEltYWdlUHJvZ3Jlc3MoaW1hZ2UsU2F2ZUltYWdlVGFnLChNYWdpY2tPZmZzZXRUeXBlKSB5LAogICAgICAgICAgICAgICAgaW1hZ2UtPnJvd3MpOwogICAgICAgICAgICAgICAgICBpZiAoc3RhdHVzID09IE1hZ2lja0ZhbHNlKQogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIEFzY2lpODVGbHVzaChpbWFnZSk7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgZWxzZQogICAgICAgIHsKICAgICAgICAgIC8qCiAgICAgICAgICAgIER1bXAgbnVtYmVyIG9mIGNvbG9ycyBhbmQgY29sb3JtYXAuCiAgICAgICAgICAqLwogICAgICAgICAgc3dpdGNoIChjb21wcmVzc2lvbikKICAgICAgICAgIHsKICAgICAgICAgICAgY2FzZSBSTEVDb21wcmVzc2lvbjoKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgewogICAgICAgICAgICAgIC8qCiAgICAgICAgICAgICAgICBBbGxvY2F0ZSBwaXhlbCBhcnJheS4KICAgICAgICAgICAgICAqLwogICAgICAgICAgICAgIGxlbmd0aD0oc2l6ZV90KSBudW1iZXJfcGl4ZWxzOwogICAgICAgICAgICAgIHBpeGVscz0odW5zaWduZWQgY2hhciAqKSBBY3F1aXJlUXVhbnR1bU1lbW9yeShsZW5ndGgsCiAgICAgICAgICAgICAgICBzaXplb2YoKnBpeGVscykpOwogICAgICAgICAgICAgIGlmIChwaXhlbHMgPT0gKHVuc2lnbmVkIGNoYXIgKikgTlVMTCkKICAgICAgICAgICAgICAgIFRocm93V3JpdGVyRXhjZXB0aW9uKFJlc291cmNlTGltaXRFcnJvciwKICAgICAgICAgICAgICAgICAgIk1lbW9yeUFsbG9jYXRpb25GYWlsZWQiKTsKICAgICAgICAgICAgICAvKgogICAgICAgICAgICAgICAgRHVtcCBSdW5sZW5ndGggZW5jb2RlZCBwaXhlbHMuCiAgICAgICAgICAgICAgKi8KICAgICAgICAgICAgICBxPXBpeGVsczsKICAgICAgICAgICAgICBmb3IgKHk9MDsgeSA8IChzc2l6ZV90KSBpbWFnZS0+cm93czsgeSsrKQogICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHA9R2V0VmlydHVhbFBpeGVscyhpbWFnZSwwLHksaW1hZ2UtPmNvbHVtbnMsMSwKICAgICAgICAgICAgICAgICAgJmltYWdlLT5leGNlcHRpb24pOwogICAgICAgICAgICAgICAgaWYgKHAgPT0gKGNvbnN0IFBpeGVsUGFja2V0ICopIE5VTEwpCiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgaW5kZXhlcz1HZXRWaXJ0dWFsSW5kZXhRdWV1ZShpbWFnZSk7CiAgICAgICAgICAgICAgICBmb3IgKHg9MDsgeCA8IChzc2l6ZV90KSBpbWFnZS0+Y29sdW1uczsgeCsrKQogICAgICAgICAgICAgICAgICAqcSsrPSh1bnNpZ25lZCBjaGFyKSBpbmRleGVzW3hdOwogICAgICAgICAgICAgICAgaWYgKGltYWdlLT5wcmV2aW91cyA9PSAoSW1hZ2UgKikgTlVMTCkKICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIHN0YXR1cz1TZXRJbWFnZVByb2dyZXNzKGltYWdlLFNhdmVJbWFnZVRhZywoTWFnaWNrT2Zmc2V0VHlwZSkgeSwKICAgICAgICAgICAgICAgIGltYWdlLT5yb3dzKTsKICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdHVzID09IE1hZ2lja0ZhbHNlKQogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiNpZiBkZWZpbmVkKE1BR0lDS0NPUkVfWkxJQl9ERUxFR0FURSkKICAgICAgICAgICAgICBpZiAoY29tcHJlc3Npb24gPT0gWmlwQ29tcHJlc3Npb24pCiAgICAgICAgICAgICAgICBzdGF0dXM9WkxJQkVuY29kZUltYWdlKGltYWdlLGxlbmd0aCxwaXhlbHMpOwogICAgICAgICAgICAgIGVsc2UKI2VuZGlmCiAgICAgICAgICAgICAgICBpZiAoY29tcHJlc3Npb24gPT0gTFpXQ29tcHJlc3Npb24pCiAgICAgICAgICAgICAgICAgIHN0YXR1cz1MWldFbmNvZGVJbWFnZShpbWFnZSxsZW5ndGgscGl4ZWxzKTsKICAgICAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgICAgc3RhdHVzPVBhY2tiaXRzRW5jb2RlSW1hZ2UoaW1hZ2UsbGVuZ3RoLHBpeGVscyk7CiAgICAgICAgICAgICAgcGl4ZWxzPSh1bnNpZ25lZCBjaGFyICopIFJlbGlucXVpc2hNYWdpY2tNZW1vcnkocGl4ZWxzKTsKICAgICAgICAgICAgICBpZiAoc3RhdHVzID09IE1hZ2lja0ZhbHNlKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAodm9pZCkgQ2xvc2VCbG9iKGltYWdlKTsKICAgICAgICAgICAgICAgICAgcmV0dXJuKE1hZ2lja0ZhbHNlKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBjYXNlIE5vQ29tcHJlc3Npb246CiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAvKgogICAgICAgICAgICAgICAgRHVtcCB1bmNvbXByZXNzZWQgUHNldWRvQ29sb3IgcGFja2V0cy4KICAgICAgICAgICAgICAqLwogICAgICAgICAgICAgIEFzY2lpODVJbml0aWFsaXplKGltYWdlKTsKICAgICAgICAgICAgICBmb3IgKHk9MDsgeSA8IChzc2l6ZV90KSBpbWFnZS0+cm93czsgeSsrKQogICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHA9R2V0VmlydHVhbFBpeGVscyhpbWFnZSwwLHksaW1hZ2UtPmNvbHVtbnMsMSwKICAgICAgICAgICAgICAgICAgJmltYWdlLT5leGNlcHRpb24pOwogICAgICAgICAgICAgICAgaWYgKHAgPT0gKGNvbnN0IFBpeGVsUGFja2V0ICopIE5VTEwpCiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgaW5kZXhlcz1HZXRWaXJ0dWFsSW5kZXhRdWV1ZShpbWFnZSk7CiAgICAgICAgICAgICAgICBmb3IgKHg9MDsgeCA8IChzc2l6ZV90KSBpbWFnZS0+Y29sdW1uczsgeCsrKQogICAgICAgICAgICAgICAgICBBc2NpaTg1RW5jb2RlKGltYWdlLCh1bnNpZ25lZCBjaGFyKSBpbmRleGVzW3hdKTsKICAgICAgICAgICAgICAgIGlmIChpbWFnZS0+cHJldmlvdXMgPT0gKEltYWdlICopIE5VTEwpCiAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBzdGF0dXM9U2V0SW1hZ2VQcm9ncmVzcyhpbWFnZSxTYXZlSW1hZ2VUYWcsKE1hZ2lja09mZnNldFR5cGUpIHksCiAgICAgICAgICAgICAgICBpbWFnZS0+cm93cyk7CiAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXR1cyA9PSBNYWdpY2tGYWxzZSkKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIEFzY2lpODVGbHVzaChpbWFnZSk7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICBvZmZzZXQ9VGVsbEJsb2IoaW1hZ2UpLW9mZnNldDsKICAgICh2b2lkKSBXcml0ZUJsb2JTdHJpbmcoaW1hZ2UsIlxuZW5kc3RyZWFtXG4iKTsKICAgICh2b2lkKSBXcml0ZUJsb2JTdHJpbmcoaW1hZ2UsImVuZG9ialxuIik7CiAgICAvKgogICAgICBXcml0ZSBMZ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24pIHx8CiAgICAgICAgKChpbWFnZV9pbmZvLT50eXBlICE9IFRydWVDb2xvclR5cGUpICYmCiAgICAgICAgIChJc0dyYXlJbWFnZSh0aWxlX2ltYWdlLCZpbWFnZS0+ZXhjZXB0aW9uKSAhPSBNYWdpY2tGYWxzZSkpKQogICAgICB7CiAgICAgICAgc3dpdGNoIChjb21wcmVzc2lvbikKICAgICAgICB7CiAgICAgICAgICBjYXNlIEZheENvbXByZXNzaW9uOgogICAgICAgICAgY2FzZSBHcm91cDRDb21wcmVzc2lvbjoKICAgICAgICAgIHsKICAgICAgICAgICAgaWYgKExvY2FsZUNvbXBhcmUoQ0NJVFRQYXJhbSwiMCIpID09IDApCiAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgKHZvaWQpIEh1ZmZtYW5FbmNvZGVJbWFnZShpbWFnZV9pbmZvLGltYWdlLHRpbGVfaW1hZ2UpOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAodm9pZCkgSHVmZm1hbjJERW5jb2RlSW1hZ2UoaW1hZ2VfaW5mbyxpbWFnZSx0aWxlX2ltYWdlKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgICBjYXNlIEpQRUdDb21wcmVzc2lvbjoKICAgICAgICAgIHsKICAgICAgICAgICAgc3RhdHVzPUluamVjdEltYWdlQmxvYihpbWFnZV9pbmZvLGltYWdlLHRpbGVfaW1hZ2UsImpwZWciLAogICAgICAgICAgICAgICZpbWFnZS0+ZXhjZXB0aW9uKTsKICAgICAgICAgICAgaWYgKHN0YXR1cyA9PSBNYWdpY2tGYWxzZSkKICAgICAgICAgICAgICBUaHJvd1dyaXRlckV4Y2VwdGlvbihDb2RlckVycm9yLHRpbGVfaW1hZ2UtPmV4Y2VwdGlvbi5yZWFzb24pOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICAgIGNhc2UgSlBFRzIwMDBDb21wcmVzc2lvbjoKICAgICAgICAgIHsKICAgICAgICAgICAgc3RhdHVzPUluamVjdEltYWdlQmxvYihpbWFnZV9pbmZvLGltYWdlLHRpbGVfaW1hZ2UsImpwMiIsCiAgICAgICAgICAgICAgJmltYWdlLT5leGNlcHRpb24pOwogICAgICAgICAgICBpZiAoc3RhdHVzID09IE1hZ2lja0ZhbHNlKQogICAgICAgICAgICAgIFRocm93V3JpdGVyRXhjZXB0aW9uKENvZGVyRXJyb3IsdGlsZV9pbWFnZS0+ZXhjZXB0aW9uLnJlYXNvbik7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgY2FzZSBSTEVDb21wcmVzc2lvbjoKICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICB7CiAgICAgICAgICAgIC8qCiAgICAgICAgICAgICAgQWxsb2NhdGUgcGl4ZWwgYXJyYXkuCiAgICAgICAgICAgICovCiAgICAgICAgICAgIGxlbmd0aD0oc2l6ZV90KSBudW1iZXJfcGl4ZWxzOwogICAgICAgICAgICBwaXhlbHM9KHVuc2lnbmVkIGNoYXIgKikgQWNxdWlyZVF1YW50dW1NZW1vcnkobGVuZ3RoLAogICAgICAgICAgICAgIHNpemVvZigqcGl4ZWxzKSk7CiAgICAgICAgICAgIGlmIChwaXhlbHMgPT0gKHVuc2lnbmVkIGNoYXIgKikgTlVMTCkKICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICB0aWxlX2ltYWdlPURlc3Ryb3lJbWFnZSh0aWxlX2ltYWdlKTsKICAgICAgICAgICAgICAgIFRocm93V3JpdGVyRXhjZXB0aW9uKFJlc291cmNlTGltaXRFcnJvciwKICAgICAgICAgICAgICAgICAgIk1lbW9yeUFsbG9jYXRpb25GYWlsZWQiKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIC8qCiAgICAgICAgICAgICAgRHVtcCBSdW5sZW5ndGggZW5jb2RlZCBwaXhlbHMuCiAgICAgICAgICAgICovCiAgICAgICAgICAgIHE9cGl4ZWxzOwogICAgICAgICAgICBmb3IgKHk9MDsgeSA8IChzc2l6ZV90KSB0aWxlX2ltYWdlLT5yb3dzOyB5KyspCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICBwPUdldFZpcnR1YWxQaXhlbHModGlsZV9pbWFnZSwwLHksdGlsZV9pbWFnZS0+Y29sdW1ucywxLAogICAgICAgICAgICAgICAgJnRpbGVfaW1hZ2UtPmV4Y2VwdGlvbik7CiAgICAgICAgICAgICAgaWYgKHAgPT0gKGNvbnN0IFBpeGVsUGFja2V0ICopIE5VTEwpCiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBmb3IgKHg9MDsgeCA8IChzc2l6ZV90KSB0aWxlX2ltYWdlLT5jb2x1bW5zOyB4KyspCiAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgKnErKz1TY2FsZVF1YW50dW1Ub0NoYXIoUGl4ZWxJbnRlbnNpdHlUb1F1YW50dW0ocCkpOwogICAgICAgICAgICAgICAgcCsrOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQojaWYgZGVmaW5lZChNQUdJQ0tDT1JFX1pMSUJfREVMRUdBVEUpCiAgICAgICAgICAgIGlmIChjb21wcmVzc2lvbiA9PSBaaXBDb21wcmVzc2lvbikKICAgICAgICAgICAgICBzdGF0dXM9WkxJQkVuY29kZUltYWdlKGltYWdlLGxlbmd0aCxwaXhlbHMpOwogICAgICAgICAgICBlbHNlCiNlbmRpZgogICAgICAgICAgICAgIGlmIChjb21wcmVzc2lvbiA9PSBMWldDb21wcmVzc2lvbikKICAgICAgICAgICAgICAgIHN0YXR1cz1MWldFbmNvZGVJbWFnZShpbWFnZSxsZW5ndGgscGl4ZWxzKTsKICAgICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICBzdGF0dXM9UGFja2JpdHNFbmNvZGVJbWFnZShpbWFnZSxsZW5ndGgscGl4ZWxzKTsKICAgICAgICAgICAgcGl4ZWxzPSh1bnNpZ25lZCBjaGFyICopIFJlbGlucXVpc2hNYWdpY2tNZW1vcnkocGl4ZWxzKTsKICAgICAgICAgICAgaWYgKHN0YXR1cyA9PSBNYWdpY2tGYWxzZSkKICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAodm9pZCkgQ2xvc2VCbG9iKGltYWdlKTsKICAgICAgICAgICAgICAgIHJldHVybihNYWdpY2tGYWxzZSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICAgIGNhc2UgTm9Db21wcmVzc2lvbjoKICAgICAgICAgIHsKICAgICAgICAgICAgLyoKICAgICAgICAgICAgICBEdW1wIHVuY29tcHJlc3NlZCBQc2V1ZG9Db2xvciBwYWNrZXRzLgogICAgICAgICAgICAqLwogICAgICAgICAgICBBc2NpaTg1SW5pdGlhbGl6ZShpbWFnZSk7CiAgICAgICAgICAgIGZvciAoeT0wOyB5IDwgKHNzaXplX3QpIHRpbGVfaW1hZ2UtPnJvd3M7IHkrKykKICAgICAgICAgICAgewogICAgICAgICAgICAgIHA9R2V0VmlydHVhbFBpeGVscyh0aWxlX2ltYWdlLDAseSx0aWxlX2ltYWdlLT5jb2x1bW5zLDEsCiAgICAgICAgICAgICAgICAmdGlsZV9pbWFnZS0+ZXhjZXB0aW9uKTsKICAgICAgICAgICAgICBpZiAocCA9PSAoY29uc3QgUGl4ZWxQYWNrZXQgKikgTlVMTCkKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGZvciAoeD0wOyB4IDwgKHNzaXplX3QpIHRpbGVfaW1hZ2UtPmNvbHVtbnM7IHgrKykKICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBBc2NpaTg1RW5jb2RlKGltYWdlLAogICAgICAgICAgICAgICAgICBTY2FsZVF1YW50dW1Ub0NoYXIoUGl4ZWxJbnRlbnNpdHlUb1F1YW50dW0ocCkpKTsKICAgICAgICAgICAgICAgIHArKzsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgQXNjaWk4NUZsdXNoKGltYWdlKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICBlbHNlCiAgICAgIGlmICgodGlsZV9pbWFnZS0+c3RvcmFnZV9jbGFzcyA9PSBEaXJlY3RDbGFzcykgfHwKICAgICAgICAgICh0aWxlX2ltYWdlLT5jb2xvcnMgPiAyNTYpIHx8IChjb21wcmVzc2lvbiA9PSBKUEVHQ29tcHJlc3Npb24pIHx8CiAgICAgICAgICAoY29tcHJlc3Npb24gPT0gSlBFRzIwMDBDb21wcmVzc2lvbikpCiAgICAgICAgc3dpdGNoIChjb21wcmVzc2lvbikKICAgICAgICB7CiAgICAgICAgICBjYXNlIEpQRUdDb21wcmVzc2lvbjoKICAgICAgICAgIHsKICAgICAgICAgICAgc3RhdHVzPUluamVjdEltYWdlQmxvYihpbWFnZV9pbmZvLGltYWdlLHRpbGVfaW1hZ2UsImpwZWciLAogICAgICAgICAgICAgICZpbWFnZS0+ZXhjZXB0aW9uKTsKICAgICAgICAgICAgaWYgKHN0YXR1cyA9PSBNYWdpY2tGYWxzZSkKICAgICAgICAgICAgICBUaHJvd1dyaXRlckV4Y2VwdGlvbihDb2RlckVycm9yLHRpbGVfaW1hZ2UtPmV4Y2VwdGlvbi5yZWFzb24pOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICAgIGNhc2UgSlBFRzIwMDBDb21wcmVzc2lvbjoKICAgICAgICAgIHsKICAgICAgICAgICAgc3RhdHVzPUluamVjdEltYWdlQmxvYihpbWFnZV9pbmZvLGltYWdlLHRpbGVfaW1hZ2UsImpwMiIsCiAgICAgICAgICAgICAgJmltYWdlLT5leGNlcHRpb24pOwogICAgICAgICAgICBpZiAoc3RhdHVzID09IE1hZ2lja0ZhbHNlKQogICAgICAgICAgICAgIFRocm93V3JpdGVyRXhjZXB0aW9uKENvZGVyRXJyb3IsdGlsZV9pbWFnZS0+ZXhjZXB0aW9uLnJlYXNvbik7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgY2FzZSBSTEVDb21wcmVzc2lvbjoKICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICB7CiAgICAgICAgICAgIC8qCiAgICAgICAgICAgICAgQWxsb2NhdGUgcGl4ZWwgYXJyYXkuCiAgICAgICAgICAgICovCiAgICAgICAgICAgIGxlbmd0aD0oc2l6ZV90KSBudW1iZXJfcGl4ZWxzOwogICAgICAgICAgICBwaXhlbHM9KHVuc2lnbmVkIGNoYXIgKikgQWNxdWlyZVF1YW50dW1NZW1vcnkobGVuZ3RoLDQqCiAgICAgICAgICAgICAgc2l6ZW9mKCpwaXhlbHMpKTsKICAgICAgICAgICAgbGVuZ3RoKj10aWxlX2ltYWdlLT5jb2xvcnNwYWNlID09IENNWUtDb2xvcnNwYWNlID8gNFVMIDogM1VMOwogICAgICAgICAgICBpZiAocGl4ZWxzID09ICh1bnNpZ25lZCBjaGFyICopIE5VTEwpCiAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgdGlsZV9pbWFnZT1EZXN0cm95SW1hZ2UodGlsZV9pbWFnZSk7CiAgICAgICAgICAgICAgICBUaHJvd1dyaXRlckV4Y2VwdGlvbihSZXNvdXJjZUxpbWl0RXJyb3IsCiAgICAgICAgICAgICAgICAgICJNZW1vcnlBbGxvY2F0aW9uRmFpbGVkIik7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAvKgogICAgICAgICAgICAgIER1bXAgcnVub2Zmc2V0IGVuY29kZWQgcGl4ZWxzLgogICAgICAgICAgICAqLwogICAgICAgICAgICBxPXBpeGVsczsKICAgICAgICAgICAgZm9yICh5PTA7IHkgPCAoc3NpemVfdCkgdGlsZV9pbWFnZS0+cm93czsgeSsrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgcD1HZXRWaXJ0dWFsUGl4ZWxzKHRpbGVfaW1hZ2UsMCx5LHRpbGVfaW1hZ2UtPmNvbHVtbnMsMSwKICAgICAgICAgICAgICAgICZ0aWxlX2ltYWdlLT5leGNlcHRpb24pOwogICAgICAgICAgICAgIGlmIChwID09IChjb25zdCBQaXhlbFBhY2tldCAqKSBOVUxMKQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgaW5kZXhlcz1HZXRWaXJ0dWFsSW5kZXhRdWV1ZSh0aWxlX2ltYWdlKTsKICAgICAgICAgICAgICBmb3IgKHg9MDsgeCA8IChzc2l6ZV90KSB0aWxlX2ltYWdlLT5jb2x1bW5zOyB4KyspCiAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgKnErKz1TY2FsZVF1YW50dW1Ub0NoYXIoR2V0UmVkUGl4ZWxDb21wb25lbnQocCkpOwogICAgICAgICAgICAgICAgKnErKz1TY2FsZVF1YW50dW1Ub0NoYXIoR2V0R3JlZW5QaXhlbENvbXBvbmVudChwKSk7CiAgICAgICAgICAgICAgICAqcSsrPVNjYWxlUXVhbnR1bVRvQ2hhcihHZXRCbHVlUGl4ZWxDb21wb25lbnQocCkpOwogICAgICAgICAgICAgICAgaWYgKGltYWdlLT5jb2xvcnNwYWNlID09IENNWUtDb2xvcnNwYWNlKQogICAgICAgICAgICAgICAgICAqcSsrPVNjYWxlUXVhbnR1bVRvQ2hhcihpbmRleGVzW3hdKTsKICAgICAgICAgICAgICAgIHArKzsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KI2lmIGRlZmluZWQoTUFHSUNLQ09SRV9aTElCX0RFTEVHQVRFKQogICAgICAgICAgICBpZiAoY29tcHJlc3Npb24gPT0gWmlwQ29tcHJlc3Npb24pCiAgICAgICAgICAgICAgc3RhdHVzPVpMSUJFbmNvZGVJbWFnZShpbWFnZSxsZW5ndGgscGl4ZWxzKTsKICAgICAgICAgICAgZWxzZQojZW5kaWYKICAgICAgICAgICAgICBpZiAoY29tcHJlc3Npb24gPT0gTFpXQ29tcHJlc3Npb24pCiAgICAgICAgICAgICAgICBzdGF0dXM9TFpXRW5jb2RlSW1hZ2UoaW1hZ2UsbGVuZ3RoLHBpeGVscyk7CiAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgc3RhdHVzPVBhY2tiaXRzRW5jb2RlSW1hZ2UoaW1hZ2UsbGVuZ3RoLHBpeGVscyk7CiAgICAgICAgICAgIHBpeGVscz0odW5zaWduZWQgY2hhciAqKSBSZWxpbnF1aXNoTWFnaWNrTWVtb3J5KHBpeGVscyk7CiAgICAgICAgICAgIGlmIChzdGF0dXMgPT0gTWFnaWNrRmFsc2UpCiAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgKHZvaWQpIENsb3NlQmxvYihpbWFnZSk7CiAgICAgICAgICAgICAgICByZXR1cm4oTWFnaWNrRmFsc2UpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgICBjYXNlIE5vQ29tcHJlc3Npb246CiAgICAgICAgICB7CiAgICAgICAgICAgIC8qCiAgICAgICAgICAgICAgRHVtcCB1bmNvbXByZXNzZWQgRGlyZWN0Q29sb3IgcGFja2V0cy4KICAgICAgICAgICAgKi8KICAgICAgICAgICAgQXNjaWk4NUluaXRpYWxpemUoaW1hZ2UpOwogICAgICAgICAgICBmb3IgKHk9MDsgeSA8IChzc2l6ZV90KSB0aWxlX2ltYWdlLT5yb3dzOyB5KyspCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICBwPUdldFZpcnR1YWxQaXhlbHModGlsZV9pbWFnZSwwLHksdGlsZV9pbWFnZS0+Y29sdW1ucywxLAogICAgICAgICAgICAgICAgJnRpbGVfaW1hZ2UtPmV4Y2VwdGlvbik7CiAgICAgICAgICAgICAgaWYgKHAgPT0gKGNvbnN0IFBpeGVsUGFja2V0ICopIE5VTEwpCiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBpbmRleGVzPUdldFZpcnR1YWxJbmRleFF1ZXVlKHRpbGVfaW1hZ2UpOwogICAgICAgICAgICAgIGZvciAoeD0wOyB4IDwgKHNzaXplX3QpIHRpbGVfaW1hZ2UtPmNvbHVtbnM7IHgrKykKICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBBc2NpaTg1RW5jb2RlKGltYWdlLFNjYWxlUXVhbnR1bVRvQ2hhcihHZXRSZWRQaXhlbENvbXBvbmVudChwKSkpOwogICAgICAgICAgICAgICAgQXNjaWk4NUVuY29kZShpbWFnZSxTY2FsZVF1YW50dW1Ub0NoYXIoR2V0R3JlZW5QaXhlbENvbXBvbmVudChwKSkpOwogICAgICAgICAgICAgICAgQXNjaWk4NUVuY29kZShpbWFnZSxTY2FsZVF1YW50dW1Ub0NoYXIoR2V0Qmx1ZVBpeGVsQ29tcG9uZW50KHApKSk7CiAgICAgICAgICAgICAgICBpZiAoaW1hZ2UtPmNvbG9yc3BhY2UgPT0gQ01ZS0NvbG9yc3BhY2UpCiAgICAgICAgICAgICAgICAgIEFzY2lpODVFbmNvZGUoaW1hZ2UsU2NhbGVRdWFudHVtVG9DaGFyKGluZGV4ZXNbeF0pKTsKICAgICAgICAgICAgICAgIHArKzsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgQXNjaWk4NUZsdXNoKGltYWdlKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgLyoKICAgICAgICAgICAgRHVtcCBudW1iZXIgb2YgY29sb3JzIGFuZCBjb2xvcm1hcC4KICAgICAgICAgICovCiAgICAgICAgICBzd2l0Y2ggKGNvbXByZXNzaW9uKQogICAgICAgICAgewogICAgICAgICAgICBjYXNlIFJMRUNvbXByZXNzaW9uOgogICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICB7CiAgICAgICAgICAgICAgLyoKICAgICAgICAgICAgICAgIEFsbG9jYXRlIHBpeGVsIGFycmF5LgogICAgICAgICAgICAgICovCiAgICAgICAgICAgICAgbGVuZ3RoPShzaXplX3QpIG51bWJlcl9waXhlbHM7CiAgICAgICAgICAgICAgcGl4ZWxzPSh1bnNpZ25lZCBjaGFyICopIEFjcXVpcmVRdWFudHVtTWVtb3J5KGxlbmd0aCwKICAgICAgICAgICAgICAgIHNpemVvZigqcGl4ZWxzKSk7CiAgICAgICAgICAgICAgaWYgKHBpeGVscyA9PSAodW5zaWduZWQgY2hhciAqKSBOVUxMKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICB0aWxlX2ltYWdlPURlc3Ryb3lJbWFnZSh0aWxlX2ltYWdlKTsKICAgICAgICAgICAgICAgICAgVGhyb3dXcml0ZXJFeGNlcHRpb24oUmVzb3VyY2VMaW1pdEVycm9yLAogICAgICAgICAgICAgICAgICAgICJNZW1vcnlBbGxvY2F0aW9uRmFpbGVkIik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgLyoKICAgICAgICAgICAgICAgIER1bXAgUnVubGVuZ3RoIGVuY29kZWQgcGl4ZWxzLgogICAgICAgICAgICAgICovCiAgICAgICAgICAgICAgcT1waXhlbHM7CiAgICAgICAgICAgICAgZm9yICh5PTA7IHkgPCAoc3NpemVfdCkgdGlsZV9pbWFnZS0+cm93czsgeSsrKQogICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHA9R2V0VmlydHVhbFBpeGVscyh0aWxlX2ltYWdlLDAseSx0aWxlX2ltYWdlLT5jb2x1bW5zLDEsCiAgICAgICAgICAgICAgICAgICZ0aWxlX2ltYWdlLT5leGNlcHRpb24pOwogICAgICAgICAgICAgICAgaWYgKHAgPT0gKGNvbnN0IFBpeGVsUGFja2V0ICopIE5VTEwpCiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgaW5kZXhlcz1HZXRWaXJ0dWFsSW5kZXhRdWV1ZSh0aWxlX2ltYWdlKTsKICAgICAgICAgICAgICAgIGZvciAoeD0wOyB4IDwgKHNzaXplX3QpIHRpbGVfaW1hZ2UtPmNvbHVtbnM7IHgrKykKICAgICAgICAgICAgICAgICAgKnErKz0odW5zaWduZWQgY2hhcikgaW5kZXhlc1t4XTsKICAgICAgICAgICAgICB9CiNpZiBkZWZpbmVkKE1BR0lDS0NPUkVfWkxJQl9ERUxFR0FURSkKICAgICAgICAgICAgICBpZiAoY29tcHJlc3Npb24gPT0gWmlwQ29tcHJlc3Npb24pCiAgICAgICAgICAgICAgICBzdGF0dXM9WkxJQkVuY29kZUltYWdlKGltYWdlLGxlbmd0aCxwaXhlbHMpOwogICAgICAgICAgICAgIGVsc2UKI2VuZGlmCiAgICAgICAgICAgICAgICBpZiAoY29tcHJlc3Npb24gPT0gTFpXQ29tcHJlc3Npb24pCiAgICAgICAgICAgICAgICAgIHN0YXR1cz1MWldFbmNvZGVJbWFnZShpbWFnZSxsZW5ndGgscGl4ZWxzKTsKICAgICAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgICAgc3RhdHVzPVBhY2tiaXRzRW5jb2RlSW1hZ2UoaW1hZ2UsbGVuZ3RoLHBpeGVscyk7CiAgICAgICAgICAgICAgcGl4ZWxzPSh1bnNpZ25lZCBjaGFyICopIFJlbGlucXVpc2hNYWdpY2tNZW1vcnkocGl4ZWxzKTsKICAgICAgICAgICAgICBpZiAoc3RhdHVzID09IE1hZ2lja0ZhbHNlKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAodm9pZCkgQ2xvc2VCbG9iKGltYWdlKTsKICAgICAgICAgICAgICAgICAgcmV0dXJuKE1hZ2lja0ZhbHNlKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBjYXNlIE5vQ29tcHJlc3Npb246CiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAvKgogICAgICAgICAgICAgICAgRHVtcCB1bmNvbXByZXNzZWQgUHNldWRvQ29sb3IgcGFja2V0cy4KICAgICAgICAgICAgICAqLwogICAgICAgICAgICAgIEFzY2lpODVJbml0aWFsaXplKGltYWdlKTsKICAgICAgIC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MWldDb21wcmVzc2lvbjoKICAgICAgICAgIHsKICAgICAgICAgICAgKHZvaWQpIEZvcm1hdE1hZ2lja1N0cmluZyhidWZmZXIsTWF4VGV4dEV4dGVudCxDRm9ybWF0LCJMWldEZWNvZGUiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgICBjYXNlIFppcENvbXByZXNzaW9uOgogICAgICAgICAgewogICAgICAgICAgICAodm9pZCkgRm9ybWF0TWFnaWNrU3RyaW5nKGJ1ZmZlcixNYXhUZXh0RXh0ZW50LENGb3JtYXQsCiAgICAgICAgICAgICAgIkZsYXRlRGVjb2RlIik7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgIHsKICAgICAgICAgICAgKHZvaWQpIEZvcm1hdE1hZ2lja1N0cmluZyhidWZmZXIsTWF4VGV4dEV4dGVudCxDRm9ybWF0LAogICAgICAgICAgICAgICJSdW5MZW5ndGhEZWNvZGUiKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgICh2b2lkKSBXcml0ZUJsb2JTdHJpbmcoaW1hZ2UsYnVmZmVyKTsKICAgICAgICAodm9pZCkgRm9ybWF0TWFnaWNrU3RyaW5nKGJ1ZmZlcixNYXhUZXh0RXh0ZW50LCIvV2lkdGggJS4yMGdcbiIsCiAgICAgICAgICAoZG91YmxlKSBpbWFnZS0+Y29sdW1ucyk7CiAgICAgICAgKHZvaWQpIFdyaXRlQmxvYlN0cmluZyhpbWFnZSxidWZmZXIpOwogICAgICAgICh2b2lkKSBGb3JtYXRNYWdpY2tTdHJpbmcoYnVmZmVyLE1heFRleHRFeHRlbnQsIi9IZWlnaHQgJS4yMGdcbiIsCiAgICAgICAgICAoZG91YmxlKSBpbWFnZS0+cm93cyk7CiAgICAgICAgKHZvaWQpIFdyaXRlQmxvYlN0cmluZyhpbWFnZSxidWZmZXIpOwogICAgICAgICh2b2lkKSBXcml0ZUJsb2JTdHJpbmcoaW1hZ2UsIi9Db2xvclNwYWNlIC9EZXZpY2VHcmF5XG4iKTsKICAgICAgICAodm9pZCkgRm9ybWF0TWFnaWNrU3RyaW5nKGJ1ZmZlcixNYXhUZXh0RXh0ZW50LCIvQml0c1BlckNvbXBvbmVudCAlZFxuIiwKICAgICAgICAgIChjb21wcmVzc2lvbiA9PSBGYXhDb21wcmVzc2lvbikgfHwgKGNvbXByZXNzaW9uID09IEdyb3VwNENvbXByZXNzaW9uKQogICAgICAgICAgPyAxIDogOCk7CiAgICAgICAgKHZvaWQpIFdyaXRlQmxvYlN0cmluZyhpbWFnZSxidWZmZXIpOwogICAgICAgICh2b2lkKSBGb3JtYXRNYWdpY2tTdHJpbmcoYnVmZmVyLE1heFRleHRFeHRlbnQsIi9MZW5ndGggJS4yMGcgMCBSXG4iLAogICAgICAgICAgKGRvdWJsZSkgb2JqZWN0KzEpOwogICAgICAgICh2b2lkKSBXcml0ZUJsb2JTdHJpbmcoaW1hZ2UsYnVmZmVyKTsKICAgICAgICAodm9pZCkgV3JpdGVCbG9iU3RyaW5nKGltYWdlLCI+PlxuIik7CiAgICAgICAgKHZvaWQpIFdyaXRlQmxvYlN0cmluZyhpbWFnZSwic3RyZWFtXG4iKTsKICAgICAgICBvZmZzZXQ9VGVsbEJsb2IoaW1hZ2UpOwogICAgICAgIG51bWJlcl9waXhlbHM9KE1hZ2lja1NpemVUeXBlKSBpbWFnZS0+Y29sdW1ucyppbWFnZS0+cm93czsKICAgICAgICBzd2l0Y2ggKGNvbXByZXNzaW9uKQogICAgICAgIHsKICAgICAgICAgIGNhc2UgUkxFQ29tcHJlc3Npb246CiAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgewogICAgICAgICAgICAvKgogICAgICAgICAgICAgIEFsbG9jYXRlIHBpeGVsIGFycmF5LgogICAgICAgICAgICAqLwogICAgICAgICAgICBsZW5ndGg9KHNpemVfdCkgbnVtYmVyX3BpeGVsczsKICAgICAgICAgICAgcGl4ZWxzPSh1bnNpZ25lZCBjaGFyICopIEFjcXVpcmVRdWFudHVtTWVtb3J5KGxlbmd0aCwKICAgICAgICAgICAgICBzaXplb2YoKnBpeGVscykpOwogICAgICAgICAgICBpZiAocGl4ZWxzID09ICh1bnNpZ25lZCBjaGFyICopIE5VTEwpCiAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaW1hZ2U9RGVzdHJveUltYWdlKGltYWdlKTsKICAgICAgICAgICAgICAgIFRocm93V3JpdGVyRXhjZXB0aW9uKFJlc291cmNlTGltaXRFcnJvciwKICAgICAgICAgICAgICAgICAgIk1lbW9yeUFsbG9jYXRpb25GYWlsZWQiKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIC8qCiAgICAgICAgICAgICAgRHVtcCBSdW5sZW5ndGggZW5jb2RlZCBwaXhlbHMuCiAgICAgICAgICAgICovCiAgICAgICAgICAgIHE9cGl4ZWxzOwogICAgICAgICAgICBmb3IgKHk9MDsgeSA8IChzc2l6ZV90KSBpbWFnZS0+cm93czsgeSsrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgcD1HZXRWaXJ0dWFsUGl4ZWxzKGltYWdlLDAseSxpbWFnZS0+Y29sdW1ucywxLAogICAgICAgICAgICAgICAgJmltYWdlLT5leGNlcHRpb24pOwogICAgICAgICAgICAgIGlmIChwID09IChjb25zdCBQaXhlbFBhY2tldCAqKSBOVUxMKQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgZm9yICh4PTA7IHggPCAoc3NpemVfdCkgaW1hZ2UtPmNvbHVtbnM7IHgrKykKICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAqcSsrPVNjYWxlUXVhbnR1bVRvQ2hhcigoUXVhbnR1bSkgKEdldEFscGhhUGl4ZWxDb21wb25lbnQocCkpKTsKICAgICAgICAgICAgICAgIHArKzsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KI2lmIGRlZmluZWQoTUFHSUNLQ09SRV9aTElCX0RFTEVHQVRFKQogICAgICAgICAgICBpZiAoY29tcHJlc3Npb24gPT0gWmlwQ29tcHJlc3Npb24pCiAgICAgICAgICAgICAgc3RhdHVzPVpMSUJFbmNvZGVJbWFnZShpbWFnZSxsZW5ndGgscGl4ZWxzKTsKICAgICAgICAgICAgZWxzZQojZW5kaWYKICAgICAgICAgICAgICBpZiAoY29tcHJlc3Npb24gPT0gTFpXQ29tcHJlc3Npb24pCiAgICAgICAgICAgICAgICBzdGF0dXM9TFpXRW5jb2RlSW1hZ2UoaW1hZ2UsbGVuZ3RoLHBpeGVscyk7CiAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgc3RhdHVzPVBhY2tiaXRzRW5jb2RlSW1hZ2UoaW1hZ2UsbGVuZ3RoLHBpeGVscyk7CiAgICAgICAgICAgIHBpeGVscz0odW5zaWduZWQgY2hhciAqKSBSZWxpbnF1aXNoTWFnaWNrTWVtb3J5KHBpeGVscyk7CiAgICAgICAgICAgIGlmIChzdGF0dXMgPT0gTWFnaWNrRmFsc2UpCiAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgKHZvaWQpIENsb3NlQmxvYihpbWFnZSk7CiAgICAgICAgICAgICAgICByZXR1cm4oTWFnaWNrRmFsc2UpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgICBjYXNlIE5vQ29tcHJlc3Npb246CiAgICAgICAgICB7CiAgICAgICAgICAgIC8qCiAgICAgICAgICAgICAgRHVtcCB1bmNvbXByZXNzZWQgUHNldWRvQ29sb3IgcGFja2V0cy4KICAgICAgICAgICAgKi8KICAgICAgICAgICAgQXNjaWk4NUluaXRpYWxpemUoaW1hZ2UpOwogICAgICAgICAgICBmb3IgKHk9MDsgeSA8IChzc2l6ZV90KSBpbWFnZS0+cm93czsgeSsrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgcD1HZXRWaXJ0dWFsUGl4ZWxzKGltYWdlLDAseSxpbWFnZS0+Y29sdW1ucywxLAogICAgICAgICAgICAgICAgJmltYWdlLT5leGNlcHRpb24pOwogICAgICAgICAgICAgIGlmIChwID09IChjb25zdCBQaXhlbFBhY2tldCAqKSBOVUxMKQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgZm9yICh4PTA7IHggPCAoc3NpemVfdCkgaW1hZ2UtPmNvbHVtbnM7IHgrKykKICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBBc2NpaTg1RW5jb2RlKGltYWdlLFNjYWxlUXVhbnR1bVRvQ2hhcigoUXVhbnR1bSkgKFF1YW50dW1SYW5nZS0KICAgICAgICAgICAgICAgICAgR2V0T3BhY2l0eVBpeGVsQ29tcG9uZW50KHApKSkpOwogICAgICAgICAgICAgICAgcCsrOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBBc2NpaTg1Rmx1c2goaW1hZ2UpOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgb2Zmc2V0PVRlbGxCbG9iKGltYWdlKS1vZmZzZXQ7CiAgICAgICAgKHZvaWQpIFdyaXRlQmxvYlN0cmluZyhpbWFnZSwiXG5lbmRzdHJlYW1cbiIpOwogICAgICB9CiAgICAodm9pZCkgV3JpdGVCbG9iU3RyaW5nKGltYWdlLCJlbmRvYmpcbiIpOwogICAgLyoKICAgICAgV3JpdGUgTGVuZ3RoIG9iamVjdC4KICAgICovCiAgICB4cmVmW29iamVjdCsrXT1UZWxsQmxvYihpbWFnZSk7CiAgICAodm9pZCkgRm9ybWF0TWFnaWNrU3RyaW5nKGJ1ZmZlcixNYXhUZXh0RXh0ZW50LCIlLjIwZyAwIG9ialxuIiwoZG91YmxlKQogICAgICBvYmplY3QpOwogICAgKHZvaWQpIFdyaXRlQmxvYlN0cmluZyhpbWFnZSxidWZmZXIpOwogICAgKHZvaWQpIEZvcm1hdE1hZ2lja1N0cmluZyhidWZmZXIsTWF4VGV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