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ZmYXQgKCZ2ZmF0KTsKICAgIHdoaWxlICgxKSB7CiAgICAgICAgaWYgKGRpcl9yZWFkIChmcywgZGlyLCBkaXJlbnQsICplbnRyeSwgJnZmYXQpIDwgMCkgewogICAgICAgICAgICBpZiAodmZhdF9zdGFydCkgewogICAgICAgICAgICAgICAgKnZmYXRfc3RhcnQgPSAqZW50cnk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfQogICAgICAgICgqZW50cnkpKys7CgogICAgICAgIC8qIEVtcHR5IHNsb3QgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICovCiAgICAgICAgaWYgKGRpcmVudCAtPiBuYW1lWzBdID09ICdcMCcpewogICAgICAgICAgICBpZiAodmZhdF9zdGFydCA9PSAwKSB7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICB9CgogICAgICAgIGlmIChkaXJlbnQgLT4gYXR0ciA9PSBBVFRSX1ZTRSkgewogICAgICAgICAgICAvKiBWU0UgZW50cnksIGNvbnRpbnVlICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICovCiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIH0KICAgICAgICBpZiAoIChkaXJlbnQgLT4gbmFtZSBbMF0gPT0gREVMTUFSSykgfHwKICAgICAgICAgICAgICgoZGlyZW50IC0+IGF0dHIgJiBBVFRSX0RJUkVDVE9SWSkgIT0gMCAmJgogICAgICAgICAgICAgIChmbGFncyAmIEFDQ0VQVF9ESVIpID09IDApIHx8CiAgICAgICAgICAgICAoKGRpcmVudCAtPiBhdHRyICYgQVRUUl9WT0xVTUUpICE9IDAgJiYKICAgICAgICAgICAgICAoZmxhZ3MgJiBBQ0NFUFRfTEFCRUwpID09IDApIHx8CiAgICAgICAgICAgICAoKChkaXJlbnQgLT4gYXR0ciAmIChBVFRSX0RJUkVDVE9SWSB8IEFUVFJfVk9MVU1FKSkgPT0gMCkgJiYKICAgICAgICAgICAgICAoZmxhZ3MgJiBBQ0NFUFRfUExBSU4pID09IDApKSB7CiAgICAgICAgICAgIGNsZWFyX3ZmYXQgKCZ2ZmF0KTsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgfQoKICAgICAgICB2ZmF0X3ByZXNlbnQgPSBjaGVja192ZmF0ICgmdmZhdCwgZGlyZW50KTsKICAgICAgICBpZiAodmZhdF9zdGFydCkgewogICAgICAgICAgICAqdmZhdF9zdGFydCA9ICplbnRyeSAtIDE7CiAgICAgICAgICAgIGlmICh2ZmF0X3ByZXNlbnQpIHsKICAgICAgICAgICAgICAgICp2ZmF0X3N0YXJ0IC09IHZmYXQuc3ViZW50cmllczsKICAgICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgaWYgKGRpcmVudCAtPiBhdHRyICYgQVRUUl9WT0xVTUUpIHsKICAgICAgICAgICAgc3RybmNweSAobmV3ZmlsZSwgZGlyZW50IC0+IG5hbWUsIDgpOwogICAgICAgICAgICBuZXdmaWxlIFs4XSA9ICdcMCc7CiAgICAgICAgICAgIHN0cm5jYXQgKG5ld2ZpbGUsIGRpcmVudCAtPiBleHQsIDMpOwogICAgICAgICAgICBuZXdmaWxlIFsxMV0gPSAnXDAnOwogICAgICAgIH0KICAgICAgICBlbHNlIHsKICAgICAgICAgICAgY29udl9uYW1lIChkaXJlbnQgLT4gbmFtZSwgZGlyZW50IC0+IGV4dCwgZGlyZW50IC0+IENhc2UsIG5ld2ZpbGUpOwogICAgICAgIH0KCiAgICAgICAgaWYgKGZsYWdzICYgTUFUQ0hfQU5ZKSB7CiAgICAgICAgICAgIGZvdW5kID0gMTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfQoKICAgICAgICBpZiAoKHZmYXRfcHJlc2VudCAmJiBtYXRjaCAodmZhdC5uYW1lLCBmaWxlbmFtZSkpIHx8CiAgICAgICAgICAgIChtYXRjaCAobmV3ZmlsZSwgZmlsZW5hbWUpKSkgewogICAgICAgICAgICBmb3VuZCA9IDE7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICBjbGVhcl92ZmF0ICgmdmZhdCk7CiAgICB9CgogICAgaWYgKGZvdW5kKSB7CiAgICAgICAgaWYgKChmbGFncyAmIERPX09QRU4pICYmIGZpbGUpIHsKICAgICAgICAgICAgaWYgKG9wZW5fZmlsZSAoZmlsZSwgZGlyZW50KSA8IDApIHsKICAgICAgICAgICAgICAgIHJldHVybiAoLTEpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChvdXRuYW1lKSB7CiAgICAgICAgICAgIGlmICh2ZmF0X3ByZXNlbnQpIHsKICAgICAgICAgICAgICAgIHN0cmNweSAob3V0bmFtZSwgdmZhdC5uYW1lKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlIHsKICAgICAgICAgICAgICAgIHN0cmNweSAob3V0bmFtZSwgbmV3ZmlsZSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuICgwKTsgICAgICAgICAgICAgICAgICAgIC8qIEZpbGUgZm91bmQgICAgICAgICAgICAgICAgICAgICAgICAgKi8KICAgIH0gZWxzZSB7CiAgICAgICAgKmVudHJ5ID0gLTE7CiAgICAgICAgcmV0dXJuIC0xOyAgICAgICAgICAgICAgICAgICAgICAvKiBGaWxlIG5vdCBmb3VuZCAgICAgICAgICAgICAgICAgICAgKi8KICAgIH0KfQoKLyotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLQogKiBkaXJfcmVhZCAtLSBSZWFkIG9uZSBkaXJlY3RvcnkgZW50cnkKICotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLQogKi8Kc3RhdGljIGludCBkaXJfcmVhZCAoRnNfdCAqZnMsCiAgICAgICAgICAgICAgU2xvdF90ICpkaXIsCiAgICAgICAgICAgICAgRGlyZWN0b3J5X3QgKmRpcmVudCwKICAgICAgICAgICAgICBpbnQgbnVtLAogICAgICAgICAgICAgIHN0cnVjdCB2ZmF0X3N0YXRlICp2KQp7CgogICAgLyogcmVhZCB0aGUgZGlyZWN0b3J5IGVudHJ5ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICovCiAgICBpZiAocmVhZF9maWxlIChmcywKICAgICAgICAgICAgICAgICAgIGRpciwKICAgICAgICAgICAgICAgICAgIChjaGFyICopZGlyZW50LAogICAgICAgICAgICAgICAgICAgbnVtICogTURJUl9TSVpFLAogICAgICAgICAgICAgICAgICAgTURJUl9TSVpFKSAhPSBNRElSX1NJWkUpIHsKICAgICAgICByZXR1cm4gKC0xKTsKICAgIH0KCiAgICBpZiAodiAmJiAoZGlyZW50IC0+IGF0dHIgPT0gQVRUUl9WU0UpKSB7CiAgICAgICAgc3RydWN0IHZmYXRfc3ViZW50cnkgKnZzZTsKICAgICAgICB1bnNpZ25lZCBjaGFyIGlkLCBsYXN0X2ZsYWc7CiAgICAgICAgY2hhciAqYzsKCiAgICAgICAgdnNlID0gKHN0cnVjdCB2ZmF0X3N1YmVudHJ5ICopIGRpcmVudDsKICAgICAgICBpZCA9IHZzZSAtPiBpZCAmIFZTRV9NQVNLOwogICAgICAgIGxhc3RfZmxhZyA9ICh2c2UgLT4gaWQgJiBWU0VfTEFTVCk7CiAgICAgICAgaWYgKGlkID4gTUFYX1ZGQVRfU1VCRU5UUklFUykgewogICAgICAgICAgICAvKiBJbnZhbGlkIFZTRSBlbnRyeSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICovCiAgICAgICAgICAgIHJldHVybiAoLTEpOwogICAgICAgIH0KCgogICAgICAgIC8qIERlY29kZSBWU0UgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICovCiAgICAgICAgaWYodiAtPiBzdW0gIT0gdnNlIC0+IHN1bSkgewogICAgICAgICAgICBjbGVhcl92ZmF0ICh2KTsKICAgICAgICAgICAgdiAtPiBzdW0gPSB2c2UgLT4gc3VtOwogICAgICAgIH0KCiAgICAgICAgCiAgICAgICAgdiAtPiBzdGF0dXMgfD0gMSA8PCAoaWQgLSAxKTsKICAgICAgICBpZiAobGFzdF9mbGFnKSB7CiAgICAgICAgICAgIHYgLT4gc3ViZW50cmllcyA9IGlkOwogICAgICAgIH0KCiAgICAgICAgYyA9ICYodiAtPiBuYW1lIFtWU0VfTkFNRUxFTiAqIChpZCAtIDEpXSk7CiAgICAgICAgYyArPSB1bmljb2RlX3JlYWQgKHZzZS0+dGV4dDEsIGMsIFZTRTFTSVpFKTsKICAgICAgICBjICs9IHVuaWNvZGVfcmVhZCAodnNlLT50ZXh0MiwgYywgVlNFMlNJWkUpOwogICAgICAgIGMgKz0gdW5pY29kZV9yZWFkICh2c2UtPnRleHQzLCBjLCBWU0UzU0laRSk7CgkJCiAgICAgICAgaWYgKGxhc3RfZmxhZykgewogICAgICAgICAgICAqYyA9ICdcMCc7CSAgICAgICAgLyogTnVsbCB0ZXJtaW5hdGUgbG9uZyBuYW1lICAgICAgICAgICAgICAgICAgKi8KICAgICAgICB9CiAgICAgICAgCiAgICB9CiAgICByZXR1cm4gKDApOwp9CgovKi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tCiAqIHVuaWNvZGVfcmVhZCAtLSAKICotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLQogKi8Kc3RhdGljIGludCB1bmljb2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nICcgJiYgZXh0IFtpXSAhPSAnXDAnKSB7CiAgICAgICAgdGV4dCBbaV0gPSBleHQgW2ldOwogICAgICAgIGkrKzsKICAgIH0KICAgIHRleHQgW2ldID0gJ1wwJzsKCiAgICBpZiAoQ2FzZSAmIEVYVENBU0UpewogICAgICAgIGZvciAoaSA9IDA7IGkgPCAzICYmIHRleHQgW2ldOyBpKyspIHsKICAgICAgICAgICAgdGV4dCBbaV0gPSB0b2xvd2VyICh0ZXh0IFtpXSk7CiAgICAgICAgfQogICAgfQoKICAgIGlmICgqdGV4dCkgewogICAgICAgIHN0cmNweSAoYW5zLCB0bmFtZSk7CiAgICAgICAgc3RyY2F0IChhbnMsICIuIik7CiAgICAgICAgc3RyY2F0IChhbnMsIHRleHQpOwogICAgfQogICAgZWxzZSB7CiAgICAgICAgc3RyY3B5KGFucywgdG5hbWUpOwogICAgfQogICAgcmV0dXJuIChhbnMpOwp9CgoKI2VuZGlmCg==