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yeCAobWF4PSVkICVkICUwMnggJTAyeClcbiIsCiAgICAgICAgICAgICAgICAgICAgICAgaGVhZCwgdHJhY2ssIHNlY3QsIDEsCiAgICAgICAgICAgICAgICAgICAgICAgKGRydi0+ZmxhZ3MgJiBGRElTS19EQkxfU0lERVMpID09IDAgPyAwIDogMSwKICAgICAgICAgICAgICAgICAgICAgICBkcnYtPm1heF90cmFjaywgZHJ2LT5sYXN0X3NlY3QpOwogICAgICAgIHJldHVybiAzOwogICAgfQogICAgc2VjdG9yID0gZmRfc2VjdG9yX2NhbGMoaGVhZCwgdHJhY2ssIHNlY3QsIGRydi0+bGFzdF9zZWN0KTsKICAgIHJldCA9IDA7CiAgICBpZiAoc2VjdG9yICE9IGZkX3NlY3RvcihkcnYpKSB7CiNpZiAwCiAgICAgICAgaWYgKCFlbmFibGVfc2VlaykgewogICAgICAgICAgICBGTE9QUFlfRVJST1IoIm5vIGltcGxpY2l0IHNlZWsgJWQgJTAyeCAlMDJ4IChtYXg9JWQgJTAyeCAlMDJ4KVxuIiwKICAgICAgICAgICAgICAgICAgICAgICAgIGhlYWQsIHRyYWNrLCBzZWN0LCAxLCBkcnYtPm1heF90cmFjaywgZHJ2LT5sYXN0X3NlY3QpOwogICAgICAgICAgICByZXR1cm4gNDsKICAgICAgICB9CiNlbmRpZgogICAgICAgIGRydi0+aGVhZCA9IGhlYWQ7CiAgICAgICAgaWYgKGRydi0+dHJhY2sgIT0gdHJhY2spCiAgICAgICAgICAgIHJldCA9IDE7CiAgICAgICAgZHJ2LT50cmFjayA9IHRyYWNrOwogICAgICAgIGRydi0+c2VjdCA9IHNlY3Q7CiAgICB9CgogICAgcmV0dXJuIHJldDsKfQoKLyogU2V0IGRyaXZlIGJhY2sgdG8gdHJhY2sgMCAqLwpzdGF0aWMgdm9pZCBmZF9yZWNhbGlicmF0ZShGRHJpdmUgKmRydikKewogICAgRkxPUFBZX0RQUklOVEYoInJlY2FsaWJyYXRlXG4iKTsKICAgIGRydi0+aGVhZCA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aXplID0gKHBhcnNlLT5tYXhfaGVhZCArIDEpICogcGFyc2UtPm1heF90cmFjayAqCiAgICAgICAgICAgICAgICAgICAgICAgIHBhcnNlLT5sYXN0X3NlY3Q7CiAgICAgICAgICAgICAgICAgICAgaWYgKG5iX3NlY3RvcnMgPT0gc2l6ZSkgewogICAgICAgICAgICAgICAgICAgICAgICBtYXRjaCA9IGk7CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoZmlyc3RfbWF0Y2ggPT0gLTEpCiAgICAgICAgICAgICAgICAgICAgICAgIGZpcnN0X21hdGNoID0gaTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAobWF0Y2ggPT0gLTEpIHsKICAgICAgICAgICAgICAgIGlmIChmaXJzdF9tYXRjaCA9PSAtMSkKICAgICAgICAgICAgICAgICAgICBtYXRjaCA9IDE7CiAgICAgICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICAgICAgbWF0Y2ggPSBmaXJzdF9tYXRjaDsKICAgICAgICAgICAgICAgIHBhcnNlID0gJmZkX2Zvcm1hdHNbbWF0Y2hdOwogICAgICAgICAgICB9CiAgICAgICAgICAgIG5iX2hlYWRzID0gcGFyc2UtPm1heF9oZWFkICsgMTsKICAgICAgICAgICAgbWF4X3RyYWNrID0gcGFyc2UtPm1heF90cmFjazsKICAgICAgICAgICAgbGFzdF9zZWN0ID0gcGFyc2UtPmxhc3Rfc2VjdDsKICAgICAgICAgICAgZHJ2LT5kcml2ZSA9IHBhcnNlLT5kcml2ZTsKICAgICAgICAgICAgRkxPUFBZX0RQUklOVEYoIiVzIGZsb3BweSBkaXNrICglZCBoICVkIHQgJWQgcykgJXNcbiIsIHBhcnNlLT5zdHIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgIG5iX2hlYWRzLCBtYXhfdHJhY2ssIGxhc3Rfc2VjdCwgcm8gPyAicm8iIDogInJ3Iik7CiAgICAgICAgfQogICAgICAgIGlmIChuYl9oZWFkcyA9PSAxKSB7CiAgICAgICAgICAgIGRydi0+ZmxhZ3MgJj0gfkZESVNLX0RCTF9TSURFUzsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBkcnYtPmZsYWdzIHw9IEZESVNLX0RCTF9TSURFUzsKICAgICAgICB9CiAgICAgICAgZHJ2LT5tYXhfdHJhY2sgPSBtYXhfdHJhY2s7CiAgICAgICAgZHJ2LT5sYXN0X3NlY3QgPSBsYXN0X3NlY3Q7CiAgICAgICAgZHJ2LT5ybyA9IHJvOwogICAgfSBlbHNlIHsKICAgICAgICBGTE9QUFlfRFBSSU5URigiTm8gZGlzayBpbiBkcml2ZVxuIik7CiAgICAgICAgZHJ2LT5sYXN0X3NlY3QgPSAwOwogICAgICAgIGRydi0+bWF4X3RyYWNrID0gMDsKICAgICAgICBkcnYtPmZsYWdzICY9IH5GRElTS19EQkxfU0lERVM7CiAgICB9Cn0KCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KLyogSW50ZWwgODIwNzggZmxvcHB5IGRpc2sgY29udHJvbGxlciBlbXVsYXRpb24gICAgICAgICAgKi8KCnN0YXRpYyB2b2lkIGZkY3RybF9yZXNldChGREN0cmwgKmZkY3RybCwgaW50IGRvX2lycSk7CnN0YXRpYyB2b2lkIGZkY3RybF9yZXNldF9maWZvKEZEQ3RybCAqZmRjdHJsKTsKc3RhdGljIGludCBmZGN0cmxfdHJhbnNmZXJfaGFuZGxlciAodm9pZCAqb3BhcXVlLCBpbnQgbmNoYW4sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGludCBkbWFfcG9zLCBpbnQgZG1hX2xlbik7CnN0YXRpYyB2b2lkIGZkY3RybF9yYWlzZV9pcnEoRkRDdHJsICpmZGN0cmwsIHVpbnQ4X3Qgc3RhdHVzMCk7CgpzdGF0aWMgdWludDMyX3QgZm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mwtPmVvdCkgewogICAgICAgIGN1cl9kcnYtPnNlY3QgPSAxOwogICAgICAgIGlmIChGRF9NVUxUSV9UUkFDSyhmZGN0cmwtPmRhdGFfc3RhdGUpKSB7CiAgICAgICAgICAgIGlmIChjdXJfZHJ2LT5oZWFkID09IDAgJiYKICAgICAgICAgICAgICAgIChjdXJfZHJ2LT5mbGFncyAmIEZESVNLX0RCTF9TSURFUykgIT0gMCkgewogICAgICAgICAgICAgICAgY3VyX2Rydi0+aGVhZCA9IDE7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBjdXJfZHJ2LT5oZWFkID0gMDsKICAgICAgICAgICAgICAgIGN1cl9kcnYtPnRyYWNrKys7CiAgICAgICAgICAgICAgICBpZiAoKGN1cl9kcnYtPmZsYWdzICYgRkRJU0tfREJMX1NJREVTKSA9PSAwKQogICAgICAgICAgICAgICAgICAgIHJldHVybiAwOwogICAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgY3VyX2Rydi0+dHJhY2srKzsKICAgICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgfQogICAgICAgIEZMT1BQWV9EUFJJTlRGKCJzZWVrIHRvIG5leHQgdHJhY2sgKCVkICUwMnggJTAyeCA9PiAlZClcbiIsCiAgICAgICAgICAgICAgICAgICAgICAgY3VyX2Rydi0+aGVhZCwgY3VyX2Rydi0+dHJhY2ssCiAgICAgICAgICAgICAgICAgICAgICAgY3VyX2Rydi0+c2VjdCwgZmRfc2VjdG9yKGN1cl9kcnYpKTsKICAgIH0gZWxzZSB7CiAgICAgICAgY3VyX2Rydi0+c2VjdCsrOwogICAgfQogICAgcmV0dXJuIDE7Cn0KCi8qIENhbGxiYWNrIGZvciB0cmFuc2ZlciBlbmQgKHN0b3Agb3IgYWJvcnQpICovCnN0YXRpYyB2b2lkIGZkY3RybF9zdG9wX3RyYW5zZmVyKEZEQ3RybCAqZmRjdHJsLCB1aW50OF90IHN0YXR1czAsCiAgICA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ZkY3RybC0+Zmlmb1s1XSkgKgogICAgICAgICAgICAgICAgICAgICAgIChjdXJfZHJ2LT5sYXN0X3NlY3QgLSBrcyArIDEpLCBmZGN0cmwtPmRhdGFfbGVuKTsKICAgICAgICBpZiAoKChkaXJlY3Rpb24gPT0gRkRfRElSX1NDQU5FIHx8IGRpcmVjdGlvbiA9PSBGRF9ESVJfU0NBTkwgfHwKICAgICAgICAgICAgICBkaXJlY3Rpb24gPT0gRkRfRElSX1NDQU5IKSAmJiBkbWFfbW9kZSA9PSAwKSB8fAogICAgICAgICAgICAoZGlyZWN0aW9uID09IEZEX0RJUl9XUklURSAmJiBkbWFfbW9kZSA9PSAyKSB8fAogICAgICAgICAgICAoZGlyZWN0aW9uID09IEZEX0RJUl9SRUFEICYmIGRtYV9tb2RlID09IDEpKSB7CiAgICAgICAgICAgIC8qIE5vIGFjY2VzcyBpcyBhbGxvd2VkIHVudGlsIERNQSB0cmFuc2ZlciBoYXMgY29tcGxldGVkICovCiAgICAgICAgICAgIGZkY3RybC0+bXNyICY9IH5GRF9NU1JfUlFNOwogICAgICAgICAgICAvKiBOb3csIHdlIGp1c3QgaGF2ZSB0byB3YWl0IGZvciB0aGUgRE1BIGNvbnRyb2xsZXIgdG8KICAgICAgICAgICAgICogcmVjYWxsIHVzLi4uCiAgICAgICAgICAgICAqLwogICAgICAgICAgICBETUFfaG9sZF9EUkVRKGZkY3RybC0+ZG1hX2NoYW5uKTsKICAgICAgICAgICAgRE1BX3NjaGVkdWxlKGZkY3RybC0+ZG1hX2NoYW5uKTsKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIEZMT1BQWV9FUlJPUigiZG1hX21vZGU9JWQgZGlyZWN0aW9uPSVkXG4iLCBkbWFfbW9kZSwgZGlyZWN0aW9uKTsKICAgICAgICB9CiAgICB9CiAgICBGTE9QUFlfRFBSSU5URigic3RhcnQgbm9uLURNQSB0cmFuc2ZlclxuIik7CiAgICBmZGN0c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GVuID0gZG1hX2xlbiAtIGZkY3RybC0+ZGF0YV9wb3M7CiAgICAgICAgaWYgKGxlbiArIHJlbF9wb3MgPiBGRF9TRUNUT1JfTEVOKQogICAgICAgICAgICBsZW4gPSBGRF9TRUNUT1JfTEVOIC0gcmVsX3BvczsKICAgICAgICBGTE9QUFlfRFBSSU5URigiY29weSAlZCBieXRlcyAoJWQgJWQgJWQpICVkIHBvcyAlZCAlMDJ4ICIKICAgICAgICAgICAgICAgICAgICAgICAiKCVkLTB4JTA4eCAweCUwOHgpXG4iLCBsZW4sIGRtYV9sZW4sIGZkY3RybC0+ZGF0YV9wb3MsCiAgICAgICAgICAgICAgICAgICAgICAgZmRjdHJsLT5kYXRhX2xlbiwgR0VUX0NVUl9EUlYoZmRjdHJsKSwgY3VyX2Rydi0+aGVhZCwKICAgICAgICAgICAgICAgICAgICAgICBjdXJfZHJ2LT50cmFjaywgY3VyX2Rydi0+c2VjdCwgZmRfc2VjdG9yKGN1cl9kcnYpLAogICAgICAgICAgICAgICAgICAgICAgIGZkX3NlY3RvcihjdXJfZHJ2KSAqIEZEX1NFQ1RPUl9MRU4pOwogICAgICAgIGlmIChmZGN0cmwtPmRhdGFfZGlyICE9IEZEX0RJUl9XUklURSB8fAogICAgICAgICAgICBsZW4gPCBGRF9TRUNUT1JfTEVOIHx8IHJlbF9wb3MgIT0gMCkgewogICAgICAgICAgICAvKiBSRUFEICYgU0NBTiBjb21tYW5kcyBhbmQgcmVhbGlnbiB0byBhIHNlY3RvciBmb3IgV1JJVEUgKi8KICAgICAgICAgICAgaWYgKGJkcnZfcmVhZChjdXJfZHJ2LT5icywgZmRfc2VjdG9yKGN1cl9kcnYpLAogICAgICAgICAgICAgICAgICAgICAgICAgIGZkY3RybC0+ZmlmbywgMSkgPCAwKSB7CiAgICAgICAgICAgICAgICBGTE9QUFlfRFBSSU5URigiRmxvcHB5OiBlcnJvciBnZXR0aW5nIHNlY3RvciAlZFxuIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZkX3NlY3RvcihjdXJfZHJ2KSk7CiAgICAgICAgICAgICAgICAvKiBTdXJlLCBpbWFnZSBzaXplIGlzIHRvbyBzbWFsbC4uLiAqLwogICAgICAgICAgICAgICAgbWVtc2V0KGZkY3RybC0+ZmlmbywgMCwgRkRfU0VDVE9SX0xFTik7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgc3dpdGNoIChmZGN0cmwtPmRhdGFfZGlyKSB7CiAgICAgICAgY2FzZSBGRF9ESVJfUkVBRDoKICAgICAgICAgICAgLyogUkVBRCBjb21tYW5kcyAqLwogICAgICAgICAgICBETUFfd3JpdGVfbWVtb3J5IChuY2hhbiwgZmRjdHJsLT5maWZvICsgcmVsX3BvcywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZmRjdHJsLT5kYXRhX3BvcywgbGVuKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBGRF9ESVJfV1JJVEU6CiAgICAgICAgICAgIC8qIFdSSVRFIGNvbW1hbmRzICovCiAgICAgICAgICAgIERNQV9yZWFkX21lbW9yeSAobmNoYW4sIGZkY3RybC0+ZmlmbyArIHJlbF9wb3MsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZmRjdHJsLT5kYXRhX3BvcywgbGVuKTsKICAgICAgICAgICAgaWYgKGJkcnZfd3JpdGUoY3VyX2Rydi0+YnMsIGZkX3NlY3RvcihjdXJfZHJ2KSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgZmRjdHJsLT5maWZvLCAxKSA8IDApIHsKICAgICAgICAgICAgICAgIEZMT1BQWV9FUlJPUigid3JpdGluZyBzZWN0b3IgJWRcbiIsIGZkX3NlY3RvcihjdXJfZHJ2KSk7CiAgICAgICAgICAgICAgICBmZGN0cmxfc3RvcF90cmFuc2ZlcihmZGN0cmwsIEZEX1NSMF9BQk5URVJNIHwgRkRfU1IwX1NFRUssIDB4MDAsIDB4MDApOwogICAgICAgICAgICAgICAgZ290byB0cmFuc2Zlcl9lcnJvcjsKICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAvKiBTQ0FOIGNvbW1hbmRzICovCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHVpbnQ4X3QgdG1wYnVmW0ZEX1NFQ1RPUl9MRU5dOwogICAgICAgICAgICAgICAgaW50IHJldDsKICAgICAgICAgICAgICAgIERNQV9yZWFkX21lbW9yeSAobmNoYW4sIHRtcGJ1ZiwgZmRjdHJsLT5kYXRhX3BvcywgbGVuKTsKICAgICAgICAgICAgICAgIHJldCA9IG1lbWNtcCh0bXBidWYsIGZkY3RybC0+ZmlmbyArIHJlbF9wb3MsIGxlbik7CiAgICAgICAgICAgICAgICBpZiAocmV0ID09IDApIHsKICAgICAgICAgICAgICAgICAgICBzdGF0dXMyID0gRkRfU1IyX1NFSDsKICAgICAgICAgICAgICAgICAgICBnb3RvIGVuZF90cmFuc2ZlcjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmICgocmV0IDwgMCAmJiBmZGN0cmwtPmRhdGFfZGlyID09IEZEX0RJUl9TQ0FOTCkgfHwKICAgICAgICAgICAgICAgICAgICAocmV0ID4gMCAmJiBmZGN0cmwtPmRhdGFfZGlyID09IEZEX0RJUl9TQ0FOSCkpIHsKICAgICAgICAgICAgICAgICAgICBzdGF0dXMyID0gMHgwMDsKICAgICAgICAgICAgICAgICAgICBnb3RvIGVuZF90cmFuc2ZlcjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgZmRjdHJsLT5kYXRhX3BvcyArPSBsZW47CiAgICAgICAgcmVsX3BvcyA9IGZkY3RybC0+ZGF0YV9wb3MgJSBGRF9TRUNUT1JfTEVOOwogICAgICAgIGlmIChyZWxfcG9zID09IDApIHsKICAgICAgICAgICAgLyogU2VlayB0byBuZXh0IHNlY3RvciAqLwogIC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gICBpZiAoIShmZGN0cmwtPm1zciAmIEZEX01TUl9SUU0pIHx8ICEoZmRjdHJsLT5tc3IgJiBGRF9NU1JfRElPKSkgewogICAgICAgIEZMT1BQWV9FUlJPUigiY29udHJvbGxlciBub3QgcmVhZHkgZm9yIHJlYWRpbmdcbiIpOwogICAgICAgIHJldHVybiAwOwogICAgfQogICAgcG9zID0gZmRjdHJsLT5kYXRhX3BvczsKICAgIGlmIChmZGN0cmwtPm1zciAmIEZEX01TUl9OT05ETUEpIHsKICAgICAgICBwb3MgJT0gRkRfU0VDVE9SX0xFTjsKICAgICAgICBpZiAocG9zID09IDApIHsKICAgICAgICAgICAgaWYgKGZkY3RybC0+ZGF0YV9wb3MgIT0gMCkKICAgICAgICAgICAgICAgIGlmICghZmRjdHJsX3NlZWtfdG9fbmV4dF9zZWN0KGZkY3RybCwgY3VyX2RydikpIHsKICAgICAgICAgICAgICAgICAgICBGTE9QUFlfRFBSSU5URigiZXJyb3Igc2Vla2luZyB0byBuZXh0IHNlY3RvciAlZFxuIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmZF9zZWN0b3IoY3VyX2RydikpOwogICAgICAgICAgICAgICAgICAgIHJldHVybiAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoYmRydl9yZWFkKGN1cl9kcnYtPmJzLCBmZF9zZWN0b3IoY3VyX2RydiksIGZkY3RybC0+ZmlmbywgMSkgPCAwKSB7CiAgICAgICAgICAgICAgICBGTE9QUFlfRFBSSU5URigiZXJyb3IgZ2V0dGluZyBzZWN0b3IgJWRcbiIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmZF9zZWN0b3IoY3VyX2RydikpOwogICAgICAgICAgICAgICAgLyogU3VyZSwgaW1hZ2Ugc2l6ZSBpcyB0b28gc21hbGwuLi4gKi8KICAgICAgICAgICAgICAgIG1lbXNldChmZGN0cmwtPmZpZm8sIDAsIEZEX1NFQ1RPUl9MRU4pOwogICAgICAgICAgICB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MgaW50IGZkY3RybF9jb25uZWN0X2RyaXZlcyhGREN0cmwgKmZkY3RybCkKewogICAgdW5zaWduZWQgaW50IGk7CiAgICBGRHJpdmUgKmRyaXZlOwoKICAgIGZvciAoaSA9IDA7IGkgPCBNQVhfRkQ7IGkrKykgewogICAgICAgIGRyaXZlID0gJmZkY3RybC0+ZHJpdmVzW2ldOwoKICAgICAgICBpZiAoZHJpdmUtPmJzKSB7CiAgICAgICAgICAgIGlmIChiZHJ2X2dldF9vbl9lcnJvcihkcml2ZS0+YnMsIDApICE9IEJMT0NLX0VSUl9TVE9QX0VOT1NQQykgewogICAgICAgICAgICAgICAgZXJyb3JfcmVwb3J0KCJmZGMgZG9lc24ndCBzdXBwb3J0IGRyaXZlIG9wdGlvbiB3ZXJyb3IiKTsKICAgICAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoYmRydl9nZXRfb25fZXJyb3IoZHJpdmUtPmJzLCAxKSAhPSBCTE9DS19FUlJfUkVQT1JUKSB7CiAgICAgICAgICAgICAgICBlcnJvcl9yZXBvcnQoImZkYyBkb2Vzbid0IHN1cHBvcnQgZHJpdmUgb3B0aW9uIHJlcnJvciIpOwogICAgICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICBmZF9pbml0KGRyaXZlKTsKICAgICAgICBmZF9yZXZhbGlkYXRlKGRyaXZlKTsKICAgICAgICBpZiAoZHJpdmUtPmJzKSB7CiAgICAgICAgICAgIGJkcnZfc2V0X3JlbW92YWJsZShkcml2ZS0+YnMsIDEpOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiAwOwp9CgpGREN0cmwgKmZkY3RybF9pbml0X2lzYShEcml2ZUluZm8gKipmZHMpCnsKICAgIElTQURldmljZSAqZGV2OwoKICAgIGRldiA9IGlzYV9jcmVhdGUoImlzYS1mZGMiKTsKICAgIGlmIChmZHNbMF0pIHsKICAgICAgICBxZGV2X3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W5kbGVyJyBsb29rdXAgdGFibGUgKi8KICAgIGlmICghY29tbWFuZF90YWJsZXNfaW5pdGVkKSB7CiAgICAgICAgY29tbWFuZF90YWJsZXNfaW5pdGVkID0gMTsKICAgICAgICBmb3IgKGkgPSBBUlJBWV9TSVpFKGhhbmRsZXJzKSAtIDE7IGkgPj0gMDsgaS0tKSB7CiAgICAgICAgICAgIGZvciAoaiA9IDA7IGogPCBzaXplb2YoY29tbWFuZF90b19oYW5kbGVyKTsgaisrKSB7CiAgICAgICAgICAgICAgICBpZiAoKGogJiBoYW5kbGVyc1tpXS5tYXNrKSA9PSBoYW5kbGVyc1tpXS52YWx1ZSkgewogICAgICAgICAgICAgICAgICAgIGNvbW1hbmRfdG9faGFuZGxlcltqXSA9IGk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CgogICAgRkxPUFBZX0RQUklOVEYoImluaXQgY29udHJvbGxlclxuIik7CiAgICBmZGN0cmwtPmZpZm8gPSBxZW11X21lbWFsaWduKDUxMiwgRkRfU0VDVE9SX0xFTik7CiAgICBmZGN0cmwtPmZpZm9fc2l6ZSA9IDUxMjsKICAgIGZkY3RybC0+cmVzdWx0X3RpbWVyID0gcWVtdV9uZXdfdGltZXIodm1fY2xvY2ssCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZkY3RybF9yZXN1bHRfdGltZXIsIGZkY3RybCk7CgogICAgZmRjdHJsLT52ZXJzaW9uID0gMHg5MDsgLyogSW50ZWwgODIwNzggY29udHJvbGxlciAqLwogICAgZmRjdHJsLT5jb25maWcgPSBGRF9DT05GSUdfRUlTIHwgRkRfQ09ORklHX0VGSUZPOyAvKiBJbXBsaWNpdCBzZWVrLCBwb2xsaW5nICYgRklGTyBlbmFibGVkICovCiAgICBmZGN0cmwtPm51bV9mbG9wcGllcyA9IE1BWF9GRDsKCiAgICBpZiAoZmRjdHJsLT5kbWFfY2hhbm4gIT0gLTEpCiAgIC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