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gICAgICAgICAgICAgICAgICAgICAgICAgY2hhciAqKnZhbHVlcykKewogICAgc3RydWN0IG1peGVyX2N0bCAqY3RsOwogICAgZW51bSBtaXhlcl9jdGxfdHlwZSB0eXBlOwogICAgdW5zaWduZWQgaW50IG51bV9jdGxfdmFsdWVzOwogICAgdW5zaWduZWQgaW50IGk7CgogICAgaWYgKGlzZGlnaXQoY29udHJvbFswXSkpCiAgICAgICAgY3RsID0gbWl4ZXJfZ2V0X2N0bChtaXhlciwgYXRvaShjb250cm9sKSk7CiAgICBlbHNlCiAgICAgICAgY3RsID0gbWl4ZXJfZ2V0X2N0bF9ieV9uYW1lKG1peGVyLCBjb250cm9sKTsKCiAgICBpZiAoIWN0bCkgewogICAgICAgIGZwcmludGYoc3RkZXJyLCAiSW52YWxpZCBtaXhlciBjb250cm9sXG4iKTsKICAgICAgICByZXR1cm47CiAgICB9CgogICAgdHlwZSA9IG1peGVyX2N0bF9nZXRfdHlwZShjdGwpOwogICAgbnVtX2N0bF92YWx1ZXMgPSBtaXhlcl9jdGxfZ2V0X251bV92YWx1ZXMoY3RsKTsKCiAgICBpZiAoaXNkaWdpdCh2YWx1ZXNbMF1bMF0pKSB7ICAgICAgICAKICAgICAgICAgICAgCiAgICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBudW1fY3RsX3ZhbHVlczsgaSsrKSB7CiAgICAgICAgICAgICAgICBpZiAobWl4ZXJfY3RsX3NldF92YWx1ZShjdGwsIGksIGF0b2kodmFsdWVzW2ldKSkpIHsKICAgICAgICAgICAgICAgICAgICBmcHJpbnRmKHN0ZGVyciwgIkVycm9yOiBpbnZhbGlkIHZhbHVlIGZvciBpbmRleCAlZFxuIiwgaSk7CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgCiAgICB9IGVsc2UgewogICAgICAgIGlmICh0eXBlID09IE1JWEVSX0NUTF9UWVBFX0VOVU0pIHsKICAgICAgICAgICA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GlmIChiaXRzID09IDE2KQogICAgICAgIGNvbmZpZy5mb3JtYXQgPSBQQ01fRk9STUFUX1MxNl9MRTsKICAgIGNvbmZpZy5zdGFydF90aHJlc2hvbGQgPSAwOwogICAgY29uZmlnLnN0b3BfdGhyZXNob2xkID0gMDsKICAgIGNvbmZpZy5zaWxlbmNlX3RocmVzaG9sZCA9IDA7CgogICAgaWYgKCFzYW1wbGVfaXNfcGxheWFibGUoY2FyZCwgZGV2aWNlLCBjaGFubmVscywgcmF0ZSwgYml0cywgcGVyaW9kX3NpemUsIHBlcmlvZF9jb3VudCkpIHsKICAgICAgICByZXR1cm47CiAgICB9CgogICAgcGNtID0gcGNtX29wZW4oY2FyZCwgZGV2aWNlLCBQQ01fT1VULCAmY29uZmlnKTsKICAgIGlmICghcGNtIHx8ICFwY21faXNfcmVhZHkocGNtKSkgewogICAgICAgIGZwcmludGYoc3RkZXJyLCAiVW5hYmxlIHRvIG9wZW4gUENNIGRldmljZSAldSAoJXMpXG4iLAogICAgICAgICAgICAgICAgZGV2aWNlLCBwY21fZ2V0X2Vycm9yKHBjbSkpOwogICAgICAgIHJldHVybjsKICAgIH0KCiAgICBzaXplID0gcGNtX2ZyYW1lc190b19ieXRlcyhwY20sIHBjbV9nZXRfYnVmZmVyX3NpemUocGNtKSk7CiAgICBidWZmZXIgPSBtYWxsb2Moc2l6ZSk7CiAgICBpZiAoIWJ1ZmZlcikgewogICAgICAgIGZwcmludGYoc3RkZXJyLCAiVW5hYmxlIHRvIGFsbG9jYXRlICVkIGJ5dGVzXG4iLCBzaXplKTsKICAgICAgICBmcmVlKGJ1ZmZlcik7CiAgICAgICAgcGNtX2Nsb3NlKHBjbSk7CiAgICAgICAgcmV0dXJuOwogICAgfQoKICAgIHByaW50ZigiUGxheWluZyBzYW1wbGU6ICV1IGNoLCAldSBoeiwgJXUgYml0XG4iLCBjaGFubmVscywgcmF0ZSwgYml0cyk7CgogICAgLyogY2F0Y2ggY3RybC1jIHRvIHNodXRkb3duIGNsZWFubHkgKi8KICAgIHNpZ25hbChTSUdJTlQsIHN0cmVhbV9jbG9zZSk7CgogICAgZG8gewogICAgICAgIG51bV9yZWFkID0gZnJlYWQoYnVmZmVyLCAxLCBzaXplLCBmaWxlKTsKICAgICAgICBpZiAobnVtX3JlYWQgPiAwKSB7CiAgICAgICAgICAgIGlmIChwY21fd3JpdGUocGNtLCBidWZmZXIsIG51bV9yZWFkKSkgewogICAgICAgICAgICAgICAgZnByaW50ZihzdGRlcnIsICJFcnJvciBwbGF5aW5nIHNhbXBsZVxuIik7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0gd2hpbGUgKHNpZ19jbG9zZSAmJiBudW1fcmVhZCA+IDApOwoKICAgIGZyZWUoYnVmZmVyKTsKICAgIHBjbV9jbG9zZShwY20pOwp9Cgp1bnNpZ25lZCBpbnQgY2FwdHVyZV9zYW1wbGUoRklMRSAqZmlsZSwgdW5zaWduZWQgaW50IGNhcmQsIHVuc2lnbmVkIGludCBkZXZpY2UsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICB1bnNpZ25lZCBpbnQgY2hhbm5lbHMsIHVuc2lnbmVkIGludCByYXRlLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgZW51bSBwY21fZm9ybWF0IGZvcm1hdCwgdW5zaWduZWQgaW50IHBlcmlvZF9zaXplLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgdW5zaWduZWQgaW50IHBlcmlvZF9jb3VudCkKewogICAgc3RydWN0IHBjbV9jb25maWcgY29uZmlnOwogICAgc3RydWN0IHBjbSAqcGNtOwogICAgY2hhciAqYnVmZmVyOwogICAgdW5zaWduZWQgaW50IHNpemU7CiAgICB1bnNpZ25lZCBpbnQgYnl0ZXNfcmVhZCA9IDA7CgogICAgbWVtc2V0KCZjb25maWcsIDAsIHNpemVvZihjb25maWcpKTsKICAgIGNvbmZpZy5jaGFubmVscyA9IGNoYW5uZWxzOwogICAgY29uZmlnLnJhdGUgPSByYXRlOwogICAgY29uZmlnLnBlcmlvZF9zaXplID0gcGVyaW9kX3NpemU7CiAgICBjb25maWcucGVyaW9kX2NvdW50ID0gcGVyaW9kX2NvdW50OwogICAgY29uZmlnLmZvcm1hdCA9IGZvcm1hdDsKICAgIGNvbmZpZy5zdGFydF90aHJlc2hvbGQgPSAwOwogICAgY29uZmlnLnN0b3BfdGhyZXNob2xkID0gMDsKICAgIGNvbmZpZy5zaWxlbmNlX3RocmVzaG9sZCA9IDA7CgogICAgcGNtID0gcGNtX29wZW4oY2FyZCwgZGV2aWNlLCBQQ01fSU4sICZjb25maWcpOwogICAgaWYgKCFwY20gfHwgIXBjbV9pc19yZWFkeShwY20pKSB7CiAgICAgICAgZnByaW50ZihzdGRlcnIsICJVbmFibGUgdG8gb3BlbiBQQ00gZGV2aWNlICglcylcbiIsCiAgICAgICAgICAgICAgICBwY21fZ2V0X2Vycm9yKHBjbSkpOwogICAgICAgIHJldHVybiAwOwogICAgfQoKICAgIHNpemUgPSBwY21fZnJhbWVzX3RvX2J5dGVzKHBjbSwgcGNtX2dldF9idWZmZXJfc2l6ZShwY20pKTsKICAgIGJ1ZmZlciA9IG1hbGxvYyhzaXplKTsKICAgIGlmICghYnVmZmVyKSB7CiAgICAgICAgZnByaW50ZihzdGRlcnIsICJVbmFibGUgdG8gYWxsb2NhdGUgJWQgYnl0ZXNcbiIsIHNpemUpOwogICAgICAgIGZyZWUoYnVmZmVyKTsKICAgICAgICBwY21fY2xvc2UocGNtKTsKICAgICAgICByZXR1cm4gMDsKICAgIH0KCiAgICBwcmludGYoIkNhcHR1cmluZyBzYW1wbGU6ICV1IGNoLCAldSBoeiwgJXUgYml0XG4iLCBjaGFubmVscywgcmF0ZSwKICAgICAgICAgICBwY21fZm9ybWF0X3RvX2JpdHMoZm9ybWF0KSk7CgogICAgd2hpbGUgKHNpZ19jbG9zZSAmJiAhcGNtX3JlYWQocGNtLCBidWZmZXIsIHNpemUpKSB7CiAgICAgICAgaWYgKGZ3cml0ZShidWZmZXIsIDEsIHNpemUsIGZpbGUpICE9IHNpemUpIHsKICAgICAgICAgICAgZnByaW50ZihzdGRlcnIsIkVycm9yIGNhcHR1cmluZyBzYW1wbGVcbiIpOwogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgYnl0ZXNfcmVhZCArPSBzaXplOwoJCWlmIChieXRlc19yZWFkPj0zMDAwMDApCgkJCWJyZWFrOwogICAgfQoKICAgIGZyZWUoYnVmZmVyKTsKICAgIHBjbV9jbG9zZShwY20pOwogICAgcmV0dXJuIHBjbV9ieXRlc190b19mcmFtZXMocGNtLCBieXRlc19yZWFkKTsKfQoKaW50IG1haW4oaW50IGFyZ2MsIGNoYXIgKiphcmd2KQp7CiAgICBGSUxFICpmaWxlOwogICAgc3RydWN0IHdhdl9oZWFkZXIgaGVhZGVyOwogICAgdW5zaWduZWQgaW50IGNhcmQgPSAwOwogICAgdW5zaWduZWQgaW50IGRldmljZSA9IDA7CiAgICB1bnNpZ25lZCBpbnQgY2hhbm5lbHMgPSAyOwogICAgdW5zaWduZWQgaW50IHJhdGUgPSA0NDEwMDsKICAgIHVuc2lnbmVkIGludCBiaXRzID0gMTY7CiAgICB1bnNpZ25lZCBpbnQgZnJhbWVzOwogICAgdW5zaWduZWQgaW50IHBlcmlvZF9zaXplID0gMTAyNDsKICAgIHVuc2lnbmVkIGludCBwZXJpb2RfY291bnQgPSA0OwoJZW51bSBwY21fZm9ybWF0IGZvcm1hdDsKCiAgICBzdHJ1Y3QgcmlmZl93YXZlX2hlYWRlciByaWZmX3dhdmVfaGVhZGVyOwogICAgc3RydWN0IGNodW5rX2hlYWRlciBjaHVua19oZWFkZXI7CiAgICBzdHJ1Y3QgY2h1bmtfZm10IGNodW5rX2ZtdDsKICAgIGNoYXIgKmZpbGVuYW1lOwogICAgaW50IG1vcmVfY2h1bmtzID0gMTsKICAgIHN0cnVjdCBtaXhlciAqbWl4ZXI7CgoKICAgIGlmIChhcmdjIDwgMikgewog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yaWZmX3dhdmVfaGVhZGVyLCBzaXplb2YocmlmZl93YXZlX2hlYWRlciksIDEsIGZpbGUpOwoJICAgIGlmICgocmlmZl93YXZlX2hlYWRlci5yaWZmX2lkICE9IElEX1JJRkYpIHx8CgkgICAgICAgIChyaWZmX3dhdmVfaGVhZGVyLndhdmVfaWQgIT0gSURfV0FWRSkpIHsKCSAgICAgICAgZnByaW50ZihzdGRlcnIsICJFcnJvcjogJyVzJyBpcyBub3QgYSByaWZmL3dhdmUgZmlsZVxuIiwgZmlsZW5hbWUpOwoJICAgICAgICBmY2xvc2UoZmlsZSk7CgkgICAgICAgIHJldHVybiAxOwoJICAgIH0KCgkgICAgZG8gewoJICAgICAgICBmcmVhZCgmY2h1bmtfaGVhZGVyLCBzaXplb2YoY2h1bmtfaGVhZGVyKSwgMSwgZmlsZSk7CgoJICAgICAgICBzd2l0Y2ggKGNodW5rX2hlYWRlci5pZCkgewoJICAgICAgICBjYXNlIElEX0ZNVDoKCSAgICAgICAgICAgIGZyZWFkKCZjaHVua19mbXQsIHNpemVvZihjaHVua19mbXQpLCAxLCBmaWxlKTsKCSAgICAgICAgICAgIC8qIElmIHRoZSBmb3JtYXQgaGVhZGVyIGlzIGxhcmdlciwgc2tpcCB0aGUgcmVzdCAqLwoJICAgICAgICAgICAgaWYgKGNodW5rX2hlYWRlci5zeiA+IHNpemVvZihjaHVua19mbXQpKQoJICAgICAgICAgICAgICAgIGZzZWVrKGZpbGUsIGNodW5rX2hlYWRlci5zeiAtIHNpemVvZihjaHVua19mbXQpLCBTRUVLX0NVUik7CgkgICAgICAgICAgICBicmVhazsKCSAgICAgICAgY2FzZSBJRF9EQVRBOgoJICAgICAgICAgICAgLyogU3RvcCBsb29raW5nIGZvciBjaHVua3MgKi8KCSAgICAgICAgICAgIG1vcmVfY2h1bmtzID0gMDsKCSAgICAgICAgICAgIGJyZWFrOwoJICAgICAgICBkZWZhdWx0OgoJICAgICAgICAgICAgLyogVW5rbm93biBjaHVuaywgc2tpcCBieXRlcyAqLwoJICAgICAgICAgICAgZnNlZWsoZmlsZSwgY2h1bmtfaGVhZGVyLnN6LCBTRUVLX0NVUik7CgkgICAgICAgIH0KCSAgICB9IHdoaWxlIChtb3JlX2NodW5rcyk7CgoJICAgIC8qIHBhcnNlIGNvbW1hbmQgbGluZSBhcmd1bWVudHMgKi8KCSAgICBhcmd2ICs9IDM7CgkgICAgd2hpbGUgKCphcmd2KSB7CgkgICAgICAgIGlmIChzdHJjbXAoKmFyZ3YsICItZCIpID09IDApIHsKCSAgICAgICAgICAgIGFyZ3YrKzsKCSAgICAgICAgICAgIGlmICgqYXJndikKCSAgICAgICAgICAgICAgICBkZXZpY2UgPSBhdG9pKCphcmd2KTsKCSAgICAgICAgfQoJICAgICAgICBpZiAoc3RyY21wKCphcmd2LCAiLXAiKSA9PSAwKSB7CgkgICAgICAgICAgICBhcmd2Kys7CgkgICAgICAgICAgICBpZiAoKmFyZ3YpCgkgICAgICAgICAgICAgICAgcGVyaW9kX3NpemUgPSBhdG9pKCphcmd2KTsKCSAgICAgICAgfQoJICAgICAgICBpZiAoc3RyY21wKCphcmd2LCAiLW4iKSA9PSAwKSB7CgkgICAgICAgICAgICBhcmd2Kys7CgkgICAgICAgICAgICBpZiAoKmFyZ3YpCgkgICAgICAgICAgICAgICAgcGVyaW9kX2NvdW50ID0gYXRvaSgqYXJndik7CgkgICAgICAgIH0KCSAgICAgICAgaWYgKHN0cmNtcCgqYXJndiwgIi1EIikgPT0gMCkgewoJICAgICAgICAgICAgYXJndisrOwoJICAgICAgICAgICAgaWYgKCphcmd2KQoJICAgICAgICAgICAgICAgIGNhcmQgPSBhdG9pKCphcmd2KTsKCSAgICAgICAgfQoJICAgICAgICBpZiAoKmFyZ3YpCgkgICAgICAgICAgICBhcmd2Kys7CgkgICAgfQoKICAgIAlwbGF5X3NhbXBsZShmaWxlLCBjYXJkLCBkZXZpY2UsIGNodW5rX2ZtdC5udW1fY2hhbm5lbHMsIGNodW5rX2ZtdC5zYW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GNoYW5uZWxzID0gYXRvaSgqYXJndik7CgkgICAgICAgIH0gZWxzZSBpZiAoc3RyY21wKCphcmd2LCAiLXIiKSA9PSAwKSB7CgkgICAgICAgICAgICBhcmd2Kys7CgkgICAgICAgICAgICBpZiAoKmFyZ3YpCgkgICAgICAgICAgICAgICAgcmF0ZSA9IGF0b2koKmFyZ3YpOwoJICAgICAgICB9IGVsc2UgaWYgKHN0cmNtcCgqYXJndiwgIi1iIikgPT0gMCkgewoJICAgICAgICAgICAgYXJndisrOwoJICAgICAgICAgICAgaWYgKCphcmd2KQoJICAgICAgICAgICAgICAgIGJpdHMgPSBhdG9pKCphcmd2KTsKCSAgICAgICAgfSBlbHNlIGlmIChzdHJjbXAoKmFyZ3YsICItRCIpID09IDApIHsKCSAgICAgICAgICAgIGFyZ3YrKzsKCSAgICAgICAgICAgIGlmICgqYXJndikKCSAgICAgICAgICAgICAgICBjYXJkID0gYXRvaSgqYXJndik7CgkgICAgICAgIH0gZWxzZSBpZiAoc3RyY21wKCphcmd2LCAiLXAiKSA9PSAwKSB7CgkgICAgICAgICAgICBhcmd2Kys7CgkgICAgICAgICAgICBpZiAoKmFyZ3YpCgkgICAgICAgICAgICAgICAgcGVyaW9kX3NpemUgPSBhdG9pKCphcmd2KTsKCSAgICAgICAgfSBlbHNlIGlmIChzdHJjbXAoKmFyZ3YsICItbiIpID09IDApIHsKCSAgICAgICAgICAgIGFyZ3YrKzsKCSAgICAgICAgICAgIGlmICgqYXJndikKCSAgICAgICAgICAgICAgICBwZXJpb2RfY291bnQgPSBhdG9pKCphcmd2KTsKCSAgICAgICAgfQoJICAgICAgICBpZiAoKmFyZ3YpCgkgICAgICAgICAgICBhcmd2Kys7CgkgICAgfQoKCSAgICBoZWFkZXIucmlmZl9pZCA9IElEX1JJRkY7CgkgICAgaGVhZGVyLnJpZmZfc3ogPSAwOwoJICAgIGhlYWRlci5yaWZmX2ZtdCA9IElEX1dBVkU7CgkgICAgaGVhZGVyLmZtdF9pZCA9IEl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