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CiAgICBzdWJ0cmVlX2NvbnRleHRfY2FjaGUgKnB0cjsKICAgIGlmICghY29udGV4dF9uYW1lKSB7CiAgICAgICAgY29udGV4dF9uYW1lID0gIiI7CiAgICB9CiAgICBmb3IgKHB0ciA9IGNvbnRleHRfc3VidHJlZXM7IHB0ciAhPSBOVUxMOyBwdHIgPSBwdHItPm5leHQpIHsKICAgICAgICBpZiAocHRyLT5jb250ZXh0X25hbWUgIT0gTlVMTCAmJgoJICAgIHN0cmNtcChwdHItPmNvbnRleHRfbmFtZSwgY29udGV4dF9uYW1lKSA9PSAwKSB7CiAgICAgICAgICAgIHB0ci0+Zmlyc3Rfc3VidHJlZSA9IG5ld190cmVlOwogICAgICAgICAgICByZXR1cm4gcHRyLT5maXJzdF9zdWJ0cmVlOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiBhZGRfc3VidHJlZShuZXdfdHJlZSwgY29udGV4dF9uYW1lKTsKfQoKTkVUU05NUF9JTkxJTkUgdm9pZApuZXRzbm1wX3N1YnRyZWVfY2hhbmdlX25leHQobmV0c25tcF9zdWJ0cmVlICpwdHIsIG5ldHNubXBfc3VidHJlZSAqdGhlbmV4dCkKewogICAgcHRyLT5uZXh0ID0gdGhlbmV4dDsKICAgIGlmICh0aGVuZXh0KQogICAgICAgIG5ldHNubXBfb2lkX2NvbXBhcmVfbGwocHRyLT5zdGFydF9hLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcHRyLT5zdGFydF9sZW4sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGVuZXh0LT5zdGFydF9hLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhlbmV4dC0+c3RhcnRfbGVuLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJnRoZW5leHQtPm9pZF9vZmYpOwp9CgpORVRTTk1QX0lOTElORSB2b2lkCm5ldHNubXBfc3VidHJlZV9jaGFuZ2VfcHJldihuZXRzbm1wX3N1YnRyZWUgKnB0ciwgbmV0c25tcF9zdWJ0cmVlICp0aGVwcmV2KQp7CiAgICBwdHItPnByZXYgPSB0aGVwcmV2OwogICAgaWYgKHRoZXByZXYpCiAgICAgICAgbmV0c25tcF9vaWRfY29tcGFyZV9sbCh0aGVwcmV2LT5zdGFydF9hLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhlcHJldi0+c3RhcnRfbGVuLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcHRyLT5zdGFydF9hLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcHRyLT5zdGFydF9sZW4sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAmcHRyLT5vaWRfb2ZmKTsKfQoKaW50Cm5ldHNubXBfc3VidHJlZV9jb21wYXJlKGNvbnN0IG5ldHNubXBfc3VidHJlZSAqYXAsIGNvbnN0IG5ldHNubXBfc3VidHJlZSAqYnApCnsKICAgIHJldHVybiBzbm1wX29pZF9jb21wYXJlKGFwLT5uYW1lX2EsIGFwLT5uYW1lbGVuLCBicC0+bmFtZV9hLCBicC0+bmFtZWxlbik7Cn0KCnZvaWQKbmV0c25tcF9zdWJ0cmVlX2pvaW4obmV0c25tcF9zdWJ0cmVlICpyb290KQp7CiAgICBuZXRzbm1wX3N1YnRyZWUgKnMsICp0bXAsICpjLCAqZDsKCiAgICB3aGlsZSAocm9vdCAhPSBOVUxMKSB7CiAgICAgICAgcyA9IHJvb3QtPm5leHQ7CiAgICAgICAgd2hpbGUgKHMgIT0gTlVMTCAmJiByb290LT5yZWdpbmZvID09IHMtPnJlZ2luZm8pIHsKICAgICAgICAgICAgdG1wID0gcy0+bmV4dDsKICAgICAgICAgICAgREVCVUdNU0dUTCgoInN1YnRyZWUiLCAicm9vdCBzdGFydCAiKSk7CiAgICAgICAgICAgIERFQlVHTVNHT0lEKCgic3VidHJlZSIsIHJvb3QtPnN0YXJ0X2EsIHJvb3QtPnN0YXJ0X2xlbikpOwogICAgICAgICAgICBERUJVR01TRygoInN1YnRyZWUiLCAiIChvcmlnaW5hbCBlbmQgIikpOwogICAgICAgICAgICBERUJVR01TR09JRCgoInN1YnRyZWUiLCByb290LT5lbmRfYSwgcm9vdC0+ZW5kX2xlbikpOwogICAgICAgICAgICBERUJVR01TRygoInN1YnRyZWUiLCAiKVxuIikpOwogICAgICAgICAgICBERUJVR01TR1RMKCgic3VidHJlZSIsICIgIEpPSU5JTkcgdG8gIikpOwogICAgICAgICAgICBERUJVR01TR09JRCgoInN1YnRyZWUiLCBzLT5zdGFydF9hLCBzLT5zdGFydF9sZW4pKTsKCgkgICAgU05NUF9GUkVFKHJvb3QtPmVuZF9hKTsKCSAgICByb290LT5lbmRfYSAgID0gcy0+ZW5kX2E7CiAgICAgICAgICAgIHJvb3QtPmVuZF9sZW4gPSBzLT5lbmRfbGVuOwoJICAgIHMtPmVuZF9hICAgICAgPSBOVUxMOwoKICAgICAgICAgICAgZm9yIChjID0gcm9vdDsgYyAhPSBOVUxMOyBjID0gYy0+Y2hpbGRyZW4pIHsKICAgICAgICAgICAgICAgIG5ldHNubXBfc3VidHJlZV9jaGFuZ2VfbmV4dChjLCBzLT5uZXh0KTsKICAgICAgICAgICAgfQogICAgICAgICAgICBmb3IgKGMgPSBzOyBjICE9IE5VTEw7IGMgPSBjLT5jaGlsZHJlbikgewogICAgICAgICAgICAgICAgbmV0c25tcF9zdWJ0cmVlX2NoYW5nZV9wcmV2KGMsIHJvb3QpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIERFQlVHTVNHKCgic3VidHJlZSIsICIgc28gbmV3IGVuZCAiKSk7CiAgICAgICAgICAgIERFQlVHTVNHT0lEKCgic3VidHJlZSIsIHJvb3QtPmVuZF9hLCByb290LT5lbmRfbGVuKSk7CiAgICAgICAgICAgIERFQlVHTVNHKCgic3VidHJlZSIsICJcbiIpKTsKICAgICAgICAgICAgLyoKICAgICAgICAgICAgICogUHJvYmFibHkgbmVlZCB0byBmcmVlIGNoaWxkcmVuIHRvbz8gIAogICAgICAgICAgICAgKi8KICAgICAgICAgICAgZm9yIChjID0gcy0+Y2hpbGRyZW47IGMgIT0gTlVMTDsgYyA9IGQpIHsKICAgICAgICAgICAgICAgIGQgPSBjLT5jaGlsZHJlbjsKICAgICAgICAgICAgICAgIG5ldHNubXBfc3VidHJlZV9mcmVlKGMpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIG5ldHNubXBfc3VidHJlZV9mcmVlKHMpOwogICAgICAgICAgICBzID0gdG1wOwogICAgICAgIH0KICAgICAgICByb290ID0gcm9vdC0+bmV4dDsKICAgIH0KfQoKCiAgICAgICAgLyoKICAgICAgICAgKiAgU3BsaXQgdGhlIHN1YnRyZWUgaW50byB0d28gYXQgdGhlIHNwZWNpZmllZCBwb2ludCwKICAgICAgICAgKiAgICByZXR1cm5pbmcgdGhlIG5ldyAoc2Vjb25kKSBzdWJ0cmVlCiAgICAgICAgICovCm5ldHNubXBfc3VidHJlZSAqCm5ldHNubXBfc3VidHJlZV9zcGxpdChuZXRzbm1wX3N1YnRyZWUgKmN1cnJlbnQsIG9pZCBuYW1lW10sIGludCBuYW1lX2xlbikKewogICAgc3RydWN0IHZhcmlhYmxlICp2cCA9IE5VTEw7CiAgICBuZXRzbm1wX3N1YnRyZWUgKm5ld19zdWIsICpwdHI7CiAgICBpbnQgaSA9IDAsIHJjID0gMCwgcmMyID0gMDsKICAgIHNpemVfdCBjb21tb25fbGVuID0gMDsKICAgIGNoYXIgKmNwOwogICAgb2lkICp0bXBfYSwgKnRtcF9iOwoKICAgIGlmIChzbm1wX29pZF9jb21wYXJlKG5hbWUsIG5hbWVfbGVuLCBjdXJyZW50LT5lbmRfYSwgY3VycmVudC0+ZW5kX2xlbik+MCkgewoJLyogU3BsaXQgY29tZXMgYWZ0ZXIgdGhlIGVuZCBvZiB0aGlzIHN1YnRyZWUgKi8KICAgICAgICByZXR1cm4gTlVMTDsKICAgIH0KCiAgICBuZXdfc3ViID0gbmV0c25tcF9zdWJ0cmVlX2RlZXBjb3B5KGN1cnJlbnQpOwog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AgICAgICAgbmV0c25tcF9zdWJ0cmVlX2NoYW5nZV9wcmV2KHB0ciwgY3VycmVudCk7CiAgICB9CiAgICBmb3IgKHB0ciA9IG5ld19zdWItPm5leHQ7IHB0ciAhPSBOVUxMOyBwdHI9cHRyLT5jaGlsZHJlbikgewogICAgICAgIG5ldHNubXBfc3VidHJlZV9jaGFuZ2VfcHJldihwdHIsIG5ld19zdWIpOwogICAgfQoKICAgIHJldHVybiBuZXdfc3ViOwp9CgppbnQKbmV0c25tcF9zdWJ0cmVlX2xvYWQobmV0c25tcF9zdWJ0cmVlICpuZXdfc3ViLCBjb25zdCBjaGFyICpjb250ZXh0X25hbWUpCnsKICAgIG5ldHNubXBfc3VidHJlZSAqdHJlZTEsICp0cmVlMiwgKm5ldzI7CiAgICBuZXRzbm1wX3N1YnRyZWUgKnByZXYsICpuZXh0OwogICAgaW50ICAgICAgICAgICAgIHJlcywgcmMgPSAwOwoKICAgIGlmIChuZXdfc3ViID09IE5VTEwpIHsKICAgICAgICByZXR1cm4gTUlCX1JFR0lTVEVSRURfT0s7ICAgICAgIC8qIERlZ2VuZXJhdGUgY2FzZSAqLwogICAgfQoKICAgIGlmICghbmV0c25tcF9zdWJ0cmVlX2ZpbmRfZmlyc3QoY29udGV4dF9uYW1lKSkgewogICAgICAgIHN0YXRpYyBpbnQgaW5sb29wID0gMDsKICAgICAgICBpZiAoIWlubG9vcCkgewogICAgICAgICAgICBvaWQgY2NpdHRbMV0gICAgICAgICAgID0geyAwIH07CiAgICAgICAgICAgIG9pZCBpc29bMV0gICAgICAgICAgICAgPSB7IDEgfTsKICAgICAgICAgICAgb2lkIGpvaW50X2NjaXR0X2lzb1sxXSA9IHsgMiB9OwogICAgICAgICAgICBpbmxvb3AgPSAxOwogICAgICAgICAgICBuZXRzbm1wX3JlZ2lzdGVyX251bGxfY29udGV4dChzbm1wX2R1cGxpY2F0ZV9vYmppZChjY2l0dCwgMSksIDEsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC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0cmVlX2ZyZWUobmV3Mik7CgkJcmV0dXJuIHJlczsKCSAgICB9CgkgICAgcmV0dXJuIG5ldHNubXBfc3VidHJlZV9sb2FkKG5ldzIsIGNvbnRleHRfbmFtZSk7Cgl9CiAgICB9CiAgICByZXR1cm4gMDsKfQoKLyoKICogTm90ZTogcmVnaW5mbyB3aWxsIGJlIGZyZWVkIG9uIGZhaWx1cmVzCiAqLwppbnQKbmV0c25tcF9yZWdpc3Rlcl9taWIoY29uc3QgY2hhciAqbW9kdWxlTmFtZSwKICAgICAgICAgICAgICAgICAgICAgc3RydWN0IHZhcmlhYmxlICp2YXIsCiAgICAgICAgICAgICAgICAgICAgIHNpemVfdCB2YXJzaXplLAogICAgICAgICAgICAgICAgICAgICBzaXplX3QgbnVtdmFycywKICAgICAgICAgICAgICAgICAgICAgb2lkICogbWlibG9jLAogICAgICAgICAgICAgICAgICAgICBzaXplX3QgbWlibG9jbGVuLAogICAgICAgICAgICAgICAgICAgICBpbnQgcHJpb3JpdHksCiAgICAgICAgICAgICAgICAgICAgIGludCByYW5nZV9zdWJpZCwKICAgICAgICAgICAgICAgICAgICAgb2lkIHJhbmdlX3Vib3VuZCwKICAgICAgICAgICAgICAgICAgICAgbmV0c25tcF9zZXNzaW9uICogc3MsCiAgICAgICAgICAgICAgICAgICAgIGNvbnN0IGNoYXIgKmNvbnRleHQsCiAgICAgICAgICAgICAgICAgICAgIGludCB0aW1lb3V0LAogICAgICAgICAgICAgICAgICAgICBpbnQgZmxhZ3MsCiAgICAgICAgICAgICAgICAgICAgIG5ldHNubXBfaGFuZGxlcl9yZWdpc3RyYXRpb24gKnJlZ2luZm8sCiAgICAgICAgICAgICAgICAgICAgIGludCBwZXJmb3JtX2NhbGxiYWNrKQp7CiAgICBuZXRzbm1wX3N1YnRyZWUgKnN1YnRyZWUsICpzdWIyOwogICAgaW50ICAgICAgICAgICAgIHJlcywgaTsKICAgIHN0cnVjdCByZWdpc3Rlcl9wYXJhbWV0ZXJzIHJlZ19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luZm8uCiAgICAgKiAod2hpY2ggYmVncyB0aGUgcXVlc3Rpb24sIHdoeSBkbyB3ZSBoYXZlIGJvdGg/IEl0IGFwcGVhcnMgdGhhdCB0aGUKICAgICAqICByZWdpbmZvIGl0ZW0gZGlkbid0IGFwcGVhciB0aWwgNS4yKQogICAgICovCiAgICBpZiggKChOVUxMID09IGNvbnRleHQpICYmIChOVUxMICE9IHJlZ2luZm8tPmNvbnRleHROYW1lKSkgfHwKICAgICAgICAoKE5VTEwgIT0gY29udGV4dCkgJiYgKE5VTEwgPT0gcmVnaW5mby0+Y29udGV4dE5hbWUpKSB8fAogICAgICAgICggKChOVUxMICE9IGNvbnRleHQpICYmIChOVUxMICE9IHJlZ2luZm8tPmNvbnRleHROYW1lKSkgJiYKICAgICAgICAgICgwICE9IHN0cmNtcChjb250ZXh0LCByZWdpbmZvLT5jb250ZXh0TmFtZSkpKSApIHsKICAgICAgICBzbm1wX2xvZyhMT0dfV0FSTklORywiY29udGV4dCBwYXNzZWQgZHVyaW5nIHJlZ2lzdHJhdGlvbiBkb2VzIG5vdCAiCiAgICAgICAgICAgICAgICAgImVxdWFsIHRoZSByZWdpbmZvIGNvbnRleHROYW1lISAoJyVzJyAhPSAnJXMnKVxuIiwKICAgICAgICAgICAgICAgICBjb250ZXh0LCByZWdpbmZvLT5jb250ZXh0TmFtZSk7CiAgICAgICAgbmV0c25tcF9hc3NlcnQoISJyZWdpc3RlciBjb250ZXh0ID09IHJlZ2luZm8tPmNvbnRleHROYW1lIik7IC8qIGFsd2F5cyBmYWxzZSAqLwogICAgfQoKICAgIC8qICBDcmVhdGUgdGhlIG5ldyBzdWJ0cmVlIG5vZGUgYmVpbmcgcmVnaXN0ZXJlZC4gICovCgogICAgc3VidHJlZS0+cmVnaW5mbyA9IHJlZ2luZm87CiAgICBzdWJ0cmVlLT5uYW1lX2EgID0gc25tcF9kdXBsaWNhdGVfb2JqaWQobWlibG9jLCBtaWJsb2NsZW4pOwogICAgc3VidHJlZS0+c3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dlX3N1YmlkIC0gMV0gID0gaTsKCiAgICAgICAgICAgIHJlcyA9IG5ldHNubXBfc3VidHJlZV9sb2FkKHN1YjIsIGNvbnRleHQpOwogICAgICAgICAgICBpZiAocmVzICE9IE1JQl9SRUdJU1RFUkVEX09LKSB7CiAgICAgICAgICAgICAgICB1bnJlZ2lzdGVyX21pYl9jb250ZXh0KG1pYmxvYywgbWlibG9jbGVuLCBwcmlvcml0eSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmFuZ2Vfc3ViaWQsIHJhbmdlX3Vib3VuZCwgY29udGV4dCk7CgkJbmV0c25tcF9zdWJ0cmVlX2ZyZWUoc3ViMik7CiAgICAgICAgICAgICAgICBuZXRzbm1wX3NldF9sb29rdXBfY2FjaGVfc2l6ZShvbGRfbG9va3VwX2NhY2hlX3ZhbCk7CiAgICAgICAgICAgICAgICBpbnZhbGlkYXRlX2xvb2t1cF9jYWNoZShjb250ZXh0KTsKICAgICAgICAgICAgICAgIHJldHVybiByZXM7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9IGVsc2UgaWYgKHJlcyA9PSBNSUJfRFVQTElDQVRFX1JFR0lTVFJBVElPTiB8fAogICAgICAgICAgICAgICByZXMgPT0gTUlCX1JFR0lTVFJBVElPTl9GQUlMRUQpIHsKICAgICAgICBuZXRzbm1wX3NldF9sb29rdXBfY2FjaGVfc2l6ZShvbGRfbG9va3VwX2NhY2hlX3ZhbCk7CiAgICAgICAgaW52YWxpZGF0ZV9sb29rdXBfY2FjaGUoY29udGV4dCk7CiAgICAgICAgbmV0c25tcF9zdWJ0cmVlX2ZyZWUoc3VidHJlZSk7CiAgICAgICAgcmV0dXJuIHJlczsKICAgIH0KCiAgICAvKgogICAgICogbWFyayB0aGUgTUlCIGFzIGRldGFjaGVkLCBpZiB0aGVyZSdzIG5vIG1hc3RlciBhZ2VudCBwcmVzZW50IGFzIG9mIG5vdyAKICAgICAqLwogICAgaWYgKG5ldHNubXBfZHNf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ICAgICAgICAgICAgc2l6ZV90IG1pYmxvY2xlbiwKICAgICAgICAgICAgICAgICAgICAgaW50IHByaW9yaXR5LAogICAgICAgICAgICAgICAgICAgICBpbnQgcmFuZ2Vfc3ViaWQsCiAgICAgICAgICAgICAgICAgICAgIG9pZCByYW5nZV91Ym91bmQsCiAgICAgICAgICAgICAgICAgICAgIG5ldHNubXBfc2Vzc2lvbiAqIHNzLAogICAgICAgICAgICAgICAgICAgICBjb25zdCBjaGFyICpjb250ZXh0LCBpbnQgdGltZW91dCwgaW50IGZsYWdzKQp7CiAgICByZXR1cm4gbmV0c25tcF9yZWdpc3Rlcl9vbGRfYXBpKG1vZHVsZU5hbWUsIHZhciwgdmFyc2l6ZSwgbnVtdmFycywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbWlibG9jLCBtaWJsb2NsZW4sIHByaW9yaXR5LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByYW5nZV9zdWJpZCwgcmFuZ2VfdWJvdW5kLCBzcywgY29udGV4dCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdGltZW91dCwgZmxhZ3MpOwp9CgppbnQKcmVnaXN0ZXJfbWliX3JhbmdlKGNvbnN0IGNoYXIgKm1vZHVsZU5hbWUsCiAgICAgICAgICAgICAgICAgICBzdHJ1Y3QgdmFyaWFibGUgKnZhciwKICAgICAgICAgICAgICAgICAgIHNpemVfdCB2YXJzaXplLAogICAgICAgICAgICAgICAgICAgc2l6ZV90IG51bXZhcnMsCiAgICAgICAgICAgICAgICAgICBvaWQgKiBtaWJsb2MsCiAgICAgICAgICAgICAgICAgICBzaXplX3QgbWlibG9jbGVuLAogICAgICAgICAgICAgICAgICAgaW50IHByaW9yaXR5LAogICAgICAgICAgICAgICAgICAgaW50IHJhbmdlX3N1YmlkLCBvaWQgcmFuZ2VfdWJvdW5kLCBuZXRzbm1wX3Nlc3Npb24gKiBzcykKewogICAgcmV0dXJuIHJlZ2lzdGVyX21pYl9jb250ZXh0KG1vZHVsZU5hbWUsIHZhciwgdmFyc2l6ZSwgbnVtdmFycywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBtaWJsb2MsIG1pYmxvY2xlbiwgcHJpb3JpdHksCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmFuZ2Vfc3ViaWQsIHJhbmdlX3Vib3VuZCwgc3MsICIiLCAtMSwgMCk7Cn0KCmludApyZWdpc3Rlcl9taWJfcHJpb3JpdHkoY29uc3QgY2hhciAqbW9kdWxlTmFtZSwKICAgICAgICAgICAgICAgICAgICAgIHN0cnVjdCB2YXJpYWJsZSAqdmFyLAogICAgICAgICAgICAgICAgICAgICAgc2l6ZV90IHZhcnNpemUsCiAgICAgICAgICAgICAgICAgICAgICBzaXplX3QgbnVtdmFycywKICAgICAgICAgICAgICAgICAgICAgIG9pZCAqIG1pYmxvYywgc2l6ZV90IG1pYmxvY2xlbiwgaW50IHByaW9yaXR5KQp7CiAgICByZXR1cm4gcmVnaXN0ZXJfbWliX3JhbmdlKG1vZHVsZU5hbWUsIHZhciwgdmFyc2l6ZSwgbnVtdmFycywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbWlibG9jLCBtaWJsb2NsZW4sIHByaW9yaXR5LCAwLCAwLCBOVUxMKTsKfQoKaW50CnJlZ2lzdGVyX21pYihjb25zdCBjaGFyICptb2R1bGVOYW1lLAogICAgICAgICAgICAgc3RydWN0IHZhcmlhYmxlICp2YXIsCiAgICAgICAgICAgICBzaXplX3QgdmFyc2l6ZSwKICAgICAgICAgICAgIHNpemVfdCBudW12YXJzLCBvaWQgKiBtaWJsb2MsIHNpemVfdCBtaWJsb2NsZW4pCnsKICAgIHJldHVybiByZWdpc3Rlcl9taWJfcHJpb3JpdHkobW9kdWxlTmFtZSwgdmFyLCB2YXJzaXplLCBudW12YXJzLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBtaWJsb2MsIG1pYmxvY2xlbiwgREVGQVVMVF9NSUJfUFJJT1JJVFkpOwp9Cgp2b2lkCm5ldHNubXBfc3VidHJlZV91bmxvYWQobmV0c25tcF9zdWJ0cmVlICpzdWIsIG5ldHNubXBfc3VidHJlZSAqcHJldiwgY29uc3QgY2hhciAqY29udGV4dCkKewogICAgbmV0c25tcF9zdWJ0cmVlICpwdHI7CgogICAgREVCVUdNU0dUTCgoInJlZ2lzdGVyX21pYiIsICJ1bmxvYWQoIikpOwogICAgaWYgKHN1YiAhPSBOVUxMKSB7CiAgICAgICAgREVCVUdNU0dPSUQoKCJyZWdpc3Rlcl9taWIiLCBzdWItPnN0YXJ0X2EsIHN1Yi0+c3RhcnRfbGVuKSk7CiAgICB9IGVsc2UgewogICAgICAgIERFQlVHTVNHKCgicmVnaXN0ZXJfbWliIiwgIltOSUxdIikpOwogICAgICAgIHJldHVybjsKICAgIH0KICAgIERFQlVHTVNHKCgicmVnaXN0ZXJfbWliIiwgIiwgIikpOwogICAgaWYgKHByZXYgIT0gTlVMTCkgewogICAgICAgIERFQlVHTVNHT0lEKCgicmVnaXN0ZXJfbWliIiwgcHJldi0+c3RhcnRfYSwgcHJldi0+c3RhcnRfbGVuKSk7CiAgICB9IGVsc2UgewogICAgICAgIERFQlVHTVNHKCgicmVnaXN0ZXJfbWliIiwgIltOSUxdIikpOwogICAgfQogICAgREVCVUdNU0coKCJyZWdpc3Rlcl9taWIiLCAiKVxuIikpOwoKICAgIGlmIChwcmV2ICE9IE5VTEwpIHsgICAgICAgICAvKiBub24tbGVhZGluZyBlbnRyaWVzIGFyZSBlYXN5ICovCiAgICAgICAgcHJldi0+Y2hpbGRyZW4gPSBzdWItPmNoaWxkcmVuOwogICAgICAgIGludmFsaWRhdGVfbG9va3VwX2NhY2hlKGNvbnRleHQpOwogICAgICAgIHJldHVybjsKICAgIH0KICAgIC8qCiAgICAgKiBvdGhlcndpc2UsIHdlIG5lZWQgdG8gYW1lbmQgb3VyIG5laWdoYm91cnMgYXMgd2VsbCAKICAgICAqLwoKICAgIGl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jYWNoZV9zaXplKDApOwoKICAgIGlmICgocmFuZ2Vfc3ViaWQgIT0gMCkgJiYgIChyYW5nZV9zdWJpZCA8PSBsZW4pKQogICAgICAgIG9yaWdfc3ViaWRfdmFsID0gbmFtZVtyYW5nZV9zdWJpZC0xXTsKCiAgICB3aGlsZSh1bnJlZ2lzdGVyaW5nKXsKICAgICAgICBERUJVR01TR1RMKCgicmVnaXN0ZXJfbWliIiwgInVucmVnaXN0ZXJpbmcgIikpOwogICAgICAgIERFQlVHTVNHT0lEUkFOR0UoKCJyZWdpc3Rlcl9taWIiLCBuYW1lLCBsZW4sIHJhbmdlX3N1YmlkLCByYW5nZV91Ym91bmQpKTsKICAgICAgICBERUJVR01TRygoInJlZ2lzdGVyX21pYiIsICJcbiIpKTsKCiAgICAgICAgbGlzdCA9IG5ldHNubXBfc3VidHJlZV9maW5kKG5hbWUsIGxlbiwgbmV0c25tcF9zdWJ0cmVlX2ZpbmRfZmlyc3QoY29udGV4dCksCiAgICAgICAgICAgICAgICAgICAgY29udGV4dCk7CiAgICAgICAgaWYgKGxpc3QgPT0gTlVMTCkgewogICAgICAgICAgICByZXR1cm4gTUlCX05PX1NVQ0hfUkVHSVNUUkFUSU9OOwogICAgICAgIH0KCiAgICAgICAgZm9yIChjaGlsZCA9IGxpc3QsIHByZXYgPSBOVUxMOyBjaGlsZCAhPSBOVUxMOwogICAgICAgICAgICBwcmV2ID0gY2hpbGQsIGNoaWxkID0gY2hpbGQtPmNoaWxkcmVuKSB7CiAgICAgICAgICAgIGlmIChuZXRzbm1wX29pZF9lcXVhbHMoY2hpbGQtPm5hbWVfYSwgY2hpbGQtPm5hbWVsZW4sIG5hbWUsIGxlbikgPT0gMCAmJgogICAgICAgICAgICAgICAgY2hpbGQtPnByaW9yaXR5ID09IHByaW9yaXR5KSB7CiAgICAgICAgICAgICAgICBicmVhazsgICAgICAgICAgICAgIC8qIGZvdW5kIGl0ICovCiAgICAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgIC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PmNoaWxkcmVuKSB7CiAgICAgICAgICAgICAgICBpZiAoKG5ldHNubXBfb2lkX2VxdWFscyhjaGlsZC0+bmFtZV9hLCBjaGlsZC0+bmFtZWxlbiwKICAgICAgICAgICAgICAgICAgICBuYW1lLCBsZW4pID09IDApICYmCiAgICAgICAgICAgIChjaGlsZC0+cHJpb3JpdHkgPT0gcHJpb3JpdHkpKSB7CiAgICAgICAgICAgICAgICAgICAgbmV0c25tcF9zdWJ0cmVlX3VubG9hZChjaGlsZCwgcHJldiwgY29udGV4dCk7CiAgICAgICAgICAgICAgICAgICAgbmV0c25tcF9zdWJ0cmVlX2ZyZWUoY2hpbGQpOwogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChjaGlsZCA9PSBOVUxMKSAgICAgIC8qIERpZG4ndCBmaW5kIHRoZSBnaXZlbiBuYW1lICovCiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICB9CgogICAgICAgIC8qIE1heWJlIHdlIGFyZSBpbiBhIHJhbmdlLi4uICovCiAgICAgICAgaWYgKG9yaWdfc3ViaWRfdmFsICE9IC0xKXsKICAgICAgICAgICAgaWYgKCsrbmFtZVtyYW5nZV9zdWJpZC0xXSA+PSBvcmlnX3N1YmlkX3ZhbCtyYW5nZV91Ym91bmQpCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICB1bnJlZ2lzdGVyaW5nPTA7CiAgICAgICAgICAgICAgICBuYW1lW3JhbmdlX3N1YmlkLTFdID0gb3JpZ19zdWJpZF92YWw7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGVsc2UgewogICAgICAgICAgICB1bnJlZ2lzdGVyaW5nPTA7CiAgICAgICAgfQogICAgfQoKICAgIG1lbXNldCgmcmVnX3Bhcm1zLCAweDAsIHNpemVvZihyZWdfcGFybXMpKTsKICAgIHJlZ19wYXJtcy5uYW1lID0gbmFtZTsKICAgIH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VTEwpIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgfQoKICAgICAgICBuZXRzbm1wX3N1YnRyZWVfdW5sb2FkKGNoaWxkLCBwcmV2LCBjb250ZXh0KTsKICAgICAgICBteXB0ciA9IGNoaWxkOyAgICAgICAgICAvKiByZW1lbWJlciB0aGlzIGZvciBsYXRlciAqLwoKICAgICAgICBmb3IgKGxpc3QgPSBteXB0ci0+bmV4dDsgbGlzdCAhPSBOVUxMOyBsaXN0ID0gZnV0dXJlcHRyKSB7CiAgICAgICAgICAgIC8qIHJlbWVtYmVyIHRoZSBuZXh0IHNwb3QgaW4gdGhlIGxpc3QgaW4gY2FzZSB3ZSBmcmVlIHRoaXMgbm9kZSAqLwogICAgICAgICAgICBmdXR1cmVwdHIgPSBsaXN0LT5uZXh0OwoKICAgICAgICAgICAgLyogY2hlY2sgZWFjaCBjaGlsZCAqLwogICAgICAgICAgICBmb3IgKGNoaWxkID0gbGlzdCwgcHJldiA9IE5VTEw7IGNoaWxkICE9IE5VTEw7CiAgICAgICAgICAgICAgICAgcHJldiA9IGNoaWxkLCBjaGlsZCA9IGNoaWxkLT5jaGlsZHJlbikgewoKICAgICAgICAgICAgICAgIGlmIChuZXRzbm1wX29pZF9lcXVhbHMoY2hpbGQtPm5hbWVfYSwgY2hpbGQtPm5hbWVsZW4sIAoJCQkJICAgICAgbmFtZSwgbGVuKSA9PSAwICYmCiAgICAgICAgICAgICAgICAgICAgKGNoaWxkLT5wcmlvcml0eSA9PSBwcmlvcml0eSkpIHsKICAgICAgICAgICAgICAgICAgICBuZXRzbm1wX3N1YnRyZWVfdW5sb2FkKGNoaWxkLCBwcmV2LCBjb250ZXh0KTsKICAgICAgICAgICAgICAgICAgICBuZXRzbm1wX3N1YnRyZWVfZnJlZShjaGlsZCk7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KCiAgICAgICAgICAgIC8qIFhYWDogd2poOiBub3Qgc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AobGlzdCA9IGNvbnRleHRwdHItPmZpcnN0X3N1YnRyZWU7IGxpc3QgIT0gTlVMTDsgbGlzdCA9IGxpc3QyKSB7CiAgICAgICAgICAgIGxpc3QyID0gbGlzdC0+bmV4dDsKCiAgICAgICAgICAgIGZvciAoY2hpbGQgPSBsaXN0LCBwcmV2ID0gTlVMTDsgY2hpbGQgIT0gTlVMTDsgY2hpbGQgPSBuZXh0X2NoaWxkKXsKICAgICAgICAgICAgICAgIG5leHRfY2hpbGQgPSBjaGlsZC0+Y2hpbGRyZW47CgogICAgICAgICAgICAgICAgaWYgKCgoIXNzIHx8IHNzLT5mbGFncyAmIFNOTVBfRkxBR1NfU1VCU0VTU0lPTikgJiYKCQkgICAgIGNoaWxkLT5zZXNzaW9uID09IHNzKSB8fAogICAgICAgICAgICAgICAgICAgICghKCFzcyB8fCBzcy0+ZmxhZ3MgJiBTTk1QX0ZMQUdTX1NVQlNFU1NJT04pICYmIGNoaWxkLT5zZXNzaW9uICYmCiAgICAgICAgICAgICAgICAgICAgIGNoaWxkLT5zZXNzaW9uLT5zdWJzZXNzaW9uID09IHNzKSkgewoKICAgICAgICAgICAgICAgICAgICBtZW1zZXQoJnJwLDB4MCxzaXplb2YocnApKTsKICAgICAgICAgICAgICAgICAgICBycC5uYW1lID0gY2hpbGQtPm5hbWVfYTsKCQkgICAgY2hpbGQtPm5hbWVfYSA9IE5VTEw7CiAgICAgICAgICAgICAgICAgICAgcnAubmFtZWxlbiA9IGNoaWxkLT5uYW1lbGVuOwogICAgICAgICAgICAgICAgICAgIHJwLnByaW9yaXR5ID0gY2hpbGQtPnByaW9yaXR5OwogICAgICAgICAgICAgICAgICAgIHJwLnJhbmdlX3N1YmlkID0gY2hpbGQtPnJhbmdlX3N1YmlkOwogICAgICAgICAgICAgICAgICAgIHJwLnJhbmdlX3Vib3VuZCA9IGNoaWxkLT5yYW5nZV91Ym91bmQ7CiAgICAgICAgICAgICAgICAgICAgcnAudGltZW91dCA9IGNoaWxkLT50aW1lb3V0OwogICAgICAgICAgICAgICAgICAgIHJwLmZsYWdzID0gY2hpbGQtPmZsYWdzOwogICAgICAgICAgICAgICAgICAgIGlmICgoTlVMTCAhPSBjaGlsZC0+cmVnaW5mbykgJiYKICAgICAgICAgICAgICAgICAgICAgICAgKE5VTEwgIT0gY2hpbGQtPnJlZ2luZm8tPmNvbnRleHROYW1lKSkKICAgICAgICAgICAgICAgICAgICAgICAgcnAuY29udGV4dE5hbWUgPSBjaGlsZC0+cmVnaW5mby0+Y29udGV4dE5hbWU7CgogICAgICAgICAgICAgICAgICAgIGlmIChjaGlsZC0+cmVnaW5mbyAhPSBOVUxMKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIC8qCiAgICAgICAgICAgICAgICAgICAgICAgICAqIERvbid0IGxldCdzIGZyZWUgdGhlIHNlc3Npb24gcG9pbnRlciBqdXN0IHlldCEgIAogICAgICAgICAgICAgICAgICAgICAgICAgKi8KICAgICAgICAgICAgICAgICAgICAgICAgY2hpbGQtPnJlZ2luZm8tPmhhbmRsZXItPm15dm9pZCA9IE5VTEw7CiAgICAgICAgICAgICAgICAgICAgICAgIG5ldHNubXBfaGFuZGxlcl9yZWdpc3RyYXRpb25fZnJlZShjaGlsZC0+cmVnaW5mbyk7CgkJCWNoaWxkLT5yZWdpbmZvID0gTlVMTDsKICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgICAgIG5ldHNubXBfc3VidHJlZV91bmxvYWQoY2hpbGQsIHByZXYsIGNvbnRleHRwdHItPmNvbnRleHRfbmFtZSk7CiAgICAgICAgICAgICAgICAgICAgbmV0c25tcF9zdWJ0cmVlX2ZyZWUoY2hpbGQpOwoKICAgICAgICAgICAgICAgICAgICBzbm1wX2NhbGxfY2FsbGJhY2tzKFNOTVBfQ0FMTEJBQ0tfQVBQTElDQVRJT04sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBTTk1QRF9DQUxMQkFDS19VTlJFR0lTVEVSX09JRCw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G5ldHNubXBfc3VidHJlZSAqbmV4dCwgbmV0c25tcF9zdWJ0cmVlICpwcmV2aW91cykgewoKICAgIHB0ci0+bmV4dCA9IG5leHQ7CiAgICBwdHItPnByZXZpb3VzID0gcHJldmlvdXM7Cn0KCk5FVFNOTVBfU1RBVElDX0lOTElORSBsb29rdXBfY2FjaGUgKgpsb29rdXBfY2FjaGVfZmluZChjb25zdCBjaGFyICpjb250ZXh0LCBvaWQgKm5hbWUsIHNpemVfdCBuYW1lX2xlbiwKICAgICAgICAgICAgICAgICAgaW50ICpyZXRjbXApIHsKICAgIGxvb2t1cF9jYWNoZV9jb250ZXh0ICpjcHRyOwogICAgbG9va3VwX2NhY2hlICpyZXQgPSBOVUxMOwogICAgaW50IGNtcDsKICAgIGludCBpOwoKICAgIGlmICgoY3B0ciA9IGdldF9jb250ZXh0X2xvb2t1cF9jYWNoZShjb250ZXh0KSkgPT0gTlVMTCkKICAgICAgICByZXR1cm4gTlVMTDsKCiAgICBmb3IoaSA9IDA7IGkgPCBjcHRyLT50aGVjYWNoZWNvdW50ICYmIGkgPCBsb29rdXBfY2FjaGVfc2l6ZTsgaSsrKSB7CiAgICAgICAgaWYgKGNwdHItPmNhY2hlW2ldLnByZXZpb3VzLT5zdGFydF9hKQogICAgICAgICAgICBjbXAgPSBzbm1wX29pZF9jb21wYXJlKG5hbWUsIG5hbWVfbGVuLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNwdHItPmNhY2hlW2ldLnByZXZpb3VzLT5zdGFydF9hLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNwdHItPmNhY2hlW2ldLnByZXZpb3VzLT5zdGFydF9sZW4pOwogICAgICAgIGVsc2UKICAgICAgICAgICAgY21wID0gMTsKICAgICAgICBpZiAoY21wID49IDApIHsKICAgICAgICAgICAgKnJldGNtcCA9IGNtcDsKICAgICAgICAgICAgcmV0ID0gJihjcHRyLT5jYWNoZVtpXSk7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIHJldDsKfQoKTkVUU05NUF9TVEFUSUNfSU5MSU5FIHZvaWQKaW52YWxpZGF0ZV9sb29rdXBfY2FjaGUoY29uc3QgY2hhciAqY29udGV4dCkgewogICAgbG9va3VwX2NhY2hlX2NvbnRleHQgKmNwdHI7CiAgICBpZiAoKGNwdHIgPSBnZXRfY29udGV4dF9sb29rdXBfY2FjaGUoY29udGV4dCkpICE9IE5VTEwpIHsKICAgICAgICBjcHRyLT50aGVjYWNoZWNvdW50ID0gMDsKICAgICAgICBjcHRyLT5jdXJyZW50cG9zID0gMDsKICAgIH0KfQoKbmV0c25tcF9zdWJ0cmVlICoKbmV0c25tcF9zdWJ0cmVlX2ZpbmRfcHJldihvaWQgKm5hbWUsIHNpemVfdCBsZW4sIG5ldHNubXBfc3VidHJlZSAqc3VidHJlZSwKCQkJICBjb25zdCBjaGFyICpjb250ZXh0X25hbWUpCnsKICAgIGxvb2t1cF9jYWNoZSAqbG9va3VwX2NhY2hlID0gTlVMTDsKICAgIG5ldHNubXBfc3VidHJlZSAqbXlwdHIgPSBOVUxMLCAqcHJldmlvdXMgPSBOVUxMOwogICAgaW50IGNtcCA9IDE7CiAgICBzaXplX3QgbGxfb2ZmID0gMDsKCiAgICBpZiAoc3VidHJlZSkgewogICAgICAgIG15cHRyID0gc3VidHJlZTsKICAgIH0gZWxzZSB7CgkvKiBsb29rIHRocm91Z2ggZXZlcnl0aGluZyAqLwogICAgICAgIGlmIChsb29rdXBfY2FjaGVfc2l6ZSkgewogICAgICAgICAgICBsb29rdXBfY2FjaGUgPSBsb29rdXBfY2FjaGVfZmluZChjb250ZXh0X25hbWUsIG5hbWUsIGxlbiwgJmNtcCk7CiAgICAgICAgICAgIGlmIChsb29rdXBfY2FjaGUpIHsKICAgICAgICAgICAgICAgIG15cHRyID0gbG9va3VwX2NhY2hlLT5uZXh0OwogICAgICAgICAgICAgICAgcHJldmlvdXMgPSBsb29rdXBfY2FjaGUtPnByZXZpb3VzOwogICAgICAgIC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IHRoYW4gdGhlCiAgICAgICAgICAgbGVuZ3RoIGJldHdlZW4gdGhpcyBwb2ludGVyIGFuZCB0aGUgbGFzdCB0aGVuIHdlIGRvbid0IG5lZWQKICAgICAgICAgICB0byBhY3R1YWxseSBwZXJmb3JtIGEgY29tcGFyaXNvbiAqLwogICAgICAgIERFQlVHTVNHVEwoKCJ3dGVzdCIsIm9pZCBjbXA6ICIpKTsKICAgICAgICBERUJVR01TR09JRCgoInd0ZXN0IiwgbXlwdHItPnN0YXJ0X2EsIG15cHRyLT5zdGFydF9sZW4pKTsKICAgICAgICBERUJVR01TRygoInd0ZXN0IiwiICAtLS0gb2ZmID0gJWQsIGluIG9mZiA9ICVkIHRlc3QgPSAlZFxuIiwKICAgICAgICAgICAgICAgICAgbXlwdHItPm9pZF9vZmYsIGxsX29mZiwKICAgICAgICAgICAgICAgICAgIShsbF9vZmYgJiYgbXlwdHItPm9pZF9vZmYgJiYKICAgICAgICAgICAgICAgICAgICBteXB0ci0+b2lkX29mZiA+IGxsX29mZikpKTsKICAgICAgICBpZiAoIShsbF9vZmYgJiYgbXlwdHItPm9pZF9vZmYgJiYgbXlwdHItPm9pZF9vZmYgPiBsbF9vZmYpICYmCiAgICAgICAgICAgIG5ldHNubXBfb2lkX2NvbXBhcmVfbGwobmFtZSwgbGVuLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG15cHRyLT5zdGFydF9hLCBteXB0ci0+c3RhcnRfbGVuLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICZsbF9vZmYpIDwgMCkgewojZWxzZQogICAgICAgIGlmIChzbm1wX29pZF9jb21wYXJlKG5hbWUsIGxlbiwgbXlwdHItPnN0YXJ0X2EsIG15cHRyLT5zdGFydF9sZW4pIDwgMCkgewojZW5kaWYKICAgICAgICAgICAgaWYgKGxvb2t1cF9jYWNoZV9zaXplICYmIHByZXZpb3VzICYmIGNtcCkgewogICAgICAgICAgICAgICAgaWYgKGxvb2t1cF9jYWNoZSkgewogICAgICAgICAgICAgICAgICAgIGxvb2t1cF9jYWNoZV9yZXBsYWNlKGxvb2t1cF9jYWNoZSwgbXlwdHIsIHByZXZpb3VzKTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgbG9va3VwX2NhY2hlX2FkZChjb250ZXh0X25hbWUsIG15cHRyLCBwcmV2aW91cyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuIHByZXZpb3VzOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiBwcmV2aW91czsKfQoKbmV0c25tcF9zdWJ0cmVlICoKbmV0c25tcF9zdWJ0cmVlX2ZpbmRfbmV4dChvaWQgKm5hbWUsIHNpemVfdCBsZW4sCgkJCSAgbmV0c25tcF9zdWJ0cmVlICpzdWJ0cmVlLCBjb25zdCBjaGFyICpjb250ZXh0X25hbWUpCnsKICAgIG5ldHNubXBfc3VidHJlZSAqbXlwdHIgPSBOVUxMOwoKICAgIG15cHRyID0gbmV0c25tcF9zdWJ0cmVlX2ZpbmRfcHJldihuYW1lLCBsZW4sIHN1YnRyZWUsIGNvbnRleHRfbmFtZSk7CgogICAgaWYgKG15cHRyICE9IE5VTEwpIHsKICAgICAgICBteXB0ciA9IG15cHRyLT5uZXh0OwogICAgICAgIHdoaWxlIChteXB0ciAhPSBOVUxMICYmIChteXB0ci0+dmFyaWFibGVzID09IE5VTEwgfHwgCgkJCQkgbXlwdHItPnZhcmlhYmxlc19sZW4gPT0gMCkpIHsKICAgICAgICAgICAgbXlwdHIgPSBteXB0ci0+bmV4dDsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG15cHRyOwogICAgfSBlbHNlIGlmIChzdWJ0cmVlICE9IE5VTEwgJiYgc25tcF9vaWRfY29tcGFyZShuYW1lLCBsZW4sIAoJCQkJICAgc3VidHJlZS0+c3RhcnRfYSwgc3VidHJlZS0+c3RhcnRfbGVuKSA8IDApIHsKICAgICAgICByZX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9pZHhfcmVnaXN0cnkodm9pZCk7CnZvaWQKZHVtcF9yZWdpc3RyeSh2b2lkKQp7CiAgICBzdHJ1Y3QgdmFyaWFibGUgKnZwID0gTlVMTDsKICAgIG5ldHNubXBfc3VidHJlZSAqbXlwdHIsICpteXB0cjI7CiAgICB1X2NoYXIgKnMgPSBOVUxMLCAqZSA9IE5VTEwsICp2ID0gTlVMTDsKICAgIHNpemVfdCBzbCA9IDI1NiwgZWwgPSAyNTYsIHZsID0gMjU2LCBzbF9vID0gMCwgZWxfbyA9IDAsIHZsX28gPSAwOwogICAgaW50IGkgPSAwOwoKICAgIGlmICgocyA9ICh1X2NoYXIgKikgY2FsbG9jKHNsLCAxKSkgIT0gTlVMTCAmJgogICAgICAgIChlID0gKHVfY2hhciAqKSBjYWxsb2Moc2wsIDEpKSAhPSBOVUxMICYmCiAgICAgICAgKHYgPSAodV9jaGFyICopIGNhbGxvYyhzbCwgMSkpICE9IE5VTEwpIHsKCiAgICAgICAgc3VidHJlZV9jb250ZXh0X2NhY2hlICpwdHI7CiAgICAgICAgZm9yIChwdHIgPSBjb250ZXh0X3N1YnRyZWVzOyBwdHI7IHB0ciA9IHB0ci0+bmV4dCkgewogICAgICAgICAgICBwcmludGYoIlN1YnRyZWVzIGZvciBDb250ZXh0OiAlc1xuIiwgcHRyLT5jb250ZXh0X25hbWUpOwogICAgICAgICAgICBmb3IgKG15cHRyID0gcHRyLT5maXJzdF9zdWJ0cmVlOyBteXB0ciAhPSBOVUxMOwogICAgICAgICAgICAgICAgIG15cHRyID0gbXlwdHItPm5leHQpIHsKICAgICAgICAgICAgICAgIHNsX28gPSBlbF9vID0gdmxfbyA9IDA7CgogICAgICAgICAgICAgICAgaWYgKCFzcHJpbnRfcmVhbGxvY19vYmppZCgmcywgJnNsLCAmc2xfbywgMSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbXlwdHItPnN0YXJ0X2EsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG15cHRyLT5zdGFydF9sZW4pKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoIXNwcmludF9yZWFsbG9jX29iamlkKCZlLCAmZWwsICZlbF9vLCAxLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBteXB0ci0+ZW5kX2EsCgkJCQkJICBteXB0ci0+ZW5kX2xlbikpIHsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICBpZiAobXlwdHItPnZhcmlhYmxlcykgewogICAgICAgICAgICAgICAgICAgIHByaW50ZigiJTAyeCAoICVzIC0gJXMgKSBbIiwgbXlwdHItPmZsYWdzLCBzLCBlKTsKICAgICAgICAgICAgICAgICAgICBmb3IgKGkgPSAwLCB2cCA9IG15cHRyLT52YXJpYWJsZXM7CiAgICAgICAgICAgICAgICAgICAgICAgICBpIDwgbXlwdHItPnZhcmlhYmxlc19sZW47IGkrKykgewogICAgICAgICAgICAgICAgICAgICAgICB2bF9vID0gMDsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCFzcHJpbnRfcmVhbGxvY19vYmppZAogICAgICAgICAgICAgICAgICAgICAgICAgICAgKCZ2LCAmdmwsICZ2bF9vLCAxLCB2cC0+bmFtZSwgdnAtPm5hbWVsZW4pKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBwcmludGYoIiVzLCAiLCB2KTsKICAgICAgICAgICAgICAgICAgICAgICAgdnAgPSAoc3RydWN0IHZhcmlhYmxlICopICgoY2hhciAqKSB2cCArCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbXlwdHItPnZhcmlhYmxlc193aWR0aCk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIHByaW50ZigiXVxuIik7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIHByaW50ZigiJTAyeCAgICVzIC0gJXMgIFxuIiwgbXlwdHItPmZsYWdzLCBzLCBlKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGZvciAobXlwdHIyID0gbXlwdHI7IG15cHRyMiAhPSBOVUxMOwogICAgICAgICAgICAgICAgICAgICBteXB0cjIgPSBteXB0cjItPmNoaWxkcmVuKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKG15cHRyMi0+bGFiZWxfYSAmJiBteXB0cjItPmxhYmVsX2FbMF0pIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHN0cmNtcChteXB0cjItPmxhYmVsX2EsICJvbGRfYXBpIikgPT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RydWN0IHZhcmlhYmxlICp2cCA9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbXlwdHIyLT5yZWdpbmZvLT5oYW5kbGVyLT5teXZvaWQ7CgogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCFzcHJpbnRfcmVhbGxvY19vYmppZCgmcywgJnNsLCAmc2xfbywgMSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHZwLT5uYW1lLCB2cC0+bmFtZWxlbikpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIHByaW50ZigiXHQlc1slc10gJXAgdmFyICVzXG4iLCBteXB0cjItPmxhYmVsX2EsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbXlwdHIyLT5yZWdpbmZvLT5oYW5kbGVyTmFtZSA/CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbXlwdHIyLT5yZWdpbmZvLT5oYW5kbGVyTmFtZSA6ICJuby1uYW1lIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBteXB0cjItPnJlZ2luZm8sIHMpOwogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcHJpbnRmKCJcdCVzICVzICVwXG4iLCBteXB0cjItPmxhYmVsX2EsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbXlwdHIyLT5yZWdpbmZvLT5oYW5kbGVyTmFtZSA/CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbXlwdHIyLT5yZWdpbmZvLT5oYW5kbGVyTmFtZSA6ICJuby1oYW5kbGVyLW5hbWUiLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG15cHRyMi0+cmVnaW5mbyk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CgogICAgaWYgKHMgIT0gTlVMTCkgewogICAgICAgIFNOTVBfRlJFRShzKTsKICAgIH0KICAgIGlmIChlICE9IE5VTEwpIHsKICAgICAgICBTTk1QX0ZSRUUoZSk7CiAgICB9CiAgICBpZiAodiAhPSBOVUxMKSB7CiAgICAgICAgU05NUF9GUkVFKHYpOwogICAgfQoKICAgIGR1bXBfaWR4X3JlZ2lzdHJ5KCk7Cn0KCmludCAgICAgICAgICAgICBleHRlcm5hbF9zaWduYWxfc2NoZWR1bGVkW05VTV9FWFRFUk5BTF9TSUdTXTsKdm9pZCAgICAgICAgICAgICgqZXh0ZXJuYWxfc2lnbmFsX2hhbmRsZXJbTlVNX0VYVEVSTkFMX1NJR1NdKSAoaW50KTsKCiNpZm5kZWYgV0lOMzIKCi8qCiAqIFRPRE86IGFkZCBhZ2VudF9TSUdYWFhfaGFuZGxlciBmdW5jdGlvbnMgYW5kIGBjYXNl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