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90ICpkcnYpCnsKICAgIGNvbnN0IGZkX2Zvcm1hdF90ICpwYXJzZTsKICAgIHVpbnQ2NF90IG5iX3NlY3RvcnMsIHNpemU7CiAgICBpbnQgaSwgZmlyc3RfbWF0Y2gsIG1hdGNoOwogICAgaW50IG5iX2hlYWRzLCBtYXhfdHJhY2ssIGxhc3Rfc2VjdCwgcm87CgogICAgRkxPUFBZX0RQUklOVEYoInJldmFsaWRhdGVcbiIpOwogICAgaWYgKGRydi0+YnMgIT0gTlVMTCAmJiBiZHJ2X2lzX2luc2VydGVkKGRydi0+YnMpKSB7CiAgICAgICAgcm8gPSBiZHJ2X2lzX3JlYWRfb25seShkcnYtPmJzKTsKICAgICAgICBiZHJ2X2dldF9nZW9tZXRyeV9oaW50KGRydi0+YnMsICZuYl9oZWFkcywgJm1heF90cmFjaywgJmxhc3Rfc2VjdCk7CiAgICAgICAgaWYgKG5iX2hlYWRzICE9IDAgJiYgbWF4X3RyYWNrICE9IDAgJiYgbGFzdF9zZWN0ICE9IDApIHsKICAgICAgICAgICAgRkxPUFBZX0RQUklOVEYoIlVzZXIgZGVmaW5lZCBkaXNrICglZCAlZCAlZCkiLAogICAgICAgICAgICAgICAgICAgICAgICAgICBuYl9oZWFkcyAtIDEsIG1heF90cmFjaywgbGFzdF9zZWN0KTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBiZHJ2X2dldF9nZW9tZXRyeShkcnYtPmJzLCAmbmJfc2VjdG9ycyk7CiAgICAgICAgICAgIG1hdGNoID0gLTE7CiAgICAgICAgICAgIGZpcnN0X21hdGNoID0gLTE7CiAgICAgICAgICAgIGZvciAoaSA9IDA7OyBpKyspIHsKICAgICAgICAgICAgICAgIHBhcnNlID0gJmZkX2Zvcm1hdHNbaV07CiAgICAgICAgICAgICAgICBpZiAocGFyc2UtPmRyaXZlID09IEZEUklWRV9EUlZfTk9ORSkKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIGlmIChkcnYtPmRyaXZlID09IHBhcnNlLT5kcml2ZSB8fAogICAgICAgICAgICAgICAgICAgIGRydi0+ZHJpdmUgPT0gRkRSSVZFX0RSVl9OT05FKSB7CiAgICAgICAgICAgICAgICAgICAgc2l6ZSA9IChwYXJzZS0+bWF4X2hlYWQgKyAxKSAqIHBhcnNlLT5tYXhfdHJhY2sgKgogICAgICAgICAgICAgICAgICAgICAgICBwYXJzZS0+bGFzdF9zZWN0OwogICAgICAgICAgICAgICAgICAgIGlmIChuYl9zZWN0b3JzID09IHNpemUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgbWF0Y2ggPSBpOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaWYgKGZpcnN0X21hdGNoID09IC0xKQogICAgICAgICAgICAgICAgICAgICAgICBmaXJzdF9tYXRjaCA9IGk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKG1hdGNoID09IC0xKSB7CiAgICAgICAgICAgICAgICBpZiAoZmlyc3RfbWF0Y2ggPT0gLTEpCiAgICAgICAgICAgICAgICAgICAgbWF0Y2ggPSAxOwogICAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgICAgIG1hdGNoID0gZmlyc3RfbWF0Y2g7CiAgICAgICAgICAgICAgICBwYXJzZSA9ICZmZF9mb3JtYXRzW21hdGNoXTsKICAgICAgICAgICAgfQogICAgICAgICAgICBuYl9oZWFkcyA9IHBhcnNlLT5tYXhfaGVhZCArIDE7CiAgICAgICAgICAgIG1heF90cmFjayA9IHBhcnNlLT5tYXhfdHJhY2s7CiAgICAgICAgICAgIGxhc3Rfc2VjdCA9IHBhcnNlLT5sYXN0X3NlY3Q7CiAgICAgICAgICAgIGRydi0+ZHJpdmUgPSBwYXJzZS0+ZHJpdmU7CiAgICAgICAgICAgIEZMT1BQWV9EUFJJTlRGKCIlcyBmbG9wcHkgZGlzayAoJWQgaCAlZCB0ICVkIHMpICVzXG4iLCBwYXJzZS0+c3RyLAogICAgICAgICAgICAgICAgICAgICAgICAgICBuYl9oZWFkcywgbWF4X3RyYWNrLCBsYXN0X3NlY3QsIHJvID8gInJvIiA6ICJydyIpOwogICAgICAgIH0KICAgICAgICBpZiAobmJfaGVhZHMgPT0gMSkgewogICAgICAgICAgICBkcnYtPmZsYWdzICY9IH5GRElTS19EQkxfU0lERVM7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgZHJ2LT5mbGFncyB8PSBGRElTS19EQkxfU0lERVM7CiAgICAgICAgfQogICAgICAgIGRydi0+bWF4X3RyYWNrID0gbWF4X3RyYWNrOwogICAgICAgIGRydi0+bGFzdF9zZWN0ID0gbGFzdF9zZWN0OwogICAgICAgIGRydi0+cm8gPSBybzsKICAgIH0gZWxzZSB7CiAgICAgICAgRkxPUFBZX0RQUklOVEYoIk5vIGRpc2sgaW4gZHJpdmVcbiIpOwogICAgICAgIGRydi0+bGFzdF9zZWN0ID0gMDsKICAgICAgICBkcnYtPm1heF90cmFjayA9IDA7CiAgICAgICAgZHJ2LT5mbGFncyAmPSB+RkRJU0tfREJMX1NJREVTOwogICAgfQp9CgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCi8qIEludGVsIDgyMDc4IGZsb3BweSBkaXNrIGNvbnRyb2xsZXIgZW11bGF0aW9uICAgICAgICAgICovCgpzdGF0aWMgdm9pZCBmZGN0cmxfcmVzZXQgKGZkY3RybF90ICpmZGN0cmwsIGludCBkb19pcnEpOwpzdGF0aWMgdm9pZCBmZGN0cmxfcmVzZXRfZmlmbyAoZmRjdHJsX3QgKmZkY3RybCk7CnN0YXRpYyBpbnQgZmRjdHJsX3RyYW5zZmVyX2hhbmRsZXIgKHZvaWQgKm9wYXF1ZSwgaW50IG5jaGFuLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpbnQgZG1hX3BvcywgaW50IGRtYV9sZW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VNSOgogICAgICAgIHJldHZhbCA9IGZkY3RybF9yZWFkX21haW5fc3RhdHVzKGZkY3RybCk7CiAgICAgICAgYnJlYWs7CiAgICBjYXNlIEZEX1JFR19GSUZPOgogICAgICAgIHJldHZhbCA9IGZkY3RybF9yZWFkX2RhdGEoZmRjdHJsKTsKICAgICAgICBicmVhazsKICAgIGNhc2UgRkRfUkVHX0RJUjoKICAgICAgICByZXR2YWwgPSBmZGN0cmxfcmVhZF9kaXIoZmRjdHJsKTsKICAgICAgICBicmVhazsKICAgIGRlZmF1bHQ6CiAgICAgICAgcmV0dmFsID0gKHVpbnQzMl90KSgtMSk7CiAgICAgICAgYnJlYWs7CiAgICB9CiAgICBGTE9QUFlfRFBSSU5URigicmVhZCByZWclZDogMHglMDJ4XG4iLCByZWcgJiA3LCByZXR2YWwpOwoKICAgIHJldHVybiByZXR2YWw7Cn0KCnN0YXRpYyB2b2lkIGZkY3RybF93cml0ZSAodm9pZCAqb3BhcXVlLCB1aW50MzJfdCByZWcsIHVpbnQzMl90IHZhbHVlKQp7CiAgICBmZGN0cmxfdCAqZmRjdHJsID0gb3BhcXVlOwoKICAgIEZMT1BQWV9EUFJJTlRGKCJ3cml0ZSByZWclZDogMHglMDJ4XG4iLCByZWcgJiA3LCB2YWx1ZSk7CgogICAgc3dpdGNoIChyZWcpIHsKICAgIGNhc2UgRkRfUkVHX0RPUjoKICAgICAgICBmZGN0cmxfd3JpdGVfZG9yKGZkY3RybCwgdmFsdWUpOwogICAgICAgIGJyZWFrOwogICAgY2FzZSBGRF9SRUdfVERSOgogICAgICAgIGZkY3RybF93cml0ZV90YXBlKGZkY3RybCwgdmFsdWUpOwogICAgICAgIGJyZWFrOwogICAgY2FzZSBGRF9SRUdfRFNSOgogICAgICAgIGZkY3RybF93cml0ZV9yYXRlKGZkY3RybCwgdmFsdWUpOwogICAgICAgIGJyZWFrOwogICAgY2FzZSBGRF9SRUdfRklGTzoKICAgICAgICBmZGN0cmxfd3JpdGVfZGF0YShmZ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AoY3VyX2Rydi0+ZmxhZ3MgJiBGRElTS19EQkxfU0lERVMpICE9IDApIHsKICAgICAgICAgICAgICAgIGN1cl9kcnYtPmhlYWQgPSAxOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgY3VyX2Rydi0+aGVhZCA9IDA7CiAgICAgICAgICAgICAgICBjdXJfZHJ2LT50cmFjaysrOwogICAgICAgICAgICAgICAgaWYgKChjdXJfZHJ2LT5mbGFncyAmIEZESVNLX0RCTF9TSURFUykgPT0gMCkKICAgICAgICAgICAgICAgICAgICByZXR1cm4gMDsKICAgICAgICAgICAgfQogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGN1cl9kcnYtPnRyYWNrKys7CiAgICAgICAgICAgIHJldHVybiAwOwogICAgICAgIH0KICAgICAgICBGTE9QUFlfRFBSSU5URigic2VlayB0byBuZXh0IHRyYWNrICglZCAlMDJ4ICUwMnggPT4gJWQpXG4iLAogICAgICAgICAgICAgICAgICAgICAgIGN1cl9kcnYtPmhlYWQsIGN1cl9kcnYtPnRyYWNrLAogICAgICAgICAgICAgICAgICAgICAgIGN1cl9kcnYtPnNlY3QsIGZkX3NlY3RvcihjdXJfZHJ2KSk7CiAgICB9IGVsc2UgewogICAgICAgIGN1cl9kcnYtPnNlY3QrKzsKICAgIH0KICAgIHJldHVybiAxOwp9CgovKiBDYWxsYmFjayBmb3IgdHJhbnNmZXIgZW5kIChzdG9wIG9yIGFib3J0KSAqLwpzdGF0aWMgdm9pZCBmZGN0cmxfc3RvcF90cmFuc2ZlciAoZmRjdHJsX3QgKmZkY3RybCwgdWludDhfdCBzdGF0dXMwLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdWludDhfdCBzdGF0dXMxLCB1aW50OF90IHN0YXR1czIpCnsKICAgIGZkcml2ZV90ICpjdXJfZHJ2OwoKICAgIGN1cl9kcnYgPSBnZXRfY3VyX2RydihmZGN0cmwpOwogICAgRkxPUFBZX0RQUklOVEYoInRyYW5zZ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Ul9TQ0FOTCB8fAogICAgICAgICAgICAgIGRpcmVjdGlvbiA9PSBGRF9ESVJfU0NBTkgpICYmIGRtYV9tb2RlID09IDApIHx8CiAgICAgICAgICAgIChkaXJlY3Rpb24gPT0gRkRfRElSX1dSSVRFICYmIGRtYV9tb2RlID09IDIpIHx8CiAgICAgICAgICAgIChkaXJlY3Rpb24gPT0gRkRfRElSX1JFQUQgJiYgZG1hX21vZGUgPT0gMSkpIHsKICAgICAgICAgICAgLyogTm8gYWNjZXNzIGlzIGFsbG93ZWQgdW50aWwgRE1BIHRyYW5zZmVyIGhhcyBjb21wbGV0ZWQgKi8KICAgICAgICAgICAgZmRjdHJsLT5tc3IgJj0gfkZEX01TUl9SUU07CiAgICAgICAgICAgIC8qIE5vdywgd2UganVzdCBoYXZlIHRvIHdhaXQgZm9yIHRoZSBETUEgY29udHJvbGxlciB0bwogICAgICAgICAgICAgKiByZWNhbGwgdXMuLi4KICAgICAgICAgICAgICovCiAgICAgICAgICAgIERNQV9ob2xkX0RSRVEoZmRjdHJsLT5kbWFfY2hhbm4pOwogICAgICAgICAgICBETUFfc2NoZWR1bGUoZmRjdHJsLT5kbWFfY2hhbm4pOwogICAgICAgICAgICByZXR1cm47CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgRkxPUFBZX0VSUk9SKCJkbWFfbW9kZT0lZCBkaXJlY3Rpb249JWRcbiIsIGRtYV9tb2RlLCBkaXJlY3Rpb24pOwogICAgICAgIH0KICAgIH0KICAgIEZMT1BQWV9EUFJJTlRGKCJzdGFydCBub24tRE1BIHRyYW5zZmVyXG4iKTsKICAgIGZkY3RybC0+bXNyIHw9IEZEX01TUl9OT05ETUE7CiAgICBpZiAoZGlyZWN0aW9uICE9IEZEX0RJUl9XUklURSkKICAgICAgICBmZGN0cmwtPm1zciB8PSBGRF9NU1JfRElPOwogICAgLyogSU8gYmFzZWQgdHJhbnNmZXI6IGNhbGN1bGF0ZSBsZW4gKi8KICAgIGZkY3RybF9yYWlzZ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igiY29weSAlZCBieXRlcyAoJWQgJWQgJWQpICVkIHBvcyAlZCAlMDJ4ICIKICAgICAgICAgICAgICAgICAgICAgICAiKCVkLTB4JTA4eCAweCUwOHgpXG4iLCBsZW4sIGRtYV9sZW4sIGZkY3RybC0+ZGF0YV9wb3MsCiAgICAgICAgICAgICAgICAgICAgICAgZmRjdHJsLT5kYXRhX2xlbiwgR0VUX0NVUl9EUlYoZmRjdHJsKSwgY3VyX2Rydi0+aGVhZCwKICAgICAgICAgICAgICAgICAgICAgICBjdXJfZHJ2LT50cmFjaywgY3VyX2Rydi0+c2VjdCwgZmRfc2VjdG9yKGN1cl9kcnYpLAogICAgICAgICAgICAgICAgICAgICAgIGZkX3NlY3RvcihjdXJfZHJ2KSAqIEZEX1NFQ1RPUl9MRU4pOwogICAgICAgIGlmIChmZGN0cmwtPmRhdGFfZGlyICE9IEZEX0RJUl9XUklURSB8fAogICAgICAgICAgICBsZW4gPCBGRF9TRUNUT1JfTEVOIHx8IHJlbF9wb3MgIT0gMCkgewogICAgICAgICAgICAvKiBSRUFEICYgU0NBTiBjb21tYW5kcyBhbmQgcmVhbGlnbiB0byBhIHNlY3RvciBmb3IgV1JJVEUgKi8KICAgICAgICAgICAgaWYgKGJkcnZfcmVhZChjdXJfZHJ2LT5icywgZmRfc2VjdG9yKGN1cl9kcnYpLAogICAgICAgICAgICAgICAgICAgICAgICAgIGZkY3RybC0+ZmlmbywgMSkgPCAwKSB7CiAgICAgICAgICAgICAgICBGTE9QUFlfRFBSSU5URigiRmxvcHB5OiBlcnJvciBnZXR0aW5nIHNlY3RvciAlZFxuIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZkX3NlY3RvcihjdXJfZHJ2KSk7CiAgICAgICAgICAgICAgICAvKiBTdXJlLCBpbWFnZSBzaXplIGlzIHRvbyBzbWFsbC4uLiAqLwogICAgICAgICAgICAgICAgbWVtc2V0KGZkY3RybC0+ZmlmbywgMCwgRkRfU0VDVE9SX0xFTik7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgc3dpdGNoIChmZGN0cmwtPmRhdGFfZGlyKSB7CiAgICAgICAgY2FzZSBGRF9ESVJfUkVBRDoKICAgICAgICAgICAgLyogUkVBRCBjb21tYW5kcyAqLwogICAgICAgICAgICBETUFfd3JpdGVfbWVtb3J5IChuY2hhbiwgZmRjdHJsLT5maWZvICsgcmVsX3BvcywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZmRjdHJsLT5kYXRhX3BvcywgbGVuKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBGRF9ESVJfV1JJVEU6CiAgICAgICAgICAgIC8qIFdSSVRFIGNvbW1hbmRzICovCiAgICAgICAgICAgIERNQV9yZWFkX21lbW9yeSAobmNoYW4sIGZkY3RybC0+ZmlmbyArIHJlbF9wb3MsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZmRjdHJsLT5kYXRhX3BvcywgbGVuKTsKICAgICAgICAgICAgaWYgKGJkcnZfd3JpdGUoY3VyX2Rydi0+YnMsIGZkX3NlY3RvcihjdXJfZHJ2KSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgZmRjdHJsLT5maWZvLCAxKSA8IDApIHsKICAgICAgICAgICAgICAgIEZMT1BQWV9FUlJPUigid3JpdGluZyBzZWN0b3IgJWRcbiIsIGZkX3NlY3RvcihjdXJfZHJ2KSk7CiAgICAgICAgICAgICAgICBmZGN0cmxfc3RvcF90cmFuc2ZlcihmZGN0cmwsIEZEX1NSMF9BQk5URVJNIHwgRkRfU1IwX1NFRUssIDB4MDAsIDB4MDApOwogICAgICAgICAgICAgICAgZ290byB0cmFuc2Zlcl9lcnJvcjsKICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAvKiBTQ0FOIGNvbW1hbmRzICovCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHVpbnQ4X3QgdG1wYnVmW0ZEX1NFQ1RPUl9MRU5dOwogICAgICAgICAgICAgICAgaW50IHJldDsKICAgICAgICAgICAgICAgIERNQV9yZWFkX21lbW9yeSAobmNoYW4sIHRtcGJ1ZiwgZmRjdHJsLT5kYXRhX3BvcywgbGVuKTsKICAgICAgICAgICAgICAgIHJldCA9IG1lbWNtcCh0bXBidWYsIGZkY3RybC0+ZmlmbyArIHJlbF9wb3MsIGxlbik7CiAgICAgICAgICAgICAgICBpZiAocmV0ID09IDApIHsKICAgICAgICAgICAgICAgICAgICBzdGF0dXMyID0gRkRfU1IyX1NFSDsKICAgICAgICAgICAgICAgICAgICBnb3RvIGVuZF90cmFuc2ZlcjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmICgocmV0IDwgMCAmJiBmZGN0cmwtPmRhdGFfZGlyID09IEZEX0RJUl9TQ0FOTCkgfHwKICAgICAgICAgICAgICAgICAgICAocmV0ID4gMCAmJiBmZGN0cmwtPmRhdGFfZGlyID09IEZEX0RJUl9TQ0FOSCkpIHsKICAgICAgICAgICAgICAgICAgICBzdGF0dXMyID0gMHgwMDsKICAgICAgICAgICAgICAgICAgICBnb3RvIGVuZF90cmFuc2ZlcjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgZmRjdHJsLT5kYXRhX3BvcyArPSBsZW47CiAgICAgICAgcmVsX3BvcyA9IGZkY3RybC0+ZGF0YV9wb3MgJSBGRF9TRUNUT1JfTEVOOwogICAgICAgIGlmIChyZWxfcG9zID09IDApIHsKICAgICAgICAgICAgLyogU2VlayB0byBuZXh0IHNlY3RvciAqLwogICAgICAgICAgICBpZiAoIWZkY3RybF9zZWVrX3RvX25leHRfc2VjdChmZGN0cmwsIGN1cl9kcnYpKQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfQogICAgfQogZW5kX3RyYW5zZmVyOgogICAgbGVuID0gZmRjdHJsLT5kYXRhX3BvcyAtIHN0YXJ0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iAgICAgICAgcmV0dXJuIDA7CiAgICB9CiAgICBwb3MgPSBmZGN0cmwtPmRhdGFfcG9zOwogICAgaWYgKGZkY3RybC0+bXNyICYgRkRfTVNSX05PTkRNQSkgewogICAgICAgIHBvcyAlPSBGRF9TRUNUT1JfTEVOOwogICAgICAgIGlmIChwb3MgPT0gMCkgewogICAgICAgICAgICBpZiAoZmRjdHJsLT5kYXRhX3BvcyAhPSAwKQogICAgICAgICAgICAgICAgaWYgKCFmZGN0cmxfc2Vla190b19uZXh0X3NlY3QoZmRjdHJsLCBjdXJfZHJ2KSkgewogICAgICAgICAgICAgICAgICAgIEZMT1BQWV9EUFJJTlRGKCJlcnJvciBzZWVraW5nIHRvIG5leHQgc2VjdG9yICVkXG4iLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZkX3NlY3RvcihjdXJfZHJ2KSk7CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChiZHJ2X3JlYWQoY3VyX2Rydi0+YnMsIGZkX3NlY3RvcihjdXJfZHJ2KSwgZmRjdHJsLT5maWZvLCAxKSA8IDApIHsKICAgICAgICAgICAgICAgIEZMT1BQWV9EUFJJTlRGKCJlcnJvciBnZXR0aW5nIHNlY3RvciAlZFxuIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZkX3NlY3RvcihjdXJfZHJ2KSk7CiAgICAgICAgICAgICAgICAvKiBTdXJlLCBpbWFnZSBzaXplIGlzIHRvbyBzbWFsbC4uLiAqLwogICAgICAgICAgICAgICAgbWVtc2V0KGZkY3RybC0+ZmlmbywgMCwgRkRfU0VDVE9SX0xFTik7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICByZXR2YWwgPSBmZGN0cmwtPmZpZm9bcG9zXTsKICAgIGlmICgrK2ZkY3RybC0+ZGF0YV9wb3MgPT0gZmRjdHJsLT5kYXRhX2xlbikgewogICAgICAgIGZkY3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ICAgKmZkY190YyA9IHFkZXZfZ2V0X2dwaW9faW4oZGV2LCAwKTsKCiAgICBmZGN0cmwtPmRtYV9jaGFubiA9IC0xOwoKICAgIGZkY3RybF9jb25uZWN0X2RyaXZlcyhmZGN0cmwsIGZkcyk7CgogICAgcmV0dXJuIGZkY3RybDsKfQoKc3RhdGljIGludCBmZGN0cmxfaW5pdF9jb21tb24oZmRjdHJsX3QgKmZkY3RybCkKewogICAgaW50IGksIGo7CiAgICBzdGF0aWMgaW50IGNvbW1hbmRfdGFibGVzX2luaXRlZCA9IDA7CgogICAgLyogRmlsbCAnY29tbWFuZF90b19oYW5kbGVyJyBsb29rdXAgdGFibGUgKi8KICAgIGlmICghY29tbWFuZF90YWJsZXNfaW5pdGVkKSB7CiAgICAgICAgY29tbWFuZF90YWJsZXNfaW5pdGVkID0gMTsKICAgICAgICBmb3IgKGkgPSBBUlJBWV9TSVpFKGhhbmRsZXJzKSAtIDE7IGkgPj0gMDsgaS0tKSB7CiAgICAgICAgICAgIGZvciAoaiA9IDA7IGogPCBzaXplb2YoY29tbWFuZF90b19oYW5kbGVyKTsgaisrKSB7CiAgICAgICAgICAgICAgICBpZiAoKGogJiBoYW5kbGVyc1tpXS5tYXNrKSA9PSBoYW5kbGVyc1tpXS52YWx1ZSkgewogICAgICAgICAgICAgICAgICAgIGNvbW1hbmRfdG9faGFuZGxlcltqXSA9IGk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CgogICAgRkxPUFBZX0RQUklOVEYoImluaXQgY29udHJvbGxlclxuIik7CiAgICBmZGN0cmwtPmZpZm8gPSBxZW11X21lbWFsaWduKDUxMiwgRkRfU0VDVE9SX0xFTik7CiAgICBmZGN0cmwtPmZpZm9fc2l6ZSA9IDUxMjsKICAgIGZkY3RybC0+cmVzdWx0X3RpbWVyID0gcWVtdV9uZXdfdGltZXIodm1fY2xvY2ssCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg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