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WTogIiBmbXQgLCAjI2FyZ3MpOyB9IHdoaWxlICgwKQojZWxzZQojZGVmaW5lIEZMT1BQWV9EUFJJTlRGKGZtdCwgYXJncy4uLikKI2VuZGlmCgojZGVmaW5lIEZMT1BQWV9FUlJPUihmbXQsIGFyZ3MuLi4pIFwKZG8geyBwcmludGYoIkZMT1BQWSBFUlJPUjogJXM6ICIgZm10LCBfX2Z1bmNfXyAsICMjYXJncyk7IH0gd2hpbGUgKDApCgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCi8qIEZsb3BweSBkcml2ZSBlbXVsYXRpb24gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKi8KCi8qIFdpbGwgYWx3YXlzIGJlIGEgZml4ZWQgcGFyYW1ldGVyIGZvciB1cyAqLwojZGVmaW5lIEZEX1NFQ1RPUl9MRU4gNTEyCiNkZWZpbmUgRkRfU0VDVE9SX1NDICAyICAgLyogU2VjdG9yIHNpemUgY29kZSAqLwoKLyogRmxvcHB5IGRpc2sgZHJpdmUgZW11bGF0aW9uICovCnR5cGVkZWYgZW51bSBmZGlza190eXBlX3QgewogICAgRkRSSVZFX0RJU0tfMjg4ICAgPSAweDAxLCAvKiAyLjg4IE1CIGRpc2sgICAgICAgICAgICovCiAgICBGRFJJVkVfRElTS18xNDQgICA9IDB4MDIsIC8qIDEuNDQgTUIgZGlzayAgICAgICAgICAgKi8KICAgIEZEUklWRV9ESVNLXzcyMCAgID0gMHgwMywgLyogNzIwIGtCIGRpc2sgICAgICAgICAgICAqLwogICAgRkRSSVZFX0RJU0tfVVNFUiAgPSAweDA0LCAvKiBVc2VyIGRlZmluZWQgZ2VvbWV0cnkgICovCiAgICBGRFJJVkVfRElTS19OT05FICA9IDB4MDUsIC8qIE5vIGRpc2sgICAgICAgICAgICAgICAgKi8KfSBmZGlza190eXBlX3Q7Cgp0eXBlZGVmIGVudW0gZmRyaXZlX3R5cGVfdCB7CiAgICBGRFJJVkV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PmhlYWQsIGRydi0+dHJhY2ssIGRydi0+c2VjdCwgZHJ2LT5sYXN0X3NlY3QpOwp9CgpzdGF0aWMgaW50IGZkX3NlZWsgKGZkcml2ZV90ICpkcnYsIHVpbnQ4X3QgaGVhZCwgdWludDhfdCB0cmFjaywgdWludDhfdCBzZWN0LAogICAgICAgICAgICAgICAgICAgIGludCBlbmFibGVfc2VlaykKewogICAgdWludDMyX3Qgc2VjdG9yOwogICAgaW50IHJldDsKCiAgICBpZiAodHJhY2sgPiBkcnYtPm1heF90cmFjayB8fAogICAgICAgIChoZWFkICE9IDAgJiYgKGRydi0+ZmxhZ3MgJiBGRElTS19EQkxfU0lERVMpID09IDApKSB7CiAgICAgICAgRkxPUFBZX0RQUklOVEYoInRyeSB0byByZWFkICVkICUwMnggJTAyeCAobWF4PSVkICVkICUwMnggJTAyeClcbiIsCiAgICAgICAgICAgICAgICAgICAgICAgaGVhZCwgdHJhY2ssIHNlY3QsIDEsCiAgICAgICAgICAgICAgICAgICAgICAgKGRydi0+ZmxhZ3MgJiBGRElTS19EQkxfU0lERVMpID09IDAgPyAwIDogMSwKICAgICAgICAgICAgICAgICAgICAgICBkcnYtPm1heF90cmFjaywgZHJ2LT5sYXN0X3NlY3QpOwogICAgICAgIHJldHVybiAyOwogICAgfQogICAgaWYgKHNlY3QgPiBkcnYtPmxhc3Rfc2VjdCkgewogICAgICAgIEZMT1BQWV9EUFJJTlRGKCJ0cnkgdG8gcmVhZCAlZCAlMDJ4ICUwMnggKG1heD0lZCAlZCAlMDJ4ICUwMngpXG4iLAogICAgICAgICAgICAgICAgICAgICAgIGhlYWQsIHRyYWNrLCBzZWN0LCAxLAogICAgICAgICAgICAgICAgICAgICAgIChkcnYtPmZsYWdzICYgRkRJU0tfREJMX1NJREVTKSA9PSAwID8gMCA6IDEsCiAgICAgICAgICAgICAgICAgICAgICAgZHJ2LT5tYXhfdHJhY2ssIGRydi0+bGFzdF9zZWN0KTsKICAgICAgICByZXR1cm4gMzsKICAgI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tPmJzKSkgewogICAgICAgIHJvID0gYmRydl9pc19yZWFkX29ubHkoZHJ2LT5icyk7CiAgICAgICAgYmRydl9nZXRfZ2VvbWV0cnlfaGludChkcnYtPmJzLCAmbmJfaGVhZHMsICZtYXhfdHJhY2ssICZsYXN0X3NlY3QpOwogICAgICAgIGlmIChuYl9oZWFkcyAhPSAwICYmIG1heF90cmFjayAhPSAwICYmIGxhc3Rfc2VjdCAhPSAwKSB7CiAgICAgICAgICAgIEZMT1BQWV9EUFJJTlRGKCJVc2VyIGRlZmluZWQgZGlzayAoJWQgJWQgJWQpIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgbmJfaGVhZHMgLSAxLCBtYXhfdHJhY2ssIGxhc3Rfc2VjdCk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgYmRydl9nZXRfZ2VvbWV0cnkoZHJ2LT5icywgJm5iX3NlY3RvcnMpOwogICAgICAgICAgICBtYXRjaCA9IC0xOwogICAgICAgICAgICBmaXJzdF9tYXRjaCA9IC0xOwogICAgICAgICAgICBmb3IgKGkgPSAwOzsgaSsrKSB7CiAgICAgICAgICAgICAgICBwYXJzZSA9ICZmZF9mb3JtYXRzW2ldOwogICAgICAgICAgICAgICAgaWYgKHBhcnNlLT5kcml2ZSA9PSBGRFJJVkVfRFJWX05PTkUpCiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICBpZiAoZHJ2LT5kcml2ZSA9PSBwYXJzZS0+ZHJpdmUgfHwKICAgICAgICAgICAgICAgICAgICBkcnYtPmRyaXZlID09IEZEUklWRV9EUlZfTk9ORSkgewogICAgICAgICAgICAgICAgICAgIHNpemUgPSAocGFyc2UtPm1heF9oZWFkICsgMSkgKiBwYXJzZS0+bWF4X3RyYWNrICoKICAgICAgICAgICAgICAgICAgICAgICAgcGFyc2UtPmxhc3Rfc2VjdDsKICAgICAgICAgICAgICAgICAgICBpZiAobmJfc2VjdG9ycyA9PSBzaXplKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIG1hdGNoID0gaTsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChmaXJzdF9tYXRjaCA9PSAtMSkKICAgICAgICAgICAgICAgICAgICAgICAgZmlyc3RfbWF0Y2ggPSBpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChtYXRjaCA9PSAtMSkgewogICAgICAgICAgICAgICAgaWYgKGZpcnN0X21hdGNoID09IC0xKQogICAgICAgICAgICAgICAgICAgIG1hdGNoID0gMTsKICAgICAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgICAgICBtYXRjaCA9IGZpcnN0X21hdGNoOwogICAgICAgICAgICAgICAgcGFyc2UgPSAmZmRfZm9ybWF0c1ttYXRjaF07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbmJfaGVhZHMgPSBwYXJzZS0+bWF4X2hlYWQgKyAxOwogICAgICAgICAgICBtYXhfdHJhY2sgPSBwYXJzZS0+bWF4X3RyYWNrOwogICAgICAgICAgICBsYXN0X3NlY3QgPSBwYXJzZS0+bGFzdF9zZWN0OwogICAgICAgICAgICBkcnYtPmRyaXZlID0gcGFyc2UtPmRyaXZlOwogICAgICAgICAgICBGTE9QUFlfRFBSSU5URigiJXMgZmxvcHB5IGRpc2sgKCVkIGggJWQgdCAlZCBzKSAlc1xuIiwgcGFyc2UtPnN0ciwKICAgICAgICAgICAgICAgICAgICAgICAgICAgbmJfaGVhZHMsIG1heF90cmFjaywgbGFzdF9zZWN0LCBybyA/ICJybyIgOiAicnciKTsKICAgICAgICB9CiAgICAgICAgaWYgKG5iX2hlYWRzID09IDEpIHsKICAgICAgICAgICAgZHJ2LT5mbGFncyAmPSB+RkRJU0tfREJMX1NJREVTOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGRydi0+ZmxhZ3MgfD0gRkRJU0tfREJMX1NJREVTOw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YgKGZkY3RybC0+c3VuNG0pIHsKICAgICAgICAgICAgLy8gSWRlbnRpZnkgdG8gTGludXggYXMgUzgyMDc4QgogICAgICAgICAgICByZXR2YWwgPSBmZGN0cmxfcmVhZF9zdGF0dXNCKGZkY3RybCk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmV0dmFsID0gKHVpbnQzMl90KSgtMSk7CiAgICAgICAgfQogICAgICAgIGJyZWFrOwogICAgY2FzZSBGRF9SRUdfU1RBVFVTQjoKICAgICAgICByZXR2YWwgPSBmZGN0cmxfcmVhZF9zdGF0dXNCKGZkY3RybCk7CiAgICAgICAgYnJlYWs7CiAgICBjYXNlIEZEX1JFR19ET1I6CiAgICAgICAgcmV0dmFsID0gZmRjdHJsX3JlYWRfZG9yKGZkY3RybCk7CiAgICAgICAgYnJlYWs7CiAgICBjYXNlIEZEX1JFR19URFI6CiAgICAgICAgcmV0dmFsID0gZmRjdHJsX3JlYWRfdGFwZShmZGN0cmwpOwogICAgICAgIGJyZWFrOwogICAgY2FzZSBGRF9SRUdfTVNSOgogICAgICAgIHJldHZhbCA9IGZkY3RybF9yZWFkX21haW5fc3RhdHVzKGZkY3RybCk7CiAgICAgICAgYnJlYWs7CiAgICBjYXNlIEZEX1JFR19GSUZPOgogICAgICAgIHJldHZhbCA9IGZkY3RybF9yZWFkX2RhdGEoZmRjdHJsKTsKICAgICAgICBicmVhazsKICAgIGNhc2UgRkRfUkVHX0RJUjoKICAgICAgICByZXR2YWwgPSBmZGN0cmxfcmVhZF9kaXIoZmRjdHJsKTsKICAgICAgICBicmVhazsKICAgIGRlZmF1bHQ6CiAgICAgICAgcmV0dmFsID0gKHVpbnQzMl90KSgtMSk7CiAgICAgICAgYnJlYWs7CiAgICB9CiAgICBGTE9QUFlfRFBSSU5URigicmVhZCByZWclZDogMHglMDJ4XG4iLCByZWcgJiA3LCByZXR2YWwpOwoKICAgIHJldHVybiByZXR2YWw7Cn0KCnN0YXRpYyB2b2lkIGZkY3RybF93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sKCiAgICByZXQgPSBmZF9sb2FkKGYsICZzLT5kcml2ZXNbMF0pOwogICAgaWYgKHJldCA9PSAwKQogICAgICAgIHJldCA9IGZkX2xvYWQoZiwgJnMtPmRyaXZlc1sxXSk7CgogICAgcmV0dXJuIHJldDsKfQoKc3RhdGljIHZvaWQgZmRjdHJsX2V4dGVybmFsX3Jlc2V0KHZvaWQgKm9wYXF1ZSkKewogICAgZmRjdHJsX3QgKnMgPSBvcGFxdWU7CgogICAgZmRjdHJsX3Jlc2V0KHMsIDApOwp9CgpzdGF0aWMgZmRjdHJsX3QgKmZkY3RybF9pbml0X2NvbW1vbiAocWVtdV9pcnEgaXJxLCBpbnQgZG1hX2NoYW5uLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdGFyZ2V0X3BoeXNfYWRkcl90IGlvX2Jhc2UsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBCbG9ja0RyaXZlclN0YXRlICoqZmRzKQp7CiAgICBmZGN0cmxfdCAqZmRjdHJsOwogICAgaW50IGk7CgogICAgRkxPUFBZX0RQUklOVEYoImluaXQgY29udHJvbGxlclxuIik7CiAgICBmZGN0cmwgPSBxZW11X21hbGxvY3ooc2l6ZW9mKGZkY3RybF90KSk7CiAgICBpZiAoIWZkY3RybCkKICAgICAgICByZXR1cm4gTlVMTDsKICAgIGZkY3RybC0+ZmlmbyA9IHFlbXVfbWVtYWxpZ24oNTEyLCBGRF9TRUNUT1JfTEVOKTsKICAgIGlmIChmZGN0cmwtPmZpZm8gPT0gTlVMTCkgewogICAgICAgIHFlbXVfZnJlZShmZGN0cmwpOwogICAgICAgIHJldHVybiBOVUxMOwogICAgfQogICAgZmRjdHJsLT5yZXN1bHRfdGltZXIgPSBxZW11X25ld190aW1lcih2bV9jbG9jaywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZmRjdHJsX3Jlc3VsdF90aW1lciwgZmRjdHJsKTsKCiAgICBmZGN0cmwt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XQgKHFlbXVfaXJxIGlycSwgaW50IGRtYV9jaGFubiwgaW50IG1lbV9tYXBwZWQsCiAgICAgICAgICAgICAgICAgICAgICAgdGFyZ2V0X3BoeXNfYWRkcl90IGlvX2Jhc2UsCiAgICAgICAgICAgICAgICAgICAgICAgQmxvY2tEcml2ZXJTdGF0ZSAqKmZkcykKewogICAgZmRjdHJsX3QgKmZkY3RybDsKICAgIGludCBpb19tZW07CgogICAgZmRjdHJsID0gZmRjdHJsX2luaXRfY29tbW9uKGlycSwgZG1hX2NoYW5uLCBpb19iYXNlLCBmZHMpOwoKICAgIGZkY3RybC0+c3VuNG0gPSAwOwogICAgaWYgKG1lbV9tYXBwZWQpIHsKICAgICAgICBpb19tZW0gPSBjcHVfcmVnaXN0ZXJfaW9fbWVtb3J5KDAsIGZkY3RybF9tZW1fcmVhZCwgZmRjdHJsX21lbV93cml0ZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZkY3RybCk7CiAgICAgICAgY3B1X3JlZ2lzdGVyX3BoeXNpY2FsX21lbW9yeShpb19iYXNlLCAweDA4LCBpb19tZW0pOwogICAgfSBlbHNlIHsKICAgICAgICByZWdpc3Rlcl9pb3BvcnRfcmVhZCgodWludDMyX3QpaW9fYmFzZSArIDB4MDEsIDUsIDEsICZmZGN0cmxfcmVhZCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmZGN0cmwpOwogICAgICAgIHJlZ2lzdGVyX2lvcG9ydF9yZWFkKCh1aW50MzJfdClpb19iYXNlICsgMHgwNywgMSwgMSwgJmZkY3RybF9yZWFkLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZkY3RybCk7CiAgICAgICAgcmVnaXN0ZXJfaW9wb3J0X3dyaXRlKCh1aW50MzJfdClpb19iYXNlICsgMHgwMSwgNSwgMSwgJmZkY3RybF93cml0ZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZmRjdHJsKTsKICAgICAgICByZWdpc3Rlcl9pb3B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M7CiAgICAgICAgRkxPUFBZX0RQUklOVEYoImRtYV9tb2RlPSVkIGRpcmVjdGlvbj0lZCAoJWQgLSAlZClcbiIsCiAgICAgICAgICAgICAgICAgICAgICAgZG1hX21vZGUsIGRpcmVjdGlvbiwKICAgICAgICAgICAgICAgICAgICAgICAoMTI4IDw8IGZkY3RybC0+Zmlmb1s1XSkgKgogICAgICAgICAgICAgICAgICAgICAgIChjdXJfZHJ2LT5sYXN0X3NlY3QgLSBrcyArIDEpLCBmZGN0cmwtPmRhdGFfbGVuKTsKICAgICAgICBpZiAoKChkaXJlY3Rpb24gPT0gRkRfRElSX1NDQU5FIHx8IGRpcmVjdGlvbiA9PSBGRF9ESVJfU0NBTkwgfHwKICAgICAgICAgICAgICBkaXJlY3Rpb24gPT0gRkRfRElSX1NDQU5IKSAmJiBkbWFfbW9kZSA9PSAwKSB8fAogICAgICAgICAgICAoZGlyZWN0aW9uID09IEZEX0RJUl9XUklURSAmJiBkbWFfbW9kZSA9PSAyKSB8fAogICAgICAgICAgICAoZGlyZWN0aW9uID09IEZEX0RJUl9SRUFEICYmIGRtYV9tb2RlID09IDEpKSB7CiAgICAgICAgICAgIC8qIE5vIGFjY2VzcyBpcyBhbGxvd2VkIHVudGlsIERNQSB0cmFuc2ZlciBoYXMgY29tcGxldGVkICovCiAgICAgICAgICAgIGZkY3RybC0+c3RhdGUgfD0gRkRfQ1RSTF9CVVNZOwogICAgICAgICAgICAvKiBOb3csIHdlIGp1c3QgaGF2ZSB0byB3YWl0IGZvciB0aGUgRE1BIGNvbnRyb2xsZXIgdG8KICAgICAgICAgICAgICogcmVjYWxsIHVzLi4uCiAgICAgICAgICAgICAqLwogICAgICAgICAgICBETUFfaG9sZF9EUkVRKGZkY3RybC0+ZG1hX2NoYW5uKTsKICAgICAgICAgICAgRE1BX3NjaGVkdWxlKGZkY3RybC0+ZG1hX2NoYW5uKTsKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICA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YpKTsKICAgICAgICAgICAgICAgIC8qIFN1cmUsIGltYWdlIHNpemUgaXMgdG9vIHNtYWxsLi4uICovCiAgICAgICAgICAgICAgICBtZW1zZXQoZmRjdHJsLT5maWZvLCAwLCBGRF9TRUNUT1JfTEVOKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzd2l0Y2ggKGZkY3RybC0+ZGF0YV9kaXIpIHsKICAgICAgICBjYXNlIEZEX0RJUl9SRUFEOgogICAgICAgICAgICAvKiBSRUFEIGNvbW1hbmRzICovCiAgICAgICAgICAgIERNQV93cml0ZV9tZW1vcnkgKG5jaGFuLCBmZGN0cmwtPmZpZm8gKyByZWxfcG9zLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmZGN0cmwtPmRhdGFfcG9zLCBsZW4pOwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIEZEX0RJUl9XUklURToKICAgICAgICAgICAgLyogV1JJVEUgY29tbWFuZHMgKi8KICAgICAgICAgICAgRE1BX3JlYWRfbWVtb3J5IChuY2hhbiwgZmRjdHJsLT5maWZvICsgcmVsX3BvcywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmZGN0cmwtPmRhdGFfcG9zLCBsZW4pOwogICAgICAgICAgICBpZiAoYmRydl93cml0ZShjdXJfZHJ2LT5icywgZmRfc2VjdG9yKGN1cl9kcnYpLAogICAgICAgICAgICAgICAgICAgICAgICAgICBmZGN0cmwtPmZpZm8sIDEpIDwgMCkgewogICAgICAgICAgICAgICAgRkxPUFBZX0VSUk9SKCJ3cml0dGluZyBzZWN0b3IgJWRcbiIsIGZkX3NlY3RvcihjdXJfZHJ2KSk7CiAgICAgICAgICAgICAgICBmZGN0cmxfc3RvcF90cmFuc2ZlcihmZGN0cmwsIEZEX1NSMF9BQk5URVJNIHwgRkRfU1IwX1NFRUssIDB4MDAsIDB4MDApOwogICAgICAgICAgICAgICAgZ290byB0cmFuc2Zlcl9lcnJvcjsKICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAvKiBTQ0FOIGNvbW1hbmRzICovCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHVpbnQ4X3QgdG1wYnVmW0ZEX1NFQ1RPUl9MRU5dOwogICAgICAgICAgICAgICAgaW50IHJldDsKICAgICAgICAgICAgICAgIERNQV9yZWFkX21lbW9yeSAobmNoYW4sIHRtcGJ1ZiwgZmRjdHJsLT5kYXRhX3BvcywgbGVuKTsKICAgICAgICAgICAgICAgIHJldCA9IG1lbWNtcCh0bXBidWYsIGZkY3RybC0+ZmlmbyArIHJlbF9wb3MsIGxlbik7CiAgICAgICAgICAgICAgICBpZiAocmV0ID09IDApIHsKICAgICAgICAgICAgICAgICAgICBzdGF0dXMyID0gMHgwODsKICAgICAgICAgICAgICAgICAgICBnb3RvIGVuZF90cmFuc2ZlcjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmICgocmV0IDwgMCAmJiBmZGN0cmwtPmRhdGFfZGlyID09IEZEX0RJUl9TQ0FOTCkgfHwKICAgICAgICAgICAgICAgICAgICAocmV0ID4gMCAmJiBmZGN0cmwtPmRhdGFfZGlyID09IEZEX0RJUl9TQ0FOSCkpIHsKICAgICAgICAgICAgICAgICAgICBzdGF0dXMyID0gMHgwMDsKICAgICAgICAgICAgICAgICAgICBnb3RvIGVuZF90cmFuc2ZlcjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgZmRjdHJsLT5kYXRhX3BvcyArPSBsZW47CiAgICAgICAgcmVsX3BvcyA9IGZkY3RybC0+ZGF0YV9wb3MgJSBGRF9TRUNUT1JfTEVOOwogICAgICAgIGlmIChyZWxfcG9zID09IDApIHsKICAgICAgICAgICAgLyogU2VlayB0byBuZXh0IHNlY3RvciAqLwogICAgICAgICAgICBGTE9QUFlfRFBSSU5URigic2VlayB0byBuZXh0IHNlY3RvciAoJWQgJTAyeCAlMDJ4ID0+ICVkKSAoJWQpXG4iLAogICAgICAgICAgICAgICAgICAgICAgICAgICBjdXJfZHJ2LT5oZWFkLCBjdXJfZHJ2LT50cmFjaywgY3VyX2Rydi0+c2VjdCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgZmRfc2VjdG9yKGN1cl9kcnYpLAogICAgICAgICAgICAgICAgICAgICAgICAgICBmZGN0cmwtPmRhdGFfcG9zIC0gbGVuKTsKICAgICAgICAgICAgLyogWFhYOiBjdXJfZHJ2LT5zZWN0ID49IGN1cl9kcnYtPmxhc3Rfc2VjdCBzaG91bGQgYmUgYW4KICAgICAgICAgICAgICAgZXJyb3IgaW4gZmFjdCAqLwogICAgICAgICAgICBpZiAoY3VyX2Rydi0+c2VjdCA+PSBjdXJfZHJ2LT5sYXN0X3NlY3QgfHwKICAgICAgICAgICAgICAgIGN1cl9kcnYtPnNlY3QgPT0gZmRjdHJsLT5lb3QpIHsKICAgICAgICAgICAgICAgIGN1cl9kcnYtPnNlY3QgPSAxOwogICAgICAgICAgICAgICAgaWYgKEZEX01VTFRJX1RSQUNLKGZkY3RybC0+ZGF0YV9zdGF0ZSkpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoY3VyX2Rydi0+aGVhZCA9PSAwICYmCiAgICAgICAgICAgICAgICAgICAgICAgIChjdXJfZHJ2LT5mbGFncyAmIEZESVNLX0RCTF9TSURFUykgIT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICBjdXJfZHJ2LT5oZWFkID0gMTsKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBjdXJfZHJ2LT5oZWFkID0gMDsKICAgICAgICAgICAgICAgICAgICAgICAgY3VyX2Rydi0+dHJhY2srKzsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKChjdXJfZHJ2LT5mbGFncyAmIEZESVNLX0RCTF9TSURFUykgPT0gMCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgY3VyX2Rydi0+dHJhY2srKzsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIEZMT1BQWV9EUFJJTlRGKCJzZWVrIHRvIG5leHQgdHJhY2sgKCVkICUwMnggJTAyeCA9PiAlZClcbiIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjdXJfZHJ2LT5oZWFkLCBjdXJfZHJ2LT50cmFjaywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGN1cl9kcnYtPnNlY3QsIGZkX3NlY3RvcihjdXJfZHJ2KSk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBjdXJfZHJ2LT5zZWN0Kys7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiBlbmRfdHJhbnNmZXI6CiAgICBsZW4gPSBmZGN0cmwtPmRhdGFfcG9zIC0gc3RhcnRfcG9zOwogICAgRkxPUFBZX0RQUklOVEYoImVuZCB0cmFuc2ZlciAlZCAlZCAlZFxuIiwKICAgICAgICAgICAgICAgICAgIGZkY3RybC0+ZGF0YV9wb3MsIGxlbiwgZmRjdHJsLT5kYXRhX2xlbik7CiAgICBpZiAoZmRjdHJsLT5kYXRhX2RpciA9PSBGRF9ESVJfU0NBTkUgfHwKICAgICAgICBmZGN0cmwtPmRhdGFfZGlyID09IEZEX0RJUl9TQ0FOTCB8fAogICAgICAgIGZkY3RybC0+ZGF0YV9kaXIgPT0gRkRfRElSX1NDQU5IKQogICAgICAgIHN0YXR1czIgPSAweDA4OwogICAgaWYgKEZEX0RJRF9TRUVLKGZkY3RybC0+ZGF0YV9zdGF0ZSkpCiAgICAgICAgc3RhdHVzMCB8PSBGRF9TUjBfU0VFSzsKICAgIGZkY3RybC0+ZGF0YV9sZW4gLT0gbGVuOwogICAgLy8gIC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FsdWUgJiBjb21tYW5kc1twb3NdLm1hc2spID09IGNvbW1hbmRzW3Bvc10udmFsdWUpIHsKICAgICAgICAgICAgICAgIEZMT1BQWV9EUFJJTlRGKCIlcyBjb21tYW5kXG4iLCBjb21tYW5kc1twb3NdLm5hbWUpOwogICAgICAgICAgICAgICAgZmRjdHJsLT5kYXRhX2xlbiA9IGNvbW1hbmRzW3Bvc10ucGFyYW1ldGVycyArIDE7CiAgICAgICAgICAgICAgICBnb3RvIGVucXVldWU7CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIC8qIFVua25vd24gY29tbWFuZCAqLwogICAgICAgIEZMT1BQWV9FUlJPUigidW5rbm93biBjb21tYW5kOiAweCUwMnhcbiIsIHZhbHVlKTsKICAgICAgICBmZGN0cmxfdW5pbXBsZW1lbnRlZChmZGN0cmwsIDApOwogICAgICAgIHJldHVybjsKICAgIH0KIGVucXVldWU6CiAgICBGTE9QUFlfRFBSSU5URigiJXM6ICUwMnhcbiIsIF9fZnVuY19fLCB2YWx1ZSk7CiAgICBmZGN0cmwtPmZpZm9bZmRjdHJsLT5kYXRhX3Bvc10gPSB2YWx1ZTsKICAgIGlmICgrK2ZkY3RybC0+ZGF0YV9wb3MgPT0gZmRjdHJsLT5kYXRhX2xlbikgewogICAgICAgIC8qIFdlIG5vdyBoYXZlIGFsbCBwYXJhbWV0ZXJzCiAgICAgICAgICogYW5kIHdpbGwgYmUgYWJsZSB0byB0cmVhdCB0aGUgY29tbWFuZAogICAgICAgICAqLwogICAgICAgIGlmIChmZGN0cmwtPmRhdGFfc3RhdGUgJiBGRF9TVEFURV9GT1JNQVQpIHsKICAgICAgICAgICAgZmRjdHJsX2Zvcm1hdF9zZWN0b3IoZmRjdHJsKTsKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgIH0KCiAgICAgICAgZm9yIChwb3MgPSAwOyBwb3MgPCBzaXplb2YoY29tbWFuZHMpL3NpemVvZihjb21tYW5kc1swXSk7IHBvcysrKSB7CiAgIC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