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cnM7ICAgIC8qIEVycm9ycyB3aGVuIHRyeWluZyB0byB0cmFuc21pdCwgcGt0cyB3aWxsIGJlIHJlLXNlbnQgKi8KCiAgICAgICAgLyogcnVudGltZSBjb3VudGVycyByZWxhdGluZyB0byBjbG9uZV9za2IgKi8KICAgICAgICBfX3U2NCBuZXh0X3R4X3VzOyAgICAgICAgICAvKiB0aW1lc3RhbXAgb2Ygd2hlbiB0byB0eCBuZXh0ICovCiAgICAgICAgX191MzIgbmV4dF90eF9uczsKICAgICAgICAKICAgICAgICBfX3U2NCBhbGxvY2F0ZWRfc2ticzsKICAgICAgICBfX3UzMiBjbG9uZV9jb3VudDsKCWludCBsYXN0X29rOyAgICAgICAgICAgLyogV2FzIGxhc3Qgc2tiIHNlbnQ/IAoJICAgICAgICAgICAgICAgICAgICAgICAgKiBPciBhIGZhaWxlZCB0cmFuc21pdCBvZiBzb21lIHNvcnQ/ICBUaGlzIHdpbGwga2VlcAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICogc2VxdWVuY2UgbnVtYmVycyBpbiBvcmRlciwgZm9yIGV4YW1wbGUuCgkJCQkqLwogICAgICAgIF9fdTY0IHN0YXJ0ZWRfYXQ7IC8qIG1pY3JvLXNlY29uZHMgKi8KICAgICAgICBfX3U2NCBzdG9wcGVkX2F0OyAvKiBtaWNyby1zZWNvbmRzICovCiAgICAgICAgX191NjQgaWRsZV9hY2M7IC8qIG1pY3JvLXNlY29uZHMgKi8KICAgICAgICBfX3UzMiBzZXFfbnVtOwogICAgICAgIAogICAgICAgIGludCBjbG9uZV9za2I7IC8qIFVzZSBtdWx0aXBsZSBTS0JzIGR1cmluZyBwYWNrZXQgZ2VuLiAgSWYgdGhpcyBudW1iZXIKICAgICAgICAgICAgICAgICAgICAgICAgICAqIGlzIGdyZWF0ZXIgdGhhbiAxLCB0aGVuIHRoYXQgbWFueSBjb3BwaWVzIG9mIHRoZSBzYW1lCiAgICAgICAgICAgICAgICAgICAgICAgICAgKiBwYWNrZXQgd2lsbCBiZSBzZW50IGJlZm9yZSBhIG5ldyBwYWNrZXQgaXMgYWxsb2NhdGVkLgogICAgICAgICAgICAgICAgICAgICAgICAgICogRm9yIGluc3RhbmNlLCBpZiB5b3Ugd2FudCB0byBzZW5kIDEwMjQgaWRlbnRpY2FsIHBhY2tldHMKICAgICAgICAgICAgICAgICAgICAgICAgICAqIGJlZm9yZSBjcmVhdGluZyBhIG5ldyBwYWNrZXQsIHNldCBjbG9uZV9za2IgdG8gMTAyNC4KICAgICAgICAgICAgICAgICAgICAgICAgICAqLwogICAgICAgIAogICAgICAgIGNoYXIgZHN0X21pbltJUF9OQU1FX1NaXTsgLyogSVAsIGllIDEuMi4zLjQgKi8KICAgICAgICBjaGFyIGRzdF9tYXhbSVBfTkFNRV9TWl07IC8qIElQLCBpZSAxLjIuMy40ICovCiAgICAgICAgY2hhciBzcmNfbWluW0lQX05BTUVfU1pdOyAvKiBJUCwgaWUgMS4yLjMuNCAqLwogICAgICAgIGNoYXIgc3JjX21heFtJUF9OQU1FX1NaXTsgLyogSVAsIGllIDEuMi4zLjQgKi8KCglzdHJ1Y3QgaW42X2FkZHIgIGluNl9zYWRkcjsKCXN0cnVjdCBpbjZfYWRkciAgaW42X2RhZGRyOwoJc3RydWN0IGluNl9hZGRyICBjdXJfaW42X2RhZGRyOwoJc3RydWN0IGluNl9hZGRyICBjdXJfaW42X3NhZGRyOwoJLyogRm9yIHJhbmdlcyAqLwoJc3RydWN0IGluNl9hZGRyICBtaW5faW42X2RhZGRyOwoJc3RydWN0IGluNl9hZGRyICBtYXhfaW42X2RhZGRyOwoJc3RydWN0IGluNl9hZGRyICBtaW5faW42X3NhZGRyOwoJc3RydWN0IGluNl9hZGRyICBtYXhfaW42X3NhZGRyOwoKICAgICAgICAvKiBJZiB3ZSdyZSBkb2luZyByYW5nZXMsIHJhbmRvbSBvciBpbmNyZW1lbnRhbCwgdGhlbiB0aGlzCiAgICAgICAgICogZGVmaW5lcyB0aGUgbWluL21heCBmb3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kYWRkcjsKICAgICAgICBfX3UxNiBjdXJfdWRwX2RzdDsKICAgICAgICBfX3UxNiBjdXJfdWRwX3NyYzsKICAgICAgICBfX3UzMiBjdXJfcGt0X3NpemU7CiAgICAgICAgCiAgICAgICAgX191OCBoaFsxNF07CiAgICAgICAgLyogPSB7IAogICAgICAgICAgIDB4MDAsIDB4ODAsIDB4QzgsIDB4NzksIDB4QjMsIDB4Q0IsIAogICAgICAgICAgIAogICAgICAgICAgIFdlIGZpbGwgaW4gU1JDIGFkZHJlc3MgbGF0ZXIKICAgICAgICAgICAweDAwLCAweDAwLCAweDAwLCAweDAwLCAweDAwLCAweDAwLAogICAgICAgICAgIDB4MDgsIDB4MDAKICAgICAgICAgICB9OwogICAgICAgICovCiAgICAgICAgX191MTYgcGFkOyAvKiBwYWQgb3V0IHRoZSBoaCBzdHJ1Y3QgdG8gYW4gZXZlbiAxNiBieXRlcyAqLwoKICAgICAgICBzdHJ1Y3Qgc2tfYnVmZiogc2tiOyAvKiBza2Igd2UgYXJlIHRvIHRyYW5zbWl0IG5leHQsIG1haW5seSB1c2VkIGZvciB3aGVuIHdlCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICogYXJlIHRyYW5zbWl0dGluZyB0aGUgc2FtZSBvbmUgbXVsdGlwbGUgdGltZXMKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKi8KICAgICAgICBzdHJ1Y3QgbmV0X2RldmljZSogb2RldjsgLyogVGhlIG91dC1nb2luZyBkZXZpY2UuICBOb3RlIHRoYXQgdGhlIGRldmljZSBzaG91bGQKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICogaGF2ZSBpdCdzIHBnX2luZm8gcG9pbnRlciBwb2ludGluZyBiYWNrIHRvIHRoaXMKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICogZGV2aWNlLiAgVGhpcyB3aWxsIGJlIHNldCB3aGVuIHRoZSB1c2VyIHNwZWNpZmllcwogICAgICAgICAgICAgICAgICAgICAg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ICAgICAgICBpZiAoYiA+IDApIHsKICAgICAgICAgICAgICAgIHdoaWxlIChiIDwgYSkgewogICAgICAgICAgICAgICAgICAgICAgICBiIDw8PSAxOwogICAgICAgICAgICAgICAgICAgICAgICBkIDw8PSAxOwogICAgICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAKICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICBpZiAoIGEgPj0gYiApIHsKICAgICAgICAgICAgICAgICAgICAgICAgYSAtPSBiOwogICAgICAgICAgICAgICAgICAgICAgICByZXMgKz0gZDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGIgPj49IDE7CiAgICAgICAgICAgICAgICBkID4+PSAxOwogICAgICAgIH0KICAgICAgICB3aGlsZSAoZCk7CgogICAgICAgIGlmIChQR19ESVYgPT0gdHlwZSkgewogICAgICAgICAgICAgICAgcmV0dXJuICgoKHggXiB5KSAmICgxbGw8PDYzKSkgPT0gMCkgPyByZXMgOiAtKHM2NClyZXM7CiAgICAgICAgfQogICAgICAgIGVsc2UgewogICAgICAgICAgICAgICAgcmV0dXJuICgoeCAmICgxbGw8PDYzKSkgPT0gMCkgPyBhIDogLShzNjQpYTsKICAgICAgICB9Cn0KCi8qIEVuZCBvZiBoYWNrcyB0byBkZWFsIHdpdGggNjQtYml0IG1hdGggb24geDg2ICovCgovKiogQ29udmVydCB0byBtaWxpc2Vjb25kcyAqLwpzdGF0aWMgaW5saW5lIF9fdTY0IHR2X3RvX21zKGNvbnN0IHN0cnVjdCB0aW1ldmFsKiB0dikgCnsKICAgICAgICBfX3U2NCBtcyA9IHR2LT50dl91c2VjIC8gMTAwMDsKICAgICAgICBtcyArPSAoX191NjQpdHYtPnR2X3NlYyAqIChfX3U2NCkxMDAwOwogICAgICAgIHJldHVybiBtczsKfQoKCi8qKiBDb252ZXJ0IHRvIG1pY3JvLXNlY29uZHMgKi8Kc3RhdGljIGlubGluZSBfX3U2NCB0dl90b191cyhjb25zdCBzdHJ1Y3QgdGltZ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SAwKSkgCgoJCWZvciAoaSA9IDA7IGkgPCA2OyBpKyspIAoJCQlwICs9IHNwcmludGYocCwgIiUwMlglcyIsIHBrdF9kZXYtPm9kZXYtPmRldl9hZGRyW2ldLCBpID09IDUgPyAiICAiIDogIjoiKTsKCgllbHNlIAoJCWZvciAoaSA9IDA7IGkgPCA2OyBpKyspIAoJCQlwICs9IHNwcmludGYocCwgIiUwMlglcyIsIHBrdF9kZXYtPnNyY19tYWNbaV0sIGkgPT0gNSA/ICIgICIgOiAiOiIpOwoKICAgICAgICBwICs9IHNwcmludGYocCwgImRzdF9tYWM6ICIpOwoJZm9yIChpID0gMDsgaSA8IDY7IGkrKykgCgkJcCArPSBzcHJpbnRmKHAsICIlMDJYJXMiLCBwa3RfZGV2LT5kc3RfbWFjW2ldLCBpID09IDUgPyAiXG4iIDogIjoiKTsKCiAgICAgICAgcCArPSBzcHJpbnRmKHAsICIgICAgIHVkcF9zcmNfbWluOiAlZCAgdWRwX3NyY19tYXg6ICVkICB1ZHBfZHN0X21pbjogJWQgIHVkcF9kc3RfbWF4OiAlZFxuIiwKICAgICAgICAgICAgICAgICAgICAgcGt0X2Rldi0+dWRwX3NyY19taW4sIHBrdF9kZXYtPnVkcF9zcmNfbWF4LCBwa3RfZGV2LT51ZHBfZHN0X21pbiwKICAgICAgICAgICAgICAgICAgICAgcGt0X2Rldi0+dWRwX2RzdF9tYXgpOwoKICAgICAgICBwICs9IHNwcmludGYocCwgIiAgICAgc3JjX21hY19jb3VudDogJWQgIGRzdF9tYWNfY291bnQ6ICVkIFxuICAgICBGbGFnczogIiwKICAgICAgICAgICAgICAgICAgICAgcGt0X2Rldi0+c3JjX21hY19jb3VudCwgcGt0X2Rldi0+ZHN0X21hY19jb3VudCk7CgoKICAgICAgICBpZiAocGt0X2Rldi0+ZmxhZ3MgJiAgRl9JUFY2KSAKICAgICAgICAgICAgICAgIHAgKz0gc3ByaW50ZihwLCAiSVBWNiAgIik7CgogICAgICAgIGlmIChwa3RfZGV2LT5mbGFncyAmICBGX0lQU1JDX1JORCkgCiAgICAgICAgICAgICAgICBwICs9IHNwcmludGYocCwgIklQU1JDX1JORCAgIik7CgogICAgICAgIGlmIChwa3RfZGV2LT5mbGFncyAmIEZfSVBEU1RfUk5EKSAKICAgICAgICAgICAgICAgIHAgKz0gc3ByaW50ZihwLCAiSVBEU1RfUk5EICAiKTsKICAgICAgICAKICAgICAgICBpZiAocGt0X2Rldi0+ZmxhZ3MgJiBGX1RYU0laRV9STkQpIAogICAgICAgICAgICAgICAgcCArPSBzcHJpbnRmKHAsICJUWFNJWkVfUk5EICAiKTsKICAgICAgICAKICAgICAgICBpZiAocGt0X2Rldi0+ZmxhZ3MgJiBGX1VEUFNSQ19STkQpIAogICAgICAgICAgICAgICAgcCArPSBzcHJpbnRmKHAsICJVRFBTUkNfUk5EICAiKTsKICAgICAgICAKICAgICAgICBpZiAocGt0X2Rldi0+ZmxhZ3MgJiBGX1VEUERTVF9STkQpIAogICAgICAgICAgICAgICAgcCArPSBzcHJpbnRmKHAsICJVRFBEU1RfUk5EICAiKTsKICAgICAgICAKICAgICAgICBpZiAocGt0X2Rldi0+ZmxhZ3MgJiBGX01BQ1NSQ19STkQpIAogICAgICAgICAgICAgICAgcCArPSBzcHJpbnRmKHAsICJNQUNTUkNfUk5EICAiKTsKICAgICAgICAKICAgICAgICBpZiAocGt0X2Rldi0+ZmxhZ3MgJiBGX01BQ0RTVF9STkQpIAogICAgICAgICAgICAgICAgcCArPSBzcHJpbnRmKHAsICJNQUNEU1RfUk5EICAiKTsKCiAgICAgICAgCiAgICAgICAgcCArPSBzcHJpbnRmKHAsICJcbiIpOwogICAgICAgIAogICAgICAgIHNhID0gcGt0X2Rldi0+c3RhcnRlZF9hdDsKICAgICAgICBzdG9wcGVkID0gcGt0X2Rldi0+c3RvcHBlZF9hdDsKICAgICAgICBpZiAocGt0X2Rldi0+cnVubmluZykgCiAgICAgICAgICAgICAgICBzdG9wcGVkID0gbm93OyAvKiBub3QgcmV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21fdXNlcihuYW1lLCAmdXNlcl9idWZmZXJbaV0sIGxlbikgKQoJCXJldHVybiAtRUZBVUxUOwoJaSArPSBsZW47CiAgCgltYXggPSBjb3VudCAtaTsKCWxlbiA9IGNvdW50X3RyYWlsX2NoYXJzKCZ1c2VyX2J1ZmZlcltpXSwgbWF4KTsKICAgICAgICBpZiAobGVuIDwgMCkgCiAgICAgICAgICAgICAgICByZXR1cm4gbGVuOwogICAgICAgIAoJaSArPSBsZW47CgoJaWYgKGRlYnVnKSB7CiAgICAgICAgICAgICAgICBjaGFyIHRiW2NvdW50ICsgMV07CiAgICAgICAgICAgICAgICBpZiAoY29weV9mcm9tX3VzZXIodGIsIHVzZXJfYnVmZmVyLCBjb3VudCkpCgkJCXJldHVybiAtRUZBVUxUOwogICAgICAgICAgICAgICAgdGJbY291bnRdID0gMDsKCQlwcmludGsoInBrdGdlbjogJXMsJWx1ICBidWZmZXIgLTolczotXG4iLCBuYW1lLCBjb3VudCwgdGIpOwogICAgICAgIH0KCglpZiAoIXN0cmNtcChuYW1lLCAibWluX3BrdF9zaXplIikpIHsKCQlsZW4gPSBudW1fYXJnKCZ1c2VyX2J1ZmZlcltpXSwgMTAsICZ2YWx1ZSk7CiAgICAgICAgICAgICAgICBpZiAobGVuIDwgMCkgeyByZXR1cm4gbGVuOyB9CgkJaSArPSBsZW47CgkJaWYgKHZhbHVlIDwgMTQrMjArOCkKCQkJdmFsdWUgPSAxNCsyMCs4OwogICAgICAgICAgICAgICAgaWYgKHZhbHVlICE9IHBrdF9kZXYtPm1pbl9wa3Rfc2l6ZSkgewogICAgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT5taW5fcGt0X3NpemUgPSB2YWx1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgcGt0X2Rldi0+Y3VyX3BrdF9zaXplID0gdmFsdWU7CiAgICAgICAgICAgICAgICB9CgkJc3ByaW50ZihwZ19yZXN1bHQsICJPSzogbWluX3BrdF9zaXplPSV1IiwgcGt0X2R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lbXNldChmLCAwLCAzMik7CgkJbGVuID0gc3Rybl9sZW4oJnVzZXJfYnVmZmVyW2ldLCBzaXplb2YoZikgLSAxKTsKICAgICAgICAgICAgICAgIGlmIChsZW4gPCAwKSB7IHJldHVybiBsZW47IH0KCQlpZiAoY29weV9mcm9tX3VzZXIoZiwgJnVzZXJfYnVmZmVyW2ldLCBsZW4pKQoJCQlyZXR1cm4gLUVGQVVMVDsKCQlpICs9IGxlbjsKICAgICAgICAgICAgICAgIGlmIChzdHJjbXAoZiwgIklQU1JDX1JORCIpID09IDApIAogICAgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT5mbGFncyB8PSBGX0lQU1JDX1JORDsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgZWxzZSBpZiAoc3RyY21wKGYsICIhSVBTUkNfUk5EIikgPT0gMCkgCiAgICAgICAgICAgICAgICAgICAgICAgIHBrdF9kZXYtPmZsYWdzICY9IH5GX0lQU1JDX1JORDsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgZWxzZSBpZiAoc3RyY21wKGYsICJUWFNJWkVfUk5EIikgPT0gMCkgCiAgICAgICAgICAgICAgICAgICAgICAgIHBrdF9kZXYtPmZsYWdzIHw9IEZfVFhTSVpFX1JORDsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgZWxzZSBpZiAoc3RyY21wKGYsICIhVFhTSVpFX1JORCIpID09IDApIAogICAgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT5mbGFncyAmPSB+Rl9UWFNJWkVfUk5EOwogICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICBlbHNlIGlmIChzdHJjbXAoZiwgIklQRFNUX1JORCIpID09IDApIAogICAgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT5mbGFncyB8PSBGX0lQRFNUX1JORDsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgZWxzZSBpZiAoc3RyY21wKGYsICIhSVBEU1RfUk5EIikgPT0gMCkgCiAgICAgICAgICAgICAgICAgICAgICAgIHBrdF9kZXYtPmZsYWdzICY9IH5GX0lQRFNUX1JORDsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgZWxzZSBpZiAoc3RyY21wKGYsICJVRFBTUkNfUk5EIikgPT0gMCkgCiAgICAgICAgICAgICAgICAgICAgICAgIHBrdF9kZXYtPmZsYWdzIHw9IEZfVURQU1JDX1JORDsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgZWxzZSBpZiAoc3RyY21wKGYsICIhVURQU1JDX1JORCIpID09IDApIAogICAgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT5mbGFncyAmPSB+Rl9VRFBTUkNfUk5EOwogICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICBlbHNlIGlmIChzdHJjbXAoZiwgIlVEUERTVF9STkQiKSA9PSAwKSAKICAgICAgICAgICAgICAgICAgICAgICAgcGt0X2Rldi0+ZmxhZ3MgfD0gRl9VRFBEU1RfUk5EOwogICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICBlbHNlIGlmIChzdHJjbXAoZiwgIiFVRFBEU1RfUk5EIikgPT0gMCkgCiAgICAgICAgICAgICAgICAgICAgICAgIHBrdF9kZXYtPmZsYWdzICY9IH5GX1VEUERTVF9STkQ7CiAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgIGVsc2UgaWYgKHN0cmNtcChmLCAiTUFDU1JDX1JORCIpID09IDApIAogICAgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT5mbGFncyB8PSBGX01BQ1NSQ19STkQ7CiAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgIGVsc2UgaWYgKHN0cmNtcChmLCAiIU1BQ1NSQ19STkQiKSA9PSAwKSAKICAgICAgICAgICAgICAgICAgICAgICAgcGt0X2Rldi0+ZmxhZ3MgJj0gfkZfTUFDU1JDX1JORDsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgZWxzZSBpZiAoc3RyY21wKGYsICJNQUNEU1RfUk5EIikgPT0gMCkgCiAgICAgICAgICAgICAgICAgICAgICAgIHBrdF9kZXYtPmZsYWdzIHw9IEZfTUFDRFNUX1JORDsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgZWxzZSBpZiAoc3RyY21wKGYsICIhTUFDRFNUX1JORCIpID09IDApIAogICAgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT5mbGFncyAmPSB+Rl9NQUNEU1RfUk5EOwogICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgc3ByaW50ZihwZ19yZXN1bHQsICJGbGFnIC06JXM6LSB1bmtub3duXG5BdmFpbGFibGUgZmxhZ3MsIChwcmVwZW5kICEgdG8gdW4tc2V0IGZsYWcpOlxuJXMiLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGYsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIklQU1JDX1JORCwgSVBEU1RfUk5ELCBUWFNJWkVfUk5ELCBVRFBTUkNfUk5ELCBVRFBEU1RfUk5ELCBNQUNTUkNfUk5ELCBNQUNEU1RfUk5EXG4iKTsKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGNvdW50OwogICAgICAgICAgICAgICAgfQoJCXNwcmludGYocGdfcmVzdWx0LCAiT0s6IGZsYWdzPTB4JXgiLCBwa3RfZGV2LT5mbGFncyk7CgkJcmV0dXJuIGNvdW50OwoJfQoJaWYgKCFzdHJjbXAobmFtZSwgImRzdF9taW4iKSB8fCAhc3RyY21wKG5hbWUsICJkc3QiKSkgewoJCWxlbiA9IHN0cm5fbGVuKCZ1c2VyX2J1ZmZlcltpXSwgc2l6ZW9mKHBrdF9kZXYtPmRzdF9taW4pIC0gMSk7CiAgICAgICAgICAgICAgICBpZiAobGVuIDwgMCkgeyByZXR1cm4gbGVuOyB9CgogICAgICAgICAgICAgICAgaWYgKGNvcHlfZnJvbV91c2VyKGJ1ZiwgJnVzZXJfYnVmZmVyW2ldLCBsZW4pKQoJCQlyZXR1cm4gLUVGQVVMVDsKICAgICAgICAgICAgICAgIGJ1ZltsZW5dID0gMDsKICAgICAgICAgICAgICAgIGlmIChzdHJjbXAoYnVmLCBwa3RfZGV2LT5kc3RfbWluKSAhPSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIG1lbXNldChwa3RfZGV2LT5kc3RfbWluLCAwLCBzaXplb2YocGt0X2Rldi0+ZHN0X21pbikpOwogICAgICAgICAgICAgICAgICAgICAgICBzdHJuY3B5KHBrdF9kZXYtPmRzdF9taW4sIGJ1ZiwgbGVuKTsKICAgICAgICAgICAgICAgICAgICAgICAgcGt0X2Rldi0+ZGFkZHJfbWluID0gaW5fYXRvbihwa3RfZGV2LT5kc3RfbWluKTsKICAgICAgICAgICAgICAgICAgICAgICAgcGt0X2Rldi0+Y3VyX2RhZGRyID0gcGt0X2Rldi0+ZGFkZHJfbWluOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYoZGVidWcpCiAgICAgICAgICAgICAgICAgICAgICAgIHByaW50aygicGt0Z2VuOiBkc3RfbWluIHNldCB0bzogJXNcbiIsIHBrdF9kZXYtPmRzdF9taW4pOwogICAgICAgICAgICAgICAgaSArPSBsZW47CgkJc3ByaW50ZihwZ19yZXN1bHQsICJPSzogZHN0X21pbj0lcyIsIHBrdF9kZXYtPmRzdF9taW4pOwoJCXJldHVybiBjb3VudDsKCX0KCWlmICghc3RyY21wKG5hbWUsICJkc3RfbWF4IikpIHsKCQlsZW4gPSBzdHJuX2xlbigmdXNlcl9idWZmZXJbaV0sIHNpemVvZihwa3RfZGV2LT5kc3RfbWF4KSAtIDEpOwogICAgICAgICAgICAgICAgaWYgKGxlbiA8IDApIHsgcmV0dXJuIGxlbjsgfQoKICAgICAgICAgICAgICAgIGlmIChjb3B5X2Zyb21fdXNlcihidWYsICZ1c2VyX2J1ZmZlcltpXSwgbGVuKSkKCQkJcmV0dXJuIC1FR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2Rldi0+c2FkZHJfbWluID0gaW5fYXRvbihwa3RfZGV2LT5zcmNfbWluKTsKICAgICAgICAgICAgICAgICAgICAgICAgcGt0X2Rldi0+Y3VyX3NhZGRyID0gcGt0X2Rldi0+c2FkZHJfbWluOwogICAgICAgICAgICAgICAgfQoJCWlmKGRlYnVnKQoJCQlwcmludGsoInBrdGdlbjogc3JjX21pbiBzZXQgdG86ICVzXG4iLCBwa3RfZGV2LT5zcmNfbWluKTsKCQlpICs9IGxlbjsKCQlzcHJpbnRmKHBnX3Jlc3VsdCwgIk9LOiBzcmNfbWluPSVzIiwgcGt0X2Rldi0+c3JjX21pbik7CgkJcmV0dXJuIGNvdW50OwoJfQoJaWYgKCFzdHJjbXAobmFtZSwgInNyY19tYXgiKSkgewoJCWxlbiA9IHN0cm5fbGVuKCZ1c2VyX2J1ZmZlcltpXSwgc2l6ZW9mKHBrdF9kZXYtPnNyY19tYXgpIC0gMSk7CiAgICAgICAgICAgICAgICBpZiAobGVuIDwgMCkgeyByZXR1cm4gbGVuOyB9CiAgICAgICAgICAgICAgICBpZiAoY29weV9mcm9tX3VzZXIoYnVmLCAmdXNlcl9idWZmZXJbaV0sIGxlbikpCgkJCXJldHVybiAtRUZBVUxUOwogICAgICAgICAgICAgICAgYnVmW2xlbl0gPSAwOwogICAgICAgICAgICAgICAgaWYgKHN0cmNtcChidWYsIHBrdF9kZXYtPnNyY19tYXgpICE9IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgbWVtc2V0KHBrdF9kZXYtPnNyY19tYXgsIDAsIHNpemVvZihwa3RfZGV2LT5zcmNfbWF4KSk7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0cm5jcHkocGt0X2Rldi0+c3JjX21heCwgYnVmLCBsZW4pOwogICAgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT5zYWRkcl9tYXggPSBpbl9hdG9uKHBrdF9kZXYtPnNyY19tYXgpOwogICAgICAgICAgICAgICAgICAgICAgICBwa3RfZGV2LT5jdX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ZGV2LT5zcmNfbWFjX2NvdW50ID4gMSkgewogICAgICAgICAgICAgICAgX191MzIgbWM7CiAgICAgICAgICAgICAgICBfX3UzMiB0bXA7CgogICAgICAgICAgICAgICAgaWYgKHBrdF9kZXYtPmZsYWdzICYgRl9NQUNTUkNfUk5EKSAKICAgICAgICAgICAgICAgICAgICAgICAgbWMgPSBwa3RnZW5fcmFuZG9tKCkgJSAocGt0X2Rldi0+c3JjX21hY19jb3VudCk7CiAgICAgICAgICAgICAgICBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgbWMgPSBwa3RfZGV2LT5jdXJfc3JjX21hY19vZmZzZXQrKzsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBrdF9kZXYtPmN1cl9zcmNfbWFjX29mZnNldCA+IHBrdF9kZXYtPnNyY19tYWNfY291bnQpIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBrdF9kZXYtPmN1cl9zcmNfbWFjX29mZnNldCA9IDA7CiAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgdG1wID0gcGt0X2Rldi0+c3JjX21hY1s1XSArIChtYyAmIDB4RkYpOwogICAgICAgICAgICAgICAgcGt0X2Rldi0+aGhbMTFdID0gdG1wOwogICAgICAgICAgICAgICAgdG1wID0gKHBrdF9kZXYtPnNyY19tYWNbNF0gKyAoKG1jID4+IDgpICYgMHhGRikgKyAodG1wID4+IDgpKTsKICAgICAgICAgICAgICAgIHBrdF9kZXYtPmhoWzEwXSA9IHRtcDsKICAgICAgICAgICAgICAgIHRtcCA9IChwa3RfZGV2LT5zcmNfbWFjWzNdICsgKChtYyA+PiAxNikgJiAweEZGKSArICh0bXAgPj4gOCkpOwogICAgICAgICAgICAgICAgcGt0X2Rldi0+aGhbOV0gPSB0bXA7CiAgICAgICAgICAgICAgICB0bXAgPSAocGt0X2Rldi0+c3JjX21hY1syXSArICgobWMgPj4gMjQpICYgMHhGRikgKyAodG1wID4+IDgpKTsKICAgICAgICAgICAgICAgIHBrdF9kZXYtPmhoWzhdID0gdG1wOwogICAgICAgICAgICAgICAgdG1wID0gKHBrdF9kZXYtPnNyY19tYWNbMV0gKyAodG1wID4+IDgpKTsKICAgICAgICAgICAgICAgIHBrdF9kZXYtPmhoWzddID0gdG1wOyAgICAgICAgCiAgICAgICAgfQoKICAgICAgICAvKiAgRGVhbCB3aXRoIERlc3RpbmF0aW9uIE1BQyAqLwogICAgICAgIGlmIChwa3RfZGV2LT5kc3RfbWFjX2NvdW50ID4gMSkgewogICAgICAgICAgICAgICAgX191MzIgbWM7CiAgICAgICAgICAgICAgICBfX3UzMiB0bXA7CgogICAgICAgICAgICAgICAgaWYgKHBrdF9kZXYtPmZsYWdzICYgRl9NQUNEU1RfUk5EKSAKICAgICAgICAgICAgICAgICAgICAgICAgbWMgPSBwa3RnZW5fcmFuZG9tKCkgJSAocGt0X2Rldi0+ZHN0X21hY19jb3VudCk7CgogICAgICAgICAgICAgICAgZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIG1jID0gcGt0X2Rldi0+Y3VyX2RzdF9tYWNfb2Zmc2V0Kys7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwa3RfZGV2LT5jdXJfZHN0X21hY19vZmZzZXQgPiBwa3RfZGV2LT5kc3RfbWFjX2NvdW50KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGt0X2Rldi0+Y3VyX2RzdF9tYWNfb2Zmc2V0ID0gMDsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgIHRtcCA9IHBrdF9kZXYtPmRzdF9tYWNbNV0gKyAobWMgJiAweEZGKTsKICAgICAgICAgICAgICAgIHBrdF9kZXYtPmhoWzVdID0gdG1wOwogICAgICAgICAgICAgICAgdG1wID0gKHBrdF9kZXYtPmRzdF9tYWNbNF0gKyAoKG1jID4+IDgpICYgMHhGRikgKyAodG1wID4+IDgpKTsKICAgICAgICAgICAgICAgIHBrdF9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AgICBmb3IocGt0X2Rldj10LT5pZl9saXN0OyBwa3RfZGV2OyBwa3RfZGV2ID0gcGt0X2Rldi0+bmV4dCApIHsKICAgICAgICAgICAgICAgIGlmIChzdHJjbXAocGt0X2Rldi0+aWZuYW1lLCBpZm5hbWUpID09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICBpZl91bmxvY2sodCk7CglQR19ERUJVRyhwcmludGsoInBrdGdlbjogZmluZF9kZXYoJXMpIHJldHVybmluZyAlcFxuIiwgaWZuYW1lLHBrdF9kZXYpKTsKICAgICAgICByZXR1cm4gcGt0X2RldjsKfQoKLyogCiAqIEFkZHMgYSBkZXYgYXQgZnJvbnQgb2YgaWZfbGlzdC4gCiAqLwoKc3RhdGljIGludCBhZGRfZGV2X3RvX3RocmVhZChzdHJ1Y3QgcGt0Z2VuX3RocmVhZCAqdCwgc3RydWN0IHBrdGdlbl9kZXYgKnBrdF9kZXYpIAp7CglpbnQgcnYgPSAwOwoJCiAgICAgICAgaWZfbG9jayh0KTsKCiAgICAgICAgaWYgKHBrdF9kZXYtPnBnX3RocmVhZCkgewogICAgICAgICAgICAgICAgcHJpbnRrKCJwa3RnZW46IEVSUk9SOiAgYWxyZWFkeSBhc3NpZ25lZCB0byBhIHRocmVhZC5cbiIpOwogICAgICAgICAgICAgICAgcnYgPSAtRUJVU1k7CiAgICAgICAgICAgICAgICBnb3RvIG91dDsKICAgICAgICB9Cglwa3RfZGV2LT5uZXh0ID10LT5pZl9saXN0OyB0LT5pZl9saXN0PXBrdF9kZXY7CiAgICAgICAgcGt0X2Rldi0+cGdfdGhyZWFkID0gdDsKCXBrdF9kZXYtPnJ1bm5pbmcgPSAwOwoKIG91dDoKICAgICAgICBpZl91bmxvY2sodCk7ICAgICAgICAKICAgICAgICByZXR1cm4gcnY7Cn0KCi8qIENhbGxlZCB1bmRlciB0aHJlYWQgbG9jayAqLwoKc3RhdGljI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AgICAgcGt0X2Rldi0+ZGVsYXlfbnMgPSBwZ19kZWxheV9kICUgMTAwMDsKICAgICAgICAgICAgICAgIHBrdF9kZXYtPmNvdW50ID0gcGdfY291bnRfZDsKICAgICAgICAgICAgICAgIHBrdF9kZXYtPnNvZmFyID0gMDsKICAgICAgICAgICAgICAgIHBrdF9kZXYtPnVkcF9zcmNfbWluID0gOTsgLyogc2luayBwb3J0ICovCiAgICAgICAgICAgICAgICBwa3RfZGV2LT51ZHBfc3JjX21heCA9IDk7CiAgICAgICAgICAgICAgICBwa3RfZGV2LT51ZHBfZHN0X21pbiA9IDk7CiAgICAgICAgICAgICAgICBwa3RfZGV2LT51ZHBfZHN0X21heCA9IDk7CgogICAgICAgICAgICAgICAgc3RybmNweShwa3RfZGV2LT5pZm5hbWUsIGlmbmFtZSwgMzEpOwogICAgICAgICAgICAgICAgc3ByaW50Zihwa3RfZGV2LT5mbmFtZSwgIiVzLyVzIiwgUEdfUFJPQ19ESVIsIGlmbmFtZSk7CgogICAgICAgICAgICAgICAgaWYgKCEgcGt0Z2VuX3NldHVwX2Rldihwa3RfZGV2KSkgewogICAgICAgICAgICAgICAgICAgICAgICBwcmludGsoInBrdGdlbjogRVJST1I6IHBrdGdlbl9zZXR1cF9kZXYgZmFpbGVkLlxuIik7CgkJCWlmIChwa3RfZGV2LT5mbG93cykKCQkJCXZmcmVlKHBrdF9kZXYtPmZsb3dzKTsKICAgICAgICAgICAgICAgICAgICAgICAga2ZyZWUocGt0X2Rldik7CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiAtRU5PREVWOwogICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgIHBrdF9kZXYtPnByb2NfZW50ID0gY3JlYXRlX3Byb2NfZW50cnkocGt0X2Rldi0+Zm5hbWUsIDA2MDAsIE5VTEwpOwogICAgICAgICAgICAgICAgaWYgKCFwa3RfZGV2LT5wcm9jX2VudCkgewogICAgICAgICAgICAgICAgICAgICAgICBwcmludGsoInBrdGdlbjogY2Fubm90IGNyZWF0ZSAlcyBwcm9jZnMgZW50cnkuXG4iLCBwa3RfZGV2LT5mbmFtZSk7CgkJCWlmIChwa3RfZGV2LT5mbG93cykKCQkJCXZmcmVlKHBrdF9kZXYtPmZsb3dzKTsKICAgICAgICAgICAgICAgICAgICAgICAga2ZyZWUocGt0X2Rldik7CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiAtRUlOVkFMOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgcGt0X2Rldi0+cHJvY19lbnQtPnJlYWRfcHJvYyA9IHByb2NfaWZfcmVhZDsKICAgICAgICAgICAgICAgIHBrdF9kZXYtPnByb2NfZW50LT53cml0ZV9wcm9jID0gcHJvY19pZl93cml0ZTsKICAgICAgICAgICAgICAgIHBrdF9kZXYtPnByb2NfZW50LT5kYXRhID0gKHZvaWQqKShwa3RfZGV2KTsKCQlwa3RfZGV2LT5wcm9jX2VudC0+b3duZXIgPSBUSElTX01PRFVMRTsKCiAgICAgICAgICAgICAgICByZXR1cm4gYWRkX2Rldl90b190aHJlYWQodCwgcGt0X2Rldik7CiAgICAgICAgfQogICAgICAgIGVsc2UgewogICAgICAgICAgICAgICAgcHJpbnRrKCJwa3RnZW46IEVSUk9SOiBpbnRlcmZhY2UgYWxyZWFkeSB1c2VkLlxuIik7CiAgICAgICAgICAgICAgICByZXR1cm4gLUVCVVNZOwogICAgICAgIH0KfQoKc3RhdGljIHN0cnVjdCBwa3RnZW5fdGhyZWFkICpwa3RnZW5fZmluZF90aHJlYWQoY29uc3QgY2hhciogbmFtZSkgCnsKICAgICAgICBzdHJ1Y3QgcGt0Z2VuX3RocmVhZCAqdCA9IE5VTEw7CgogICAgICAgdGhyZWFkX2xvY2soKTsKCiAgICAgICAgdCA9IHBrdGdlbl90aHJlYWRzOwogICAgICAgIHdoaWxlICh0KSB7CiAgICAgICAgICAgICAgICBpZiAoc3RyY21wKHQtPm5hbWUsIG5hbWUpID09IDApIAogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKCiAgICAgICAgICAgICAgICB0ID0gdC0+bmV4dDsKICAgICAgICB9CiAgICAgICAgdGhyZWFkX3VubG9jaygpOwogICAgICAgIHJldHVybiB0Owp9CgpzdGF0aWMgaW50IHBrdGdlbl9jcmVhdGVfdGhyZWFkKGNvbnN0IGNoYXIqIG5hbWUsIGludCBjcHUpIAp7CiAgICAgICAgc3RydWN0IHBrdGdlbl90aHJlYWQgKnQgPSBOVUxMOwoKICAgICAgICBpZiAoc3RybGVuKG5hbWUpID4gMzEpIHsKICAgICAgICAgICAgICAgIHByaW50aygicGt0Z2VuOiBFUlJPUjogIFRocmVhZCBuYW1lIGNhbm5vdCBiZSBtb3JlIHRoYW4gMzEgY2hhcmFjdGVycy5cbiIpOwogICAgICAgICAgICAgICAgcmV0dXJuIC1FSU5WQUw7CiAgICAgICAgfQogICAgICAgIAogICAgICAgIGlmIChwa3RnZW5fZmluZF90aHJlYWQobmFtZSkpIHsKICAgICAgICAgICAgICAgIHByaW50aygicGt0Z2VuOiBFUlJPUjogdGhyZWFkOiAlcyBhbHJlYWR5IGV4aXN0c1xuIiwgbmFtZSk7CiAgICAgICAgICAgICAgICByZXR1cm4gLUVJTlZBTDsKICAgICAgICB9CgogICAgICAgIHQgPSBremFsbG9jKHNpemVvZihzdHJ1Y3QgcGt0Z2VuX3RocmVhZCksIEdGUF9LRVJORUwpOwogICAgICAgIGlmICghdCkgewogICAgICAgICAgICAgICAgcHJpbnRrKCJwa3RnZW46IEVSUk9SOiBvdXQgb2YgbWVtb3J5LCBjYW4ndCBjcmVhdGUgbmV3IHRocmVhZC5cbiIpOwogICAgICAgICAgICAgICAgcmV0dXJuIC1FTk9NRU07CiAgICAgICAgfQoKICAgICAgICBzdHJjcHkodC0+bmFtZSwgbmFtZSk7CiAgICAgICAgc3Bpbl9sb2NrX2luaXQoJnQtPmlmX2xvY2spOwoJdC0+Y3B1ID0gY3B1OwogICAgICAgIAogICAgICAgIHNwcmludGYodC0+Zm5h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