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CisgKiBUaGlzIHNpbXBseSBnb2VzIHRocm91Z2ggdGhlIGZpbGUtbmFtZSBkYXRhIGFuZCBwcmludHMgb3V0IHRoZQorICogY3VycmVudCBmaWxlLgorICovCit2b2lkIHByaW50X2N1cnJlbnRfbmFtZSh2b2lkKQoreworCWludCBpPTA7CisKKwl3aGlsZSAoaTxuYW1lX2RlcHRoKQorCQlwcmludGYoIi8lLipzIixuYW1lbGVuLG5hbWVfbGlzdFtpKytdKTsKKwlpZiAoaSA9PSAwKQorCQlwcmludGYgKCIvIik7Cit9CisKK2ludCBhc2soY29uc3QgY2hhciAqIHN0cmluZywgaW50IGRlZikKK3sKKwlpbnQgYzsKKworCWlmICghcmVwYWlyKSB7CisJCXByaW50ZigiXG4iKTsKKwkJZXJyb3JzX3VuY29ycmVjdGVkID0gMTsKKwkJcmV0dXJuIDA7CisJfQorCWlmIChhdXRvbWF0aWMpIHsKKwkJcHJpbnRmKCJcbiIpOworCQlpZiAoIWRlZikKKwkJICAgICAgZXJyb3JzX3VuY29ycmVjdGVkID0gMTsKKwkJcmV0dXJuIGRlZjsKKwl9CisJcHJpbnRmKGRlZj8iJXMgKHkvbik/ICI6IiVzIChuL3kpPyAiLHN0cmluZyk7CisJZm9yICg7OykgeworCQlmZmx1c2goc3Rkb3V0KTsKKwkJaWYgKChjPWdldGNoYXIoKSk9PUVPRikgeworCQkgICAgICAgIGlmICghZGVmKQorCQkJICAgICAgZXJyb3JzX3VuY29ycmVjdGVkID0gMTsKKwkJCXJldHVybiBkZWY7CisJCX0KKwkJYz10b3VwcGVyKGMpOworCQlpZiAoYyA9PSAnWScpIHsKKwkJCWRlZiA9IDE7CisJCQlicmVhazsKKwkJfSBlbHNlIGlmIChjID09ICdOJykgeworCQkJZGVmID0gMDsKKwkJCWJyZWFrOworCQl9IGVsc2UgaWYgKGMgPT0gJyAnIHx8IGMgPT0gJ1xuJykKKwkJCWJyZWFrOworCX0KKwlpZiAoZGVmKQorCQlwcmludGYoInlcbiIpOworCW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rID0gcmVzdWx0OworCXJlYWRfYmxvY2soYmxvY2ssIChjaGFyICopIGluZCk7CisJYmxrX2NoZyA9IDA7CisJcmVzdWx0ID0gY2hlY2tfem9uZV9ucihpbmQgKyAoYmxrbnIlNTEyKSwgJmJsa19jaGcpOworCWlmIChibGtfY2hnKQorCQl3cml0ZV9ibG9jayhibG9jaywgKGNoYXIgKikgaW5kKTsKKwlyZXR1cm4gcmVzdWx0OworfQorCisjaWZkZWYgSEFWRV9NSU5JWDIKK2ludCBtYXBfYmxvY2syIChzdHJ1Y3QgbWluaXgyX2lub2RlICppbm9kZSwgdW5zaWduZWQgaW50IGJsa25yKQoreworICAJdW5zaWduZWQgaW50IGluZFtCTE9DS19TSVpFID4+IDJdOworCXVuc2lnbmVkIGludCBkaW5kW0JMT0NLX1NJWkUgPj4gMl07CisJdW5zaWduZWQgaW50IHRpbmRbQkxPQ0tfU0laRSA+PiAyXTsKKwlpbnQgYmxrX2NoZywgYmxvY2ssIHJlc3VsdDsKKworCWlmIChibGtuciA8IDcpCisJCXJldHVybiBjaGVja196b25lX25yMiAoaW5vZGUtPmlfem9uZSArIGJsa25yLCAmY2hhbmdlZCk7CisJYmxrbnIgLT0gNzsKKwlpZiAoYmxrbnIgPCAyNTYpIHsKKwkJYmxvY2sgPSBjaGVja196b25lX25yMiAoaW5vZGUtPmlfem9uZSArIDcsICZjaGFuZ2VkKTsKKwkJcmVhZF9ibG9jayAoYmxvY2ssIChjaGFyICopIGluZCk7CisJCWJsa19jaGcgPSAwOworCQlyZXN1bHQgPSBjaGVja196b25lX25yMiAoYmxrbnIgKyBpbmQsICZibGtfY2hnKTsKKwkJaWYgKGJsa19jaGcpCisJCQl3cml0ZV9ibG9jayAoYmxvY2ssIChjaGFyICopIGluZCk7CisJCXJldHVybiByZXN1bHQ7CisJfQorCWJsa25yIC09IDI1NjsKKwlpZiAoYmxrbnIgPj0gMjU2ICogMjU2KSB7CisJCWJsb2NrID0gY2hlY2tfem9uZV9ucjIgKGlub2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ja2RldisrOworCQllbHNlIGlmIChTX0lTTE5LIChpbm9kZS0+aV9tb2RlKSkKKwkJCXN5bWxpbmtzKys7CisJCWVsc2UgaWYgKFNfSVNTT0NLIChpbm9kZS0+aV9tb2RlKSk7CisJCWVsc2UgaWYgKFNfSVNGSUZPIChpbm9kZS0+aV9tb2RlKSk7CisJCWVsc2UgeworCQkJcHJpbnRfY3VycmVudF9uYW1lICgpOworCQkJcHJpbnRmIChfKCIgaGFzIG1vZGUgJTA1b1xuIiksIGlub2RlLT5pX21vZGUpOworCQl9CisJfSBlbHNlCisJCWxpbmtzKys7CisJaWYgKCErK2lub2RlX2NvdW50W25yXSkgeworCQlwcmludGYgKF8oIldhcm5pbmc6IGlub2RlIGNvdW50IHRvbyBiaWcuXG4iKSk7CisJCWlub2RlX2NvdW50W25yXS0tOworCQllcnJvcnNfdW5jb3JyZWN0ZWQgPSAxOworCX0KKwlyZXR1cm4gaW5vZGU7Cit9CisjZW5kaWYKKwordm9pZCBjaGVja19yb290KHZvaWQpCit7CisJc3RydWN0IG1pbml4X2lub2RlICogaW5vZGUgPSBJbm9kZSArIFJPT1RfSU5POworCisJaWYgKCFpbm9kZSB8fCAhU19JU0RJUihpbm9kZS0+aV9tb2RlKSkKKwkJZGllKF8oInJvb3QgaW5vZGUgaXNuJ3QgYSBkaXJlY3RvcnkiKSk7Cit9CisKKyNpZmRlZiBIQVZFX01JTklYMgordm9pZCBjaGVja19yb290MiAodm9pZCkKK3sKKwlzdHJ1Y3QgbWluaXgyX2lub2RlICppbm9kZSA9IElub2RlMiArIFJPT1RfSU5POworCisJaWYgKCFpbm9kZSB8fCAhU19JU0RJUiAoaW5vZGUtPmlfbW9kZSkpCisJCWRpZSAoInJvb3QgaW5vZGUgaXNuJ3QgYSBkaXJlY3RvcnkiKTsKK30KKyNlbmRpZgorCitzdGF0aWMgaW50IGFkZF96b25lKHVuc2lnbmVkIHNob3J0ICogem5yLCBpbnQgKiBjb3JyZWN0ZWQpCit7CisJaW50IHJlc3VsdDsKKwlpbnQgYmxvY2s7CisKKwlyZXN1bHQgPSAwOworCWJsb2NrID0gY2hlY2tfem9uZV9ucih6bnIsIGNvcnJlY3RlZCk7CisJaWYgKCFibG9jaykKKwkJcmV0dXJuIDA7CisJaWYgKHpvbmVfY291bnRbYmxvY2tdKSB7CisJCXByaW50ZihfKCJCbG9jayBoYXMgYmVlbiB1c2VkIGJlZm9yZS4gTm93IGluIGZpbGUgYCIpKTsKKwkJcHJpbnRfY3VycmVudF9uYW1lKCk7CisJCXByaW50ZigiJy4iKTsKKwkJaWYgKGFzayhfKCJDbGVhciIpLDEpKSB7CisJCQkqem5yID0gMDsKKwkJCWJsb2NrID0gMDsKKwkJCSpjb3JyZWN0ZWQgPSAxOworCQl9CisJfQorCWlmICghYmxvY2spCisJCXJldHVybiAwOworCWlmICghem9uZV9pbl91c2UoYmxvY2spKSB7CisJCXByaW50ZihfKCJCbG9jayAlZCBpbiBmaWxlIGAiKSxibG9jayk7CisJCXByaW50X2N1cnJlbnRfbmFtZSgpOworCQlwcmludGYoXygiJyBpcyBtYXJrZWQgbm90IGluIHVzZS4iKSk7CisJCWlmIChhc2soXygiQ29ycmVjdCIpLDEpKQorCQkJbWFya196b25lKGJsb2NrKTsKKwl9CisJaWYgKCErK3pvbmVfY291bnRbYmxvY2tdKQorCQl6b25lX2NvdW50W2Jsb2NrXS0tOworCXJldHVybiBibG9jazsKK30KKworI2lmZGVmIEhBVkVfTUlOSVgyCitzdGF0aWMgaW50IGFkZF96b25lMiAodW5zaWduZWQgaW50ICp6bnIsIGludCAqY29ycmVjdGVkKQoreworCWludCByZXN1bHQ7CisJaW50IGJsb2NrOworCisJcmVzdWx0ID0gMDsKKwlibG9jayA9IGNoZWNrX3pvbmVfbnIyICh6bnIsIGNvcnJlY3RlZCk7CisJaWYgKCFibG9jaykKKwkJcmV0dXJuIDA7CisJaWYgKHpvbmVfY291bnRbYmxvY2tdKSB7CisJCXByaW50ZiAoXygiQmxvY2sgaGFzIGJl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hBVkVfTUlOSVgyCitzdGF0aWMgdm9pZAorYWRkX3pvbmVfaW5kMiAodW5zaWduZWQgaW50ICp6bnIsIGludCAqY29ycmVjdGVkKQoreworCXN0YXRpYyBjaGFyIGJsa1tCTE9DS19TSVpFXTsKKwlpbnQgaSwgY2hnX2JsayA9IDA7CisJaW50IGJsb2NrOworCisJYmxvY2sgPSBhZGRfem9uZTIgKHpuciwgY29ycmVjdGVkKTsKKwlpZiAoIWJsb2NrKQorCQlyZXR1cm47CisJcmVhZF9ibG9jayAoYmxvY2ssIGJsayk7CisJZm9yIChpID0gMDsgaSA8IEJMT0NLX1NJWkUgPj4gMjsgaSsrKQorCQlhZGRfem9uZTIgKGkgKyAodW5zaWduZWQgaW50ICopIGJsaywgJmNoZ19ibGspOworCWlmIChjaGdfYmxrKQorCQl3cml0ZV9ibG9jayAoYmxvY2ssIGJsayk7Cit9CisjZW5kaWYKKworc3RhdGljIHZvaWQgYWRkX3pvbmVfZGluZCh1bnNpZ25lZCBzaG9ydCAqIHpuciwgaW50ICogY29ycmVjdGVkKQoreworCXN0YXRpYyBjaGFyIGJsa1tCTE9DS19TSVpFXTsKKwlpbnQgaSwgYmxrX2NoZz0wOworCWludCBibG9jazsKKworCWJsb2NrID0gYWRkX3pvbmUoem5yLCBjb3JyZWN0ZWQpOworCWlmICghYmxvY2spCisJCXJldHVybjsKKwlyZWFkX2Jsb2NrKGJsb2NrLCBibGspOworCWZvciAoaT0wIDsgaSA8IChCTE9DS19TSVpFPj4xKSA7IGkrKykKKwkJYWRkX3pvbmVfaW5kKGkgKyAodW5zaWduZWQgc2hvcnQgKikgYmxrLCAmYmxrX2NoZyk7CisJaWYgKGJsa19jaGcpCisJCXdyaXRlX2Jsb2NrKGJsb2NrLCBibGspOworfQorCisjaWZkZWYgSEFWRV9NSU5JWDIKK3N0YXRpYyB2b2lkCithZGRfem9uZV9kaW5kMiAodW5zaWduZWQgaW50ICp6bnIsIGludCAqY29ycmVjdGVkKQoreworCXN0YXRpYyBjaGFyIGJsa1tCTE9DS19TSVpFXTsKKwlpbnQgaSwgYmxrX2NoZyA9IDA7CisJaW50IGJsb2NrOworCisJYmxvY2sgPSBhZGRfem9uZTIgKHpuciwgY29ycmVjdGVkKTsKKwlpZiAoIWJsb2NrKQorCQlyZXR1cm47CisJcmVhZF9ibG9jayAoYmxvY2ssIGJsayk7CisJZm9yIChpID0gMDsgaSA8IEJMT0NLX1NJWkUgPj4gMjsgaSsrKQorCQlhZGRfem9uZV9pbmQyIChpICsgKHVuc2lnbmVkIGludCAqKSBibGssICZibGtfY2hnKTsKKwlpZiAoYmxrX2NoZykKKwkJd3JpdGVfYmxvY2sgKGJsb2NrLCBibGspOworfQorCitzdGF0aWMgdm9pZAorYWRkX3pvbmVfdGluZDIgKHVuc2lnbmVkIGludCAqem5yLCBpbnQgKmNvcnJlY3RlZCkKK3sKKwlzdGF0aWMgY2hhciBibGtbQkxPQ0tfU0laRV07CisJaW50IGksIGJsa19jaGcgPSAwOworCWludCBibG9jazsKKworCWJsb2NrID0gYWRkX3pvbmUyICh6bnIsIGNvcnJlY3RlZCk7CisJaWYgKCFibG9jaykKKwkJcmV0dXJuOworCXJlYWRfYmxvY2sgKGJsb2NrLCBibGspOworCWZvciAoaSA9IDA7IGkgPCBCTE9DS19TSVpFID4+IDI7IGkrKykKKwkJYWRkX3pvbmVfZGluZDIgKGkgKyAodW5zaWduZWQgaW50ICopIGJsaywgJmJsa19jaGcpOworCWlmIChibGtfY2hnKQorCQl3cml0ZV9ibG9jayAoYmxvY2ssIGJsayk7Cit9CisjZW5kaWYKKwordm9pZCBjaGVja196b25lcyh1bnNpZ25lZCBpbnQgaSkKK3sKKwlzdHJ1Y3QgbWluaXhfaW5vZGUgKiBpbm9kZTsKKworCWlmICghaSB8fCBpID4gSU5PREVTKQorCQlyZXR1cm47CisJaWYgKGlub2RlX2NvdW50W2ldID4gMSkJLyogaGF2ZSB3ZSBjb3VudGVkIHRoaXMgZmlsZSBhbHJlYWR5PyAqLwor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mIChhc2sgKF8oIkNsZWFyIiksIDEpKQorCQkJCXVubWFya19pbm9kZSAoaSk7CisJCQljb250aW51ZTsKKwkJfQorCQlpZiAoIWlub2RlX2luX3VzZSAoaSkpIHsKKwkJCXByaW50ZiAoXygiSW5vZGUgJWQgdXNlZCwgbWFya2VkIHVudXNlZCBpbiB0aGUgYml0bWFwLiIpLCBpKTsKKwkJCWlmIChhc2sgKF8oIlNldCIpLCAxKSkKKwkJCQltYXJrX2lub2RlIChpKTsKKwkJfQorCQlpZiAoSW5vZGUyW2ldLmlfbmxpbmtzICE9IGlub2RlX2NvdW50W2ldKSB7CisJCQlwcmludGYgKF8oIklub2RlICVkIChtb2RlID0gJTA3byksIGlfbmxpbmtzPSVkLCBjb3VudGVkPSVkLiIpLAorCQkJCWksIElub2RlMltpXS5pX21vZGUsIElub2RlMltpXS5pX25saW5rcywgaW5vZGVfY291bnRbaV0pOworCQkJaWYgKGFzayAoXygiU2V0IGlfbmxpbmtzIHRvIGNvdW50IiksIDEpKSB7CisJCQkJSW5vZGUyW2ldLmlfbmxpbmtzID0gaW5vZGVfY291bnRbaV07CisJCQkJY2hhbmdlZCA9IDE7CisJCQl9CisJCX0KKwl9CisJZm9yIChpID0gRklSU1RaT05FOyBpIDwgWk9ORVM7IGkrKykgeworCQlpZiAoem9uZV9pbl91c2UgKGkpID09IHpvbmVfY291bnRbaV0pCisJCQljb250aW51ZTsKKwkJaWYgKCF6b25lX2NvdW50W2ldKSB7CisJCQlpZiAoYmFkX3pvbmUgKGkpKQorCQkJCWNvbnRpbnVlOworCQkJcHJpbnRmIChfKCJab25lICVkOiBtYXJrZWQgaW4gdXNlLCBubyBmaWxlIHVzZXMgaXQuIiksIGkpOworCQkJaWYgKGFzayAoXygiVW5tYXJrIiksIDEpKQorCQkJCXVubWFya196b25lIChpKTsKKwkJCWNvbnRpbnVlOworCQl9CisJCXByaW50ZiAoXygiWm9uZSAlZDogJXNpbiB1c2UsIGNvdW50ZWQ9JWRcbiIpLAorCQkJaSwgem9uZV9pbl91c2UgKGkpID8gIiIgOiBfKCJub3QgIiksIHpvbmVfY291bnRbaV0pOworCX0KK30KKyNlbmRpZgorCit2b2lkIGNoZWNrKHZvaWQpCit7CisJbWVtc2V0KGlub2RlX2NvdW50LDAsKElOT0RFUyArIDEpICogc2l6ZW9mKCppbm9kZV9jb3VudCkpOworCW1lbXNldCh6b25lX2NvdW50LDAsWk9ORVMqc2l6ZW9mKCp6b25lX2NvdW50KSk7CisJY2hlY2tfem9uZXMoUk9PVF9JTk8pOworCXJlY3Vyc2l2ZV9jaGVjayhST09UX0lOTyk7CisJY2hlY2tfY291bnRzKCk7Cit9CisKKyNpZmRlZiBIQVZFX01JTklYMgordm9pZAorY2hlY2syICh2b2lkKQoreworCW1lbXNldCAoaW5vZGVfY291bnQsIDAsIChJTk9ERVMgKyAxKSAqIHNpemVvZiAoKmlub2RlX2NvdW50KSk7CisJbWVtc2V0ICh6b25lX2NvdW50LCAwLCBaT05FUyAqIHNpemVvZiAoKnpvbmVfY291bnQpKTsKKwljaGVja196b25lczIgKFJPT1RfSU5PKTsKKwlyZWN1cnNpdmVfY2hlY2syIChST09UX0lOTyk7CisJY2hlY2tfY291bnRzMiAoKTsKK30KKyNlbmRpZgorCitleHRlcm4gaW50IAorZnNja19taW5peF9tYWluKGludCBhcmdjLCBjaGFyICoqIGFyZ3YpCit7CisJc3RydWN0IHRlcm1pb3MgdG1wOworCWludCBjb3VudDsKKwlpbnQgcmV0Y29kZSA9IDA7CisKKwlzZXRsb2NhbGUoTENfQUxMLCAiIik7CisJYmluZHRleHRkb21haW4oUEFDS0FHRSwgTE9DQUxFRElSKTsKKwl0ZXh0ZG9tYWluKFBBQ0tBR0UpOworCQorCisJaWYgKGFyZ2MgJiYgKmFyZ3YpCisJCXByb2dyYW1fbmFtZSA9ICphcmd2OworCWlmIChJTk9ERV9TSVpFICogTUlOSVhfSU5PREVTX1BFUl9CTE9DSyAhPSBCTE9DS19TSVpFKQorCQlkaWUoXygi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B0cnkpCisJCQljb250aW51ZTsKKwkJaWYgKGN1cnJlbnRseV90ZXN0aW5nIDwgRklSU1RaT05FKQorCQkJZGllKF8oImJhZCBibG9ja3MgYmVmb3JlIGRhdGEtYXJlYTogY2Fubm90IG1ha2UgZnMiKSk7CisJCW1hcmtfem9uZShjdXJyZW50bHlfdGVzdGluZyk7CisJCWJhZGJsb2NrcysrOworCQljdXJyZW50bHlfdGVzdGluZysrOworCX0KKwlpZiAoYmFkYmxvY2tzID4gMSkKKwkJcHJpbnRmKF8oIiVkIGJhZCBibG9ja3NcbiIpLCBiYWRibG9ja3MpOworCWVsc2UgaWYgKGJhZGJsb2NrcyA9PSAxKQorCQlwcmludGYoXygib25lIGJhZCBibG9ja1xuIikpOworfQorCit2b2lkIGdldF9saXN0X2Jsb2NrcyhmaWxlbmFtZSkKK2NoYXIgKmZpbGVuYW1lOworCit7CisgIEZJTEUgKmxpc3RmaWxlOworICB1bnNpZ25lZCBsb25nIGJsb2Nrbm87CisKKyAgbGlzdGZpbGU9Zm9wZW4oZmlsZW5hbWUsInIiKTsKKyAgaWYobGlzdGZpbGUgPT0gKEZJTEUgKilOVUxMKSB7CisgICAgZGllKF8oImNhbid0IG9wZW4gZmlsZSBvZiBiYWQgYmxvY2tzIikpOworICB9CisgIHdoaWxlKCFmZW9mKGxpc3RmaWxlKSkgeworICAgIGZzY2FuZihsaXN0ZmlsZSwiJWxkXG4iLCAmYmxvY2tubyk7CisgICAgbWFya196b25lKGJsb2Nrbm8pOworICAgIGJhZGJsb2NrcysrOworICB9CisgIGlmKGJhZGJsb2NrcyA+IDEpCisgICAgcHJpbnRmKF8oIiVkIGJhZCBibG9ja3NcbiIpLCBiYWRibG9ja3MpOworICBlbHNlIGlmIChiYWRibG9ja3MgPT0gMSkKKyAgICBwcmludGYoXygib25lIGJhZCBibG9ja1xuIikpOworfQorCitleHRlcm4gaW50IAorbWtmc19taW5peF9tYWluKGludCBhcmdjLCBjaGFyICoqIGFyZ3YpCit7CisgIG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WFkeSBtb3VudGVkPyAqLworICB0bXAgPSByb290X2Jsb2NrOworICAqKHNob3J0ICopdG1wID0gMTsKKyAgc3RyY3B5KHRtcCsyLCIuIik7CisgIHRtcCArPSBkaXJzaXplOworICAqKHNob3J0ICopdG1wID0gMTsKKyAgc3RyY3B5KHRtcCsyLCIuLiIpOworICB0bXAgKz0gZGlyc2l6ZTsKKyAgKihzaG9ydCAqKXRtcCA9IDI7CisgIHN0cmNweSh0bXArMiwiLmJhZGJsb2NrcyIpOworICBERVYgPSBvcGVuKGRldmljZV9uYW1lLE9fUkRXUiApOworICBpZiAoREVWPDApCisgICAgZGllKF8oInVuYWJsZSB0byBvcGVuICVzIikpOworICBpZiAoZnN0YXQoREVWLCZzdGF0YnVmKTwwKQorICAgIGRpZShfKCJ1bmFibGUgdG8gc3RhdCAlcyIpKTsKKyAgaWYgKCFTX0lTQkxLKHN0YXRidWYuc3RfbW9kZSkpCisgICAgY2hlY2s9MDsKKyAgZWxzZSBpZiAoc3RhdGJ1Zi5zdF9yZGV2ID09IDB4MDMwMCB8fCBzdGF0YnVmLnN0X3JkZXYgPT0gMHgwMzQwKQorICAgIGRpZShfKCJ3aWxsIG5vdCB0cnkgdG8gbWFrZSBmaWxlc3lzdGVtIG9uICclcyciKSk7CisgIHNldHVwX3RhYmxlcygpOworICBpZiAoY2hlY2spCisgICAgY2hlY2tfYmxvY2tzKCk7CisgIGVsc2UgaWYgKGxpc3RmaWxlKQorICAgIGdldF9saXN0X2Jsb2NrcyhsaXN0ZmlsZSk7CisjaWZkZWYgSEFWRV9NSU5JWDIKKyAgaWYgKHZlcnNpb24yKSB7CisgICAgbWFrZV9yb290X2lub2RlMiAoKTsKKyAgICBtYWtlX2JhZF9pbm9kZTIgKCk7CisgIH0gZWxzZQorI2VuZGlmCisgICAgeworICAgICAgbWFrZV9yb290X2lub2RlKCk7CisgICAgICBtYWtlX2JhZF9pbm9kZSgpOworICAgIH0KKyAgbWFya19nb29kX2Jsb2NrcygpOworICB3c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cmVhZCBpbm9kZXMiKSk7CisJaWYgKE5PUk1fRklSU1RaT05FICE9IEZJUlNUWk9ORSkgeworCQlwcmludGYoXygiV2FybmluZzogRmlyc3R6b25lICE9IE5vcm1fZmlyc3R6b25lXG4iKSk7CisJCWVycm9yc191bmNvcnJlY3RlZCA9IDE7CisJfQorCWdldF9kaXJzaXplICgpOworCWlmIChzaG93KSB7CisJCXByaW50ZihfKCIlbGQgaW5vZGVzXG4iKSxJTk9ERVMpOworCQlwcmludGYoXygiJWxkIGJsb2Nrc1xuIiksWk9ORVMpOworCQlwcmludGYoXygiRmlyc3RkYXRhem9uZT0lbGQgKCVsZClcbiIpLEZJUlNUWk9ORSxOT1JNX0ZJUlNUWk9ORSk7CisJCXByaW50ZihfKCJab25lc2l6ZT0lZFxuIiksQkxPQ0tfU0laRTw8Wk9ORVNJWkUpOworCQlwcmludGYoXygiTWF4c2l6ZT0lbGRcbiIpLE1BWFNJWkUpOworCQlwcmludGYoXygiRmlsZXN5c3RlbSBzdGF0ZT0lZFxuIiksIFN1cGVyLnNfc3RhdGUpOworCQlwcmludGYoXygibmFtZWxlbj0lZFxuXG4iKSxuYW1lbGVuKTsKKwl9Cit9CisKK3N0cnVjdCBtaW5peF9pbm9kZSAqIGdldF9pbm9kZSh1bnNpZ25lZCBpbnQgbnIpCit7CisJc3RydWN0IG1pbml4X2lub2RlICogaW5vZGU7CisKKwlpZiAoIW5yIHx8IG5yID4gSU5PREVTKQorCQlyZXR1cm4gTlVMTDsKKwl0b3RhbCsrOworCWlub2RlID0gSW5vZGUgKyBucjsKKwlpZiAoIWlub2RlX2NvdW50W25yXSkgeworCQlpZiAoIWlub2RlX2luX3VzZShucikpIHsKKwkJCXByaW50ZihfKCJJbm9kZSAlZCBtYXJrZWQgbm90IHVzZWQsIGJ1dCB1c2VkIGZvciBmaWxlICciKSwKKwkJCQlucik7CisJCQlwcmludF9jdXJyZW50X25hbWUoKTsKKwkJCXByaW50ZigiJ1xuIik7CisJCQlpZiAocm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VycmVudF9uYW1lKCk7CisJCXByaW50ZigiJy4iKTsKKwkJaWYgKGFzayhfKCJDbGVhciIpLDEpKSB7CisJCQkqem5yID0gMDsKKwkJCWJsb2NrID0gMDsKKwkJCSpjb3JyZWN0ZWQgPSAxOworCQl9CisJfQorCWlmICghYmxvY2spCisJCXJldHVybiAwOworCWlmICghem9uZV9pbl91c2UoYmxvY2spKSB7CisJCXByaW50ZihfKCJCbG9jayAlZCBpbiBmaWxlIGAiKSxibG9jayk7CisJCXByaW50X2N1cnJlbnRfbmFtZSgpOworCQlwcmludGYoXygiJyBpcyBtYXJrZWQgbm90IGluIHVzZS4iKSk7CisJCWlmIChhc2soXygiQ29ycmVjdCIpLDEpKQorCQkJbWFya196b25lKGJsb2NrKTsKKwl9CisJaWYgKCErK3pvbmVfY291bnRbYmxvY2tdKQorCQl6b25lX2NvdW50W2Jsb2NrXS0tOworCXJldHVybiBibG9jazsKK30KKworI2lmZGVmIEhBVkVfTUlOSVgyCitzdGF0aWMgaW50IGFkZF96b25lMiAodW5zaWduZWQgaW50ICp6bnIsIGludCAqY29ycmVjdGVkKQoreworCWludCByZXN1bHQ7CisJaW50IGJsb2NrOworCisJcmVzdWx0ID0gMDsKKwlibG9jayA9IGNoZWNrX3pvbmVfbnIyICh6bnIsIGNvcnJlY3RlZCk7CisJaWYgKCFibG9jaykKKwkJcmV0dXJuIDA7CisJaWYgKHpvbmVfY291bnRbYmxvY2tdKSB7CisJCXByaW50ZiAoXygiQmxvY2sgaGFzIGJlZW4gdXNlZCBiZWZvcmUuIE5vdyBpbiBmaWxlIGAiKSk7CisJCXByaW50X2N1cnJlbnRfbmFtZSAoKTsKKwkJcHJpbnRmICgiJy4iKTsKKwkJaWYgKGFzayAoXygiQ2xlYXIiKSwgMSkpIHsKKwkJCSp6bnIgPSAwOworCQkJYmxvY2sgPSAwOworCQkJKmNvcnJlY3RlZCA9IDE7CisJCX0KKwl9CisJaWYgKCFibG9jaykKKwkJcmV0dXJuIDA7CisJaWYgKCF6b25lX2luX3VzZSAoYmxvY2spKSB7CisJCXByaW50ZiAoXygiQmxvY2sgJWQgaW4gZmlsZSBgIiksIGJsb2NrKTsKKwkJcHJpbnRfY3VycmVudF9uYW1lICgpOworCQlwcmludGYgKF8oIicgaXMgbWFya2VkIG5vdCBpbiB1c2UuIikpOworCQlpZiAoYXNrIChfKCJDb3JyZWN0IiksIDEpKQorCQkJbWFya196b25lIChibG9jayk7CisJfQorCWlmICghKyt6b25lX2NvdW50W2Jsb2NrXSkKKwkJem9uZV9jb3VudFtibG9ja10tLTsKKwlyZXR1cm4gYmxvY2s7Cit9CisjZW5kaWYKKworc3RhdGljIHZvaWQgYWRkX3pvbmVfaW5kKHVuc2lnbmVkIHNob3J0ICogem5yLCBpbnQgKiBjb3JyZWN0ZWQpCit7CisJc3RhdGljIGNoYXIgYmxrW0JMT0NLX1NJWkVdOworCWludCBpLCBjaGdfYmxrPTA7CisJaW50IGJsb2NrOworCisJYmxvY2sgPSBhZGRfem9uZSh6bnIsIGNvcnJlY3RlZCk7CisJaWYgKCFibG9jaykKKwkJcmV0dXJuOworCXJlYWRfYmxvY2soYmxvY2ssIGJsayk7CisJZm9yIChpPTAgOyBpIDwgKEJMT0NLX1NJWkU+PjEpIDsgaSsrKQorCQlhZGRfem9uZShpICsgKHVuc2lnbmVkIHNob3J0ICopIGJsaywgJmNoZ19ibGspOworCWlmIChjaGdfYmxrKQorCQl3cml0ZV9ibG9jayhibG9jaywgYmxrKTsKK30KKworI2lmZGVmIEhBVkVfTUlOSVgyCitzdGF0aWMgdm9pZAorYWRkX3pvbmVfaW5kMiAodW5zaWduZWQgaW50ICp6bnIsIGludCAqY29ycmVjdGVkKQoreworCXN0YXRpYyBjaGFyIGJsa1tCTE9DS19TSVpFXTsKKwlpbnQgaSwgY2hnX2JsayA9IDA7CisJaW50IGJsb2NrOworCisJYmxvY2sgPSBhZGRfem9uZTIgKHpuciwgY29ycmVjdGVkKTsKKwlpZiAoIWJsb2NrKQorCQlyZ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V9pbmQyIChpICsgKHVuc2lnbmVkIGludCAqKSBibGssICZibGtfY2hnKTsKKwlpZiAoYmxrX2NoZykKKwkJd3JpdGVfYmxvY2sgKGJsb2NrLCBibGspOworfQorCitzdGF0aWMgdm9pZAorYWRkX3pvbmVfdGluZDIgKHVuc2lnbmVkIGludCAqem5yLCBpbnQgKmNvcnJlY3RlZCkKK3sKKwlzdGF0aWMgY2hhciBibGtbQkxPQ0tfU0laRV07CisJaW50IGksIGJsa19jaGcgPSAwOworCWludCBibG9jazsKKworCWJsb2NrID0gYWRkX3pvbmUyICh6bnIsIGNvcnJlY3RlZCk7CisJaWYgKCFibG9jaykKKwkJcmV0dXJuOworCXJlYWRfYmxvY2sgKGJsb2NrLCBibGspOworCWZvciAoaSA9IDA7IGkgPCBCTE9DS19TSVpFID4+IDI7IGkrKykKKwkJYWRkX3pvbmVfZGluZDIgKGkgKyAodW5zaWduZWQgaW50ICopIGJsaywgJmJsa19jaGcpOworCWlmIChibGtfY2hnKQorCQl3cml0ZV9ibG9jayAoYmxvY2ssIGJsayk7Cit9CisjZW5kaWYKKwordm9pZCBjaGVja196b25lcyh1bnNpZ25lZCBpbnQgaSkKK3sKKwlzdHJ1Y3QgbWluaXhfaW5vZGUgKiBpbm9kZTsKKworCWlmICghaSB8fCBpID4gSU5PREVTKQorCQlyZXR1cm47CisJaWYgKGlub2RlX2NvdW50W2ldID4gMSkJLyogaGF2ZSB3ZSBjb3VudGVkIHRoaXMgZmlsZSBhbHJlYWR5PyAqLworCQlyZXR1cm47CisJaW5vZGUgPSBJbm9kZSArIGk7CisJaWYgKCFTX0lTRElSKGlub2RlLT5pX21vZGUpICYmICFTX0lTUkVHKGlub2RlLT5pX21vZGUpICYmCisJICAgICFTX0lTTE5LKGlub2RlLT5pX21vZGUpKQorCQlyZXR1cm47CisJZm9yIChpPTAgOyBpPDcgOyBpKyspCisJCWFkZF96b25lKGkgKyBpbm9kZS0+aV96b25lLCAmY2hhbmdlZCk7CisJYWRkX3pvb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pKTsKKwkJfQorCQlpZiAoSW5vZGUyW2ldLmlfbmxpbmtzICE9IGlub2RlX2NvdW50W2ldKSB7CisJCQlwcmludGYgKF8oIklub2RlICVkIChtb2RlID0gJTA3byksIGlfbmxpbmtzPSVkLCBjb3VudGVkPSVkLiIpLAorCQkJCWksIElub2RlMltpXS5pX21vZGUsIElub2RlMltpXS5pX25saW5rcywgaW5vZGVfY291bnRbaV0pOworCQkJaWYgKGFzayAoXygiU2V0IGlfbmxpbmtzIHRvIGNvdW50IiksIDEpKSB7CisJCQkJSW5vZGUyW2ldLmlfbmxpbmtzID0gaW5vZGVfY291bnRbaV07CisJCQkJY2hhbmdlZCA9IDE7CisJCQl9CisJCX0KKwl9CisJZm9yIChpID0gRklSU1RaT05FOyBpIDwgWk9ORVM7IGkrKykgeworCQlpZiAoem9uZV9pbl91c2UgKGkpID09IHpvbmVfY291bnRbaV0pCisJCQljb250aW51ZTsKKwkJaWYgKCF6b25lX2NvdW50W2ldKSB7CisJCQlpZiAoYmFkX3pvbmUgKGkpKQorCQkJCWNvbnRpbnVlOworCQkJcHJpbnRmIChfKCJab25lICVkOiBtYXJrZWQgaW4gdXNlLCBubyBmaWxlIHVzZXMgaXQuIiksIGkpOworCQkJaWYgKGFzayAoXygiVW5tYXJrIiksIDEpKQorCQkJCXVubWFya196b25lIChpKTsKKwkJCWNvbnRpbnVlOworCQl9CisJCXByaW50ZiAoXygiWm9uZSAlZDogJXNpbiB1c2UsIGNvdW50ZWQ9JWRcbiIpLAorCQkJaSwgem9uZV9pbl91c2UgKGkpID8gIiIgOiBfKCJub3QgIiksIHpvbmVfY291bnRbaV0pOworCX0KK30KKyNlbmRpZgorCit2b2lkIGNoZWNrKHZvaWQpCit7CisJbWVtc2V0KGlub2RlX2NvdW50LDAsKElOT0RFUyArIDEpICogc2l6ZW9mKCppbm9kZV9jb3VudCkpOworCW1lbXNldCh6b25lX2NvdW50LDAsWk9ORVMqc2l6ZW9mKCp6b25lX2NvdW50KSk7CisJY2hlY2tfem9uZXMoUk9PVF9JTk8pOworCXJlY3Vyc2l2ZV9jaGVjayhST09UX0lOTyk7CisJY2hlY2tfY291bnRzKCk7Cit9CisKKyNpZmRlZiBIQVZFX01JTklYMgordm9pZAorY2hlY2syICh2b2lkKQoreworCW1lbXNldCAoaW5vZGVfY291bnQsIDAsIChJTk9ERVMgKyAxKSAqIHNpemVvZiAoKmlub2RlX2NvdW50KSk7CisJbWVtc2V0ICh6b25lX2NvdW50LCAwLCBaT05FUyAqIHNpemVvZiAoKnpvbmVfY291bnQpKTsKKwljaGVja196b25lczIgKFJPT1RfSU5PKTsKKwlyZWN1cnNpdmVfY2hlY2syIChST09UX0lOTyk7CisJY2hlY2tfY291bnRzMiAoKTsKK30KKyNlbmRpZgorCitleHRlcm4gaW50IAorZnNja19taW5peF9tYWluKGludCBhcmdjLCBjaGFyICoqIGFyZ3YpCit7CisJc3RydWN0IHRlcm1pb3MgdG1wOworCWludCBjb3VudDsKKwlpbnQgcmV0Y29kZSA9IDA7CisKKwlzZXRsb2NhbGUoTENfQUxMLCAiIik7CisJYmluZHRleHRkb21haW4oUEFDS0FHRSwgTE9DQUxFRElSKTsKKwl0ZXh0ZG9tYWluKFBBQ0tBR0UpOworCQorCisJaWYgKGFyZ2MgJiYgKmFyZ3YpCisJCXByb2dyYW1fbmFtZSA9ICphcmd2OworCWlmIChJTk9ERV9TSVpFICogTUlOSVhfSU5PREVTX1BFUl9CTE9DSyAhPSBCTE9DS19TSVpFKQorCQlkaWUoXygiYmFkIGlub2RlIHNpemUiKSk7CisjaWZkZWYgSEFWRV9NSU5JWDIKKwlpZiAoSU5PREVfU0laRTIgKiBNSU5JWDJfSU5PREVTX1BFUl9CTE9DSyAhPSBCTE9DS19TSVpFKQorCQlkaWUoXygiYmFkIHYyIGlub2RlIHNpemUiKSk7CisjZW5kaWYKKwl3aGlsZSAoYXJnYy0tID4gMSkgeworCQlhcmd2Kys7CisJCWlmIChhcmd2WzBdWzBdICE9ICctJykgeworCQk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ICAgcHJpbnRmKF8oIiVkIGJhZCBibG9ja3NcbiIpLCBiYWRibG9ja3MpOworICBlbHNlIGlmIChiYWRibG9ja3MgPT0gMSkKKyAgICBwcmludGYoXygib25lIGJhZCBibG9ja1xuIikpOworfQorCitleHRlcm4gaW50IAorbWtmc19taW5peF9tYWluKGludCBhcmdjLCBjaGFyICoqIGFyZ3YpCit7CisgIGludCBpOworICBjaGFyICogdG1wOworICBzdHJ1Y3Qgc3RhdCBzdGF0YnVmOworICBjaGFyICogbGlzdGZpbGUgPSBOVUxMOworCisgIGlmIChhcmdjICYmICphcmd2KQorICAgIHByb2dyYW1fbmFtZSA9ICphcmd2OworICBpZiAoSU5PREVfU0laRSAqIE1JTklYX0lOT0RFU19QRVJfQkxPQ0sgIT0gQkxPQ0tfU0laRSkKKyAgICBkaWUoXygiYmFkIGlub2RlIHNpemUiKSk7CisjaWZkZWYgSEFWRV9NSU5JWDIKKyAgaWYgKElOT0RFX1NJWkUyICogTUlOSVgyX0lOT0RFU19QRVJfQkxPQ0sgIT0gQkxPQ0tfU0laRSkKKyAgICBkaWUoXygiYmFkIGlub2RlIHNpemUiKSk7CisjZW5kaWYKKyAgb3B0ZXJyID0gMDsKKyAgd2hpbGUgKChpID0gZ2V0b3B0KGFyZ2MsIGFyZ3YsICJjaTpsOm46diIpKSAhPSBFT0YpCisgICAgc3dpdGNoIChpKSB7CisgICAgICBjYXNlICdjJzoKKwljaGVjaz0xOyBicmVhazsKKyAgICAgIGNhc2UgJ2knOgorICAgICAgICByZXFfbnJfaW5vZGVzID0gKHVuc2lnbmVkIGxvbmcpIGF0b2wob3B0YXJnKTsKKwlicmVhazsKKyAgICAgIGNhc2UgJ2wnOgorCWxpc3RmaWxlID0gb3B0YXJnOyBicmVhazsKKyAgICAgIGNhc2UgJ24nOgorCWkgPSBzdHJ0b3VsKG9wdGFyZywmdG1wLDApOworCWlmICgqdG1wKQorCSAgdXNhZ2UoKTsKKwlpZiAoaSA9PSAxNCkKKwkgIG1hZ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