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Rm9yIDMyYnBwIHBpeGVscyBvbiB0aGUgZm9ybSAweDAwcnJnZ2JiOgogKiBJZiB3ZSB0cmVhdCB0aGUgbWlkZGxlIGNvbXBvbmVudCBzZXBhcmF0ZWx5LCB3ZSBjYW4gcHJvY2VzcyB0aGUgdHdvCiAqIHJlbWFpbmluZyBpbiBwYXJhbGxlbC4gVGhpcyBpcyBzYWZlIHRvIGRvIGJlY2F1c2Ugb2YgdGhlIGdhcCB0byB0aGUgbGVmdAogKiBvZiBlYWNoIGNvbXBvbmVudCwgc28gdGhlIGJpdHMgZnJvbSB0aGUgbXVsdGlwbGljYXRpb24gZG9uJ3QgY29sbGlkZS4KICogVGhpcyBjYW4gYmUgdXNlZCBmb3IgYW55IFJHQiBwZXJtdXRhdGlvbiBvZiBjb3Vyc2UuCiAqLwojZGVmaW5lIEFMUEhBX0JMSVQzMl84ODgodG8sIGZyb20sIGxlbmd0aCwgYnBwLCBhbHBoYSkgICAgICBcCiAgICBkbyB7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICBpbnQgaTsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgIFVpbnQzMiAqc3JjID0gKFVpbnQzMiAqKShmcm9tKTsgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgVWludDMyICpkc3QgPSAoVWludDMyICopKHRvKTsgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICBmb3IgKGkgPSAwOyBpIDwgKGludCkobGVuZ3RoKTsgaSsrKSB7ICAgICAgICAgICAgICAgXAogICAgICAgICAgICBVaW50MzIgcyA9ICpzcmMrKzsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIFVpbnQzMiBkID0gKmRzdDsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgVWludDMyIHMxID0gcyAmIDB4ZmYwMGZmOyAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICBVaW50MzIgZDEgPSBkICYgMHhmZjAwZmY7ICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIGQxID0gKGQxICsgKChzMSAtIGQxKSAqIGFscGhhID4+IDgpKSAmIDB4ZmYwMGZmOyBcCiAgICAgICAgICAgIHMgJj0gMHhmZjAwOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgZCAmPSAweGZmMDA7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICBkID0gKGQgKyAoKHMgLSBkKSAqIGFscGhhID4+IDgpKSAmIDB4ZmYwMDsgICAgICBcCiAgICAgICAgICAgICpkc3QrKyA9IGQxIHwgZDsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICB9ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgfSB3aGlsZSAoMCkKCi8qCiAqIEZvciAxNmJwcCBwaXhlbHMgd2UgY2FuIGdvIGEgc3RlcCBmdXJ0aGVyOiBwdXQgdGhlIG1pZGRsZSBjb21wb25lbnQKICogaW4gdGhlIGhpZ2ggMTYgYml0cyBvZiBhIDMyIGJpdCB3b3JkLCBhbmQgcHJvY2VzcyBhbGwgdGhyZWUgUkdCCiAqIGNvbXBvbmVudHMgYXQgdGhlIHNhbWUgdGltZS4gU2luY2UgdGhlIHNtYWxsZXN0IGdhcCBpcyBoZXJlIGp1c3QKICogNSBiaXRzLCB3ZSBoYXZlIHRvIHNjYWxlIGFscGhhIGRvd24gdG8gNSBiaXRzIGFzIHdlbGwuCiAqLwojZGVmaW5lIEFMUEhBX0JMSVQxNl81NjUodG8sIGZyb20sIGxlbmd0aCwgYnBwLCBhbHBoYSkgIFwKICAgIGRvIHsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgaW50IGk7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgIFVpbnQxNiAqc3JjID0gKFVpbnQxNiAqKShmcm9tKTsgICAgICAgICAgICAgICAgIFwKICAgICAgICBVaW50MTYgKmRzdCA9IChVaW50MTYgKikodG8pOyAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgVWludDMyIEFMUEhBID0gYWxwaGEgPj4gMzsgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgIGZvcihpID0gMDsgaSA8IChpbnQpKGxlbmd0aCk7IGkrKykgeyAgICAgICAgICAgIFwKICAgICAgICAgICAgVWludDMyIHMgPSAqc3JjKys7ICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIFVpbnQzMiBkID0gKmRzdDsgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICBzID0gKHMgfCBzIDw8IDE2KSAmIDB4MDdlMGY4MWY7ICAgICAgICAgICAgIFwKICAgICAgICAgICAgZCA9IChkIHwgZCA8PCAxNikgJiAweDA3ZTBmODFmOyAgICAgICAgICAgICBcCiAgICAgICAgICAgIGQgKz0gKHMgLSBkKSAqIEFMUEhBID4+IDU7ICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICBkICY9IDB4MDdlMGY4MWY7ICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgKmRzdCsrID0gKFVpbnQxNikoZCB8IGQgPj4gMTYpOyAgICAgICAgICAgICBcCiAgICAgICAgfSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgfSB3aGlsZSgwKQoKI2RlZmluZSBBTFBIQV9CTElUMTZfNTU1KHRvLCBmcm9tLCBsZW5ndGgsIGJwcCwgYWxwaGEpICBcCiAgICBkbyB7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgIGludCBpOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICBVaW50MTYgKnNyYyA9IChVaW50MTYgKikoZnJvbSk7ICAgICAgICAgICAgICAgICBcCiAgICAgICAgVWludDE2ICpkc3QgPSAoVWludDE2ICopKHRvKTsgICAgICAgICAgICAgICAgICAgXAogICAgICAgIFVpbnQzMiBBTFBIQSA9IGFscGhhID4+IDM7ICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICBmb3IoaSA9IDA7IGkgPCAoaW50KShsZW5ndGgpOyBpKyspIHsgICAgICAgICAgICBcCiAgICAgICAgICAgIFVpbnQzMiBzID0gKnNyYysrOyAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICBVaW50MzIgZCA9ICpkc3Q7ICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgcyA9IChzIHwgcyA8PCAxNikgJiAweDAzZTA3YzFmOyAgICAgICAgICAgICBcCiAgICAgICAgICAgIGQgPSAoZCB8IGQgPDwgMTYpICYgMHgwM2UwN2MxZjsgICAgICAgICAgICAgXAogICAgICAgICAgICBkICs9IChzIC0gZCkgKiBBTFBIQSA+PiA1OyAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgZCAmPSAweDAzZTA3YzFmOyAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICpkc3QrKyA9IChVaW50MTYpKGQgfCBkID4+IDE2KTsgICAgICAgICAgICAgXAogICAgICAgIH0gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgIH0gd2hpbGUoMCkKCi8qCiAqIFRoZSBnZW5lcmFsIHNsb3cgY2F0Y2gtYWxsIGZ1bmN0aW9uLCBmb3IgcmVtYWluaW5nIGRlcHRocyBhbmQgZm9ybWF0cwogKi8KI2RlZmluZSBBTFBIQV9CTElUX0FOWSh0bywgZnJvbSwgbGVuZ3RoLCBicHAsIGFscGhhKSAgICAgICAgICAgIFwKICAgIGRvIHsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICBpbnQgaTsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICBVaW50OCAqc3JjID0gZnJvbTsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICBVaW50OCAqZHN0ID0gdG87ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICBmb3IgKGkgPSAwOyBpIDwgKGludCkobGVuZ3RoKTsgaSsrKSB7ICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgVWludDMyIHMsIGQ7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgdW5zaWduZWQgcnMsIGdzLCBicywgcmQsIGdkLCBiZDsgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgc3dpdGNoIChicHApIHsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgY2FzZSAyOiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgICAgIHMgPSAqKFVpbnQxNiAqKXNyYzsgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgICAgIGQgPSAqKFVpbnQxNiAqKWRzdDsgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgICAgIGJyZWFrOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgY2FzZSAzOiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgICAgIGlmIChTRExfQllURU9SREVSID09IFNETF9CSUdfRU5ESUFOKSB7ICAgICAgICAgIFwKICAgICAgICAgICAgICAgICAgICBzID0gKHNyY1swXSA8PCAxNikgfCAoc3JjWzFdIDw8IDgpIHwgc3JjWzJdOyBcCiAgICAgICAgICAgICAgICAgICAgZCA9IChkc3RbMF0gPDwgMTYpIHwgKGRzdFsxXSA8PCA4KSB8IGRzdFsyXTsgXAogICAgICAgICAgICAgICAgfSBlbHNlIHsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgICAgIHMgPSAoc3JjWzJdIDw8IDE2KSB8IChzcmNbMV0gPDwgOCkgfCBzcmNbMF07IFwKICAgICAgICAgICAgICAgICAgICBkID0gKGRzdFsyXSA8PCAxNikgfCAoZHN0WzFdIDw8IDgpIHwgZHN0WzBdOyBcCiAgICAgICAgICAgICAgICB9ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBicmVhazsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIGNhc2UgNDogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBzID0gKihVaW50MzIgKilzcmM7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBkID0gKihVaW50MzIgKilkc3Q7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBicmVhazsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIH0gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIFJHQl9GUk9NX1BJWEVMKHMsIGZtdCwgcnMsIGdzLCBicyk7ICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIFJHQl9GUk9NX1BJWEVMKGQsIGZtdCwgcmQsIGdkLCBiZCk7ICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIHJkICs9IChycyAtIHJkKSAqIGFscGhhID4+IDg7ICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIGdkICs9IChncyAtIGdkKSAqIGFscGhhID4+IDg7ICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIGJkICs9IChicyAtIGJkKSAqIGFscGhhID4+IDg7ICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIFBJWEVMX0ZST01fUkdCKGQsIGZtdCwgcmQsIGdkLCBiZCk7ICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIHN3aXRjaCAoYnBwKSB7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIGNhc2UgMjogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICAqKFVpbnQxNiAqKWRzdCA9IChVaW50MTYpZDsgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBicmVhazsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIGNhc2UgMzogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBpZiAoU0RMX0JZVEVPUkRFUiA9PSBTRExfQklHX0VORElBTikgeyAgICAgICAgICBcCiAgICAgICAgICAgICAgICAgICAgZHN0WzBdID0gKFVpbnQ4KShkID4+IDE2KTsgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICAgICAgZHN0WzFdID0gKFVpbnQ4KShkID4+IDgpOyAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICAgICAgZHN0WzJdID0gKFVpbnQ4KShkKTsgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICB9IGVsc2UgeyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICAgICAgZHN0WzBdID0gKFVpbnQ4KWQ7ICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICAgICAgZHN0WzFdID0gKFVpbnQ4KShkID4+IDgpOyAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICAgICAgZHN0WzJdID0gKFVpbnQ4KShkID4+IDE2KTsgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICB9ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBicmVhazsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIGNhc2UgNDogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICAqKFVpbnQzMiAqKWRzdCA9IGQ7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBicmVhazsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIH0gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIHNyYyArPSBicHA7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIGRzdCArPSBicHA7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgfSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICB9IHdoaWxlKDApCgovKgogKiBTcGVjaWFsIGNhc2U6IDUwJSBhbHBoYSAoYWxwaGE9MTI4KQogKiBUaGlzIGlzIHRyZWF0ZWQgc3BlY2lhbGx5IGJlY2F1c2UgaXQgY2FuIGJlIG9wdGltaXplZCB2ZXJ5IHdlbGwsIGFuZAogKiBzaW5jZSBpdCBpcyBnb29kIGZvciBtYW55IGNhc2VzIG9mIHNlbWktdHJhbnNsdWNlbmN5LgogKiBUaGUgdGhlb3J5IGlzIHRvIGRvIGFsbCB0aHJlZSBjb21wb25lbnRzIGF0IHRoZSBzYW1lIHRpbWU6CiAqIEZpcnN0IHplcm8gdGhlIGxvd2VzdCBiaXQgb2YgZWFjaCBjb21wb25lbnQsIHdoaWNoIGdpdmVzIHVzIHJvb20gdG8KICogYWRkIHRoZW0uIFRoZW4gc2hpZnQgcmlnaHQgYW5kIGFkZCB0aGUgc3VtIG9mIHRoZSBsb3dlc3QgYml0cy4KICovCiNkZWZpbmUgQUxQSEFfQkxJVDMyXzg4OF81MCh0bywgZnJvbSwgbGVuZ3RoLCBicHAsIGFscGhhKSAgICAgICBcCiAgICBkbyB7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgaW50IGk7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgVWludDMyICpzcmMgPSAoVWludDMyICopKGZyb20pOyAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgVWludDMyICpkc3QgPSAoVWludDMyICopKHRvKTsgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgZm9yKGkgPSAwOyBpIDwgKGludCkobGVuZ3RoKTsgaSsrKSB7ICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIFVpbnQzMiBzID0gKnNyYysrOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIFVpbnQzMiBkID0gKmRzdDsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICpkc3QrKyA9ICgoKHMgJiAweDAwZmVmZWZlKSArIChkICYgMHgwMGZlZmVmZSkpID4+IDEpIFwKICAgICAgICAgICAgICAgICArIChzICYgZCAmIDB4MDAwMTAxMDEpOyAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICB9ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgIH0gd2hpbGUoMCkKCi8qCiAqIEZvciAxNmJwcCwgd2UgY2FuIGFjdHVhbGx5IGJsZW5kIHR3byBwaXhlbHMgaW4gcGFyYWxsZWwsIGlmIHdlIHRha2UKICogY2FyZSB0byBzaGlmdCBiZWZvcmUgd2UgYWRkLCBub3QgYWZ0ZXIuCiAqLwoKLyogaGVscGVyOiBibGVuZCBhIHNpbmdsZSAxNiBiaXQgcGl4ZWwgYXQgNTAlICovCiNkZWZpbmUgQkxFTkQxNl81MChkc3QsIHNyYywgbWFzaykgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICBkbyB7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgVWludDMyIHMgPSAqc3JjKys7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgVWludDMyIGQgPSAqZHN0OyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgKmRzdCsrID0gKFVpbnQxNikoKCgocyAmIG1hc2spICsgKGQgJiBtYXNrKSkgPj4gMSkgKyAgICBcCiAgICAgICAgICAgICAgICAgICAgICAgICAgKHMgJiBkICYgKH5tYXNrICYgMHhmZmZmKSkpOyAgICAgICAgICBcCiAgICB9IHdoaWxlKDApCgovKiBiYXNpYyAxNmJwcCBibGVuZGVyLiBtYXNrIGlzIHRoZSBwaXhlbHMgdG8ga2VlcCB3aGVuIGFkZGluZy4gKi8KI2RlZmluZSBBTFBIQV9CTElUMTZfNTAodG8sIGZyb20sIGxlbmd0aCwgYnBwLCBhbHBoYSwgbWFzaykgICAgIFwKICAgIGRvIHsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICB1bnNpZ25lZCBuID0gKGxlbmd0aCk7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICBVaW50MTYgKnNyYyA9IChVaW50MTYgKikoZnJvbSk7ICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICBVaW50MTYgKmRzdCA9IChVaW50MTYgKikodG8pOyAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICBpZiAoKCh1aW50cHRyX3Qpc3JjIF4gKHVpbnRwdHJfdClkc3QpICYgMykgeyAgICAgICAgICAgIFwKICAgICAgICAgICAgLyogc291cmNlIGFuZCBkZXN0aW5hdGlvbiBub3QgaW4gcGhhc2UsIGJsaXQgb25lIGJ5IG9uZSAqLyBcCiAgICAgICAgICAgIHdoaWxlIChuLS0pICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBCTEVORDE2XzUwKGRzdCwgc3JjLCBtYXNrKTsgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgfSBlbHNlIHsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIGlmICgodWludHB0cl90KXNyYyAmIDMpIHsgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICAvKiBmaXJzdCBvZGQgcGl4ZWwgKi8gICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBCTEVORDE2XzUwKGRzdCwgc3JjLCBtYXNrKTsgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBuLS07ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIH0gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIGZvciAoOyBuID4gMTsgbiAtPSAyKSB7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBVaW50MzIgcyA9ICooVWludDMyICopc3JjOyAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBVaW50MzIgZCA9ICooVWludDMyICopZHN0OyAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICAqKFVpbnQzMiAqKWRzdCA9ICgocyAmIChtYXNrIHwgbWFzayA8PCAxNikpID4+IDEpIFwKICAgICAgICAgICAgICAgICAgICArICgoZCAmIChtYXNrIHwgbWFzayA8PCAxNikpID4+IDEpICAgICAgICAgIFwKICAgICAgICAgICAgICAgICAgICArIChzICYgZCAmICh+KG1hc2sgfCBtYXNrIDw8IDE2KSkpOyAgICAgICAgIFwKICAgICAgICAgICAgICAgIHNyYyArPSAyOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgICAgIGRzdCArPSAyOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgfSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgaWYgKG4pICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgICAgIEJMRU5EMTZfNTAoZHN0LCBzcmMsIG1hc2spOyAvKiBsYXN0IG9kZCBwaXhlbCAqLyBcCiAgICAgICAgfSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICB9IHdoaWxlKDApCgojZGVmaW5lIEFMUEhBX0JMSVQxNl81NjVfNTAodG8sIGZyb20sIGxlbmd0aCwgYnBwLCBhbHBoYSkgICAgICAgXAogICAgQUxQSEFfQkxJVDE2XzUwKHRvLCBmcm9tLCBsZW5ndGgsIGJwcCwgYWxwaGEsIDB4ZjdkZSkKCiNkZWZpbmUgQUxQSEFfQkxJVDE2XzU1NV81MCh0bywgZnJvbSwgbGVuZ3RoLCBicHAsIGFscGhhKSAgICAgICBcCiAgICBBTFBIQV9CTElUMTZfNTAodG8sIGZyb20sIGxlbmd0aCwgYnBwLCBhbHBoYSwgMHhmYmRlKQoKI2RlZmluZSBDSE9PU0VfQkxJVChibGl0dGVyLCBhbHBoYSwgZm10KSAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgIGRvIHsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICBpZiAoYWxwaGEgPT0gMjU1KSB7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgc3dpdGNoIChmbXQtPkJ5dGVzUGVyUGl4ZWwpIHsgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgY2FzZSAxOiBibGl0dGVyKDEsIFVpbnQ4LCBPUEFRVUVfQkxJVCk7IGJyZWFrOyAgICAgIFwKICAgICAgICAgICAgY2FzZSAyOiBibGl0dGVyKDIsIFVpbnQ4LCBPUEFRVUVfQkxJVCk7IGJyZWFrOyAgICAgIFwKICAgICAgICAgICAgY2FzZSAzOiBibGl0dGVyKDMsIFVpbnQ4LCBPUEFRVUVfQkxJVCk7IGJyZWFrOyAgICAgIFwKICAgICAgICAgICAgY2FzZSA0OiBibGl0dGVyKDQsIFVpbnQxNiwgT1BBUVVFX0JMSVQpOyBicmVhazsgICAgIFwKICAgICAgICAgICAgfSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICB9IGVsc2UgeyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgc3dpdGNoIChmbXQtPkJ5dGVzUGVyUGl4ZWwpIHsgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgY2FzZSAxOiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgICAgIC8qIE5vIDhicHAgYWxwaGEgYmxpdHRpbmcgKi8gICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgICAgIGJyZWFrOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgY2FzZSAyOiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgICAgIHN3aXRjaCAoZm10LT5SbWFzayB8IGZtdC0+R21hc2sgfCBmbXQtPkJtYXNrKSB7IFwKICAgICAgICAgICAgICAgIGNhc2UgMHhmZmZmOiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgICAgICAgICBpZiAoZm10LT5HbWFzayA9PSAweDA3ZTAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgICAgICAgICAgICAgfHwgZm10LT5SbWFzayA9PSAweDA3ZTAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgICAgICAgICAgICAgfHwgZm10LT5CbWFzayA9PSAweDA3ZTApIHsgICAgICAgICAgICAgIFwKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGFscGhhID09IDEyOCkgeyAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJsaXR0ZXIoMiwgVWludDgsIEFMUEhBX0JMSVQxNl81NjVfNTApOyBcCiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBibGl0dGVyKDIsIFVpbnQ4LCBBTFBIQV9CTElUMTZfNTY1KTsgXAogICAgICAgICAgICAgICAgICAgICAgICB9ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgICAgIH0gZWxzZSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgICAgICAgICBnb3RvIGdlbmVyYWwxNjsgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgICAgIGJyZWFrOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgY2FzZSAweDdmZmY6ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgICAgIGlmIChmbXQtPkdtYXNrID09IDB4MDNlMCAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgICAgICAgICB8fCBmbXQtPlJtYXNrID09IDB4MDNlMCAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgICAgICAgICB8fCBmbXQtPkJtYXNrID09IDB4MDNlMCkgeyAgICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgICAgICAgICBpZiAoYWxwaGEgPT0gMTI4KSB7ICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgICAgICAgICAgICAgYmxpdHRlcigyLCBVaW50OCwgQUxQSEFfQkxJVDE2XzU1NV81MCk7IFwKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJsaXR0ZXIoMiwgVWludDgsIEFMUEhBX0JMSVQxNl81NTUpOyBcCiAgICAgICAgICAgICAgICAgICAgICAgIH0gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICAgICAgfSBlbHNlICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICAgICAgICAgIGdvdG8gZ2VuZXJhbDE2OyAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICAgICAgYnJlYWs7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBkZWZhdWx0OiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICBnZW5lcmFsMTY6ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICAgICAgYmxpdHRlcigyLCBVaW50OCwgQUxQSEFfQkxJVF9BTlkpOyAgICAgICAgICBcCiAgICAgICAgICAgICAgICB9ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBicmVhazsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIGNhc2UgMzogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBibGl0dGVyKDMsIFVpbnQ4LCBBTFBIQV9CTElUX0FOWSk7ICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBicmVhazsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIGNhc2UgNDogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBpZiAoKGZtdC0+Um1hc2sgfCBmbXQtPkdtYXNrIHwgZm10LT5CbWFzaykgPT0gMHgwMGZmZmZmZiBcCiAgICAgICAgICAgICAgICAgICAgJiYgKGZtdC0+R21hc2sgPT0gMHhmZjAwIHx8IGZtdC0+Um1hc2sgPT0gMHhmZjAwIFwKICAgICAgICAgICAgICAgICAgICB8fCBmbXQtPkJtYXNrID09IDB4ZmYwMCkpIHsgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgICAgICAgICBpZiAoYWxwaGEgPT0gMTI4KSB7ICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgICAgICAgICAgICAgYmxpdHRlcig0LCBVaW50MTYsIEFMUEhBX0JMSVQzMl84ODhfNTApOyBcCiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICAgICAgICAgIGJsaXR0ZXIoNCwgVWludDE2LCBBTFBIQV9CTElUMzJfODg4KTsgICBcCiAgICAgICAgICAgICAgICAgICAgfSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICB9IGVsc2UgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICAgICAgYmxpdHRlcig0LCBVaW50MTYsIEFMUEhBX0JMSVRfQU5ZKTsgICAgICAgICBcCiAgICAgICAgICAgICAgICBicmVhazsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIH0gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgfSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICB9IHdoaWxlKDApCgovKgogKiBTZXQgYSBwaXhlbCB2YWx1ZSB1c2luZyB0aGUgZ2l2ZW4gZm9ybWF0LCBleGNlcHQgdGhhdCB0aGUgYWxwaGEgdmFsdWUgaXMKICogcGxhY2VkIGluIHRoZSB0b3AgYnl0ZS4gVGhpcyBpcyB0aGUgZm9ybWF0IHVzZWQgZm9yIFJMRSB3aXRoIGFscGhhLgogKi8KI2RlZmluZSBSTEVQSVhFTF9GUk9NX1JHQkEoUGl4ZWwsIGZtdCwgciwgZywgYiwgYSkgICAgICAgICAgICAgICAgICAgICAgXAp7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICBQaXhlbCA9ICgocj4+Zm10LT5SbG9zcyk8PGZtdC0+UnNoaWZ0KXwgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAoKGc+PmZtdC0+R2xvc3MpPDxmbXQtPkdzaGlmdCl8ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICgoYj4+Zm10LT5CbG9zcyk8PGZtdC0+QnNoaWZ0KXwgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgKGE8PDI0KTsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKfQoKLyoKICogVGhpcyB0YWtlcyBjYXJlIG9mIHRoZSBjYXNlIHdoZW4gdGhlIHN1cmZhY2UgaXMgY2xpcHBlZCBvbiB0aGUgbGVmdCBhbmQvb3IKICogcmlnaHQuIFRvcCBjbGlwcGluZyBoYXMgYWxyZWFkeSBiZWVuIHRha2VuIGNhcmUgb2YuCiAqLwpzdGF0aWMgdm9pZApSTEVDbGlwQmxpdChpbnQgdywgVWludDggKiBzcmNidWYsIFNETF9TdXJmYWNlICogc3VyZl9kc3QsCiAgICAgICAgICAgIFVpbnQ4ICogZHN0YnVmLCBTRExfUmVjdCAqIHNyY3JlY3QsIHVuc2lnbmVkIGFscGhhKQp7CiAgICBTRExfUGl4ZWxGb3JtYXQgKmZtdCA9IHN1cmZfZHN0LT5mb3JtYXQ7CgojZGVmaW5lIFJMRUNMSVBCTElUKGJwcCwgVHlwZSwgZG9fYmxpdCkgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgZG8geyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgIGludCBsaW5lY291bnQgPSBzcmNyZWN0LT5oOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgIGludCBvZnMgPSAwOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgIGludCBsZWZ0ID0gc3JjcmVjdC0+eDsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgIGludCByaWdodCA9IGxlZnQgKyBzcmNyZWN0LT53OyAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgIGRzdGJ1ZiAtPSBsZWZ0ICogYnBwOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgIGZvciAoOzspIHsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICBpbnQgcnVuOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICBvZnMgKz0gKihUeXBlICopc3JjYnVmOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICBydW4gPSAoKFR5cGUgKilzcmNidWYpWzFdOyAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICBzcmNidWYgKz0gMiAqIHNpemVvZihUeXBlKTsgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICBpZiAocnVuKSB7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgLyogY2xpcCB0byBsZWZ0IGFuZCByaWdodCBib3JkZXJzICovICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgaWYgKG9mcyA8IHJpZ2h0KSB7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgICAgIGludCBzdGFydCA9IDA7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgICAgIGludCBsZW4gPSBydW47ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgICAgIGludCBzdGFydGNvbDsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgICAgIGlmIChsZWZ0IC0gb2ZzID4gMCkgeyAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgICAgICAgICBzdGFydCA9IGxlZnQgLSBvZnM7ICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gc3RhcnQ7ICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgICAgICAgICBpZiAobGVuIDw9IDApICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgICAgICAgICAgICAgZ290byBub2NvcHkgIyMgYnBwICMjIGRvX2JsaXQ7ICAgICAgXAogICAgICAgICAgICAgICAgICAgIH0gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgICAgIHN0YXJ0Y29sID0gb2ZzICsgc3RhcnQ7ICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgICAgIGlmIChsZW4gPiByaWdodCAtIHN0YXJ0Y29sKSAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgICAgICAgICBsZW4gPSByaWdodCAtIHN0YXJ0Y29sOyAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgICAgIGRvX2JsaXQoZHN0YnVmICsgc3RhcnRjb2wgKiBicHAsIHNyY2J1ZiArIHN0YXJ0ICogYnBwLCBcCiAgICAgICAgICAgICAgICAgICAgICAgIGxlbiwgYnBwLCBhbHBoYSk7ICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICB9ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICBub2NvcHkgIyMgYnBwICMjIGRvX2JsaXQ6ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBzcmNidWYgKz0gcnVuICogYnBwOyAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBvZnMgKz0gcnVuOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIH0gZWxzZSBpZiAoIW9mcykgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBicmVhazsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIGlmIChvZnMgPT0gdykgeyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBvZnMgPSAwOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBkc3RidWYgKz0gc3VyZl9kc3QtPnBpdGNoOyAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBpZiAoIS0tbGluZWNvdW50KSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICAgICAgYnJlYWs7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIH0gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgf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xpbmVzIGF0IHRoZSB0b3AgaWYgbmVjZXNzYXJ5ICovCiAgICAgICAgaW50IHZza2lwID0gc3JjcmVjdC0+eTsKICAgICAgICBpbnQgb2ZzID0gMDsKICAgICAgICBpZiAodnNraXApIHsKCiNkZWZpbmUgUkxFU0tJUChicHAsIFR5cGUpICAgICAgICAgIFwKICAgICAgICBmb3IoOzspIHsgICAgICAgICAgIFwKICAgICAgICAgICAgaW50IHJ1bjsgICAgICAgICAgICBcCiAgICAgICAgICAgIG9mcyArPSAqKFR5cGUgKilzcmNidWY7IFwKICAgICAgICAgICAgcnVuID0gKChUeXBlICopc3JjYnVmKVsxXTsgIFwKICAgICAgICAgICAgc3JjYnVmICs9IHNpemVvZihUeXBlKSAqIDI7IFwKICAgICAgICAgICAgaWYocnVuKSB7ICAgICAgICAgICBcCiAgICAgICAgICAgIHNyY2J1ZiArPSBydW4gKiBicHA7ICAgIFwKICAgICAgICAgICAgb2ZzICs9IHJ1bjsgICAgIFwKICAgICAgICAgICAgfSBlbHNlIGlmKCFvZnMpICAgICBcCiAgICAgICAgICAgIGdvdG8gZG9uZTsgICAgICBcCiAgICAgICAgICAgIGlmKG9mcyA9PSB3KSB7ICAgICAgXAogICAgICAgICAgICBvZnMgPSAwOyAgICAgICAgXAogICAgICAgICAgICBpZighLS12c2tpcCkgICAgICAgIFwKICAgICAgICAgICAgICAgIGJyZWFrOyAgICAgIFwKICAgICAgICAgICAgfSAgICAgICAgICAgICAgIFwKICAgICAgICB9CgogICAgICAgICAgICBzd2l0Y2ggKHN1cmZfc3JjLT5mb3JtYXQtPkJ5dGVzUGVyUGl4ZWwpIHsKICAgICAgICAgICAgY2FzZSAxOgogICAgICAgICAgICAgICAgUkxFU0tJUCgxLCBVaW50OCk7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgY2FzZSAyOgogICAgICAgICAgICAgICAgUkxFU0tJUCgyLCBVaW50OCk7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgY2FzZSAzOgogICAgICAgICAgICAgICAgUkxFU0tJUCgzLCBVaW50OCk7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgY2FzZSA0OgogICAgICAgICAgICAgICAgUkxFU0tJUCg0LCBVaW50MTYpOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KCiN1bmRlZiBSTEVTS0lQCgogICAgICAgIH0KICAgIH0KCiAgICBhbHBoYSA9IHN1cmZfc3JjLT5tYXAtPmluZm8uYTsKICAgIC8qIGlmIGxlZnQgb3IgcmlnaHQgZWRnZSBjbGlwcGluZyBuZWVkZWQsIGNhbGwgY2xpcCBibGl0ICovCiAgICBpZiAoc3JjcmVjdC0+eCB8fCBzcmNyZWN0LT53ICE9IHN1cmZfc3JjLT53KSB7CiAgICAgICAgUkxFQ2xpcEJsaXQodywgc3JjYnVmLCBzdXJmX2RzdCwgZHN0YnVmLCBzcmNyZWN0LCBhbHBoYSk7CiAgICB9IGVsc2UgewogICAgICAgIFNETF9QaXhlbEZvcm1hdCAqZm10ID0gc3VyZl9zcmMtPmZvcm1hdDsKCiNkZWZpbmUgUkxFQkxJVChicHAsIFR5cGUsIGRvX2JsaXQpICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgZG8geyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgaW50IGxpbmVjb3VudCA9IHNyY3JlY3QtPmg7ICAgICAgICAgICAgICAgICAgIFwKICAgICAgICBpbnQgb2ZzID0gMDsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgZm9yKDs7KSB7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIHVuc2lnbmVkIHJ1bjsgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICBvZnMgKz0gKihUeXBlICopc3JjYnVmOyAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIHJ1biA9ICgoVHlwZSAqKXNyY2J1ZilbMV07ICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIHNyY2J1ZiArPSAyICogc2l6ZW9mKFR5cGUpOyAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIGlmKHJ1bikgeyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICBkb19ibGl0KGRzdGJ1ZiArIG9mcyAqIGJwcCwgc3JjYnVmLCBydW4sIGJwcCwgYWxwaGEpOyBcCiAgICAgICAgICAgIHNyY2J1ZiArPSBydW4gKiBicHA7ICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgb2ZzICs9IHJ1bjsgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgfSBlbHNlIGlmKCFvZnMpICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIGJyZWFrOyAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIGlmKG9mcyA9PSB3KSB7ICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICBvZnMgPSAwOyAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICBkc3RidWYgKz0gc3VyZl9kc3QtPnBpdGNoOyAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgaWYoIS0tbGluZWNvdW50KSAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBicmVhazsgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIH0gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgfSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICB9IHdoaWxlKDApCgogICAgICAgIENIT09TRV9CTElUKFJMRUJMSVQsIGFscGhhLCBmbXQpOwoKI3VuZGVmIFJMRUJMSVQKICAgIH0KCiAgZG9uZToKICAgIC8qIFVubG9jayB0aGUgZGVzdGluYXRpb24gaWYgbmVjZXNzYXJ5ICovCiAgICBpZiAoU0RMX01VU1RMT0NLKHN1cmZfZHN0KSkgewogICAgICAgIFNETF9VbmxvY2tTdXJmYWNlKHN1cmZfZHN0KTsKICAgIH0KICAgIHJldHVybiAoMCk7Cn0KCiN1bmRlZiBPUEFRVUVfQkxJVAoKLyoKICogUGVyLXBpeGVsIGJsaXR0aW5nIG1hY3JvcyBmb3IgdHJhbnNsdWNlbnQgcGl4ZWxzOgogKiBUaGVzZSB1c2UgdGhlIHNhbWUgdGVjaG5pcXVlcyBhcyB0aGUgcGVyLXN1cmZhY2UgYmxpdHRpbmcgbWFjcm9zCiAqLwoKLyoKICogRm9yIDMyYnBwIHBpeGVscywgd2UgaGF2ZSBtYWRlIHN1cmUgdGhlIGFscGhhIGlzIHN0b3JlZCBpbiB0aGUgdG9wCiAqIDggYml0cywgc28gcHJvY2VlZCBhcyB1c3VhbAogKi8KI2RlZmluZSBCTElUX1RSQU5TTF84ODgoc3JjLCBkc3QpICAgICAgICAgICAgICAgXAogICAgZG8geyAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgVWludDMyIHMgPSBzcmM7ICAgICAgICAgICAgICAgICAgICAgXAogICAgVWludDMyIGQgPSBkc3Q7ICAgICAgICAgICAgICAgICAgICAgXAogICAgdW5zaWduZWQgYWxwaGEgPSBzID4+IDI0OyAgICAgICAgICAgICAgIFwKICAgIFVpbnQzMiBzMSA9IHMgJiAweGZmMDBmZjsgICAgICAgICAgICAgICBcCiAgICBVaW50MzIgZDEgPSBkICYgMHhmZjAwZmY7ICAgICAgICAgICAgICAgXAogICAgZDEgPSAoZDEgKyAoKHMxIC0gZDEpICogYWxwaGEgPj4gOCkpICYgMHhmZjAwZmY7ICAgIFwKICAgIHMgJj0gMHhmZjAwOyAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgIGQgJj0gMHhmZjAwOyAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgIGQgPSAoZCArICgocyAtIGQpICogYWxwaGEgPj4gOCkpICYgMHhmZjAwOyAgICAgIFwKICAgIGRzdCA9IGQxIHwgZCB8IDB4ZmYwMDAwMDA7ICAgICAgICAgICAgICBcCiAgICB9IHdoaWxlKDApCgovKgogKiBGb3IgMTZicHAgcGl4ZWxzLCB3ZSBoYXZlIHN0b3JlZCB0aGUgNSBtb3N0IHNpZ25pZmljYW50IGFscGhhIGJpdHMgaW4KICogYml0cyA1LTEwLiBBcyBiZWZvcmUsIHdlIGNhbiBwcm9jZXNzIGFsbCAzIFJHQiBjb21wb25lbnRzIGF0IHRoZSBzYW1lIHRpbWUuCiAqLwojZGVmaW5lIEJMSVRfVFJBTlNMXzU2NShzcmMsIGRzdCkgICAgICAgXAogICAgZG8geyAgICAgICAgICAgICAgICAgICAgXAogICAgVWludDMyIHMgPSBzcmM7ICAgICAgICAgICAgIFwKICAgIFVpbnQzMiBkID0gZHN0OyAgICAgICAgICAgICBcCiAgICB1bnNpZ25lZCBhbHBoYSA9IChzICYgMHgzZTApID4+IDU7ICBcCiAgICBzICY9IDB4MDdlMGY4MWY7ICAgICAgICAgICAgXAogICAgZCA9IChkIHwgZCA8PCAxNikgJiAweDA3ZTBmODFmOyAgICAgXAogICAgZCArPSAocyAtIGQpICogYWxwaGEgPj4gNTsgICAgICBcCiAgICBkICY9IDB4MDdlMGY4MWY7ICAgICAgICAgICAgXAogICAgZHN0ID0gKFVpbnQxNikoZCB8IGQgPj4gMTYpOyAgICAgICAgICAgIFwKICAgIH0gd2hpbGUoMCkKCiNkZWZpbmUgQkxJVF9UUkFOU0xfNTU1KHNyYywgZHN0KSAgICAgICBcCiAgICBkbyB7ICAgICAgICAgICAgICAgICAgICBcCiAgICBVaW50MzIgcyA9IHNyYzsgICAgICAgICAgICAgXAogICAgVWludDMyIGQgPSBkc3Q7ICAgICAgICAgICAgIFwKICAgIHVuc2lnbmVkIGFscGhhID0gKHMgJiAweDNlMCkgPj4gNTsgIFwKICAgIHMgJj0gMHgwM2UwN2MxZjsgICAgICAgICAgICBcCiAgICBkID0gKGQgfC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F9QaXhlbEZvcm1hdCAqZGYgPSBzdXJmX2RzdC0+Zm9ybWF0OwogICAgLyoKICAgICAqIGNsaXBwZWQgYmxpdHRlcjogUHR5cGUgaXMgdGhlIGRlc3RpbmF0aW9uIHBpeGVsIHR5cGUsCiAgICAgKiBDdHlwZSB0aGUgdHJhbnNsdWNlbnQgY291bnQgdHlwZSwgYW5kIGRvX2JsZW5kIHRoZSBtYWNybwogICAgICogdG8gYmxlbmQgb25lIHBpeGVsLgogICAgICovCiNkZWZpbmUgUkxFQUxQSEFDTElQQkxJVChQdHlwZSwgQ3R5cGUsIGRvX2JsZW5kKSAgICAgICAgICAgICAgXAogICAgZG8geyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICBpbnQgbGluZWNvdW50ID0gc3JjcmVjdC0+aDsgICAgICAgICAgICAgICAgICAgXAogICAgaW50IGxlZnQgPSBzcmNyZWN0LT54OyAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgIGludCByaWdodCA9IGxlZnQgKyBzcmNyZWN0LT53OyAgICAgICAgICAgICAgICAgICAgXAogICAgZHN0YnVmIC09IGxlZnQgKiBzaXplb2YoUHR5cGUpOyAgICAgICAgICAgICAgICAgICBcCiAgICBkbyB7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICBpbnQgb2ZzID0gMDsgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAvKiBibGl0IG9wYXF1ZSBwaXhlbHMgb24gb25lIGxpbmUgKi8gICAgICAgICAgICAgIFwKICAgICAgICBkbyB7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgIHVuc2lnbmVkIHJ1bjsgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgIG9mcyArPSAoKEN0eXBlICopc3JjYnVmKVswXTsgICAgICAgICAgICAgICAgICBcCiAgICAgICAgcnVuID0gKChDdHlwZSAqKXNyY2J1ZilbMV07ICAgICAgICAgICAgICAgXAogICAgICAgIHNyY2J1ZiArPSAyICogc2l6ZW9mKEN0eXBlKTsgICAgICAgICAgICAgICAgICBcCiAgICAgICAgaWYocnVuKSB7ICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgLyogY2xpcCB0byBsZWZ0IGFuZCByaWdodCBib3JkZXJzICovICAgICAgICAgIFwKICAgICAgICAgICAgaW50IGNvZnMgPSBvZnM7ICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgaW50IGNydW4gPSBydW47ICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgaWYobGVmdCAtIGNvZnMgPiAwKSB7ICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIGNydW4gLT0gbGVmdCAtIGNvZnM7ICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICBjb2ZzID0gbGVmdDsgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICB9ICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIGlmKGNydW4gPiByaWdodCAtIGNvZnMpICAgICAgICAgICAgICAgXAogICAgICAgICAgICBjcnVuID0gcmlnaHQgLSBjb2ZzOyAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgaWYoY3J1biA+IDApICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgUElYRUxfQ09QWShkc3RidWYgKyBjb2ZzICogc2l6ZW9mKFB0eXBlKSwgICAgIFwKICAgICAgICAgICAgICAgICAgIHNyY2J1ZiArIChjb2ZzIC0gb2ZzKSAqIHNpemVvZihQdHlwZSksIFwKICAgICAgICAgICAgICAgICAgICh1bnNpZ25lZCljcnVuLCBzaXplb2YoUHR5cGUpKTsgICAgXAogICAgICAgICAgICBzcmNidWYgKz0gcnVuICogc2l6ZW9mKFB0eXBlKTsgICAgICAgICAgICBcCiAgICAgICAgICAgIG9mcyArPSBydW47ICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgfSBlbHNlIGlmKCFvZnMpICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIHJldHVybjsgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICB9IHdoaWxlKG9mcyA8IHcpOyAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgLyogc2tpcCBwYWRkaW5nIGlmIG5lY2Vzc2FyeSAqLyAgICAgICAgICAgICAgIFwKICAgICAgICBpZihzaXplb2YoUHR5cGUpID09IDIpICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgc3JjYnVmICs9ICh1aW50cHRyX3Qpc3JjYnVmICYgMjsgICAgICAgICAgICAgIFwKICAgICAgICAvKiBibGl0IHRyYW5zbHVjZW50IHBpeGVscyBvbiB0aGUgc2FtZSBsaW5lICovICAgICAgICBcCiAgICAgICAgb2ZzID0gMDsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgZG8geyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICB1bnNpZ25lZCBydW47ICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICBvZnMgKz0gKChVaW50MTYgKilzcmNidWYpWzBdOyAgICAgICAgICAgICAgICAgXAogICAgICAgIHJ1biA9ICgoVWludDE2ICopc3JjYnVmKVsxXTsgICAgICAgICAgICAgICAgICBcCiAgICAgICAgc3JjYnVmICs9IDQ7ICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgaWYocnVuKSB7ICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgLyogY2xpcCB0byBsZWZ0IGFuZCByaWdodCBib3JkZXJzICovICAgICAgICAgIFwKICAgICAgICAgICAgaW50IGNvZnMgPSBvZnM7ICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgaW50IGNydW4gPSBydW47ICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgaWYobGVmdCAtIGNvZnMgPiAwKSB7ICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIGNydW4gLT0gbGVmdCAtIGNvZnM7ICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICBjb2ZzID0gbGVmdDsgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICB9ICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIGlmKGNydW4gPiByaWdodCAtIGNvZnMpICAgICAgICAgICAgICAgXAogICAgICAgICAgICBjcnVuID0gcmlnaHQgLSBjb2ZzOyAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgaWYoY3J1biA+IDApIHsgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgUHR5cGUgKmRzdCA9IChQdHlwZSAqKWRzdGJ1ZiArIGNvZnM7ICAgICAgICAgIFwKICAgICAgICAgICAgVWludDMyICpzcmMgPSAoVWludDMyICopc3JjYnVmICsgKGNvZnMgLSBvZnMpOyAgICBcCiAgICAgICAgICAgIGludCBpOyAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgZm9yKGkgPSAwOyBpIDwgY3J1bjsgaSsrKSAgICAgICAgICAgICBcCiAgICAgICAgICAgICAgICBkb19ibGVuZChzcmNbaV0sIGRzdFtpXSk7ICAgICAgICAgICAgIFwKICAgICAgICAgICAgfSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICBzcmNidWYgKz0gcnVuICogNDsgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgb2ZzICs9IHJ1bjsgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICB9ICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgfSB3aGlsZShvZnMgPCB3KTsgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgIGRzdGJ1ZiArPSBzdXJmX2RzdC0+cGl0Y2g7ICAgICAgICAgICAgICAgICAgICAgXAogICAgfSB3aGlsZSgtLWxpbmVjb3VudCk7ICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgIH0gd2hpbGUoMCkK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VjdC0+eDsKICAgIHkgPSBkc3RyZWN0LT55OwogICAgZHN0YnVmID0gKFVpbnQ4ICopIHN1cmZfZHN0LT5waXhlbHMgKyB5ICogc3VyZl9kc3QtPnBpdGNoICsgeCAqIGRmLT5CeXRlc1BlclBpeGVsOwogICAgc3JjYnVmID0gKFVpbnQ4ICopIHN1cmZfc3JjLT5tYXAtPmRhdGEgKyBzaXplb2YoUkxFRGVzdEZvcm1hdCk7CgogICAgewogICAgICAgIC8qIHNraXAgbGluZXMgYXQgdGhlIHRvcCBpZiBuZWNlc3NhcnkgKi8KICAgICAgICBpbnQgdnNraXAgPSBzcmNyZWN0LT55OwogICAgICAgIGlmICh2c2tpcCkgewogICAgICAgICAgICBpbnQgb2ZzOwogICAgICAgICAgICBpZiAoZGYtPkJ5dGVzUGVyUGl4ZWwgPT0gMikgewogICAgICAgICAgICAgICAgLyogdGhlIDE2LzMyIGludGVybGVhdmVkIGZvcm1hdCAqLwogICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgIC8qIHNraXAgb3BhcXVlIGxpbmUgKi8KICAgICAgICAgICAgICAgICAgICBvZnMgPSAwOwogICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgaW50IHJ1bjsKICAgICAgICAgICAgICAgICAgICAgICAgb2ZzICs9IHNyY2J1ZlswXTsKICAgICAgICAgICAgICAgICAgICAgICAgcnVuID0gc3JjYnVmWzFdOwogICAgICAgICAgICAgICAgICAgICAgICBzcmNidWYgKz0gMjsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHJ1bikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgc3JjYnVmICs9IDIgKiBydW47CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvZnMgKz0gcnVuOwogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKCFvZnMpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBnb3RvIGRvbmU7CiAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAob2ZzIDwgdyk7CgogICAgICAgICAgICAgICAgICAgIC8qIHNraXAgcGFkZGluZyAqLwogICAgICAgICAgICAgICAgICAgIHNyY2J1ZiArPSAodWludHB0cl90KSBzcmNidWYgJiAyOwoKICAgICAgICAgICAgICAgICAgICAvKiBza2lwIHRyYW5zbHVjZW50IGxpbmUgKi8KICAgICAgICAgICAgICAgICAgICBvZnMgPSAwOwogICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgaW50IHJ1bjsKICAgICAgICAgICAgICAgICAgICAgICAgb2ZzICs9ICgoVWludDE2ICopIHNyY2J1ZilbMF07CiAgICAgICAgICAgICAgICAgICAgICAgIHJ1biA9ICgoVWludDE2ICopIHNyY2J1ZilbMV07CiAgICAgICAgICAgICAgICAgICAgICAgIHNyY2J1ZiArPSA0ICogKHJ1biArIDEpOwogICAgICAgICAgICAgICAgICAgICAgICBvZnMgKz0gcnVuOwogICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKG9mcyA8IHcpOwogICAgICAgICAgICAgICAgfSB3aGlsZSAoLS12c2tpcCk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAvKiB0aGUgMzIvMzIgaW50ZXJsZWF2ZWQgZm9ybWF0ICovCiAgICAgICAgICAgICAgICB2c2tpcCA8PD0gMTsgICAgLyogb3BhcXVlIGFuZCB0cmFuc2x1Y2VudCBoYXZlIHNhbWUgZm9ybWF0ICovCiAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgb2ZzID0gMDsKICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgIGludCBydW47CiAgICAgICAgICAgICAgICAgICAgICAgIG9mcyArPSAoKFVpbnQxNiAqKSBzcmNidWYpWzBdOwogICAgICAgICAgICAgICAgICAgICAgICBydW4gPSAoKFVpbnQxNiAqKSBzcmNidWYpWzFdOwogICAgICAgICAgICAgICAgICAgICAgICBzcmNidWYgKz0gNDsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHJ1bikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgc3JjYnVmICs9IDQgKiBydW47CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvZnMgKz0gcnVuOwogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKCFvZnMpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBnb3RvIGRvbmU7CiAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAob2ZzIDwgdyk7CiAgICAgICAgICAgICAgICB9IHdoaWxlICgtLXZza2lwKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KCiAgICAvKiBpZiBsZWZ0IG9yIHJpZ2h0IGVkZ2UgY2xpcHBpbmcgbmVlZGVkLCBjYWxsIGNsaXAgYmxpdCAqLwogICAgaWYgKHNyY3JlY3QtPnggfHwgc3JjcmVjdC0+dyAhPSBzdXJmX3NyYy0+dykgewogICAgICAgIFJMRUFscGhhQ2xpcEJsaXQodywgc3JjYnVmLCBzdXJmX2RzdCwgZHN0YnVmLCBzcmNyZWN0KTsKICAgIH0gZWxzZSB7CgogICAgICAgIC8qCiAgICAgICAgICogbm9uLWNsaXBwZWQgYmxpdHRlci4gUHR5cGUgaXMgdGhlIGRlc3RpbmF0aW9uIHBpeGVsIHR5cGUsCiAgICAgICAgICogQ3R5cGUgdGhlIHRyYW5zbHVjZW50IGNvdW50IHR5cGUsIGFuZCBkb19ibGVuZCB0aGUKICAgICAgICAgKiBtYWNybyB0byBibGVuZCBvbmUgcGl4ZWwuCiAgICAgICAgICovCiNkZWZpbmUgUkxFQUxQSEFCTElUKFB0eXBlLCBDdHlwZSwgZG9fYmxlbmQpICAgICAgICAgICAgICAgICBcCiAgICBkbyB7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgIGludCBsaW5lY291bnQgPSBzcmNyZWN0LT5oOyAgICAgICAgICAgICAgICAgIFwKICAgICAgICBkbyB7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgaW50IG9mcyA9IDA7ICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAvKiBibGl0IG9wYXF1ZSBwaXhlbHMgb24gb25lIGxpbmUgKi8gICAgICAgICAgICAgXAogICAgICAgIGRvIHsgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgdW5zaWduZWQgcnVuOyAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICBvZnMgKz0gKChDdHlwZSAqKXNyY2J1ZilbMF07ICAgICAgICAgICAgIFwKICAgICAgICAgICAgcnVuID0gKChDdHlwZSAqKXNyY2J1ZilbMV07ICAgICAgICAgICAgICBcCiAgICAgICAgICAgIHNyY2J1ZiArPSAyICogc2l6ZW9mKEN0eXBlKTsgICAgICAgICAgICAgXAogICAgICAgICAgICBpZihydW4pIHsgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIFBJWEVMX0NPUFkoZHN0YnVmICsgb2ZzICogc2l6ZW9mKFB0eXBlKSwgc3JjYnVmLCBcCiAgICAgICAgICAgICAgICAgICBydW4sIHNpemVvZihQdHlwZSkpOyAgICAgICAgICBcCiAgICAgICAgICAgIHNyY2J1ZiArPSBydW4gKiBzaXplb2YoUHR5cGUpOyAgICAgICAgICAgXAogICAgICAgICAgICBvZnMgKz0gcnVuOyAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgfSBlbHNlIGlmKCFvZnMpICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICBnb3RvIGRvbmU7ICAgICAgICAgICAgICAgICAgIFwKICAgICAgICB9IHdoaWxlKG9mcyA8IHcpOyAgICAgICAgICAgICAgICAgICAgXAogICAgICAgIC8qIHNraXAgcGFkZGluZyBpZiBuZWNlc3NhcnkgKi8gICAgICAgICAgICAgIFwKICAgICAgICBpZihzaXplb2YoUHR5cGUpID09IDIpICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgc3JjYnVmICs9ICh1aW50cHRyX3Qpc3JjYnVmICYgMjsgICAgICAgICAgICAgXAogICAgICAgIC8qIGJsaXQgdHJhbnNsdWNlbnQgcGl4ZWxzIG9uIHRoZSBzYW1lIGxpbmUgKi8gICAgICAgXAogICAgICAgIG9mcyA9IDA7ICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICBkbyB7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIHVuc2lnbmVkIHJ1bjsgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgb2ZzICs9ICgoVWludDE2ICopc3JjYnVmKVswXTsgICAgICAgICAgICBcCiAgICAgICAgICAgIHJ1biA9ICgoVWludDE2ICopc3JjYnVmKVsxXTsgICAgICAgICAgICAgXAogICAgICAgICAgICBzcmNidWYgKz0gNDsgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIGlmKHJ1bikgeyAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgUHR5cGUgKmRzdCA9IChQdHlwZSAqKWRzdGJ1ZiArIG9mczsgICAgICBcCiAgICAgICAgICAgIHVuc2lnbmVkIGk7ICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICBmb3IoaSA9IDA7IGkgPCBydW47IGkrKykgeyAgICAgICAgICAgXAogICAgICAgICAgICAgICAgVWludDMyIHNyYyA9ICooVWludDMyICopc3JjYnVmOyAgICAgIFwKICAgICAgICAgICAgICAgIGRvX2JsZW5kKHNyYywgKmRzdCk7ICAgICAgICAgICAgIFwKICAgICAgICAgICAgICAgIHNyY2J1ZiArPSA0OyAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICAgICAgZHN0Kys7ICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgfSAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgb2ZzICs9IHJ1bjsgICAgICAgICAgICAgICAgICBcCiAgICAgICAgICAgIH0gICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgIH0gd2hpbGUob2ZzIDwgdyk7ICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgZHN0YnVmICs9IHN1cmZfZHN0LT5waXRjaDsgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICB9IHdoaWxlKC0tbGluZWNvdW50KTsgICAgICAgICAgICAgICAgICAgIFwKICAgIH0gd2hpbGUoMCkKCiAgICAgICAgc3dpdGNoIChkZi0+Qnl0ZXNQZXJQaXhlbCkgewogICAgICAgIGNhc2UgMjoKICAgICAgICAgICAgaWYgKGRmLT5HbWFzayA9PSAweDA3ZTAgfHwgZGYtPlJtYXNrID09IDB4MDdlMAogICAgICAgICAgICAgICAgfHwgZGYtPkJtYXNrID09IDB4MDdlMCkKICAgICAgICAgICAgICAgIFJMRUFMUEhBQkxJVChVaW50MTYsIFVpbnQ4LCBCTElUX1RSQU5TTF81NjUpOwogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICBSTEVBTFBIQUJMSVQoVWludDE2LCBVaW50OCwgQkxJVF9UUkFOU0xfNTU1KTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSA0OgogICAgICAgICAgICBSTEVBTFBIQUJMSVQoVWludDMyLCBVaW50MTYsIEJMSVRfVFJBTlNMXzg4OCk7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgIH0KCiAgZG9uZToKICAgIC8qIFVubG9jayB0aGUgZGVzdGluYXRpb24gaWYgbmVjZXNzYXJ5ICovCiAgICBpZiAoU0RMX01VU1RMT0NLKHN1cmZfZHN0KSkgewogICAgICAgIFNETF9VbmxvY2tTdXJmYWNlKHN1cmZfZHN0KTsKICAgIH0KICAgIHJldHVybiAwOwp9CgovKgogKiBBdXhpbGlhcnkgZnVuY3Rpb25zOgogKiBUaGUgZW5jb2RpbmcgZnVuY3Rpb25zIHRha2UgMzJicHAgcmdiICsgYSwgYW5kCiAqIHJldHVybiB0aGUgb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AgaW50ICgqY29weV90cmFuc2wpICh2b2lkICosIFVpbnQzMiAqLCBpbnQsCiAgICAgICAgICAgICAgICAgICAgICAgIFNETF9QaXhlbEZvcm1hdCAqLCBTRExfUGl4ZWxGb3JtYXQgKik7CgogICAgZGVzdCA9IHN1cmZhY2UtPm1hcC0+ZHN0OwogICAgaWYgKCFkZXN0KQogICAgICAgIHJldHVybiAtMTsKICAgIGRmID0gZGVzdC0+Zm9ybWF0OwogICAgaWYgKHN1cmZhY2UtPmZvcm1hdC0+Qml0c1BlclBpeGVsICE9IDMyKQogICAgICAgIHJldHVybiAtMTsgICAgICAgICAgICAgIC8qIG9ubHkgMzJicHAgc291cmNlIHN1cHBvcnRlZCAqLwoKICAgIC8qIGZpbmQgb3V0IHdoZXRoZXIgdGhlIGRlc3RpbmF0aW9uIGlzIG9uZSB3ZSBzdXBwb3J0LAogICAgICAgYW5kIGRldGVybWluZSB0aGUgbWF4IHNpemUgb2YgdGhlIGVuY29kZWQgcmVzdWx0ICovCiAgICBtYXNrc3VtID0gZGYtPlJtYXNrIHwgZGYtPkdtYXNrIHwgZGYtPkJtYXNrOwogICAgc3dpdGNoIChkZi0+Qnl0ZXNQZXJQaXhlbCkgewogICAgY2FzZSAyOgogICAgICAgIC8qIDE2YnBwOiBvbmx5IHN1cHBvcnQgNTY1IGFuZCA1NTUgZm9ybWF0cyAqLwogICAgICAgIHN3aXRjaCAobWFza3N1bSkgewogICAgICAgIGNhc2UgMHhmZmZmOgogICAgICAgICAgICBpZiAoZGYtPkdtYXNrID09IDB4MDdlMAogICAgICAgICAgICAgICAgfHwgZGYtPlJtYXNrID09IDB4MDdlMCB8fCBkZi0+Qm1hc2sgPT0gMHgwN2UwKSB7CiAgICAgICAgICAgICAgICBjb3B5X29wYXF1ZSA9IGNvcHlfb3BhcXVlXzE2OwogICAgICAgICAgICAgICAgY29weV90cmFuc2wgPSBjb3B5X3RyYW5zbF81NjU7CiAgICAgICAgICAgIH0gZWxzZQogICAgICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIDB4N2ZmZjoKICAgICAgICAgICAgaWYgKGRmLT5HbWFzayA9PSAweDAzZTAKICAgICAgICAgICAgICAgIHx8IGRmLT5SbWFzayA9PSAweDAzZTAgfHwgZGYtPkJtYXNrID09IDB4MDNlMCkgewogICAgICAgICAgICAgICAgY29weV9vcGFxdWUgPSBjb3B5X29wYXF1ZV8xNjsKICAgICAgICAgICAgICAgIGNvcHlfdHJhbnNsID0gY29weV90cmFuc2xfNTU1OwogICAgICAgICAgICB9IGVsc2UKICAgICAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgIH0KICAgICAgICBtYXhfb3BhcXVlX3J1biA9IDI1NTsgICAvKiBydW5zIHN0b3JlZCBhcyBieXRlcyAqLwoKICAgICAgICAvKiB3b3JzdCBjYXNlIGlzIGFsdGVybmF0aW5nIG9wYXF1ZSBhbmQgdHJhbnNsdWNlbnQgcGl4ZWxzLAogICAgICAgICAgIHdpdGggcm9vbSBmb3IgYWxpZ25tZW50IHBhZGRpbmcgYmV0d2VlbiBsaW5lcyAqLwogICAgICAgIG1heHNpemUgPSBzdXJmYWNlLT5oICogKDIgKyAoNCArIDIpICogKHN1cmZhY2UtPncgKyAxKSkgKyAyOwogICAgICAgIGJyZWFrOwogICAgY2FzZSA0OgogICAgICAgIGlmIChtYXNrc3VtICE9IDB4MDBmZmZmZmYpCiAgICAgICAgICAgIHJldHVybiAtMTsgICAgICAgICAgLyogcmVxdWlyZXMgdW51c2VkIGhpZ2ggYnl0ZSAqLwogICAgICAgIGNvcHlfb3BhcXVlID0gY29weV8zMjsKICAgICAgICBjb3B5X3RyYW5zbCA9IGNvcHlfMzI7CiAgICAgICAgbWF4X29wYXF1ZV9ydW4gPSAyNTU7ICAgLyogcnVucyBzdG9yZWQgYXMgc2hv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yogdHJhbnNsdWNlbnQgY291bnRzIGFyZSBhbHdheXMgMTYgYml0ICovCiNkZWZpbmUgQUREX1RSQU5TTF9DT1VOVFMobiwgbSkgICAgIFwKICAgICgoKFVpbnQxNiAqKWRzdClbMF0gPSBuLCAoKFVpbnQxNiAqKWRzdClbMV0gPSBtLCBkc3QgKz0gNCkKCiAgICAgICAgZm9yICh5ID0gMDsgeSA8IGg7IHkrKykgewogICAgICAgICAgICBpbnQgcnVuc3RhcnQsIHNraXBzdGFydDsKICAgICAgICAgICAgaW50IGJsYW5rbGluZSA9IDA7CiAgICAgICAgICAgIC8qIEZpcnN0IGVuY29kZSBhbGwgb3BhcXVlIHBpeGVscyBvZiBhIHNjYW4gbGluZSAqLwogICAgICAgICAgICB4ID0gMDsKICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgaW50IHJ1biwgc2tpcCwgbGVuOwogICAgICAgICAgICAgICAgc2tpcHN0YXJ0ID0geDsKICAgICAgICAgICAgICAgIHdoaWxlICh4IDwgdyAmJiAhSVNPUEFRVUUoc3JjW3hdLCBzZikpCiAgICAgICAgICAgICAgICAgICAgeCsrOwogICAgICAgICAgICAgICAgcnVuc3RhcnQgPSB4OwogICAgICAgICAgICAgICAgd2hpbGUgKHggPCB3ICYmIElTT1BBUVVFKHNyY1t4XSwgc2YpKQogICAgICAgICAgICAgICAgICAgIHgrKzsKICAgICAgICAgICAgICAgIHNraXAgPSBydW5zdGFydCAtIHNraXBzdGFydDsKICAgICAgICAgICAgICAgIGlmIChza2lwID09IHcpCiAgICAgICAgICAgICAgICAgICAgYmxhbmtsaW5lID0gMTsKICAgICAgICAgICAgICAgIHJ1biA9IHggLSBydW5zdGFydDsKICAgICAgICAgICAgICAgIHdoaWxlIChza2lwID4gbWF4X29wYXF1ZV9ydW4pIHsKICAgICAgICAgICAgICAgICAgICBBRERfT1BBUVVFX0NPVU5UUyhtYXhfb3BhcXVlX3J1biwgMCk7CiAgICAgICAgICAgICAgICAgICAgc2tpcCAtPSBtYXhfb3BhcXVlX3J1bjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGxlbiA9IE1JTihydW4sIG1heF9vcGFxdWVfcnVuKTsKICAgICAgICAgICAgICAgIEFERF9PUEFRVUVfQ09VTlRTKHNraXAsIGxlbik7CiAgICAgICAgICAgICAgICBkc3QgKz0gY29weV9vcGFxdWUoZHN0LCBzcmMgKyBydW5zdGFydCwgbGVuLCBzZiwgZGYpOwogICAgICAgICAgICAgICAgcnVuc3RhcnQgKz0gbGVuOwogICAgICAgICAgICAgICAgcnVuIC09IGxlbjsKICAgICAgICAgICAgICAgIHdoaWxlIChydW4pIHsKICAgICAgICAgICAgICAgICAgICBsZW4gPSBNSU4ocnVuLCBtYXhfb3BhcXVlX3J1bik7CiAgICAgICAgICAgICAgICAgICAgQUREX09QQVFVRV9DT1VOVFMoMCwgbGVuKTsKICAgICAgICAgICAgICAgICAgICBkc3QgKz0gY29weV9vcGFxdWUoZHN0LCBzcmMgKyBydW5zdGFydCwgbGVuLCBzZiwgZGYpOwogICAgICAgICAgICAgICAgICAgIHJ1bnN0YXJ0ICs9IGxlbjsKICAgICAgICAgICAgICAgICAgICBydW4gLT0gbGVuOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IHdoaWxlICh4IDwgdyk7CgogICAgICAgICAgICAvKiBNYWtlIHN1cmUgdGhlIG5leHQgb3V0cHV0IGFkZHJlc3MgaXMgMzItYml0IGFsaWduZWQgKi8KICAgICAgICAgICAgZHN0ICs9ICh1aW50cHRyX3QpIGRzdCAmIDI7CgogICAgICAgICAgICAvKiBOZXh0LCBlbmNvZGUgYWxsIHRyYW5zbHVjZW50IHBpeGVscyBvZiB0aGUgc2FtZSBzY2FuIGxpbmUgKi8KICAgICAgICAgICAgeCA9IDA7CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgIGludCBydW4sIHNraXAsIGxlbjsKICAgICAgICAgICAgICAgIHNraXBzdGFydCA9IHg7CiAgICAgICAgICAgICAgICB3aGlsZSAoeCA8IHcgJiYgIUlTVFJBTlNMKHNyY1t4XSwgc2YpKQogICAgICAgICAgICAgICAgICAgIHgrKzsKICAgICAgICAgICAgICAgIHJ1bnN0YXJ0ID0geDsKICAgICAgICAgICAgICAgIHdoaWxlICh4IDwgdyAmJiBJU1RSQU5TTChzcmNbeF0sIHNmKSkKICAgICAgICAgICAgICAgICAgICB4Kys7CiAgICAgICAgICAgICAgICBza2lwID0gcnVuc3RhcnQgLSBza2lwc3RhcnQ7CiAgICAgICAgICAgICAgICBibGFua2xpbmUgJj0gKHNraXAgPT0gdyk7CiAgICAgICAgICAgICAgICBydW4gPSB4IC0gcnVuc3RhcnQ7CiAgICAgICAgICAgICAgICB3aGlsZSAoc2tpcCA+IG1heF90cmFuc2xfcnVuKSB7CiAgICAgICAgICAgICAgICAgICAgQUREX1RSQU5TTF9DT1VOVFMobWF4X3RyYW5zbF9ydW4sIDApOwogICAgICAgICAgICAgICAgICAgIHNraXAgLT0gbWF4X3RyYW5zbF9ydW47CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBsZW4gPSBNSU4ocnVuLCBtYXhfdHJhbnNsX3J1bik7CiAgICAgICAgICAgICAgICBBRERfVFJBTlNMX0NPVU5UUyhza2lwLCBsZW4pOwogICAgICAgICAgICAgICAgZHN0ICs9IGNvcHlfdHJhbnNsKGRzdCwgc3JjICsgcnVuc3RhcnQsIGxlbiwgc2YsIGRmKTsKICAgICAgICAgICAgICAgIHJ1bnN0YXJ0ICs9IGxlbjsKICAgICAgICAgICAgICAgIHJ1biAtPSBsZW47CiAgICAgICAgICAgICAgICB3aGlsZSAocnVuKSB7CiAgICAgICAgICAgICAgICAgICAgbGVuID0gTUlOKHJ1biwgbWF4X3RyYW5zbF9ydW4pOwogICAgICAgICAgICAgICAgICAgIEFERF9UUkFOU0xfQ09VTlRTKDAsIGxlbik7CiAgICAgICAgICAgICAgICAgICAgZHN0ICs9IGNvcHlfdHJhbnNsKGRzdCwgc3JjICsgcnVuc3RhcnQsIGxlbiwgc2YsIGRmKTsKICAgICAgICAgICAgICAgICAgICBydW5zdGFydCArPSBsZW47CiAgICAgICAgICAgICAgICAgICAgcnVuIC09IGxlbjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmICghYmxhbmtsaW5lKQogICAgICAgICAgICAgICAgICAgIGxhc3RsaW5lID0gZHN0OwogICAgICAgICAgICB9IHdoaWxlICh4IDwgdyk7CgogICAgICAgICAgICBzcmMgKz0gc3VyZmFjZS0+cGl0Y2ggPj4gMjsKICAgICAgICB9CiAgICAgICAgZHN0ID0gbGFzdGxpbmU7ICAgICAgICAgLyogYmFjayB1cCBwYXN0IHRyYWlsaW5nIGJsYW5rIGxpbmVzICovCiAgICAgICAgQUREX09QQVFVRV9DT1VOVFMoMCwgMCk7CiAgICB9CgojdW5kZWYgQUREX09QQVFVRV9DT1VOVFMKI3VuZGVmIEFERF9UUkFOU0xfQ09VTlRTCgogICAgLyogTm93IHRoYXQgd2UgaGF2ZSBpdCBlbmNvZGVkLCByZWxlYXNlIHRoZSBvcmlnaW5hbCBwaXhlbHMgKi8KICAgIGlmICghKHN1cmZhY2UtPmZsYWdzICYgU0RMX1BSRUFMTE9DKSkgewogICAgICAgIFNETF9mcmVlKHN1cmZhY2UtPnBpeGVscyk7CiAgICAgICAgc3VyZmFjZS0+cGl4ZWxzID0gTlVMTDsKICAgIH0KCiAgICAvKiByZWFsbG9jIHRoZSBidWZmZXIgdG8gcmVsZWFzZSB1bnVzZWQgbWVtb3J5ICovCiAgICB7CiAgICAgICAgVWludDggKnAgPSBTRExfcmVhbGxvYyhybGVidWYsIGRzdCAtIHJsZWJ1Zik7CiAgICAgICAgaWYgKCFwKQogICAgICAgICAgICBwID0gcmxlYnVmOwogICAgICAgIHN1cmZhY2UtPm1hcC0+ZGF0YSA9IHA7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0KCnN0YXRpYyBVaW50MzIKZ2V0cGl4XzgoVWludDgg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gdGhlIHdvcnN0IGNhc2Ugc2l6ZSBmb3IgdGhlIGNvbXByZXNzZWQgc3VyZmFjZSAqLwogICAgc3dpdGNoIChicHApIHsKICAgIGNhc2UgMToKICAgICAgICAvKiB3b3JzdCBjYXNlIGlzIGFsdGVybmF0aW5nIG9wYXF1ZSBhbmQgdHJhbnNwYXJlbnQgcGl4ZWxzLAogICAgICAgICAgIHN0YXJ0aW5nIHdpdGggYW4gb3BhcXVlIHBpeGVsICovCiAgICAgICAgbWF4c2l6ZSA9IHN1cmZhY2UtPmggKiAzICogKHN1cmZhY2UtPncgLyAyICsgMSkgKyAyOwogICAgICAgIGJyZWFrOwogICAgY2FzZSAyOgogICAgY2FzZSAzOgogICAgICAgIC8qIHdvcnN0IGNhc2UgaXMgc29saWQgcnVucywgYXQgbW9zdCAyNTUgcGl4ZWxzIHdpZGUgKi8KICAgICAgICBtYXhzaXplID0gc3VyZmFjZS0+aCAqICgyICogKHN1cmZhY2UtPncgLyAyNTUgKyAxKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICsgc3VyZmFjZS0+dyAqIGJwcCkgKyAyOwogICAgICAgIGJyZWFrOwogICAgY2FzZSA0OgogICAgICAgIC8qIHdvcnN0IGNhc2UgaXMgc29saWQgcnVucywgYXQgbW9zdCA2NTUzNSBwaXhlbHMgd2lkZSAqLwogICAgICAgIG1heHNpemUgPSBzdXJmYWNlLT5oICogKDQgKiAoc3VyZmFjZS0+dyAvIDY1NTM1ICsgMSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICArIHN1cmZhY2UtPncgKiA0KSArIDQ7CiAgICAgICAgYnJlYWs7CgogICAgZGVmYXVsdDoKICAgICAgICByZXR1cm4gLTE7CiAgICB9CgogICAgcmxlYnVmID0gKFVpbnQ4ICopIFNETF9tYWxsb2MobWF4c2l6ZSk7CiAgICBpZiAocmxlYnVmID09IE5VTEwpIHsKICAgICAgICByZXR1cm4gU0RMX091dE9mTWVtb3J5KCk7CiAgICB9CgogICAgLyogU2V0IHVwIHRoZSBjb252ZXJzaW9uICovCiAgICBzcmNidWYgPSAoVWludDggKikgc3VyZmFjZS0+cGl4ZWxzOwogICAgbWF4biA9IGJwcCA9PSA0ID8gNjU1MzUgOiAyNTU7CiAgICBkc3QgPSBybGVidWY7CiAgICByZ2JtYXNrID0gfnN1cmZhY2UtPmZvcm1hdC0+QW1hc2s7CiAgICBja2V5ID0gc3VyZmFjZS0+bWFwLT5pbmZvLmNvbG9ya2V5ICYgcmdibWFzazsKICAgIGxhc3RsaW5lID0gZHN0OwogICAgZ2V0cGl4ID0gZ2V0cGl4ZXNbYnBwIC0gMV07CiAgICB3ID0gc3VyZmFjZS0+dzsKICAgIGggPSBzdXJmYWNlLT5oOwoKI2RlZmluZSBBRERfQ09VTlRTKG4sIG0pICAgICAgICAgICAgXAogICAgaWYoYnBwID09IDQpIHsgICAgICAgICAgICAgIFwKICAgICAgICAoKFVpbnQxNiAqKWRzdClbMF0gPSBuOyAgICAgXAogICAgICAgICgoVWludDE2ICopZHN0KVsxXSA9IG07ICAgICBcCiAgICAgICAgZHN0ICs9IDQ7ICAgICAgICAgICAgICAgXAogICAgfSBlbHNlIHsgICAgICAgICAgICAgICAgXAogICAgICAgIGRzdFswXSA9IG47ICAgICAgICAgICAgIFwKICAgICAgICBkc3RbMV0gPSBtOyAgICAgICAgICAgICBcCiAgICAgICAgZHN0ICs9IDI7ICAgICAgICAgICAgICAgXAogICAgfQoKICAgIGZvciAoeSA9IDA7IHkgPCBoOyB5KyspIHsKICAgICAgICBpbnQgeCA9IDA7CiAgICAgICAgaW50IGJsYW5rbGluZSA9IDA7CiAgICAgICAgZG8gewogICAgICAgICAgICBpbnQgcnVuLCBza2lwLCBsZW47CiAgICAgICAgICAgIGludCBydW5zdGFydDsKICAgICAgICAgICAgaW50IHNraXBzdGFydCA9IHg7CgogICAgICAgICAgICAvKiBmaW5kIHJ1biBvZiB0cmFuc3BhcmVudCwgdGhlbiBvcGFxdWUgcGl4ZWxzICovCiAgICAgICAgICAgIHdoaWxlICh4IDwgdyAmJiAoZ2V0cGl4KHNyY2J1ZiArIHggKiBicHApICYgcmdibWFzaykgPT0gY2tleSkKICAgICAgICAgICAgICAgIHgrKzsKICAgICAgICAgICAgcnVuc3RhcnQgPSB4OwogICAgICAgICAgICB3aGlsZSAoeCA8IHcgJiYgKGdldHBpeChzcmNidWYgKyB4ICogYnBwKSAmIHJnYm1hc2spICE9IGNrZXkpCiAgICAgICAgICAgICAgICB4Kys7CiAgICAgICAgICAgIHNraXAgPSBydW5zdGFydCAtIHNraXBzdGFydDsKICAgICAgICAgICAgaWYgKHNraXAgPT0gdykKICAgICAgICAgICAgICAgIGJsYW5rbGluZSA9IDE7CiAgICAgICAgICAgIHJ1biA9IHggLSBydW5zdGFydDsKCiAgICAgICAgICAgIC8qIGVuY29kZSBzZWdtZW50ICovCiAgICAgICAgICAgIHdoaWxlIChza2lwID4gbWF4bikgewogICAgICAgICAgICAgICAgQUREX0NPVU5UUyhtYXhuLCAwKTsKICAgICAgICAgICAgICAgIHNraXAgLT0gbWF4bjsKICAgICAgICAgICAgfQogICAgICAgICAgICBsZW4gPSBNSU4ocnVuLCBtYXhuKTsKICAgICAgICAgICAgQUREX0NPVU5UUyhza2lwLCBsZW4pOwogICAgICAgICAgICBTRExfbWVtY3B5KGRzdCwgc3JjYnVmICsgcnVuc3RhcnQgKiBicHAsIGxlbiAqIGJwcCk7CiAgICAgICAgICAgIGRzdCArPSBsZW4gKiBicHA7CiAgICAgICAgICAgIHJ1biAtPSBsZW47CiAgICAgICAgICAgIHJ1bnN0YXJ0ICs9IGxlbjsKICAgICAgICAgICAgd2hpbGUgKHJ1bikgewogICAgICAgICAgICAgICAgbGVuID0gTUlOKHJ1biwgbWF4bik7CiAgICAgICAgICAgICAgICBBRERfQ09VTlRTKDAsIGxlbik7CiAgICAgICAgICAgICAgICBTRExfbWVtY3B5KGRzdCwgc3JjYnVmICsgcnVuc3RhcnQgKiBicHAsIGxlbiAqIGJwcCk7CiAgICAgICAgICAgICAgICBkc3QgKz0gbGVuICogYnBwOwogICAgICAgICAgICAgICAgcnVuc3RhcnQgKz0gbGVuOwogICAgICAgICAgICAgICAgcnVuIC09IGxlbjsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoIWJsYW5rbGluZSkKICAgICAgICAgICAgICAgIGxhc3RsaW5lID0gZHN0OwogICAgICAgIH0gd2hpbGUgKHggPCB3KTsKCiAgICAgICAgc3JjYnVmICs9IHN1cmZhY2UtPnBpdGNoOwogICAgfQogICAgZHN0ID0gbGFzdGxpbmU7ICAgICAgICAgICAgIC8qIGJhY2sgdXAgYmFzdCB0cmFpbGluZyBibGFuayBsaW5lcyAqLwogICAgQUREX0NPVU5UUygwLCAwKTsKCiN1bmRlZiBBRERfQ09VTlRTCgogICAgLyogTm93IHRoYXQgd2UgaGF2ZSBpdCBlbmNvZGVkLCByZWxlYXNlIHRoZSBvcmlnaW5hbCBwaXhlbHMgKi8KICAgIGlmICghKHN1cmZhY2UtPmZsYWdzICYgU0RMX1BSRUFMTE9DKSkgewogICAgICAgIFNETF9mcmVlKHN1cmZhY2UtPnBpeGVscyk7CiAgICAgICAgc3VyZmFjZS0+cGl4ZWxzID0gTlVMTDsKICAgIH0KCiAgICAvKiByZWFsbG9jIHRoZSBidWZmZXIgdG8gcmVsZWFzZSB1bnVzZWQgbWVtb3J5ICovCiAgICB7CiAgICAgICAgLyogSWYgcmVhbGxvYyByZXR1cm5zIE5VTEwsIHRoZSBvcmlnaW5hbCBibG9jayBpcyBsZWZ0IGludGFjdCAqLwogICAgICAgIFVpbnQ4ICpwID0gU0RMX3JlYWxsb2MocmxlYnVmLCBkc3QgLSBybGVidWYpOwogICAgICAgIGlmICghcCkKICAgICAgICAgICAgcCA9IHJsZWJ1ZjsKICAgICAgICBzdXJmYWNlLT5tYXAtPmRhdGEgPSBwOwogICAgfQoKICAgIHJldHVybiAwOwp9CgppbnQKU0RMX1JMRVN1cmZhY2UoU0RMX1N1cmZhY2U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KSB7CiAgICAgICAgcmV0dXJuIChTRExfRkFMU0UpOwogICAgfQogICAgLyogZmlsbCBiYWNrZ3JvdW5kIHdpdGggdHJhbnNwYXJlbnQgcGl4ZWxzICovCiAgICBTRExfbWVtc2V0KHN1cmZhY2UtPnBpeGVscywgMCwgc3VyZmFjZS0+aCAqIHN1cmZhY2UtPnBpdGNoKTsKCiAgICBkc3QgPSBzdXJmYWNlLT5waXhlbHM7CiAgICBzcmNidWYgPSAoVWludDggKikgKGRmICsgMSk7CiAgICBmb3IgKDs7KSB7CiAgICAgICAgLyogY29weSBvcGFxdWUgcGl4ZWxzICovCiAgICAgICAgaW50IG9mcyA9IDA7CiAgICAgICAgZG8gewogICAgICAgICAgICB1bnNpZ25lZCBydW47CiAgICAgICAgICAgIGlmIChicHAgPT0gMikgewogICAgICAgICAgICAgICAgb2ZzICs9IHNyY2J1ZlswXTsKICAgICAgICAgICAgICAgIHJ1biA9IHNyY2J1ZlsxXTsKICAgICAgICAgICAgICAgIHNyY2J1ZiArPSAyOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgb2ZzICs9ICgoVWludDE2ICopIHNyY2J1ZilbMF07CiAgICAgICAgICAgICAgICBydW4gPSAoKFVpbnQxNiAqKSBzcmNidWYpWzFdOwogICAgICAgICAgICAgICAgc3JjYnVmICs9IDQ7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHJ1bikgewogICAgICAgICAgICAgICAgc3JjYnVmICs9IHVuY29weV9vcGFxdWUoZHN0ICsgb2ZzLCBzcmNidWYsIHJ1biwgZGYsIHNmKTsKICAgICAgICAgICAgICAgIG9mcyArPSBydW47CiAgICAgICAgICAgIH0gZWxzZSBpZiAoIW9mcykKICAgICAgICAgICAgICAgIHJldHVybiAoU0RMX1RSVUUpOwogICAgICAgIH0gd2hpbGUgKG9mcyA8IHcpOwoKICAgICAgICAvKiBza2lwIHBhZGRpbmcgaWYgbmVlZGVkICovCiAgICAgICAgaWYgKGJwcCA9PSAyKQogICAgICAgICAgICBzcmNidWYgKz0gKHVpbnRwdHJfdCkgc3JjYnVmICYgMjsKCiAgICAgICAgLyogY29weSB0cmFuc2x1Y2VudCBwaXhlbHMgKi8KICAgICAgICBvZnMgPSAwOwogICAgICAgIGRvIHsKICAgICAgICAgICAgdW5zaWduZWQgcnVuOwogICAgICAgICAgICBvZnMgKz0gKChVaW50MTYgKikgc3JjYnVmKVswXTsKICAgICAgICAgICAgcnVuID0gKChVaW50MTYgKikgc3JjYnVmKVsxXTsKICAgICAgICAgICAgc3JjYnVmICs9IDQ7CiAgICAgICAgICAgIGlmIChydW4pIHsKICAgICAgICAgICAgICAgIHNyY2J1ZiArPSB1bmNvcHlfdHJhbnNsKGRzdCArIG9mcywgc3JjYnVmLCBydW4sIGRmLCBzZik7CiAgICAgICAgICAgICAgICBvZnMgKz0gcnVuOwogICAgICAgICAgICB9CiAgICAgICAgfSB3aGlsZSAob2ZzIDwgdyk7CiAgICAgICAgZHN0ICs9IHN1cmZhY2UtPnBpdGNoID4+IDI7CiAgICB9CiAgICAvKiBNYWtlIHRoZSBjb21waWxlciBoYXBweSAqLwogICAgcmV0dXJuIChTRExfVFJVRSk7Cn0KCnZvaWQKU0RMX1VuUkxFU3VyZmFjZShTRExfU3VyZmFjZSAqIHN1cmZhY2UsIGludCByZWNvZGUpCnsKICAgIGlmIChzdXJmYWNlLT5mbGFncyAmIFNETF9STEVBQ0NFTCkgewogICAgICAgIHN1cmZhY2UtPmZsYWdzICY9IH5TRExfUkxFQUNDRUw7CgogICAgICAgIGlmIChyZWNvZGUgJiYgIShzdXJmYWNlLT5mbGFncyAmIFNETF9QUkVBTExPQykpIHsKICAgICAgICAgICAgaWYgKHN1cmZhY2UtPm1hcC0+aW5mby5mbGFncyAmIFNETF9DT1BZX1JMRV9DT0xPUktFWSkgewogICAgICAgICAgICAgICAgU0RMX1JlY3QgZnVsbDsKCiAgICAgICAgICAgICAgICAvKiByZS1jcmVhdGUgdGhlIG9yaWdpbmFsIHN1cmZhY2UgKi8KICAgICAgICAgICAgICAgIHN1cmZhY2UtPnBpeGVscyA9IFNETF9tYWxsb2Moc3VyZmFjZS0+aCAqIHN1cmZhY2UtPnBpdGNoKTsKICAgICAgICAgICAgICAgIGlmICghc3VyZmFjZS0+cGl4ZWxzKSB7CiAgICAgICAgICAgICAgICAgICAgLyogT2ggY3JhcC4uLiAqLwogICAgICAgICAgICAgICAgICAgIHN1cmZhY2UtPmZsYWdzIHw9IFNETF9STEVBQ0NFTDsKICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgLyogZmlsbCBpdCB3aXRoIHRoZSBiYWNrZ3JvdW5kIGNvbG9yICovCiAgICAgICAgICAgICAgICBTRExfRmlsbFJlY3Qoc3VyZmFjZSwgTlVMTCwgc3VyZmFjZS0+bWFwLT5pbmZvLmNvbG9ya2V5KTsKCiAgICAgICAgICAgICAgICAvKiBub3cgcmVuZGVyIHRoZSBlbmNvZGVkIHN1cmZhY2UgKi8KICAgICAgICAgICAgICAgIGZ1bGwueCA9IGZ1bGwueSA9IDA7CiAgICAgICAgICAgICAgICBmdWxsLncgPSBzdXJmYWNlLT53OwogICAgICAgICAgICAgICAgZnVsbC5oID0gc3VyZmFjZS0+aDsKICAgICAgICAgICAgICAgIFNETF9STEVCbGl0KHN1cmZhY2UsICZmdWxsLCBzdXJmYWNlLCAmZnVsbCk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBpZiAoIVVuUkxFQWxwaGEoc3VyZmFjZSkpIHsKICAgICAgICAgICAgICAgICAgICAvKiBPaCBjcmFwLi4uICovCiAgICAgICAgICAgICAgICAgICAgc3VyZmFjZS0+ZmxhZ3MgfD0gU0RMX1JMRUFDQ0VMOwogICAgICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzdXJmYWNlLT5tYXAtPmluZm8uZmxhZ3MgJj0KICAgICAgICAgICAgfihTRExfQ09QWV9STEVfQ09MT1JLRVkgfCBTRExfQ09QWV9STEVfQUxQSEFLRVkpOwoKICAgICAgICBTRExfZnJlZShzdXJmYWNlLT5tYXAtPmRhdGEpOwogICAgICAgIHN1cmZhY2UtPm1hcC0+ZGF0YSA9IE5VTEw7CiAgICB9Cn0KCi8qIHZpOiBzZXQgdHM9NCBzdz00IGV4cGFuZHRhYjogKi8K