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IHNlY3RvciBpcyBpbnZhbGlkCiAqIHJldHVybnMgNCBpZiBzZWVrIGlzIGRpc2FibGVkCiAqLwpzdGF0aWMgaW50IGZkX3NlZWsgKGZkcml2ZV90ICpkcnYsIHVpbnQ4X3QgaGVhZCwgdWludDhfdCB0cmFjaywgdWludDhfdCBzZWN0LAogICAgICAgICAgICAgICAgICAgIGludCBlbmFibGVfc2VlaykKewogICAgdWludDMyX3Qgc2VjdG9yOwogICAgaW50IHJldDsKCiAgICBpZiAodHJhY2sgPiBkcnYtPm1heF90cmFjayB8fAogICAgICAgIChoZWFkICE9IDAgJiYgKGRydi0+ZmxhZ3MgJiBGRElTS19EQkxfU0lERVMpID09IDApKSB7CiAgICAgICAgRkxPUFBZX0RQUklOVEYoInRyeSB0byByZWFkICVkICUwMnggJTAyeCAobWF4PSVkICVkICUwMnggJTAyeClcbiIsCiAgICAgICAgICAgICAgICAgICAgICAgaGVhZCwgdHJhY2ssIHNlY3QsIDEsCiAgICAgICAgICAgICAgICAgICAgICAgKGRydi0+ZmxhZ3MgJiBGRElTS19EQkxfU0lERVMpID09IDAgPyAwIDogMSwKICAgICAgICAgICAgICAgICAgICAgICBkcnYtPm1heF90cmFjaywgZHJ2LT5sYXN0X3NlY3QpOwogICAgICAgIHJldHVybiAyOwogICAgfQogICAgaWYgKHNlY3QgPiBkcnYtPmxhc3Rfc2VjdCkgewogICAgICAgIEZMT1BQWV9EUFJJTlRGKCJ0cnkgdG8gcmVhZCAlZCAlMDJ4ICUwMnggKG1heD0lZCAlZCAlMDJ4ICUwMngpXG4iLAogICAgICAgICAgICAgICAgICAgICAgIGhlYWQsIHRyYWNrLCBzZWN0LCAxLAogICAgICAgICAgICAgICAgICAgICAgIChkcnYtPmZsYWdzICYgRkRJU0tfREJMX1NJREVTKSA9PSAwID8gMCA6IDEsCiAgICAgICAgICAgICAgICAgICAgICAgZHJ2LT5tYXhfdHJhY2ssIGRydi0+bGFzdF9zZWN0KTsKICAgICAgICByZXR1cm4gMzs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YnMpOwogICAgICAgIGJkcnZfZ2V0X2dlb21ldHJ5X2hpbnQoZHJ2LT5icywgJm5iX2hlYWRzLCAmbWF4X3RyYWNrLCAmbGFzdF9zZWN0KTsKICAgICAgICBpZiAobmJfaGVhZHMgIT0gMCAmJiBtYXhfdHJhY2sgIT0gMCAmJiBsYXN0X3NlY3QgIT0gMCkgewogICAgICAgICAgICBGTE9QUFlfRFBSSU5URigiVXNlciBkZWZpbmVkIGRpc2sgKCVkICVkICVkKSIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgIG5iX2hlYWRzIC0gMSwgbWF4X3RyYWNrLCBsYXN0X3NlY3QpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGJkcnZfZ2V0X2dlb21ldHJ5KGRydi0+YnMsICZuYl9zZWN0b3JzKTsKICAgICAgICAgICAgbWF0Y2ggPSAtMTsKICAgICAgICAgICAgZmlyc3RfbWF0Y2ggPSAtMTsKICAgICAgICAgICAgZm9yIChpID0gMDs7IGkrKykgewogICAgICAgICAgICAgICAgcGFyc2UgPSAmZmRfZm9ybWF0c1tpXTsKICAgICAgICAgICAgICAgIGlmIChwYXJzZS0+ZHJpdmUgPT0gRkRSSVZFX0RSVl9OT05FKQogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgaWYgKGRydi0+ZHJpdmUgPT0gcGFyc2UtPmRyaXZlIHx8CiAgICAgICAgICAgICAgICAgICAgZHJ2LT5kcml2ZSA9PSBGRFJJVkVfRFJWX05PTkUpIHsKICAgICAgICAgICAgICAgICAgICBzaXplID0gKHBhcnNlLT5tYXhfaGVhZCArIDEpICogcGFyc2UtPm1heF90cmFjayAqCiAgICAgICAgICAgICAgICAgICAgICAgIHBhcnNlLT5sYXN0X3NlY3Q7CiAgICAgICAgICAgICAgICAgICAgaWYgKG5iX3NlY3RvcnMgPT0gc2l6ZSkgewogICAgICAgICAgICAgICAgICAgICAgICBtYXRjaCA9IGk7CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoZmlyc3RfbWF0Y2ggPT0gLTEpCiAgICAgICAgICAgICAgICAgICAgICAgIGZpcnN0X21hdGNoID0gaTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAobWF0Y2ggPT0gLTEpIHsKICAgICAgICAgICAgICAgIGlmIChmaXJzdF9tYXRjaCA9PSAtMSkKICAgICAgICAgICAgICAgICAgICBtYXRjaCA9IDE7CiAgICAgICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICAgICAgbWF0Y2ggPSBmaXJzdF9tYXRjaDsKICAgICAgICAgICAgICAgIHBhcnNlID0gJmZkX2Zvcm1hdHNbbWF0Y2hdOwogICAgICAgICAgICB9CiAgICAgICAgICAgIG5iX2hlYWRzID0gcGFyc2UtPm1heF9oZWFkICsgMTsKICAgICAgICAgICAgbWF4X3RyYWNrID0gcGFyc2UtPm1heF90cmFjazsKICAgICAgICAgICAgbGFzdF9zZWN0ID0gcGFyc2UtPmxhc3Rfc2VjdDsKICAgICAgICAgICAgZHJ2LT5kcml2ZSA9IHBhcnNlLT5kcml2ZTsKICAgICAgICAgICAgRkxPUFBZX0RQUklOVEYoIiVzIGZsb3BweSBkaXNrICglZCBoICVkIHQgJWQgcykgJXNcbiIsIHBhcnNlLT5zdHIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgIG5iX2hlYWRzLCBtYXhfdHJhY2ssIGxhc3Rfc2VjdCwgcm8gPyAicm8iIDogInJ3Iik7CiAgICAgICAgfQogICAgICAgIGlmIChuYl9oZWFkcyA9PSAxKSB7CiAgICAgICAgICAgIGRydi0+ZmxhZ3MgJj0gfkZESVNLX0RCTF9TSURFUzsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBkcnYtPmZsYWdzIHw9IEZESVNLX0RCTF9TSURFUzsKICAgICAgICB9CiAgICAgICAgZHJ2LT5tYXhfd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5lbCBpcyB3ZWxsIHByb2dyYW1tZWQgKi8KICAgICAgICBkbWFfbW9kZSA9IERNQV9nZXRfY2hhbm5lbF9tb2RlKGZkY3RybC0+ZG1hX2NoYW5uKTsKICAgICAgICBkbWFfbW9kZSA9IChkbWFfbW9kZSA+PiAyKSAmIDM7CiAgICAgICAgRkxPUFBZX0RQUklOVEYoImRtYV9tb2RlPSVkIGRpcmVjdGlvbj0lZCAoJWQgLSAlZClcbiIsCiAgICAgICAgICAgICAgICAgICAgICAgZG1hX21vZGUsIGRpcmVjdGlvbiwKICAgICAgICAgICAgICAgICAgICAgICAoMTI4IDw8IGZkY3RybC0+Zmlmb1s1XSkgKgogICAgICAgICAgICAgICAgICAgICAgIChjdXJfZHJ2LT5sYXN0X3NlY3QgLSBrcyArIDEpLCBmZGN0cmwtPmRhdGFfbGVuKTsKICAgICAgICBpZiAoKChkaXJlY3Rpb24gPT0gRkRfRElSX1NDQU5FIHx8IGRpcmVjdGlvbiA9PSBGRF9ESVJfU0NBTkwgfHwKICAgICAgICAgICAgICBkaXJlY3Rpb24gPT0gRkRfRElSX1NDQU5IKSAmJiBkbWFfbW9kZSA9PSAwKSB8fAogICAgICAgICAgICAoZGlyZWN0aW9uID09IEZEX0RJUl9XUklURSAmJiBkbWFfbW9kZSA9PSAyKSB8fAogICAgICAgICAgICAoZGlyZWN0aW9uID09IEZEX0RJUl9SRUFEICYmIGRtYV9tb2RlID09IDEpKSB7CiAgICAgICAgICAgIC8qIE5vIGFjY2VzcyBpcyBhbGxvd2VkIHVudGlsIERNQSB0cmFuc2ZlciBoYXMgY29tcGxldGVkICovCiAgICAgICAgICAgIGZkY3RybC0+bXNyICY9IH5GRF9NU1JfUlFNOwogICAgICAgICAgICAvKiBOb3csIHdlIGp1c3QgaGF2ZSB0byB3YWl0IGZvciB0aGUgRE1BIGNvbnRyb2xsZXIgdG8KICAgICAgICAgICAgICogcmVjYWxsIHVzLi4uCiAgICAgICAgICAgICAqLwogICAgICAgICAgICBETUF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sKICAgICAgICAgICAgLyogUkVBRCAmIFNDQU4gY29tbWFuZHMgYW5kIHJlYWxpZ24gdG8gYSBzZWN0b3IgZm9yIFdSSVRFICovCiAgICAgICAgICAgIGlmIChiZHJ2X3JlYWQoY3VyX2Rydi0+YnMsIGZkX3NlY3RvcihjdXJfZHJ2KSwKICAgICAgICAgICAgICAgICAgICAgICAgICBmZGN0cmwtPmZpZm8sIDEpIDwgMCkgewogICAgICAgICAgICAgICAgRkxPUFBZX0RQUklOVEYoIkZsb3BweTogZXJyb3IgZ2V0dGluZyBzZWN0b3IgJWRcbiIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmZF9zZWN0b3IoY3VyX2RydikpOwogICAgICAgICAgICAgICAgLyogU3VyZSwgaW1hZ2Ugc2l6ZSBpcyB0b28gc21hbGwuLi4gKi8KICAgICAgICAgICAgICAgIG1lbXNldChmZGN0cmwtPmZpZm8sIDAsIEZEX1NFQ1RPUl9MRU4pOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHN3aXRjaCAoZmRjdHJsLT5kYXRhX2RpcikgewogICAgICAgIGNhc2UgRkRfRElSX1JFQUQ6CiAgICAgICAgICAgIC8qIFJFQUQgY29tbWFuZHMgKi8KICAgICAgICAgICAgRE1BX3dyaXRlX21lbW9yeSAobmNoYW4sIGZkY3RybC0+ZmlmbyArIHJlbF9wb3MsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZkY3RybC0+ZGF0YV9wb3MsIGxlbik7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgRkRfRElSX1dSSVRFOgogICAgICAgICAgICAvKiBXUklURSBjb21tYW5kcyAqLwogICAgICAgICAgICBETUFfcmVhZF9tZW1vcnkgKG5jaGFuLCBmZGN0cmwtPmZpZm8gKyByZWxfcG9zLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZkY3RybC0+ZGF0YV9wb3MsIGxlbik7CiAgICAgICAgICAgIGlmIChiZHJ2X3dyaXRlKGN1cl9kcnYtPmJzLCBmZF9zZWN0b3IoY3VyX2RydiksCiAgICAgICAgICAgICAgICAgICAgICAgICAgIGZkY3RybC0+ZmlmbywgMSkgPCAwKSB7CiAgICAgICAgICAgICAgICBGTE9QUFlfRVJST1IoIndyaXRpbmcgc2VjdG9yICVkXG4iLCBmZF9zZWN0b3IoY3VyX2RydikpOwogICAgICAgICAgICAgICAgZmRjdHJsX3N0b3BfdHJhbnNmZXIoZmRjdHJsLCBGRF9TUjBfQUJOVEVSTSB8IEZEX1NSMF9TRUVLLCAweDAwLCAweDAwKTsKICAgICAgICAgICAgICAgIGdvdG8gdHJhbnNmZXJfZXJyb3I7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgLyogU0NBTiBjb21tYW5kcyAqLwogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICB1aW50OF90IHRtcGJ1ZltGRF9TRUNUT1JfTEVOXTsKICAgICAgICAgICAgICAgIGludCByZXQ7CiAgICAgICAgICAgICAgICBETUFfcmVhZF9tZW1vcnkgKG5jaGFuLCB0bXBidWYsIGZkY3RybC0+ZGF0YV9wb3MsIGxlbik7CiAgICAgICAgICAgICAgICByZXQgPSBtZW1jbXAodG1wYnVmLCBmZGN0cmwtPmZpZm8gKyByZWxfcG9zLCBsZW4pOwogICAgICAgICAgICAgICAgaWYgKHJldCA9PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgc3RhdHVzMiA9IEZEX1NSMl9TRUg7CiAgICAgICAgICAgICAgICAgICAgZ290byBlbmRfdHJhbnNmZXI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoKHJldCA8IDAgJiYgZmRjdHJsLT5kYXRhX2RpciA9PSBGRF9ESVJfU0NBTkwpIHx8CiAgICAgICAgICAgICAgICAgICAgKHJldCA+IDAgJiYgZmRjdHJsLT5kYXRhX2RpciA9PSBGRF9ESVJfU0NBTkgpKSB7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cmwsIHN0YXR1czAsIHN0YXR1czEsIHN0YXR1czIpOwogdHJhbnNmZXJfZXJyb3I6CgogICAgcmV0dXJuIGxlbjsKfQoKLyogRGF0YSByZWdpc3RlciA6IDB4MDUgKi8Kc3RhdGljIHVpbnQzMl90IGZkY3RybF9yZWFkX2RhdGEgKGZkY3RybF90ICpmZGN0cmwpCnsKICAgIGZkcml2ZV90ICpjdXJfZHJ2OwogICAgdWludDMyX3QgcmV0dmFsID0gMDsKICAgIGludCBwb3M7CgogICAgY3VyX2RydiA9IGdldF9jdXJfZHJ2KGZkY3RybCk7CiAgICBmZGN0cmwtPmRzciAmPSB+RkRfRFNSX1BXUkRPV047CiAgICBpZiAoIShmZGN0cmwtPm1zciAmIEZEX01TUl9SUU0pIHx8ICEoZmRjdHJsLT5tc3IgJiBGRF9NU1JfRElPKSkgewogICAgICAgIEZMT1BQWV9FUlJPUigiY29udHJvbGxlciBub3QgcmVhZHkgZm9yIHJlYWRpbmdcbiIpOwogICAgICAgIHJldHVybiAwOwogICAgfQogICAgcG9zID0gZmRjdHJsLT5kYXRhX3BvczsKICAgIGlmIChmZGN0cmwtPm1zciAmIEZEX01TUl9OT05ETUEpIHsKICAgICAgICBwb3MgJT0gRkRfU0VDVE9SX0xFTjsKICAgICAgICBpZiAocG9zID09IDApIHsKICAgICAgICAgICAgaWYgKGZkY3RybC0+ZGF0YV9wb3MgIT0gMCkKICAgICAgICAgICAgICAgIGlmICghZmRjdHJsX3NlZWtfdG9fbmV4dF9zZWN0KGZkY3RybCwgY3VyX2RydikpIHsKICAgICAgICAgICAgICAgICAgICBGTE9QUFlfRFBSSU5URigiZXJyb3Igc2Vla2luZyB0byBuZXh0IHNlY3RvciAlZFxuIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmZF9zZWN0b3IoY3VyX2RydikpOwogICAgICAgICAgICAgICAgICAgIHJldHVybiAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoYmRydl9yZWFkKGN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Y3VyX2RydiA9IGdldF9jdXJfZHJ2KGZkY3RybCk7CiAgICAgICAgICAgIGlmIChiZHJ2X3dyaXRlKGN1cl9kcnYtPmJzLCBmZF9zZWN0b3IoY3VyX2RydiksIGZkY3RybC0+ZmlmbywgMSkgPCAwKSB7CiAgICAgICAgICAgICAgICBGTE9QUFlfRVJST1IoIndyaXRpbmcgc2VjdG9yICVkXG4iLCBmZF9zZWN0b3IoY3VyX2RydikpOwogICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICghZmRjdHJsX3NlZWtfdG9fbmV4dF9zZWN0KGZkY3RybCwgY3VyX2RydikpIHsKICAgICAgICAgICAgICAgIEZMT1BQWV9EUFJJTlRGKCJlcnJvciBzZWVraW5nIHRvIG5leHQgc2VjdG9yICVkXG4iLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZmRfc2VjdG9yKGN1cl9kcnYpKTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAvKiBTd2l0Y2ggZnJvbSB0cmFuc2ZlciBtb2RlIHRvIHN0YXR1cyBtb2RlCiAgICAgICAgICogdGhlbiBmcm9tIHN0YXR1cyBtb2RlIHRvIGNvbW1hbmQgbW9kZQogICAgICAgICAqLwogICAgICAgIGlmIChmZGN0cmwtPmRhdGFfcG9zID09IGZkY3RybC0+ZGF0YV9sZW4pCiAgICAgICAgICAgIGZkY3RybF9zdG9wX3RyYW5zZmVyKGZkY3RybCwgRkRfU1IwX1NFRUssIDB4MDAsIDB4MDApOwogICAgICAgIHJldHVybjsKICAgIH0KICAgIGlmIChmZGN0cmwtPmRhdGFfcG9zID09IDApIHsKICAgICAgICAvKiBDb21tYW5kICovCiAgICAgICAgcG9zID0gY29tbWFuZF90b19oYW5kbGVyW3ZhbHVlICYgMHhmZl07CiAgICAgICAgRkxPUFBZX0RQUklOVEYoIiVzIGNvbW1hbmRcbiIsIGhhbmRsZXJzW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AgICAgICAgICAgICAgICAgZmRjdHJsKTsKICAgICAgICByZWdpc3Rlcl9pb3BvcnRfcmVhZCgodWludDMyX3QpaW9fYmFzZSArIDB4MDcsIDEsIDEsICZmZGN0cmxfcmVhZCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmZGN0cmwpOwogICAgICAgIHJlZ2lzdGVyX2lvcG9ydF93cml0ZSgodWludDMyX3QpaW9fYmFzZSArIDB4MDEsIDUsIDEsICZmZGN0cmxfd3JpdGUsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZkY3RybCk7CiAgICAgICAgcmVnaXN0ZXJfaW9wb3J0X3dyaXRlKCh1aW50MzJfdClpb19iYXNlICsgMHgwNywgMSwgMSwgJmZkY3RybF93cml0ZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZmRjdHJsKTsKICAgIH0KCiAgICByZXR1cm4gZmRjdHJsOwp9CgpmZGN0cmxfdCAqc3VuNG1fZmRjdHJsX2luaXQgKHFlbXVfaXJxIGlycSwgdGFyZ2V0X3BoeXNfYWRkcl90IGlvX2Jhc2UsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgQmxvY2tEcml2ZXJTdGF0ZSAqKmZkcywgcWVtdV9pcnEgKmZkY190YykKewogICAgZmRjdHJsX3QgKmZkY3RybDsKICAgIGludCBpb19tZW07CgogICAgZmRjdHJsID0gZmRjdHJsX2luaXRfY29tbW9uKGlycSwgLTEsIGlvX2Jhc2UsIGZkcyk7CiAgICBmZGN0cmwtPnN1bjRtID0gMTsKICAgIGlvX21lbSA9IGNwdV9yZWdpc3Rlcl9pb19tZW1vcnkoMCwgZmRjdHJsX21lbV9yZWFkX3N0cmljdCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZmRjdHJsX21lbV93cml0ZV9zdHJpY3QsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZkY3RybCk7CiAgICBjcHVfcmVnaXN0ZXJfcGh5c2ljYWxfbWV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