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IHNmYk9mZnNldCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICBTSE9SVCAqUkVTVFJJQ1QgcXVhbnRTcGVjdHJ1bSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICBVSU5UICpSRVNUUklDVCBtYXhWYWx1ZSk7CgpzdGF0aWMgdm9pZCBGREthYWNFbmNfY3Jhc2hSZWNvdmVyeShJTlQgICAgICAgICAgICAgICBuQ2hhbm5lbHMsCiAgICAgICAgICAgICAgICAgICAgICAgICAgUFNZX09VVF9FTEVNRU5UKiAgcHN5T3V0RWxlbWVudCwKICAgICAgICAgICAgICAgICAgICAgICAgICBRQ19PVVQqICAgICAgICAgICBxY091dCwKICAgICAgICAgICAgICAgICAgICAgICAgICBRQ19PVVRfRUxFTUVOVCAgICpxY0VsZW1lbnQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgSU5UICAgICAgICAgICAgICAgYml0c1RvU2F2ZSwKICAgICAgICAgICAgICAgICAgICAgICAgICBBVURJT19PQkpFQ1RfVFlQRSBhb3QsCiAgICAgICAgICAgICAgICAgICAgICAgICAgVUlOVCAgICAgICAgICAgICAgc3ludGF4RmxhZ3MsCiAgICAgICAgICAgICAgICAgICAgICAgICAgU0NIQVIgICAgICAgICAgICAgZXBDb25maWcpOwoKc3RhdGljCkFBQ19FTkNPREVSX0VSUk9SIEZES2FhY0VuY19yZWR1Y2VCaXRDb25zdW1wdGlvbihpbnQqICAgICAgICAgICAgIGl0ZXJhdGlvbnMsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IGludCAgICAgICAgbWF4SXRlcmF0aW9ucywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaW50ICAgICAgICAgICAgICBnYWluQWRqdXN0bWVudCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaW50KiAgICAgICAgICAgICBjaENvbnN0cmFpbnRzRnVsZmlsbGVkLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpbnQqICAgICAgICAgICAgIGNhbGN1bGF0ZVF1YW50LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpbnQgICAgICAgICAgICAgIG5DaGFubmVscywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgUFNZX09VVF9FTEVNRU5UKiBwc3lPdXRFbGVtZW50LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBRQ19PVVQqICAgICAgICAgIHFjT3V0LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBRQ19PVVRfRUxFTUVOVCogIHFjT3V0RWxlbWVudCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgRUxFTUVOVF9CSVRTKiAgICBlbEJpdHMsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIEFVRElPX09CSkVDVF9UWVBFICBhb3QsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFVJTlQgICAgICAgICAgICAgc3ludGF4RmxhZ3MsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFNDSEFSICAgICAgICAgICAgZXBDb25maWcpOwoKCnZvaWQgIEZES2FhY0VuY19RQ0Nsb3NlIChRQ19TVEFURSAgKipwaFFDc3RhdGUsIFFDX09VVCAqKnBoUUMpOwoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCgogICAgZnVuY3Rpb25uYW1lOiBGREthYWNFbmNfY2FsY0ZyYW1lTGVuCiAgICBkZXNjcmlwdGlvbjoKICAgIHJldHVybnM6CiAgICBpbnB1dDoKICAgIG91dHB1dDoKCioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwpzdGF0aWMgSU5UIEZES2FhY0VuY19jYWxjRnJhbWVMZW4oSU5UIGJpdFJhdGUsCiAgICAgICAgICAgICAgICAgICAgICAgIElOVCBzYW1wbGVSYXRlLAogICAgICAgICAgICAgICAgICAgICAgICBJTlQgZ3JhbnVsZUxlbmd0aCwKICAgICAgICAgICAgICAgICAgICAgICAgRlJBTUVfTEVOX1JFU1VMVF9NT0RFIG1vZGUpCnsKCiAgIElOVCByZXN1bHQ7CgogICByZXN1bHQgPSAoKGdyYW51bGVMZW5ndGgpPj4zKSooYml0UmF0ZSk7CgogICBzd2l0Y2gobW9kZSkgewogICAgIGNhc2UgRlJBTUVfTEVOX0JZVEVTX01PRFVMTzoKICAgICAgICAgcmVzdWx0ICU9IHNhbXBsZVJhdGU7CiAgICAgYnJlYWs7CiAgICAgY2FzZSBGUkFNRV9MRU5fQllURVNfSU5UOgogICAgICAgICByZXN1bHQgLz0gc2FtcGxlUmF0ZTsKICAgICBicmVhazsKICAgfQogICByZXR1cm4ocmVzdWx0KTsKfQoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCgogICAgZnVuY3Rpb25uYW1lOkZES2FhY0VuY19mcmFtZVBhZGRpbmcKICAgIGRlc2NyaXB0aW9uOiBDYWxjdWxhdGVzIGlmIHBhZGRpbmcgaXMgbmVlZGVkIGZvciBhY3R1YWwgZnJhbWUKICAgIHJldHVybnM6CiAgICBpbnB1dDoKICAgIG91dHB1dDoKCioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwpzdGF0aWMgSU5UIEZES2FhY0VuY19mcmFtZVBhZGRpbmcoSU5UIGJpdFJhdGUsCiAgICAgICAgICAgICAgICAgICAgICAgIElOVCBzYW1wbGVSYXRlLAogICAgICAgICAgICAgICAgICAgICAgICBJTlQgZ3JhbnVsZUxlbmd0aCwKICAgICAgICAgICAgICAgICAgICAgICAgSU5UICpwYWRkaW5nUmVzdCkKewogIElOVCBwYWRkaW5nT247CiAgSU5UIGRpZmZlcmVuY2U7CgogIHBhZGRpbmdPbiA9IDA7CgogIGRpZmZlcmVuY2UgPSBGREthYWNFbmNfY2FsY0ZyYW1lTGVuKCBiaXRSYXRlLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNhbXBsZVJhdGUsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZ3JhbnVsZUxlbmd0aCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICBGUkFNRV9MRU5fQllURVNfTU9EVUxPICk7CiAgKnBhZGRpbmdSZXN0LT1kaWZmZXJlbmNlOwoKICBpZiAoKnBhZGRpbmdSZXN0IDw9IDAgKSB7CiAgICBwYWRkaW5nT24gPSAxOwogICAgKnBhZGRpbmdSZXN0ICs9IHNhbXBsZVJhdGU7CiAgfQoKICByZXR1cm4oIHBhZGRpbmdPbiApOwp9CgoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgoKICAgICAgICAgZnVuY3Rpb25uYW1lOiBGREthYWNFbmNfUUNPdXROZXcKICAgICAgICAgZGVzY3JpcHRpb246CiAgICAgICAgIHJldHVybjoKCioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCkFBQ19FTkNPREVSX0VSUk9SIEZES2FhY0VuY19RQ091dE5ldyhRQ19PVVQgICAgKipwaFFDLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3QgSU5UICAgbkVsZW1lbnRzLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3QgSU5UICAgbkNoYW5uZWxzLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3QgSU5UICAgblN1YkZyYW1lcwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAsVUNIQVIgICAgICAqZHluYW1pY19SQU0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKQp7CiAgQUFDX0VOQ09ERVJfRVJST1IgRXJyb3JTdGF0dXM7CiAgaW50IG4sIGk7CiAgaW50IGVsSW5jID0gMCwgY2hJbmMgPSAwOwoKICBmb3IgKG49MDsgbjxuU3ViRnJhbWVzOyBuKyspIHsKICAgIHBoUUNbbl0gPSBHZXRSYW1fYWFjRW5jX1FDb3V0KG4pOwogICAgaWYgKHBoUUNbbl0gPT0gTlVMTCkgewogICAgICBFcnJvclN0YXR1cyA9IEFBQ19FTkNfTk9fTUVNT1JZOwogICAgICBnb3RvIFFDT3V0TmV3X2JhaWw7CiAgICB9CgogICAgZm9yIChpPTA7IGk8bkNoYW5uZWxzOyBpKyspIHsKICAgICAgcGhRQ1tuXS0+cFFjT3V0Q2hhbm5lbHNbaV0gPSBHZXRSYW1fYWFjRW5jX1FDY2hhbm5lbChjaEluYywgZHluYW1pY19SQU0pOwogICAgICBpZiAoIHBoUUNbbl0tPnBRY091dENoYW5uZWxzW2ldID09IE5VTEwKICAgICAgICAgKQogICAgICB7CiAgICAgICAgIEVycm9yU3RhdHVzID0gQUFDX0VOQ19OT19NRU1PUlk7CiAgICAgICAgIGdvdG8gUUNPdXROZXdfYmFpbDsKICAgICAgfQogICAgICBjaEluYysrOwogICAgfSAvKiBuQ2hhbm5lbHMgKi8KCiAgICBmb3IgKGk9MDsgaTxuRWxlbWVudHM7IGkrKykgewogICAgICBwaFFDW25dLT5xY0VsZW1lbnRbaV0gICAgICA9IEdldFJhbV9hYWNFbmNfUUNlbGVtZW50KGVsSW5jKTsKICAgICAgaWYgKHBoUUNbbl0tPnFjRWxlbWVudFtpXSA9PSBOVUxMKQogICAgICB7CiAgICAgICAgRXJyb3JTdGF0dXMgPSBBQUNfRU5DX05PX01FTU9SWTsKICAgICAgICBnb3RvIFFDT3V0TmV3X2JhaWw7CiAgICAgIH0KICAgICAgZWxJbmMrKzsKICAgIH0gLyogbkVsZW1lbnRzICovCgogIH0gLyogblN1YkZyYW1lcyAqLwoKCiAgcmV0dXJuIEFBQ19FTkNfT0s7CgpRQ091dE5ld19iYWlsOgogIHJldHVybiBFcnJvclN0YXR1czsKfQoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgoKICAgICAgICAgZnVuY3Rpb25uYW1lOiBGREthYWNFbmNfUUNPdXRJbml0CiAgICAgICAgIGRlc2NyaXB0aW9uOgogICAgICAgICByZXR1cm46CgoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwpBQUNfRU5DT0RFUl9FUlJPUiBGREthYWNFbmNfUUNPdXRJbml0KFFDX09VVCAgICAgICAgICAqcGhRQ1soMSldLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IElOVCAgICAgICAgblN1YkZyYW1lcywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBDSEFOTkVMX01BUFBJTkcgKmNtKQp7CiAgSU5UIG4saSxjaDsKCiAgZm9yIChuPTA7IG48blN1YkZyYW1lczsgbisrKSB7CiAgICBJTlQgY2hJbmMgPSAwOwogICAgZm9yIChpPTA7IGk8Y20tPm5FbGVtZW50czsgaSsrKSB7CiAgICAgIGZvciAoY2g9MDsgY2g8Y20tPmVsSW5mb1tpXS5uQ2hhbm5lbHNJbkVsOyBjaCsrKSB7CiAgICAgICAgcGhRQ1tuXS0+cWNFbGVtZW50W2ldLT5xY091dENoYW5uZWxbY2hdID0gcGhRQ1tuXS0+cFFjT3V0Q2hhbm5lbHNbY2hJbmNdOwogICAgICAgIGNoSW5jKys7CiAgICAgIH0gLyogY2hJbkVsICovCiAgICB9IC8qIG5FbGVtZW50cyAqLwogIH0gLyogblN1YkZyYW1lcyAqLwoKICByZXR1cm4gQUFDX0VOQ19PSzsKfQoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgoKICAgICAgICAgZnVuY3Rpb25uYW1lOiBGREthYWNFbmNfUUNOZXcKICAgICAgICAgZGVzY3JpcHRpb246CiAgICAgICAgIHJldHVybjoKCioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCkFBQ19FTkNPREVSX0VSUk9SIEZES2FhY0VuY19RQ05ldyhRQ19TVEFURSAgKipwaFFDLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgSU5UICAgICAgICAgbkVsZW1lbnRzCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICxVQ0hBUiogICAgICBkeW5hbWljX1JBTQogICAgICAgICAgICkKewogIEFBQ19FTkNPREVSX0VSUk9SIEVycm9yU3RhdHVzOwogIGludCBpOwoKICBRQ19TVEFURSogaFFDID0gR2V0UmFtX2FhY0VuY19RQ3N0YXRlKCk7CiAgKnBoUUMgPSBoUUM7CiAgaWYgKGhRQyA9PSBOVUxMKSB7CiAgICBFcnJvclN0YXR1cyA9IEFBQ19FTkNfTk9fTUVNT1JZOwogICAgZ290byBRQ05ld19iYWlsOwogIH0KCiAgaWYgKEZES2FhY0VuY19BZGpUaHJOZXcoJmhRQy0+aEFkalRociwgbkVsZW1lbnRzKSkgewogICAgRXJyb3JTdGF0dXMgPSBBQUNfRU5DX05PX01FTU9SWTsKICAgIGdvdG8gUUNOZXdfYmFpbDsKICB9CgogIGlmIChGREthYWNFbmNfQkNOZXcoJihoUUMtPmhCaXRDb3VudGVyKSwgZHluYW1pY19SQU0pKSB7CiAgICBFcnJvclN0YXR1cyA9IEFBQ19FTkNfTk9fTUVNT1JZOwogICAgZ290byBRQ05ld19iYWlsOwogIH0KCiAgZm9yIChpPTA7IGk8bkVsZW1lbnRzOyBpKyspIHsKICAgIGhRQy0+ZWxlbWVudEJpdHNbaV0gPSBHZXRSYW1fYWFjRW5jX0VsZW1lbnRCaXRzKGkpOwogICAgaWYgKGhRQy0+ZWxlbWVudEJpdHNbaV0gPT0gTlVMTCkgewogICAgICBFcnJvclN0YXR1cyA9IEFBQ19FTkNfTk9fTUVNT1JZOwogICAgICBnb3RvIFFDTmV3X2JhaWw7CiAgICB9CiAgfQoKICByZXR1cm4gQUFDX0VOQ19PSzsKClFDTmV3X2JhaWw6CiAgRkRLYWFjRW5jX1FDQ2xvc2UocGhRQywgTlVMTCk7CiAgcmV0dXJuIEVycm9yU3RhdHVzOwp9CgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCgogICAgICAgICBmdW5jdGlvbm5hbWU6IEZES2FhY0VuY19RQ0luaXQKICAgICAgICAgZGVzY3JpcHRpb246CiAgICAgICAgIHJldHVybjoKCioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCkFBQ19FTkNPREVSX0VSUk9SIEZES2FhY0VuY19RQ0luaXQoUUNfU1RBVEUgKmhRQywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdHJ1Y3QgUUNfSU5JVCAqaW5pdCkKewogIGhRQy0+bWF4Qml0c1BlckZyYW1lID0gaW5pdC0+bWF4Qml0czsKICBoUUMtPm1pbkJpdHNQZXJGcmFtZSA9IGluaXQtPm1pbkJpdHM7CiAgaFFDLT5uRWxlbWVudHMgICAgICAgPSBpbml0LT5jaGFubmVsTWFwcGluZy0+bkVsZW1lbnRzOwogIGhRQy0+Yml0UmVzVG90TWF4ICAgID0gaW5pdC0+Yml0UmVzOwogIGhRQy0+Yml0UmVz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IEZMMkZYQ09OU1RfREJMKDAuZik7CiAgICAgIGJyZWFrOwogIH0KCiAgRkRLYWFjRW5jX0FkalRockluaXQoaFFDLT5oQWRqVGhyLAogICAgICAgICAgICAgaW5pdC0+bWVhblBlLAogICAgICAgICAgICAgaFFDLT5lbGVtZW50Qml0cywgICAgICAgICAgICAgICAgIC8qIG9yIGNoYW5uZWxCaXRyYXRlcywgd2FzOiBjaGFubmVsQml0cmF0ZSAqLwogICAgICAgICAgICAgaW5pdC0+Y2hhbm5lbE1hcHBpbmctPm5FbGVtZW50cywKICAgICAgICAgICAgIGhRQy0+dmJyUXVhbEZhY3Rvcik7CgogIHJldHVybiBBQUNfRU5DX09LOwp9CgoKCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKCiAgICAgICAgIGZ1bmN0aW9ubmFtZTogRkRLYWFjRW5jX1FDTWFpblByZXBhcmUKICAgICAgICAgZGVzY3JpcHRpb246CiAgICAgICAgIHJldHVybjoKCioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCkFBQ19FTkNPREVSX0VSUk9SIEZES2FhY0VuY19RQ01haW5QcmVwYXJlKEVMRU1FTlRfSU5GTyAgICAgICAgICAgICAgKmVsSW5mbywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgQVRTX0VMRU1FTlQqIFJFU1RSSUNUICAgICAgYWRqVGhyU3RhdGVFbGVtZW50LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBQU1lfT1VUX0VMRU1FTlQqIFJFU1RSSUNUICBwc3lPdXRFbGVtZW50LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBRQ19PVVRfRUxFTUVOVCogUkVTVFJJQ1QgICBxY091dEVsZW1lbnQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIEFVRElPX09CSkVDVF9UWVBFICAgICAgICAgIGFvdCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgVUlOVCAgICAgICAgICAgICAgICAgICAgICAgc3ludGF4RmxhZ3MsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFNDSEFSICAgICAgICAgICAgICAgICAgICAgIGVwQ29uZmlnCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKQp7CiAgQUFDX0VOQ09ERVJfRVJST1IgRXJyb3JTdGF0dXMgPSBBQUNfRU5DX09LOwogIElOVCAgbkNoYW5uZWxzID0gZWxJbmZvLT5uQ2hhbm5lbHNJbkVsOwoKICBQU1lfT1VUX0NIQU5ORUwqKiBSRVNUUklDVCBwc3lPdXRDaGFubmVsID0gcHN5T3V0RWxlbWVudC0+cHN5T3V0Q2hhbm5lbDsgICAgLyogbWF5IGJlIG1vZGlmaWVkIGluLXBsYWNlICovCgogIEZES2FhY0VuY19DYWxjRm9ybUZhY3RvcihxY091dEVsZW1lbnQtPnFjT3V0Q2hhbm5lbCwgcHN5T3V0Q2hhbm5lbCwgbkNoYW5uZWxzKTsKCiAgLyogcHJlcGFyZSBhbmQgY2FsY3VsYXRlIFBFIHdpdGhvdXQgcmVkdWN0aW9uICovCiAgRkRLYWFjRW5jX3BlQ2FsY3VsYXRpb24oJnFjT3V0RWxlbWVudC0+cGVEYXRhLCBwc3lPdXRDaGFubmVsLCBxY091dEVsZW1lbnQtPnFjT3V0Q2hhbm5lbCwgJnBzeU91dEVsZW1lbnQtPnRvb2xzSW5mbywgYWRqVGhyU3RhdGVFbGVtZW50LCBuQ2hhbm5lbHMpOwoKICBFcnJvclN0YXR1cyA9IEZES2FhY0VuY19DaGFubmVsRWxlbWVudFdyaXRlKCBOVUxMLCBlbEluZm8sIE5VTEwsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcHN5T3V0RWxlbWVudCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwc3lPdXRFbGVtZW50LT5wc3lPdXRDaGFubmVsLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN5bnRheEZsYWdzLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGFvdCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBlcENvbmZpZywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICZxY091dEVsZW1lbnQtPnN0YXRpY0JpdHNVc2VkLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDAgKTsKCiAgcmV0dXJuIEVycm9yU3RhdHVzOwp9CgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCgogICAgICAgICBmdW5jdGlvbm5hbWU6IEZES2FhY0VuY19BZGp1c3RCaXRyYXRlCiAgICAgICAgIGRlc2NyaXB0aW9uOiAgYWRqdXN0cyBmcmFtZWxlbmd0aCB2aWEgcGFkZGluZyBvbiBhIGZyYW1lIHRvIGZyYW1lIGJhc2lzLAogICAgICAgICAgICAgICAgICAgICAgIHRvIGFjaGlldmUgYSBiaXRyYXRlIHRoYXQgZGVtYW5kcyBhIG5vbiBieXRlIGFsaWduZWQKICAgICAgICAgICAgICAgICAgICAgICBmcmFtZWxlbmd0aAogICAgICAgICByZXR1cm46ICAgICAgIGVycm9yY29kZQoKKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KQUFDX0VOQ09ERVJfRVJST1IgRkRLYWFjRW5jX0FkanVzdEJpdHJhdGUoUUNfU1RBVEUgICAgICAgICpSRVNUUklDVCBoUUMsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIENIQU5ORUxfTUFQUElORyAqUkVTVFJJQ1QgY20sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIElOVCAgICAgICAgICAgICAqYXZnVG90YWxCaXRzLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBJTlQgICAgICAgICAgICAgIGJpdFJhdGUsICAgICAgIC8qIHRvdGFsIGJpdHJhdGUgKi8KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgSU5UICAgICAgICAgICAgICBzYW1wbGVSYXRlLCAgICAvKiBvdXRwdXQgc2FtcGxpbmcgcmF0ZSAqLwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBJTlQgICAgICAgICAgICAgIGdyYW51bGVMZW5ndGgpIC8qIGZyYW1lIGxlbmd0aCAqLwp7CiAgSU5UIHBhZGRpbmdPbjsKICBJTlQgZnJhbWVMZW47CgogIC8qIERvIHdlIG5lZWQgYW4gZXh0cmEgcGFkZGluZyBieXRlPyAqLwogIHBhZGRpbmdPbiA9IEZES2FhY0VuY19mcmFtZVBhZGRpbmcoYml0UmF0ZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgc2FtcGxlUmF0ZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgZ3JhbnVsZUxlbmd0aCwKICAgICAgICAgICAgICAgICAgICAgICAgICAmaFFDLT5wYWRkaW5nLnBhZGRpbmdSZXN0KTsKCiAgZnJhbWVMZW4gPSBwYWRkaW5nT24gKyBGREthYWNFbmNfY2FsY0ZyYW1lTGVuKGJpdFJhdGUsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2FtcGxlUmF0ZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBncmFudWxlTGVuZ3RoLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIEZSQU1FX0xFTl9CWVRFU19JTlQpOwoKICAqYXZnVG90YWxCaXRzID0gZnJhbWVMZW48PDM7CgogIHJldHVybiBBQUNfRU5DX09LOwp9CgpzdGF0aWMgQUFDX0VOQ09ERVJfRVJST1IgRkRLYWFjRW5jX2Rpc3RyaWJ1dGVFbGVtZW50RHluQml0cyhRQ19TVEFURSogICAgICAgICBoUUMsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgUUNfT1VUX0VMRU1FTlQqICAgcWNFbGVtZW50Wyg2KV0sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgQ0hBTk5FTF9NQVBQSU5HKiAgY20sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgSU5UICAgICAgICAgICAgICAgY29kZUJpdHMpCnsKCiAgSU5UIGksIGZpcnN0RWwgPSBjbS0+bkVsZW1lbnRzLTE7CiAgSU5UIHRvdGFsQml0cyA9IDA7CgogIGZvciAoaT0oY20tPm5FbGVtZW50cy0xKTsgaT49MDsgaS0tKSB7CiAgICBpZiAoKGNtLT5lbEluZm9baV0uZWxUeXBlID09IElEX1NDRSkgfHwgKGNtLT5lbEluZm9baV0uZWxUeXBlID09IElEX0NQRSkgfHwKICAgICAgICAoY20tPmVsSW5mb1tpXS5lbFR5cGUgPT0gSURfTEZFKSkKICAgIHsKICAgICAgcWNFbGVtZW50W2ldLT5ncmFudGVkRHluQml0cyA9ICAoSU5UKWZNdWx0KGhRQy0+ZWxlbWVudEJpdHNbaV0tPnJlbGF0aXZlQml0c0VsLCAoRklYUF9EQkwpY29kZUJpdHMpOwogICAgICB0b3RhbEJpdHMgKz0gcWNFbGVtZW50W2ldLT5ncmFudGVkRHluQml0czsKICAgICAgZmlyc3RFbCA9IGk7CiAgICB9CiAgfQogIHFjRWxlbWVudFtmaXJzdEVsXS0+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WR1Y3Rpb24gLAogICAgICAgICAgICAgICAgICAgICAgIHRvIHplcm8gc3BlY3RydW0gYW5kIGRlYWN0aXZhdGluZyB0bnMgYW5kIE1TCiAgICAgICAgIHJldHVybjogICAgICAgbnVtYmVyIG9mIHN0YXRpYyBiaXRzCgoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwpzdGF0aWMgaW50IEZES2FhY0VuY19nZXRNaW5pbWFsU3RhdGljQml0ZGVtYW5kKENIQU5ORUxfTUFQUElORyogICAgIGNtLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFBTWV9PVVQqKiAgICAgICAgICAgIHBzeU91dCkKewogIEFVRElPX09CSkVDVF9UWVBFIGFvdCA9IEFPVF9BQUNfTEM7CiAgVUlOVCAgc3ludGF4RmxhZ3MgPSAwOwogIFNDSEFSIGVwQ29uZmlnID0gLTE7CiAgaW50IGksIGJpdGNvdW50ID0gMDsKCiAgZm9yIChpPTA7IGk8Y20tPm5FbGVtZW50czsgaSsrKSB7CiAgICAgIEVMRU1FTlRfSU5GTyBlbEluZm8gPSBjbS0+ZWxJbmZvW2ldOwoKICAgICAgaWYgKCAoZWxJbmZvLmVsVHlwZSA9PSBJRF9TQ0UpCiAgICAgICAgfHwgKGVsSW5mby5lbFR5cGUgPT0gSURfQ1BFKQogICAgICAgIHx8IChlbEluZm8uZWxUeXBlID09IElEX0xGRSkgKQogICAgICB7CiAgICAgICAgSU5UIG1pbkVsQml0cyA9IDA7CgogICAgICAgIEZES2FhY0VuY19DaGFubmVsRWxlbWVudFdyaXRlKCBOVUxMLCAmZWxJbmZvLCBOVUxMLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwc3lPdXRbMF0tPnBzeU91dEVsZW1lbnRbaV0sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBzeU91dFswXS0+cHN5T3V0RWxlbWVudFtpXS0+cHN5T3V0Q2hhbm5lbCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3ludGF4RmxhZ3MsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGFvdCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZXBDb25maWcsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJm1pbkVsQml0cywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgMSApOwogICAgICAgIGJpdGNvdW50ICs9IG1pbkVsQml0czsKICAgICAgfQogIH0KCiAgcmV0dXJuIGJpdGNvdW50Owp9CgovLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLwoKc3RhdGljIEFBQ19FTkNPREVSX0VSUk9SIEZES2FhY0VuY19wcmVwYXJlQml0RGlzdHJpYnV0aW9uKFFDX1NUQVRFKiAgICAgICAgICAgIGhRQywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgUFNZX09VVCoqICAgICAgICAgICAgcHN5T3V0LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBRQ19PVVQqKiAgICAgICAgICAgICBxY091dCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgQ0hBTk5FTF9NQVBQSU5HKiAgICAgY20sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFFDX09VVF9FTEVNRU5UKiAgICAgIHFjRWxlbWVudFsoMSldWyg2KV0sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIElOVCAgICAgICAgICAgICAgICAgIGF2Z1RvdGFsQml0cywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgSU5UICAgICAgICAgICAgICAgICAqdG90YWxBdmFpbGFibGVCaXRzLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBJTlQgICAgICAgICAgICAgICAgICphdmdUb3RhbER5bkJpdHMpCnsKICAgIGludCBpOwogICAgICAvKiBnZXQgbWF4aW1hbCBhbGxvd2VkIGR5bmFtaWMgYml0cyAqLwogICAgICBxY091dFswXS0+Z3JhbnRlZER5bkJpdHMgPSAgKGZpeE1pbihoUUMtPm1heEJpdHNQZXJGcmFtZSwgYXZnVG90YWxCaXRzKSAtIGhRQy0+Z2xvYkhkckJpdHMpJn43OwogICAgICBxY091dFswXS0+Z3JhbnRlZER5bkJpdHMgLT0gKHFjT3V0WzBdLT5nbG9iYWxFeHRCaXRzICsgcWNPdXRbMF0tPnN0YXRpY0JpdHMgKyBxY091dFswXS0+ZWxlbWVudEV4dEJpdHMpOwogICAgICBxY091dFswXS0+bWF4RHluQml0cyA9ICgoaFFDLT5tYXhCaXRzUGVyRnJhbWUpJn43KSAtIChxY091dFswXS0+Z2xvYmFsRXh0Qml0cyArIHFjT3V0WzBdLT5zdGF0aWNCaXRzICsgcWNPdXRbMF0tPmVsZW1lbnRFeHRCaXRzKTsKICAgICAgLyogYXNzdXJlIHRoYXQgZW5vdWdoIGJpdHMgYXJlIGF2YWlsYWJsZSAqLwogICAgICBpZiAoKHFjT3V0WzBdLT5ncmFudGVkRHluQml0cytoUUMtPmJpdFJlc1RvdCkgPCAwKSB7CiAgICAgICAgLyogY3Jhc2ggcmVjb3ZlcnkgYWxsb3dzIHRvIHJlZHVjZSBzdGF0aWMgYml0cyB0byBhIG1pbmltdW0gKi8KICAgICAgICBpZiAoIChxY091dFswXS0+Z3JhbnRlZER5bkJpdHMraFFDLT5iaXRSZXNUb3QpIDwgKEZES2FhY0VuY19nZXRNaW5pbWFsU3RhdGljQml0ZGVtYW5kKGNtLCBwc3lPdXQpLXFjT3V0WzBdLT5zdGF0aWNCaXRzKSApCiAgICAgICAgICByZXR1cm4gQUFDX0VOQ19CSVRSRVNfVE9PX0xPVzsKICAgICAgfQoKICAgICAgLyogZGlzdHJpYnV0ZSBkeW5hbWljIGJpdHMgdG8gZWFjaCBlbGVtZW50ICovCiAgICAgIEZES2FhY0VuY19kaXN0cmlidXRlRWxlbWVudER5bkJpdHMoaFFDLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcWNFbGVtZW50WzBdLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY20sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBxY091dFswXS0+Z3JhbnRlZER5bkJpdHMpOwoKICAgICAgKmF2Z1RvdGFsRHluQml0cyA9IDA7IC8qZnJhbWVEeW5CaXRzOyovCgogICAgKnRvdGFsQXZhaWxhYmxlQml0cyA9IGF2Z1RvdGFsQml0czsKCiAgICAvKiBzdW0gdXAgY29ycmVjdGVkIGdyYW50ZWQgUEUgKi8KICAgIHFjT3V0WzBdLT50b3RhbEdyYW50ZWRQZUNvcnIgPSAwOwoKICAgIGZvciAoaT0wOyBpPGNtLT5uRWxlbWVudHM7IGkrKykKICAgIHsKICAgICAgICBFTEVNRU5UX0lORk8gZWxJbmZvID0gY20tPmVsSW5mb1tpXTsKICAgICAgICBpbnQgbkNoYW5uZWxzID0gZWxJbmZvLm5DaGFubmVsc0luRWw7CgogICAgICAgIGlmICgoZWxJbmZvLmVsVHlwZSA9PSBJRF9TQ0UpIHx8IChlbEluZm8uZWxUeXBlID09IElEX0NQRSkgfHwKICAgICAgICAgICAgKGVsSW5mby5lbFR5cGUgPT0gSURfTEZFKSkKICAgICAgICB7CiAgICAgICAgICAgICAgICAvKiBmb3IgKCBhbGwgc3ViIGZyYW1lcyApIC4uLiAqLwogICAgICAgICAgICAgICAgRkRLYWFjRW5jX0Rpc3RyaWJ1dGVCaXRzKGhRQy0+aEFkalRociwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBoUUMtPmhBZGpUaHItPmFkalRoclN0YXRlRWxlbVtpXSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwc3lPdXRbMF0tPnBzeU91dEVsZW1lbnRbaV0tPnBzeU91dENoYW5uZWwsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAmcWNFbGVtZW50WzBdW2ldLT5wZURhdGEsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAmcWNFbGVtZW50WzBdW2ldLT5ncmFudGVkUGUsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAmcWNFbGVtZW50WzBdW2ldLT5ncmFudGVkUGVDb3JyLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG5DaGFubmVscywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwc3lPdXRbMF0tPnBzeU91dEVsZW1lbnRbaV0tPmNvbW1vbldpbmRvdywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBxY0VsZW1lbnRbMF1baV0tPmdyYW50ZWREeW5CaXRzLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGhRQy0+ZWxlbWVudEJpdHNbaV0tPmJpdFJlc0xldmVsRWwsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaFFDLT5lbGVtZW50Qml0c1tpXS0+bWF4Qml0UmVzQml0c0VsLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGhRQy0+bWF4Qml0RmFjLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGhRQy0+Yml0RGlzdHJpYnV0ZW5Nb2RlKTsKCiAgICAgICAgICAgICAgIC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EVNRU5UX0lORk8gZWxJbmZvID0gY20tPmVsSW5mb1tpXTsKCiAgICAgIGlmICgoZWxJbmZvLmVsVHlwZSA9PSBJRF9TQ0UpIHx8IChlbEluZm8uZWxUeXBlID09IElEX0NQRSkgfHwKICAgICAgICAgIChlbEluZm8uZWxUeXBlID09IElEX0xGRSkpCiAgICAgIHsKICAgICAgICAgIC8qIHN1bSB1cCBiaXRzIGNvbnN1bWVkICovCiAgICAgICAgICAqc3VtRHluQml0c0NvbnN1bWVkICArPSBxY0VsZW1lbnRbaV0tPmR5bkJpdHNVc2VkOwogICAgICB9ICAvKiAgLWVuZC0gaWYoSURfU0NFIHx8IElEX0NQRSB8fCBJRF9MRkUpICovCgogIH0gIC8qIC1lbmQtIGVsZW1lbnQgbG9vcCAqLwoKICByZXR1cm4gQUFDX0VOQ19PSzsKfQoKCnN0YXRpYyBJTlQgRkRLYWFjRW5jX2dldFRvdGFsQ29uc3VtZWREeW5CaXRzKFFDX09VVCoqIHFjT3V0LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIElOVCBuU3ViRnJhbWVzKQp7CiAgICBJTlQgYywgdG90YWxCaXRzPTA7CgogICAgLyogc3VtIHVwIGJpdCBjb25zdW1wdGlvbiBmb3IgYWxsIHN1YiBmcmFtZXMgKi8KICAgIGZvciAoYz0wOyBjPG5TdWJGcmFtZXM7IGMrKykKICAgIHsKICAgICAgICAvKiBiaXQgY29uc3VtcHRpb24gbm90IHZhbGlkIGlmIGR5bmFtaWMgYml0cwogICAgICAgICAgIG5vdCBhdmFpbGFibGUgaW4gb25lIHN1YiBmcmFtZSAqLwogICAgICAgIGlmIChxY091dFtjXS0+dXNlZER5bkJpdHM9PS0xKSByZXR1cm4gLTE7CiAgICAgICAgdG90YWxCaXRzICs9IHFjT3V0W2NdLT51c2VkRHluQml0czsKICAgIH0KCiAgICByZXR1cm4gdG90YWxCaXRzOwoKfQoKc3RhdGljIElOVCBGREthYWNFbmNfZ2V0VG90YWxDb25zdW1lZEJpdHMoUUNfT1VUKiogICAgICAgICAgcWNPdXQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgUUNfT1VUX0VMRU1FTlQqICAgcWNFbGVtZW50WygxKV1bKDYpXSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBDSEFOTkVMX01BUFBJTkcqICBjbSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBJTlQgICAgICAgICAgICAgICBnbG9iSGRyQml0cywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBJTlQgICAgICAgICAgICAgICBuU3ViRnJhbWVzKQp7CiAgICBpbnQgYywgaTsKICAgIGludCB0b3RhbFVzZWRCaXRzID0gMDsKCiAgICBmb3IgKGMgPSAwIDsgYyA8IG5TdWJGcmFtZXMgOyBjKysgKQogICAgewogICAgICAgIGludCBkYXRhQml0cyA9IDA7CiAgICAgICAgZm9yIChpPTA7IGk8Y20tPm5FbGVtZW50czsgaSsrKQogICAgICAgIHsKICAgICAgICAgICAgaWYgKChjbS0+ZWxJbmZvW2ldLmVsVHlwZSA9PSBJRF9TQ0UpIHx8IChjbS0+ZWxJbmZvW2ldLmVsVHlwZSA9PSBJRF9DUEUpIHx8CiAgICAgICAgICAgICAgICAoY20tPmVsSW5mb1tpXS5lbFR5cGUgPT0gSURfTEZFKSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgZGF0YUJpdHMgKz0gcWNFbGVtZW50W2NdW2ldLT5keW5CaXRzVXNlZCArIHFjRWxlbWVudFtjXVtpXS0+c3RhdGljQml0c1VzZWQgKyBxY0VsZW1lbnRbY11baV0tPmV4dEJpdHNVc2VkOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGRhdGFCaXRzICs9IHFjT3V0W2NdLT5nbG9iYWxFeHRCaXRzOwoKICAgICAgICB0b3RhbFVzZWRCaXRzICs9ICg4IC0gKGRhdGFCaXRzKSAlIDgpICUgODsKICAgICAgICB0b3RhbFVzZWRCaXRzICs9IG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AtIHRvdGFsQml0czsKICAgICAgaFFDLT5lbGVtZW50Qml0c1tmaXJzdEVsXS0+bWF4Qml0UmVzQml0c0VsICs9IHRvdGFsQml0cmVzZXJ2b2lyTWF4IC0gdG90YWxCaXRzX21heDsKICAgIH0KCiAgICByZXR1cm4gQUFDX0VOQ19PSzsKfQoKCkFBQ19FTkNPREVSX0VSUk9SIEZES2FhY0VuY19RQ01haW4oUUNfU1RBVEUqIFJFU1RSSUNUICAgICAgICAgaFFDLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFBTWV9PVVQqKiAgICAgICAgICAgICAgICAgIHBzeU91dCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBRQ19PVVQqKiAgICAgICAgICAgICAgICAgICBxY091dCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBJTlQgICAgICAgICAgICAgICAgICAgICAgICBhdmdUb3RhbEJpdHMsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgQ0hBTk5FTF9NQVBQSU5HKiAgICAgICAgICAgY20KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICxBVURJT19PQkpFQ1RfVFlQRSAgICAgICAgICBhb3QsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgVUlOVCAgICAgICAgICAgICAgICAgICAgICAgc3ludGF4RmxhZ3MsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgU0NIQVIgICAgICAgICAgICAgICAgICAgICAgZXBDb25maWcKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICkKewogIGludCBpLCBjOwogIEFBQ19FTkNPREVSX0VSUk9SIEVycm9yU3RhdHVzID0gQUFDX0VOQ19PSzsKICBJTlQgYXZnVG90YWxEeW5CaXRzID0gMDsgLyogbWF4aW1hbCBhbGxvd2QgZHluYW1pYyBiaXRzIGZvciBhbGwgZnJhbWVzICovCiAgSU5UIHRvdGFsQXZhaWxhYmxlQml0cyA9IDA7C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9MRkUpKQogICAgICAgICAgewogICAgICAgICAgICAgIC8qIGZvciAoIGFsbCBzdWIgZnJhbWVzICkgLi4uICovCiAgICAgICAgICAgICAgZm9yIChjID0gMCA7IGMgPCBuU3ViRnJhbWVzIDsgYysrICkKICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgIHFjRWxlbWVudFtjXVtpXSA9IHFjT3V0W2NdLT5xY0VsZW1lbnRbaV07CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgIH0KCiAgICAgIC8qLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0gKi8KICAgICAgLyotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSAqLwogICAgICBpZiAoIGlzQ29uc3RhbnRCaXRyYXRlTW9kZShoUUMtPmJpdHJhdGVNb2RlKSApCiAgICAgIHsKICAgICAgICAgIC8qIGNhbGMgZ3JhbnRlZCBkeW5hbWljIGJpdHMgZm9yIHN1YiBmcmFtZSBhbmQKICAgICAgICAgICAgIGRpc3RyaWJ1dGUgaXQgdG8gZWFjaCBlbGVtZW50ICovCiAgICAgICAgICBFcnJvclN0YXR1cyA9IEZES2FhY0VuY19wcmVwYXJlQml0RGlzdHJpYnV0aW9uKAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBoUUMsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBzeU91dCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcWNPdXQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNtLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBxY0VsZW1lbnQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGF2Z1RvdGFsQml0cywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAmdG90YWxBdmFpbGFibGVCaXRzLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICZhdmdUb3RhbER5bkJpdHMpOwoKICAgICAgICAgIGlmIChFcnJvclN0YXR1cyAhPSBBQUNfRU5DX09LKSB7CiAgICAgICAgICAgIHJldHVybiBFcnJvclN0YXR1czsKICAgICAgICAgIH0KICAgICAgfQogICAgICBlbHNlIHsKICAgICAgICAgIHFjT3V0WzBdLT5ncmFudGVkRHluQml0cyA9ICgoaFFDLT5tYXhCaXRzUGVyRnJhbWUgLSAoaFFDLT5nbG9iSGRyQml0cykpJn43KQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC0gKHFjT3V0WzBdLT5nbG9iYWxFeHRCaXRzICsgcWNPdXRbMF0tPnN0YXRpY0JpdHMgKyBxY091dFswXS0+ZWxlbWVudEV4dEJpdHMpOwogICAgICAgICAgcWNPdXRbMF0tPm1heER5bkJpdHMgICAgID0gcWNPdXRbMF0tPmdyYW50ZWREeW5CaXRzOwoKICAgICAgICAgIHRvdGFsQXZhaWxhYmxlQml0cyA9IGhRQy0+bWF4Qml0c1BlckZyYW1lOwogICAgICAgICAgYXZnVG90YWxEeW5CaXRzID0gMDsKICAgICAgfQoKI2lmZGVmIFBOU19QUkVDT1VOVF9FTkFCTEUKICAgICAgLyogQ2FsY3VsYXRlIGVzdGltYXRlZCBwbnMgYml0cyBhbmQgc3Vic3RyYWN0IHRoZW0gZnJvbSBncmFudGVkRHluQml0cyB0byBnZXQgYSBtb3JlIGFjY3VyYXRlIG51bWJlciBvZiBhdmFpbGFibGUgYml0cy4gKi8KICAgICAgaWYgKHN5bnRheEZsYWdzICYgKEFDX0xEfEFDX0VMRCkpCiAgICAgIHsKICAgICAgICBpbnQgZXN0aW1hdGVkUG5zQml0cyA9IDAsIGNoOwoKICAgICAgICBmb3IgKGNoPTA7IGNoPGNtLT5uQ2hhbm5lbHM7IGNoKyspIHsKICAgICAgICAgIHFjT3V0WzBdLT5wUWNPdXRDaGFubmVsc1tjaF0tPnNlY3Rpb25EYXRhLm5vaXNlTnJnQml0cyA9IG5vaXNlUHJlQ291bnQocHN5T3V0WzBdLT5wUHN5T3V0Q2hhbm5lbHNbY2hdLT5ub2lzZU5yZywgcHN5T3V0WzBdLT5wUHN5T3V0Q2hhbm5lbHNbY2hdLT5tYXhTZmJQZXJHcm91cCk7CiAgICAgICAgICBlc3RpbWF0ZWRQbnNCaXRzICs9IHFjT3V0WzBdLT5wUWNPdXRDaGFubmVsc1tjaF0tPnNlY3Rpb25EYXRhLm5vaXNlTnJnQml0czsKICAgICAgICB9CiAgICAgICAgcWNPdXRbMF0tPmdyYW50ZWREeW5CaXRzIC09IGVzdGltYXRlZFBuc0JpdHM7CiAgICAgIH0KI2VuZGlmCgogICAgICAvKiBmb3IgKCBhbGwgc3ViIGZyYW1lcyApIC4uLiAqLwogICAgICBmb3IgKGMgPSAwIDsgYyA8IG5TdWJGcmFtZXMgOyBjKysgKQogICAgICB7CiAgICAgICAgICAvKiBmb3IgQ0JSIGFuZCBWQlIgbW9kZSAqLwogICAgICAgICAgRkRLYWFjRW5jX0FkanVzdFRocmVzaG9sZHMoaFFDLT5oQWRqVGhyLT5hZGpUaHJTdGF0ZUVsZW0sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBxY0VsZW1lbnRbY10sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBxY091dFtjXSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBzeU91dFtjXS0+cHN5T3V0RWxlbWVudCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlzQ29uc3RhbnRCaXRyYXRlTW9kZShoUUMtPmJpdHJhdGVNb2RlKSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNtKTsKCiAgICAgIH0gLyogLWVuZC0gc3ViIGZyYW1lIGNvdW50ZXIgKi8KCiAgICAgIC8qLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0gKi8KICAgICAgSU5UIGl0ZXJhdGlvbnNbKDEpXVsoNildOwogICAgICBJTlQgY2hDb25zdHJhaW50c0Z1bGZpbGxlZFsoMSldWyg2KV1bKDIpXTsKICAgICAgSU5UIGNhbGN1bGF0ZVF1YW50WygxKV1bKDYpXVsoMildOwogICAgICBJTlQgY29uc3RyYWludHNGdWxmaWxsZWRbKDEpXVsoNildOwogICAgICAvKi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tICovCgoKICAgICAgLyogZm9yICggYWxsIHN1YiBmcmFtZXMgKSAuLi4gKi8KICAgICAgZm9yIChjID0gMCA7IGMgPCBuU3ViRnJhbWVzIDsgYysrICkKICAgICAgewogICAgICAgICAgZm9yIChpPTA7IGk8Y20tPm5FbGVtZW50czsgaSsrKQogICAgICAgICAgewogICAgICAgICAgICAgIEVMRU1FTlRfSU5GTyBlbEluZm8gPSBjbS0+ZWxJbmZvW2ldOwogICAgICAgICAgICAgIElOVCBjaCwgbkNoYW5uZWxzID0gZWxJbmZvLm5DaGFubmVsc0luRWw7CgogICAgICAgICAgICAgIGlmICgoZWxJbmZvLmVsVHlwZSA9PSBJRF9TQ0UpIHx8IChlbEluZm8uZWxUeXBlID09IElEX0NQRSkgfHwKICAgICAgICAgICAgICAgICAgKGVsSW5mby5lbFR5cGUgPT0gSURfTEZFKSkKICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAvKiBUdXJuIHRocmVzaG9sZHMgaW50byBzY2FsZWZhY3RvcnMsIG9wdGltaXplIGJpdCBjb25zdW1wdGlvbiBhbmQgdmVyaWZ5IGNvbmZvcm1hbmNlICovCiAgICAgICAgICAgICAgICAgICAgICBGREthYWNFbmNfRXN0aW1hdGVTY2FsZUZhY3RvcnMocHN5T3V0W2NdLT5wc3lPdXRFbGVtZW50W2ldLT5wc3lPdXRDaGFubmVsLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHFjRWxlbWVudFtjXVtpXS0+cWNPdXRDaGFubmVsLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGhRQy0+aW52UXVhbnQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY20tPmVsSW5mb1tpXS5uQ2hhbm5lbHNJbkVsKTsKCgogICAgICAgICAgICAgICAgICAgICAgLyotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSAqLwogICAgICAgICAgICAgICAgICAgICAgY29uc3RyYWludHNGdWxmaWxsZWRbY11baV0gPSAxOwogICAgICAgICAgICAgICAgICAgICAgaXRlcmF0aW9uc1tjXVtpXSA9IDAgOwoKICAgICAgICAgICAgICAgICAgICAgIGZvciAoY2ggPSAwOyBjaCA8IG5DaGFubmVsczsgY2grKykKICAgICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBjaENvbnN0cmFpbnRzRnVsZmlsbGVkW2NdW2ldW2NoXSA9IDE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgY2FsY3VsYXRlUXVhbnRbY11baV1bY2hdID0gMTsKICAgICAgICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICAgICAgICAvKi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tICovCgogICAgICAgICAgICAgIH0gIC8qICAtZW5kLSBpZihJRF9TQ0UgfHwgSURfQ1BFIHx8IElEX0xGRSkgKi8KCiAgICAgICAgICB9ICAvKiAtZW5kLSBlbGVtZW50IGxvb3AgKi8KCiAgICAgICAgICBxY091dFtjXS0+dXNlZER5bkJpdHMgPSAtMTsKCiAgICAgIH0gLyogLWVuZC0gc3ViIGZyYW1lIGNvdW50ZXIgKi8KCgoKICAgICAgSU5UIHF1YW50aXphdGlvbkRvbmUgPSAwOwogICAgICBJTlQgc3VtRHluQml0c0NvbnN1bWVkVG90YWwgID0gMDsKICAgICAgSU5UIGRlY3JlYXNlQml0Q29uc3VtcHRpb24gPSAtMTsgLyogbm8gZGlyZWN0aW9uIHlldCEgKi8KCiAgICAgIC8qLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0gKi8KICAgICAgLyogLXN0YXJ0LSBRdWFudGl6YXRpb24gbG9vcCAuLi4gICAgICAgICAgICAgICAqLwogICAgICAvKi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tICovCiAgICAgIGRvIC8qIHVudGlsIG1heCBhbGxvd2VkIGJpdHMgcGVyIGZyYW1lIGFuZCBtYXhEeW5CaXRzIT0tMSovCiAgICAgIHsKICAgICAgICAgIHF1YW50aXphdGlvbkRvbmUgPSAwOwoKICAgICAgICAgICAgICBjID0gMDsgICAgICAgICAgICAgIC8qIGdldCBmcmFtZSB0byBwcm9jZXNzICovCgogICAgICAgICAgICAgIGZvciAoaT0wOyBpPGNtLT5uRWxlbWVudHM7IGkrKykKICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgIEVMRU1FTlRfSU5GTyBlbEluZm8gPSBjbS0+ZWxJbmZvW2ldOwogICAgICAgICAgICAgICAgICBJTlQgY2gsIG5DaGFubmVscyA9IGVsSW5mby5uQ2hhbm5lbHNJbkVsOwoKICAgICAgICAgICAgICAgICAgaWYgKChlbEluZm8uZWxUeXBlID09IElEX1NDRSkgfHwgKGVsSW5mby5lbFR5cGUgPT0gSURfQ1BFKSB8fAogICAgICAgICAgICAgICAgICAgICAgKGVsSW5mby5lbFR5cGUgPT0gSURfTEZFKSkKICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgZG8gLyogdW50aWwgc3BlY3RyYWwgdmFsdWVzIDwgTUFYX1FVQU5UICovCiAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgLyotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSAqLwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmICghY29uc3RyYWludHNGdWxmaWxsZWRbY11baV0pCiAgICAgICAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBGREthYWNFbmNfcmVkdWNlQml0Q29uc3VtcHRpb24oJml0ZXJhdGlvbnNbY11baV0sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBoUUMtPm1heEl0ZXJhdGlvbnMsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAoZGVjcmVhc2VCaXRDb25zdW1wdGlvbikgPyAxIDogLTEsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjaENvbnN0cmFpbnRzRnVsZmlsbGVkW2NdW2ldLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY2FsY3VsYXRlUXVhbnRbY11baV0sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBuQ2hhbm5lbHMsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwc3lPdXRbY10tPnBzeU91dEVsZW1lbnRbaV0sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBxY091dFtjXSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHFjRWxlbWVudFtjXVtpXSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGhRQy0+ZWxlbWVudEJpdHNbaV0sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBhb3QsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzeW50YXhGbGFncywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVwQ29uZmlnKTsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgICAgICAgICAgIC8qLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0gKi8KICAgICAgICAgICAgICAgICAgICAgICAgICAvKi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tICovCiAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3RyYWludHNGdWxmaWxsZWRbY11baV0gPSAxIDsKCiAgICAgICAgICAgICAgICAgICAgICAgICAgLyotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSAqLwogICAgICAgICAgICAgICAgICAgICAgICAgIC8qIHF1YW50aXplIHNwZWN0cnVtIChwZXIgZWFjaCBjaGFubmVsKSAqLwogICAgICAgICAgICAgICAgICAgICAgICAgIGZvciAoY2ggPSAwOyBjaCA8IG5DaGFubmVsczsgY2grKykKICAgICAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8qLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0gKi8KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY2hDb25zdHJhaW50c0Z1bGZpbGxlZFtjXVtpXVtjaF0gPSAxOwoKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLyotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSAqLwoKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGNhbGN1bGF0ZVF1YW50W2NdW2ldW2NoXSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgUUNfT1VUX0NIQU5ORUwqIHFjT3V0Q2ggPSBxY0VsZW1lbnRbY11baV0tPnFjT3V0Q2hhbm5lbFtjaF07CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBQU1lfT1VUX0NIQU5ORUwqIHBzeU91dENoID0gcHN5T3V0W2NdLT5wc3lPdXRFbGVtZW50W2ldLT5wc3lPdXRDaGFubmVsW2NoXTsKCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjYWxjdWxhdGVRdWFudFtjXVtpXVtjaF0gPSAwOyAvKiBjYWxjdWxhdGUgcXVhbnRpemF0aW9uIG9ubHkgaWYgbmVjZXNzYXJ5ICovCgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLyotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSAqLwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgRkRLYWFjRW5jX1F1YW50aXplU3BlY3RydW0ocHN5T3V0Q2gtPnNmYkNudCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBzeU91dENoLT5tYXhTZmJQZXJHcm91cCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBzeU91dENoLT5zZmJQZXJHcm91cCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBzeU91dENoLT5zZmJPZmZzZXRzLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcWNPdXRDaC0+bWRjdFNwZWN0cnVtLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcWNPdXRDaC0+Z2xvYmFsR2FpbiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHFjT3V0Q2gtPnNjZiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHFjT3V0Q2gtPnF1YW50U3BlYykgOwoKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8qLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0gKi8KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChGREthYWNFbmNfY2FsY01heFZhbHVlSW5TZmIocHN5T3V0Q2gtPnNmYkNudCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwc3lPdXRDaC0+bWF4U2ZiUGVyR3JvdXAsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcHN5T3V0Q2gtPnNmYlBlckdyb3VwLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBzeU91dENoLT5zZmJPZmZzZXRzLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHFjT3V0Q2gtPnF1YW50U3BlYywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBxY091dENoLT5tYXhWYWx1ZUluU2ZiKSA+IE1BWF9RVUFOVCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY2hDb25zdHJhaW50c0Z1bGZpbGxlZFtjXVtpXVtjaF0gPSAwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zdHJhaW50c0Z1bGZpbGxlZFtjXVtpXSA9IDAgOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvKiBpZiBxdWFuaXp0ZWQgdmFsdWUgb3V0IG9mIHJhbmdlOyBpbmNyZWFzZSBnbG9iYWwgZ2FpbiEgKi8KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZGVjcmVhc2VCaXRDb25zdW1wdGlvbiA9IDE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLyotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSAqLwoKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSAvKiBpZiBjYWxjdWxhdGVRdWFudFtjXVtpXVtjaF0gKi8KCiAgICAgICAgICAgICAgICAgICAgICAgICAgfSAvKiBjaGFubmVsIGxvb3AgKi8KCiAgICAgICAgICAgICAgICAgICAgICAgICAgLyotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSAqLwogICAgICAgICAgICAgICAgICAgICAgICAgIC8qIHF1YW50aXplIHNwZWN0cnVtIChwZXIgZWFjaCBjaGFubmVsKSAqLwoKICAgICAgICAgICAgICAgICAgICAgICAgICAvKi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tICovCgogICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoIWNvbnN0cmFpbnRzRnVsZmlsbGVkW2NdW2ldKSA7IC8qIGRvZXMgbm90IHJlZ2FyZCBiaXQgY29uc3VtcHRpb24gKi8KCgogICAgICAgICAgICAgICAgICAgICAgLyotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSAqLwogICAgICAgICAgICAgICAgICAgICAgLyotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSAqLwogICAgICAgICAgICAgICAgICAgICAgcWNFbGVtZW50W2NdW2ldLT5keW5CaXRzVXNlZCA9IDAgOyAvKiByZXNldCBkeW5hbWljIGJpdHMgKi8KCiAgICAgICAgICAgICAgICAgICAgICAvKiBxdWFudGl6YXRpb24gdmFsaWQgaW4gY3VycmVudCBjaGFubmVsISAqLwogICAgICAgICAgICAgICAgICAgICAgZm9yIChjaCA9IDA7IGNoIDwgbkNoYW5uZWxzOyBjaCsrKQogICAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAgIFFDX09VVF9DSEFOTkVMKiBxY091dENoID0gcWNFbGVtZW50W2NdW2ldLT5xY091dENoYW5uZWxbY2hdOwogICAgICAgICAgICAgICAgICAgICAgICAgIFBTWV9PVVRfQ0hBTk5FTCAqcHN5T3V0Q2ggPSBwc3lPdXRbY10tPnBzeU91dEVsZW1lbnRbaV0tPnBzeU91dENoYW5uZWxbY2hdOwoKICAgICAgICAgICAgICAgICAgICAgICAgICAvKiBjb3VudCBkeW5hbWljIGJpdHMgKi8KICAgICAgICAgICAgICAgICAgICAgICAgICBJTlQgY2hEeW5CaXRzID0gRkRLYWFjRW5jX2R5bkJpdENvdW50KGhRQy0+aEJpdENvdW50ZXIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBxY091dENoLT5xdWFudFNwZWMsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBxY091dENoLT5tYXhWYWx1ZUluU2ZiLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcWNPdXRDaC0+c2NmLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcHN5T3V0Q2gtPmxhc3RXaW5kb3dTZXF1ZW5jZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBzeU91dENoLT5zZmJDbnQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwc3lPdXRDaC0+bWF4U2ZiUGVyR3JvdXAsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwc3lPdXRDaC0+c2ZiUGVyR3JvdXAsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwc3lPdXRDaC0+c2ZiT2Zmc2V0cywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICZxY091dENoLT5zZWN0aW9uRGF0YSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBzeU91dENoLT5ub2lzZU5yZywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBzeU91dENoLT5pc0Jvb2ssCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwc3lPdXRDaC0+aXNTY2FsZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN5bnRheEZsYWdzKSA7CgogICAgICAgICAgICAgICAgICAgICAgICAgIC8qIHN1bSB1cCBkeW5hbWljIGNoYW5uZWwgYml0cyAqLwogICAgICAgICAgICAgICAgICAgICAgICAgIHFjRWxlbWVudFtjXVtpXS0+ZHluQml0c1VzZWQgKz0gY2hEeW5CaXRzOwogICAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICAgIC8qIHNhdmUgZHluQml0c1VzZWQgZm9yIGNvcnJlY3Rpb24gb2YgYml0czJwZSByZWxhdGlvbiAqLwogICAgICAgICAgICAgICAgICAgICAgaWYoaFFDLT5oQWRqVGhyLT5hZGpUaHJTdGF0ZUVsZW1baV0tPmR5bkJpdHNMYXN0PT0tMSkgewogICAgICAgICAgICAgICAgICAgICAgICAgIGhRQy0+aEFkalRoci0+YWRqVGhyU3RhdGVFbGVtW2ldLT5keW5CaXRzTGFzdCA9IHFjRWxlbWVudFtjXVtpXS0+ZHluQml0c1VzZWQ7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gIC8qICAtZW5kLSBpZihJRF9TQ0UgfHwgSURfQ1BFIHx8IElEX0xGRSkgKi8KCiAgICAgICAgICAgICAgfSAgLyogLWVuZC0gZWxlbWVudCBsb29wICovCgogICAgICAgICAgICAgIC8qIHVwZGF0ZSBkeW5CaXRzIG9mIGN1cnJlbnQgc3ViRnJhbWUgKi8KICAgICAgICAgICAgICBGREthYWNFbmNfdXBkYXRlVXNlZER5bkJpdHMoJnFjT3V0W2NdLT51c2VkRHluQml0cywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcWNFbGVtZW50W2NdLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjbSk7CgogICAgICAgICAgICAgIC8qIGdldCB0b3RhbCBjb25zdW1lZCBiaXRzLCBkeW4gYml0cyBpbiBhbGwgc3ViIGZyYW1lcyBoYXZlIHRvIGJlIHZhbGlkICovCiAgICAgICAgICAgICAgc3VtRHluQml0c0NvbnN1bWVkVG90YWwgPSBGREthYWNFbmNfZ2V0VG90YWxDb25zdW1lZER5bkJpdHMocWNPdXQsIG5TdWJGcmFtZXMpOwoKICAgICAgICAgICAgICBpZiAoc3VtRHluQml0c0NvbnN1bWVkVG90YWw9PS0xKQogICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgcXVhbnRpemF0aW9uRG9uZSA9IDA7IC8qIGJpdCBjb25zdW1wdGlvbiBub3QgdmFsaWQgaW4gYWxsIHN1YiBmcmFtZXMgKi8KICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGludCBzdW1CaXRzQ29uc3VtZWRUb3RhbCA9IEZES2FhY0VuY19nZXRUb3RhbENvbnN1bWVkQml0cyhxY091dCwgcWNFbGVtZW50LCBjbSwgaFFDLT5nbG9iSGRyQml0cywgblN1YkZyYW1lcyk7CgogICAgICAgICAgICAgICAgLyogaW4gYWxsIGZyYW1lcyBhcmUgdmFsaWQgZHluYW1pYyBiaXRzICovCiAgICAgICAgICAgICAgICBpZiAoc3VtQml0c0NvbnN1bWVkVG90YWwgPCB0b3RhbEF2YWlsYWJsZUJpdHMgJiYgKGRlY3JlYXNlQml0Q29uc3VtcHRpb249PTEpICYmIGNoZWNrTWluRnJhbWVCaXRzRGVtYW5kKHFjT3V0LGhRQy0+bWluQml0c1BlckZyYW1lLG5TdWJGcmFtZXMpCiAgICAgICAgICAgICAgICAgICAgICAvKigpKi8gICkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBxdWFudGl6YXRpb25Eb25lID0gMTsgLyogZXhpdCBiaXQgYWRqdXN0bWVudCAqLwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN1bUJpdHNDb25zdW1lZFRvdGFsID4gdG90YWxBdmFpbGFibGVCaXRzICYmIChkZWNyZWFzZUJpdENvbnN1bXB0aW9uPT0wKSApCi8vICAgICAgICAgICAgICAgICAgICAgIC8qKCkqLyAgKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIHF1YW50aXphdGlvbkRvbmUgPSAwOyAvKiByZXNldCEgKi8KICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CgoKICAgICAgICAgIC8qLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0gKi8KCiAgICAgICAgICAgICAgaW50IGVtZXJnZW5jeUl0ZXJhdGlvbnMgPSAxOwogICAgICAgICAgICAgIGludCBkeW5CaXRzT3ZlcnNob290ICAgID0gMDsKCiAgICAgICAgICAgICAgZm9yIChjID0gMCA7IGMgPCBuU3ViRnJhbWVzIDsgYysrICkKICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgIGZvciAoaT0wOyBpPGNtLT5uRWxlbWVudHM7IGkrKykKICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgRUxFTUVOVF9JTkZPIGVsSW5mbyA9IGNtLT5lbEluZm9baV07CgogICAgICAgICAgICAgICAgICAgICAgaWYgKChlbEluZm8uZWxUeXBlID09IElEX1NDRSkgfHwgKGVsSW5mby5lbFR5cGUgPT0gSURfQ1BFKSB8fAogICAgICAgICAgICAgICAgICAgICAgICAgIChlbEluZm8uZWxUeXBlID09IElEX0xGRSkpCiAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIC8qIGl0ZXJhdGlvbiBsaW1pdGF0aW9uICovCiAgICAgICAgICAgICAgICAgICAgICAgIGVtZXJnZW5jeUl0ZXJhdGlvbnMgJj0gKChpdGVyYXRpb25zW2NdW2ldIDwgaFFDLT5tYXhJdGVyYXRpb25zKSA/IDAgOiAxKTsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAvKiBkZXRlY3Rpb24gaWYgdXNlZCBkeW4gYml0cyBleGNlZWRzIHRoZSBtYXhpbWFsIGFsbG93ZWQgY3JpdGVyaW9uICovCiAgICAgICAgICAgICAgICAgIGR5bkJpdHNPdmVyc2hvb3QgfD0gKChxY091dFtjXS0+dXNlZER5bkJpdHMgPiBxY091dFtjXS0+bWF4RHluQml0cykgPyAxIDogMCk7CiAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICBpZiAocXVhbnRpemF0aW9uRG9uZT09MCB8fCBkeW5CaXRzT3ZlcnNob290KQogICAgICAgICAgICAgIHsKCiAgICAgICAgICAgICAgICAgIGludCBzdW1CaXRzQ29uc3VtZWRUb3RhbCA9IEZES2FhY0VuY19nZXRUb3RhbENvbnN1bWVkQml0cyhxY091dCwgcWNFbGVtZW50LCBjbSwgaFFDLT5nbG9iSGRyQml0cywgblN1YkZyYW1lcyk7CgogICAgICAgICAgICAgICAgICBpZiAoIChzdW1EeW5CaXRzQ29uc3VtZWRUb3RhbCA+PSBhdmdUb3RhbER5bkJpdHMpIHx8IChzdW1EeW5CaXRzQ29uc3VtZWRUb3RhbD09MCkgKSB7CiAgICAgICAgICAgICAgICAgICAgICBxdWFudGl6YXRpb25Eb25lID0gMTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoZW1lcmdlbmN5SXRlcmF0aW9ucyAmJiAoc3VtQml0c0NvbnN1bWVkVG90YWwgPCB0b3RhbEF2YWlsYWJsZUJpdHMpKSB7CiAgICAgICAgICAgICAgICAgICAgICBxdWFudGl6YXRpb25Eb25lID0gMTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoKHN1bUJpdHNDb25zdW1lZFRvdGFsID4gdG90YWxBdmFpbGFibGVCaXRzKSB8fCAhY2hlY2tNaW5GcmFtZUJpdHNEZW1hbmQocWNPdXQsaFFDLT5taW5CaXRzUGVyRnJhbWUsblN1YkZyYW1lcykpIHsKICAgICAgICAgICAgICAgICAgICAgIHF1YW50aXphdGlvbkRvbmUgPSAwOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmICgoc3VtQml0c0NvbnN1bWVkVG90YWwgPCB0b3RhbEF2YWlsYWJsZUJpdHMpICYmIGNoZWNrTWluRnJhbWVCaXRzRGVtYW5kKHFjT3V0LGhRQy0+bWluQml0c1BlckZyYW1lLG5TdWJGcmFtZXMpKSB7CiAgICAgICAgICAgICAgICAgICAgICBkZWNyZWFzZUJpdENvbnN1bXB0aW9uID0gMDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgIGRlY3JlYXNlQml0Q29uc3VtcHRpb24gPSAxOwogICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgICBpZiAoZHluQml0c092ZXJzaG9vdCkgewogICAgICAgICAgICAgICAgICAgICBxdWFudGl6YXRpb25Eb25lID0gMDsKICAgICAgICAgICAgICAgICAgICAgZGVjcmVhc2VCaXRDb25zdW1wdGlvbiA9IDE7CiAgICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICAgIC8qIHJlc2V0IGNvbnN0cmFpbnRzIGZ1bGxmaWxsZWQgZmxhZ3MgKi8KICAgICAgICAgICAgICAgICAgRkRLbWVtY2xlYXIoY29uc3RyYWludHNGdWxmaWxsZWQsIHNpemVvZihjb25zdHJhaW50c0Z1bGZpbGxlZCkpOwogICAgICAgICAgICAgICAgICBGREttZW1jbGVhcihjaENvbnN0cmFpbnRzRnVsZmlsbGVkLCBzaXplb2YoY2hDb25zdHJhaW50c0Z1bGZpbGxlZCkpOwoKCiAgICAgICAgICAgICAgfS8qIHF1YW50aXphdGlvbkRvbmUgKi8KCiAgICAgIH0gd2hpbGUgKCFxdWFudGl6YXRpb25Eb25lKSA7CgogICAgICAvKi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tICovCiAgICAgIC8qIC4uLiAtZW5kLSBRdWFudGl6YXRpb24gbG9vcCAgICAgICAgICAgICAgICAgKi8KICAgICAgLyotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSAqLwoKICAvKi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tICovCiAgLyotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSAqLwoKICByZXR1cm4gQUFDX0VOQ19PSzsKfQoKCnN0YXRpYyBBQUNfRU5DT0RFUl9FUlJPUiBGREthYWNFbmNfcmVkdWNlQml0Q29uc3VtcHRpb24oaW50KiAgICAgICAgICAgICBpdGVyYXRpb25zLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3QgaW50ICAgICAgICBtYXhJdGVyYXRpb25zLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaW50ICAgICAgICAgICAgICBnYWluQWRqdXN0bWVudCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGludCogICAgICAgICAgICAgY2hDb25zdHJhaW50c0Z1bGZpbGxlZCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGludCogICAgICAgICAgICAgY2FsY3VsYXRlUXVhbnQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpbnQgICAgICAgICAgICAgIG5DaGFubmVscywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFBTWV9PVVRfRUxFTUVOVCogcHN5T3V0RWxlbWVudCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFFDX09VVCogICAgICAgICAgcWNPdXQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBRQ19PVVRfRUxFTUVOVCogIHFjT3V0RWxlbWVudCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIEVMRU1FTlRfQklUUyogICAgZWxCaXRzLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgQVVESU9fT0JKRUNUX1RZUEUgYW90LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgVUlOVCAgICAgICAgICAgICBzeW50YXhGbGFncywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFNDSEFSICAgICAgICAgICAgZXBDb25maWcpCnsKICBpbnQgY2g7CgogIC8qKiBTT0xWSU5HIFBST0JMRU0gKiovCiAgaWYgKCgqaXRlcmF0aW9ucykrKyA+PSBtYXhJdGVyYXRpb25zKQogIHsKICAgIGlmIChxY091dEVsZW1lbnQtPmR5bkJpdHNVc2VkPT0wKSB7CiAgICB9CiAgICAvKiBjcmFzaCByZWNvdmVyeSAqLwogICAgZWxzZSB7CiAgICAgIElOVCBiaXRzVG9TYXZlID0gMDsKICAgICAgaWYgKCAoYml0c1RvU2F2ZSA9IGZpeE1heCgocWNPdXRFbGVtZW50LT5keW5CaXRzVXNlZCArIDgpIC0gKGVsQml0cy0+Yml0UmVzTGV2ZWxFbCArIHFjT3V0RWxlbWVudC0+Z3JhbnRlZER5bkJpdHMpLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChxY091dEVsZW1lbnQtPmR5bkJpdHNVc2VkICsgcWNPdXRFbGVtZW50LT5zdGF0aWNCaXRzVXNlZCArIDgpIC0gKGVsQml0cy0+bWF4Qml0c0VsKSkpID4gMCApCiAgICAgIHsKICAgICAgICBGREthYWNFbmNfY3Jhc2hSZWNvdmVyeShuQ2hhbm5lbHMsCiAgICAgICAgICAgICAgICAgICAgICBwc3lPdXRFbGVtZW50LAogICAgICAgICAgICAgICAgICAgICAgcWNPdXQsCiAgICAgICAgICAgICAgICAgICAgICBxY091dEVsZW1lbnQsCiAgICAgICAgICAgICAgICAgICAgICBiaXRzVG9TYXZlLAogICAgICAgICAgICAgICAgICAgICAgYW90LAogICAgICAgICAgICAgICAgICAgICAgc3ludGF4RmxhZ3MsCiAgICAgICAgICAgICAgICAgICAgICBlcENvbmZpZykgOwogICAgfQogICAgZWxzZQogICAgewogICAgICBm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S03KSZ+NykpKTsKICAgICAgYnJlYWs7CiAgfSAvKiBzd2l0Y2ggKHFjS2VybmVsLT5iaXRyYXRlTW9kZSkgKi8KCiAgcmV0dXJuIEFBQ19FTkNfT0s7Cn0KCgoKCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKCiAgICAgICAgIGZ1bmN0aW9ubmFtZTogRkRLYWFjRW5jX2NhbGNNYXhWYWx1ZUluU2ZiCiAgICAgICAgIGRlc2NyaXB0aW9uOgogICAgICAgICByZXR1cm46CgoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwoKc3RhdGljIElOVCBGREthYWNFbmNfY2FsY01heFZhbHVlSW5TZmIoSU5UICAgc2ZiQ250LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgIElOVCAgIG1heFNmYlBlckdyb3VwLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgIElOVCAgIHNmYlBlckdyb3VwLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgIElOVCAgKlJFU1RSSUNUIHNmYk9mZnNldCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICBTSE9SVCAqUkVTVFJJQ1QgcXVhbnRTcGVjdHJ1bSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICBVSU5UICpSRVNUUklDVCBtYXhWYWx1ZSkKewogIElOVCBzZmJPZmZzLHNmYjsKICBJTlQgbWF4VmFsdWVBbGwgPSAwOwoKICBmb3IgKHNmYk9mZnM9MDtzZmJPZmZzPHNmYkNudDtzZmJPZmZzKz1zZmJQZXJHcm91cCkKICAgIGZvciAoc2ZiID0gMDsgc2ZiIDwgbWF4U2ZiUGVyR3JvdXA7IHNmYisrKQogICAgewogICAgICBJTlQgbGluZTsKICAgICAgSU5UIG1heFRoaXNTZmIgPSAwOwogICAgICBmb3IgKGxpbmUgPSBzZmJPZmZzZXRbc2ZiT2ZmcytzZmJdOyBsaW5lIDwgc2ZiT2Zmc2V0W3NmYk9mZnMrc2ZiKzFdOyBsaW5lKyspCiAgICAgIHsKICAgICAgICBJTlQgdG1wID0gZml4cF9hYnMocXVhbnRTcGVjdHJ1bVtsaW5lXSk7CiAgICAgICAgbWF4VGhpc1NmYiA9IGZpeE1heCh0bXAsIG1heFRoaXNTZmIpOwogICAgICB9CgogICAgICBtYXhWYWx1ZVtzZmJPZmZzK3NmYl0gPSBtYXhUaGlzU2ZiOwogICAgICBtYXhWYWx1ZUFsbCA9IGZpeE1heChtYXhUaGlzU2ZiLCBtYXhWYWx1ZUFsbCk7CiAgICB9CiAgcmV0dXJuIG1heFZhbHVlQWxsOwp9CgoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgoKICAgICAgICAgZnVuY3Rpb25uYW1lOiBGREthYWNFbmNfdXBkYXRlQml0cmVzCiAgICAgICAgIGRlc2NyaXB0aW9uOgogICAgICAgICByZXR1cm46CgoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwp2b2lkIEZES2FhY0VuY191cGRhdGVCaXRyZXMoQ0hBTk5FTF9NQVBQSU5HICpjbSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgIFFDX1NUQVRFKiBxY0tlcm5lbCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgIFFDX09VVCoqIHFjT3V0KQp7CiAgc3dpdGNoIChxY0tlcm5lbC0+Yml0cmF0ZU1vZGUpIHsKICAgIGNhc2UgUUNEQVRBX0JSX01PREVfRkY6CiAgICBjYXNlIFFDREFUQV9CUl9NT0RFX1ZCUl8xOgogICAgY2FzZSBRQ0RBVEFfQlJfTU9ERV9WQlJfMjoKICAgIGNhc2UgUUNEQVRBX0JSX01PREVfVkJSXzM6CiAgICBjYXNlIFFDREFUQV9CUl9NT0RFX1ZCUl80OgogICAgY2FzZSBRQ0RBVEFfQlJfTU9ERV9WQlJfNToKICAgICAgLyogdmFyaWFibGUgYml0cmF0ZSAqLwogICAgICBxY0tlcm5lbC0+Yml0UmVzVG90ID0gRkRLbWluKHFjS2VybmVsLT5tYXhCaXRzUGVyRnJhbWUsIHFjS2VybmVsLT5iaXRSZXNUb3RNYXgpOwogICAgICBicmVhazsKCiAgICBjYXNlIFFDREFUQV9CUl9NT0RFX0NCUjoKICAgIGNhc2UgUUNEQVRBX0JSX01PREVfU0ZSOgogICAgY2FzZSBRQ0RBVEFfQlJfTU9ERV9JTlZBTElEOgogICAgZGVmYXVsdDoKICAgICAgaW50IGMgPSAwOwogICAgICAvKiBjb25zdGFudCBiaXRyYXRlICovCiAgICAgIHsKICAgICAgICBxY0tlcm5lbC0+Yml0UmVzVG90ICs9IHFjT3V0W2NdLT5ncmFudGVkRHluQml0cyAtIChxY091dFtjXS0+dXNlZER5bkJpdHMgKyBxY091dFtjXS0+dG90RmlsbEJpdHMgKyBxY091dFtjXS0+YWxpZ25CaXRzKTsKICAgICAgfQogICAgICBicmVhazsKICB9Cn0KCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKCiAgICAgICAgIGZ1bmN0aW9ubmFtZTogRkRLYWFjRW5jX0ZpbmFsaXplQml0Q29uc3VtcHRpb24KICAgICAgICAgZGVzY3JpcHRpb246CiAgICAgICAgIHJldHVybjoKCioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCkFBQ19FTkNPREVSX0VSUk9SIEZES2FhY0VuY19GaW5hbGl6ZUJpdENvbnN1bXB0aW9uKENIQU5ORUxfTUFQUElORyAqY20sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFFDX1NUQVRFICpxY0tlcm5lbCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgUUNfT1VUICpxY091dCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgUUNfT1VUX0VMRU1FTlQqKiBxY0VsZW1lbnQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIEhBTkRMRV9UUkFOU1BPUlRFTkMgaFRwRW5jLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBBVURJT19PQkpFQ1RfVFlQRSAgIGFvdCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgVUlOVCAgICAgICAgICAgICAgICBzeW50YXhGbGFncywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgU0NIQVIgICAgICAgICAgICAgICBlcENvbmZpZykKewogIFFDX09VVF9FWFRFTlNJT04gZmlsbEV4dFBheWxvYWQ7CiAgSU5UIHRvdEZpbGxCaXRzLCBhbGlnbkJpdHM7CgogIHsKICAgIGludCBleGFjdFRwQml0czsKICAgIGludCBtYXhfaXRlciA9IDM7CgogICAgLyogR2V0IHRvdGFsIGNvbnN1bWVkIGJpdHMgaW4gQVUgKi8KICAgIHFjT3V0LT50b3RhbEJpdHMgPSBxY091dC0+c3RhdGljQml0cyArIHFjT3V0LT51c2VkRHluQml0cyAgKyBxY091dC0+dG90RmlsbEJpdHMgKwogICAgICAgICAgICAgICAgICAgICAgIHFjT3V0LT5lbGVtZW50RXh0Qml0cyArIHFjT3V0LT5nbG9iYWxFeHRCaXRzOwoKICAgIC8qIE5vdyB3ZSBjYW4gZ2V0IHRoZSBleGFjdCB0cmFuc3BvcnQgYml0IGFtb3VudCwgYW5kIGhvcGVmdWxseSBpdCBpc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ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN5bnRheEZsYWdzLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGFvdCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBlcENvbmZpZyApOwoKICAvKiBub3cgZGlzdHJpYnV0ZSBleHRyYSBmaWxsYml0cyBhbmQgYWxpZ25iaXRzICovCiAgYWxpZ25CaXRzID0gNyAtIChxY091dC0+c3RhdGljQml0cyArIHFjT3V0LT51c2VkRHluQml0cyArIHFjT3V0LT5lbGVtZW50RXh0Qml0cwogICAgICAgICAgICAgICAgICAgKyBxY091dC0+dG90RmlsbEJpdHMgKyBxY091dC0+Z2xvYmFsRXh0Qml0cyAtMSklODsKCiAgLyogTWF5YmUgd2UgY291bGQgcmVtb3ZlIHRoaXMgKi8KICBpZiggKChhbGlnbkJpdHMgKyBxY091dC0+dG90RmlsbEJpdHMgLSB0b3RGaWxsQml0cyk9PTgpICYmIChxY091dC0+dG90RmlsbEJpdHM+OCkgKQogICAgICAgIHFjT3V0LT50b3RGaWxsQml0cyAtPSA4OwoKICBxY091dC0+dG90YWxCaXRzID0gcWNPdXQtPnN0YXRpY0JpdHMgKyBxY091dC0+dXNlZER5bkJpdHMgKyBxY091dC0+dG90RmlsbEJpdHMgKwogICAgICAgICAgICAgICAgICAgICBhbGlnbkJpdHMgKyBxY091dC0+ZWxlbWVudEV4dEJpdHMgKyBxY091dC0+Z2xvYmFsRXh0Qml0czsKCiAgaWYgKCAocWNPdXQtPnRvdGFsQml0cz5xY0tlcm5lbC0+bWF4Qml0c1BlckZyYW1lKSB8fCAocWNPdXQtPnRvdGFsQml0czxxY0tlcm5lbC0+bWluQml0c1BlckZyYW1lKSApIHsKICAgIHJldHVybiBBQUNfRU5DX1FVQU5UX0VSUk9SOwogIH0KCiAgcWNPdXQtPmFsaWduQml0cyA9IGFsaWduQml0czsKCiAgcmV0dXJuIEFBQ19FTkNfT0s7Cn0KCgoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgoKICAgICAgICAgZnVuY3Rpb25uYW1lOiBGREthYWNFbmNfY3Jhc2hSZWNvdmVyeQogICAgICAgICBkZXNjcmlwdGlvbjogIGZ1bGZpbGxzIGNvbnN0cmFpbnRzIGJ5IG1lYW5zIG9mIGJydXRlIGZvcmNlLi4uCiAgICAgICAgICAgICAgICAgICAgICAgPT4gYml0cyBhcmUgc2F2ZWQgYnkgY2FuY2VsbGluZyBvdXQgc3BlY3RyYWwgbGluZXMhIQogICAgICAgICAgICAgICAgICAgICAgICAgIChiZWdpbm5pbmcgYXQgdGhlIGhpZ2hlc3QgZnJlcXVlbmNpZXMpCiAgICAgICAgIHJldHVybjogICAgICAgZXJyb3Jjb2RlCgoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwoKc3RhdGljIHZvaWQgRkRLYWFjRW5jX2NyYXNoUmVjb3ZlcnkoSU5UICAgICAgICAgICAgICAgbkNoYW5uZWxzLAogICAgICAgICAgICAgICAgICAgICAgICAgIFBTWV9PVVRfRUxFTUVOVCogIHBzeU91dEVsZW1lbnQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgUUNfT1VUKiAgICAgICAgICAgcWNPdXQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgUUNfT1VUX0VMRU1FTlQgICAqcWNFbGVtZW50LAogICAgICAgICAgICAgICAgICAgICAgICAgIElOVCAgICAgICAgICAgICAgIGJpdHNUb1NhdmUsCiAgICAgICAgICAgICAgICAgICAgICAgICAgQVVESU9fT0JKRUNUX1RZUEUgYW90LAogICAgICAgICAgICAgICAgICAgICAgICAgIFVJTlQgICAgICAgICAgICAgIHN5bnRheEZsYWdzLAogICAgICAgICAgICAgICAgICA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gTlVMTCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwc3lPdXRFbGVtZW50LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBzeUNoYW5uZWwsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3ludGF4RmxhZ3MsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYW90LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVwQ29uZmlnLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJnN0YXRCaXRzTmV3LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDAgKTsKICB9CgogIHNhdmVkQml0cyA9IHFjRWxlbWVudC0+c3RhdGljQml0c1VzZWQgLSBzdGF0Qml0c05ldzsKCiAgLyogdXBkYXRlIHN0YXRpYyBhbmQgZHluYW1pYyBiaXRzICovCiAgcWNFbGVtZW50LT5zdGF0aWNCaXRzVXNlZCAtPSBzYXZlZEJpdHM7CiAgcWNFbGVtZW50LT5ncmFudGVkRHluQml0cyArPSBzYXZlZEJpdHM7CgogIHFjT3V0LT5zdGF0aWNCaXRzICAgICAtPSBzYXZlZEJpdHM7CiAgcWNPdXQtPmdyYW50ZWREeW5CaXRzICs9IHNhdmVkQml0czsKICBxY091dC0+bWF4RHluQml0cyAgICAgKz0gc2F2ZWRCaXRzOwoKCn0KCgoKdm9pZCAgRkRLYWFjRW5jX1FDQ2xvc2UgKFFDX1NUQVRFICAqKnBoUUNzdGF0ZSwgUUNfT1VUICoqcGhRQykKewogIGludCBuLCBpOwoKICBpZiAocGhRQyE9TlVMTCkgewoKICAgIGZvciAobj0wO248KDEpO24rKykgewogICAgICBpZiAocGhRQ1tuXSAhPSBOVUxMKSB7CiAgICAgICAgUUNfT1VUICAgICpoUUMgICAgICA9IHBoUUNbbl07CiAgICAgICAgZm9yIChpPTA7IGk8KDYpOyBpKyspIHsKICAgICAgICB9CgogICAgICAgIGZvciAoa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