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ZGVmaW5lIE1BWEVYUDIgICAgICAgICAoKDEgPDxFWFBTSVpFMikgLSAxKSAgICAvKiBNYXhpbXVtIGV4cG9uZW50LiAqLworCitzdGF0aWMgY29tcDJfdCBlbmNvZGVfY29tcDJfdCh1NjQgdmFsdWUpCit7CisgICAgICAgIGludCBleHAsIHJuZDsKKworICAgICAgICBleHAgPSAodmFsdWUgPiAoTUFYRlJBQ1QyPj4xKSk7CisgICAgICAgIHJuZCA9IDA7CisgICAgICAgIHdoaWxlICh2YWx1ZSA+IE1BWEZSQUNUMikgeworICAgICAgICAgICAgICAgIHJuZCA9IHZhbHVlICYgMTsKKyAgICAgICAgICAgICAgICB2YWx1ZSA+Pj0gMTsKKyAgICAgICAgICAgICAgICBleHArKzsKKyAgICAgICAgfQorCisgICAgICAgIC8qCisgICAgICAgICAqIElmIHdlIG5lZWQgdG8gcm91bmQgdXAsIGRvIGl0IChhbmQgaGFuZGxlIG92ZXJmbG93IGNvcnJlY3RseSkuCisgICAgICAgICAqLworICAgICAgICBpZiAocm5kICYmICgrK3ZhbHVlID4gTUFYRlJBQ1QyKSkgeworICAgICAgICAgICAgICAgIHZhbHVlID4+PSAxOworICAgICAgICAgICAgICAgIGV4cCsrOworICAgICAgICB9CisKKyAgICAgICAgaWYgKGV4cCA+IE1BWEVYUDIpIHsKKyAgICAgICAgICAgICAgICAvKiBPdmVyZmxvdy4gUmV0dXJuIGxhcmdlc3QgcmVwcmVzZW50YWJsZSBudW1iZXIgaW5zdGVhZC4gKi8KKyAgICAgICAgICAgICAgICByZXR1cm4gKDF1bCA8PCAoTUFOVFNJWkUyK0VYUFNJWkUyLTEpKSAtIDE7CisgICAgICAgIH0gZWxzZSB7CisgICAgICAgICAgICAgICAgcmV0dXJuICh2YWx1ZSAmIChNQVhGUkFDVDI+PjEpKSB8IChleHAgPDwgKE1BTlRTSVpFMi0xKSk7CisgICAgICAgIH0KK30KKyNlbmRpZgorCisjaWYgQUNDVF9WRVJTSU9OPT0zCisvKgorICogZ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c2l6ZW9mKGluaGVyaXRhYmxlKSkgfHwKKwkgY29weV9mcm9tX3VzZXIoJnBlcm1pdHRlZCwgJmRhdGEtPnBlcm1pdHRlZCwgc2l6ZW9mKHBlcm1pdHRlZCkpKQorCSAgICAgcmV0dXJuIC1FRkFVTFQ7IAorCisgICAgIHNwaW5fbG9jaygmdGFza19jYXBhYmlsaXR5X2xvY2spOworICAgICByZWFkX2xvY2soJnRhc2tsaXN0X2xvY2spOworCisgICAgIGlmIChwaWQgPiAwICYmIHBpZCAhPSBjdXJyZW50LT5waWQpIHsKKyAgICAgICAgICB0YXJnZXQgPSBmaW5kX3Rhc2tfYnlfcGlkKHBpZCk7CisgICAgICAgICAgaWYgKCF0YXJnZXQpIHsKKyAgICAgICAgICAgICAgIHJldCA9IC1FU1JDSDsKKyAgICAgICAgICAgICAgIGdvdG8gb3V0OworICAgICAgICAgIH0KKyAgICAgfSBlbHNlCisgICAgICAgICAgICAgICB0YXJnZXQgPSBjdXJyZW50OworCisgICAgIHJldCA9IDA7CisKKyAgICAgLyogaGF2aW5nIHZlcmlmaWVkIHRoYXQgdGhlIHByb3Bvc2VkIGNoYW5nZXMgYXJlIGxlZ2FsLAorICAgICAgICAgICB3ZSBub3cgcHV0IHRoZW0gaW50byBlZmZlY3QuICovCisgICAgIGlmIChwaWQgPCAwKSB7CisgICAgICAgICAgICAgaWYgKHBpZCA9PSAtMSkgIC8qIGFsbCBwcm9jcyBvdGhlciB0aGFuIGN1cnJlbnQgYW5kIGluaXQgKi8KKyAgICAgICAgICAgICAgICAgICAgIHJldCA9IGNhcF9zZXRfYWxsKCZlZmZlY3RpdmUsICZpbmhlcml0YWJsZSwgJnBlcm1pdHRlZCk7CisKKyAgICAgICAgICAgICBlbHNlICAgICAgICAgICAgLyogYWxsIHByb2NzIGluIHByb2Nlc3MgZ3JvdXAgKi8KKyAgICAgICAgICAgICAgICAgICAgIHJldCA9IGNhcF9zZXRfcGcoLXBpZCwgJmVmZmVjdGl2ZSwgJmlua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VjLCAmby0+aXRfdmFsdWUudHZfc2VjKSB8CisJCSBfX3B1dF91c2VyKGktPml0X3ZhbHVlLnR2X3VzZWMsICZvLT5pdF92YWx1ZS50dl91c2VjKSkpOworfQorCithc21saW5rYWdlIGxvbmcgY29tcGF0X3N5c19nZXRpdGltZXIoaW50IHdoaWNoLAorCQlzdHJ1Y3QgY29tcGF0X2l0aW1lcnZhbCBfX3VzZXIgKml0KQoreworCXN0cnVjdCBpdGltZXJ2YWwga2l0OworCWludCBlcnJvcjsKKworCWVycm9yID0gZG9fZ2V0aXRpbWVyKHdoaWNoLCAma2l0KTsKKwlpZiAoIWVycm9yICYmIHB1dF9jb21wYXRfaXRpbWVydmFsKGl0LCAma2l0KSkKKwkJZXJyb3IgPSAtRUZBVUxUOworCXJldHVybiBlcnJvcjsKK30KKworYXNtbGlua2FnZSBsb25nIGNvbXBhdF9zeXNfc2V0aXRpbWVyKGludCB3aGljaCwKKwkJc3RydWN0IGNvbXBhdF9pdGltZXJ2YWwgX191c2VyICppbiwKKwkJc3RydWN0IGNvbXBhdF9pdGltZXJ2YWwgX191c2VyICpvdXQpCit7CisJc3RydWN0IGl0aW1lcnZhbCBraW4sIGtvdXQ7CisJaW50IGVycm9yOworCisJaWYgKGluKSB7CisJCWlmIChnZXRfY29tcGF0X2l0aW1lcnZhbCgma2luLCBpbikpCisJCQlyZXR1cm4gLUVGQVVMVDsKKwl9IGVsc2UKKwkJbWVtc2V0KCZraW4sIDAsIHNpemVvZihraW4pKTsKKworCWVycm9yID0gZG9fc2V0aXRpbWVyKHdoaWNoLCAma2luLCBvdXQgPyAma291dCA6IE5VTEwpOworCWlmIChlcnJvciB8fCAhb3V0KQorCQlyZXR1cm4gZXJyb3I7CisJaWYgKHB1dF9jb21wYXRfaXRpbWVydmFsKG91dCwgJmtvdXQpKQorCQlyZXR1cm4gLUVGQVVMVDsKKwlyZXR1cm4gMDsKK30KKworYXNtbGlua2FnZSBsb25nIGNvbXBhdF9zeXNfdGltZXMoc3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IE5VTEwsCisJCQkgICAgICBvc2V0ID8gKG9sZF9zaWdzZXRfdCBfX3VzZXIgKikgJnMgOiBOVUxMKTsKKwlzZXRfZnMob2xkX2ZzKTsKKwlpZiAocmV0ID09IDApCisJCWlmIChvc2V0KQorCQkJcmV0ID0gcHV0X3VzZXIocywgb3NldCk7CisJcmV0dXJuIHJldDsKK30KKworI2lmZGVmIENPTkZJR19GVVRFWAorYXNtbGlua2FnZSBsb25nIGNvbXBhdF9zeXNfZnV0ZXgodTMyIF9fdXNlciAqdWFkZHIsIGludCBvcCwgaW50IHZhbCwKKwkJc3RydWN0IGNvbXBhdF90aW1lc3BlYyBfX3VzZXIgKnV0aW1lLCB1MzIgX191c2VyICp1YWRkcjIsCisJCWludCB2YWwzKQoreworCXN0cnVjdCB0aW1lc3BlYyB0OworCXVuc2lnbmVkIGxvbmcgdGltZW91dCA9IE1BWF9TQ0hFRFVMRV9USU1FT1VUOworCWludCB2YWwyID0gMDsKKworCWlmICgob3AgPT0gRlVURVhfV0FJVCkgJiYgdXRpbWUpIHsKKwkJaWYgKGdldF9jb21wYXRfdGltZXNwZWMoJnQsIHV0aW1lKSkKKwkJCXJldHVybiAtRUZBVUxUOworCQl0aW1lb3V0ID0gdGltZXNwZWNfdG9famlmZmllcygmdCkgKyAxOworCX0KKwlpZiAob3AgPj0gRlVURVhfUkVRVUVVRSkKKwkJdmFsMiA9IChpbnQpICh1bnNpZ25lZCBsb25nKSB1dGltZTsKKworCXJldHVybiBkb19mdXRleCgodW5zaWduZWQgbG9uZyl1YWRkciwgb3AsIHZhbCwgdGltZW91dCwKKwkJCSh1bnNpZ25lZCBsb25nKXVhZGRyMiwgdmFsMiwgdmFsMyk7Cit9CisjZW5kaWYKKworYXNtbGlua2FnZSBsb25nIGNvbXBhdF9zeXNfc2V0cmxpbWl0KHVuc2lnbmVkIGludCByZXNvdXJjZSwKKwkJc3RydWN0IGNvbXBhdF9ybGltaXQgX191c2VyICpybGltKQoreworCXN0cnVjdCBybGlt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hc2tfdCk7CisKKwlrID0gY3B1c19hZGRyKCpuZXdfbWFzayk7CisJcmV0dXJuIGNvbXBhdF9nZXRfYml0bWFwKGssIHVzZXJfbWFza19wdHIsIGxlbiAqIDgpOworfQorCithc21saW5rYWdlIGxvbmcgY29tcGF0X3N5c19zY2hlZF9zZXRhZmZpbml0eShjb21wYXRfcGlkX3QgcGlkLAorCQkJCQkgICAgIHVuc2lnbmVkIGludCBsZW4sCisJCQkJCSAgICAgY29tcGF0X3Vsb25nX3QgX191c2VyICp1c2VyX21hc2tfcHRyKQoreworCWNwdW1hc2tfdCBuZXdfbWFzazsKKwlpbnQgcmV0dmFsOworCisJcmV0dmFsID0gY29tcGF0X2dldF91c2VyX2NwdV9tYXNrKHVzZXJfbWFza19wdHIsIGxlbiwgJm5ld19tYXNrKTsKKwlpZiAocmV0dmFsKQorCQlyZXR1cm4gcmV0dmFsOworCisJcmV0dXJuIHNjaGVkX3NldGFmZmluaXR5KHBpZCwgbmV3X21hc2spOworfQorCithc21saW5rYWdlIGxvbmcgY29tcGF0X3N5c19zY2hlZF9nZXRhZmZpbml0eShjb21wYXRfcGlkX3QgcGlkLCB1bnNpZ25lZCBpbnQgbGVuLAorCQkJCQkgICAgIGNvbXBhdF91bG9uZ190IF9fdXNlciAqdXNlcl9tYXNrX3B0cikKK3sKKwlpbnQgcmV0OworCWNwdW1hc2tfdCBtYXNrOworCXVuc2lnbmVkIGxvbmcgKms7CisJdW5zaWduZWQgaW50IG1pbl9sZW5ndGggPSBzaXplb2YoY3B1bWFza190KTsKKworCWlmIChOUl9DUFVTIDw9IEJJVFNfUEVSX0NPTVBBVF9MT05HKQorCQltaW5fbGVuZ3RoID0gc2l6ZW9mKGNvbXBhdF91bG9uZ190KTsKKworCWlmIChsZW4gPCBtaW5fbGVuZ3RoKQorCQlyZXR1cm4gLUVJTlZBTDsKKworCXJldCA9IHNjaGVkX2dldGFmZmluaXR5KHBpZCwgJm1hc2spOworCWlmIChyZXQgPCAwKQorCQlyZ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oreworCWxvZmZfdCBwb3MgPSAqb2Zmc2V0OworCXNzaXplX3QgY291bnQ7CisKKwlpZiAocG9zID49IGtlcm5lbF9jb25maWdfZGF0YV9zaXplKQorCQlyZXR1cm4gMDsKKworCWNvdW50ID0gbWluKGxlbiwgKHNpemVfdCkoa2VybmVsX2NvbmZpZ19kYXRhX3NpemUgLSBwb3MpKTsKKwlpZiAoY29weV90b191c2VyKGJ1Ziwga2VybmVsX2NvbmZpZ19kYXRhICsgTUFHSUNfU0laRSArIHBvcywgY291bnQpKQorCQlyZXR1cm4gLUVGQVVMVDsKKworCSpvZmZzZXQgKz0gY291bnQ7CisJcmV0dXJuIGNvdW50OworfQorCitzdGF0aWMgc3RydWN0IGZpbGVfb3BlcmF0aW9ucyBpa2NvbmZpZ19maWxlX29wcyA9IHsKKwkub3duZXIgPSBUSElTX01PRFVMRSwKKwkucmVhZCA9IGlrY29uZmlnX3JlYWRfY3VycmVudCwKK307CisKKy8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCisvKiBpa2NvbmZpZ19pbml0OiBzdGFydCB1cCBldmVyeXRoaW5nIHdlIG5lZWQgdG8gKi8KKworc3RhdGljIGludCBfX2luaXQgaWtjb25maWdfaW5pdCh2b2lkKQoreworCXN0cnVjdCBwcm9jX2Rpcl9lbnRyeSAqZW50cnk7CisKKwkvKiBjcmVhdGUgdGhlIGN1cnJlbnQgY29uZmlnIGZpbGUgKi8KKwllbnRyeSA9IGNyZWF0ZV9wcm9jX2VudHJ5KCJjb25maWcuZ3oiLCBTX0lGUkVHIHwgU19JUlVHTywKKwkJCQkgICZwcm9jX3Jvb3QpOworCWlmICghZW50cnkpCisJCXJldHVybiAtRU5PTUVNOworCisJZW50cnktPnByb2NfZm9wcyA9ICZpa2NvbmZpZ19maWxlX29wczsKKwllbnRyeS0+c2l6ZSA9IGtlcm5lbF9jb25maWdfZGF0YV9zaXplOworCisJcmV0dXJuIDA7Cit9CisKKy8qKioq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50IHRpbWUgdGhpcyBjcHVzZXQgY2hhbmdlZCBpdHMgbWVtc19hbGxvd2VkLgorCSAqLworCSBpbnQgbWVtc19nZW5lcmF0aW9uOworfTsKKworLyogYml0cyBpbiBzdHJ1Y3QgY3B1c2V0IGZsYWdzIGZpZWxkICovCit0eXBlZGVmIGVudW0geworCUNTX0NQVV9FWENMVVNJVkUsCisJQ1NfTUVNX0VYQ0xVU0lWRSwKKwlDU19SRU1PVkVELAorCUNTX05PVElGWV9PTl9SRUxFQVNFCit9IGNwdXNldF9mbGFnYml0c190OworCisvKiBjb252ZW5pZW50IHRlc3RzIGZvciB0aGVzZSBiaXRzICovCitzdGF0aWMgaW5saW5lIGludCBpc19jcHVfZXhjbHVzaXZlKGNvbnN0IHN0cnVjdCBjcHVzZXQgKmNzKQoreworCXJldHVybiAhIXRlc3RfYml0KENTX0NQVV9FWENMVVNJVkUsICZjcy0+ZmxhZ3MpOworfQorCitzdGF0aWMgaW5saW5lIGludCBpc19tZW1fZXhjbHVzaXZlKGNvbnN0IHN0cnVjdCBjcHVzZXQgKmNzKQoreworCXJldHVybiAhIXRlc3RfYml0KENTX01FTV9FWENMVVNJVkUsICZjcy0+ZmxhZ3MpOworfQorCitzdGF0aWMgaW5saW5lIGludCBpc19yZW1vdmVkKGNvbnN0IHN0cnVjdCBjcHVzZXQgKmNzKQoreworCXJldHVybiAhIXRlc3RfYml0KENTX1JFTU9WRUQsICZjcy0+ZmxhZ3MpOworfQorCitzdGF0aWMgaW5saW5lIGludCBub3RpZnlfb25fcmVsZWFzZShjb25zdCBzdHJ1Y3QgY3B1c2V0ICpjcykKK3sKKwlyZXR1cm4gISF0ZXN0X2JpdChDU19OT1RJRllfT05fUkVMRUFTRSwgJmNzLT5mbGFncyk7Cit9CisKKy8qCisgKiBJbmNyZW1lbnQgdGhpcyBhdG9taWMgaW50ZWdlciBldmVyeXRpbWUgYW55IGNwdXNldCBjaGFuZ2VzIGl0cworICogbWVtc19hbGxvd2VkIHZhbHVlL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gc3RyIGludG8gbmFtZSwgaW5kZXgsIG9wdGlvbnMuCisJICovCisJaWYgKHN0clswXSA+PSAnMCcgJiYgc3RyWzBdIDw9ICc5JykgeworCQlzdHJjcHkobmFtZSwgInR0eVMiKTsKKwkJc3RybmNweShuYW1lICsgNCwgc3RyLCBzaXplb2YobmFtZSkgLSA1KTsKKwl9IGVsc2UKKwkJc3RybmNweShuYW1lLCBzdHIsIHNpemVvZihuYW1lKSAtIDEpOworCW5hbWVbc2l6ZW9mKG5hbWUpIC0gMV0gPSAwOworCWlmICgob3B0aW9ucyA9IHN0cmNocihzdHIsICcsJykpICE9IE5VTEwpCisJCSoob3B0aW9ucysrKSA9IDA7CisjaWZkZWYgX19zcGFyY19fCisJaWYgKCFzdHJjbXAoc3RyLCAidHR5YSIpKQorCQlzdHJjcHkobmFtZSwgInR0eVMwIik7CisJaWYgKCFzdHJjbXAoc3RyLCAidHR5YiIpKQorCQlzdHJjcHkobmFtZSwgInR0eVMxIik7CisjZW5kaWYKKwlmb3IocyA9IG5hbWU7ICpzOyBzKyspCisJCWlmICgoKnMgPj0gJzAnICYmICpzIDw9ICc5JykgfHwgKnMgPT0gJywnKQorCQkJYnJlYWs7CisJaWR4ID0gc2ltcGxlX3N0cnRvdWwocywgTlVMTCwgMTApOworCSpzID0gMDsKKworCWFkZF9wcmVmZXJyZWRfY29uc29sZShuYW1lLCBpZHgsIG9wdGlvbnMpOworCXJldHVybiAxOworfQorCitfX3NldHVwKCJjb25zb2xlPSIsIGNvbnNvbGVfc2V0dXApOworCisvKioKKyAqIGFkZF9wcmVmZXJyZWRfY29uc29sZSAtIGFkZCBhIGRldmljZSB0byB0aGUgbGlzdCBvZiBwcmVmZXJyZWQgY29uc29sZXMuCisgKgorICogVGhlIGxhc3QgcHJlZmVycmVkIGNvbnNvbGUgYWRkZWQgd2lsbCBiZSB1c2VkIGZvciBrZXJuZWwgbWVzc2FnZXMKKyAqIGFuZCBzdGRpbi9vdXQvZXJyIGZvciBpbml0LiA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lkIHphcF9sb2Nrcyh2b2lkKQoreworCXN0YXRpYyB1bnNpZ25lZCBsb25nIG9vcHNfdGltZXN0YW1wOworCisJaWYgKHRpbWVfYWZ0ZXJfZXEoamlmZmllcywgb29wc190aW1lc3RhbXApICYmCisJCQkhdGltZV9hZnRlcihqaWZmaWVzLCBvb3BzX3RpbWVzdGFtcCArIDMwKkhaKSkKKwkJcmV0dXJuOworCisJb29wc190aW1lc3RhbXAgPSBqaWZmaWVzOworCisJLyogSWYgYSBjcmFzaCBpcyBvY2N1cnJpbmcsIG1ha2Ugc3VyZSB3ZSBjYW4ndCBkZWFkbG9jayAqLworCXNwaW5fbG9ja19pbml0KCZsb2didWZfbG9jayk7CisJLyogQW5kIG1ha2Ugc3VyZSB0aGF0IHdlIHByaW50IGltbWVkaWF0ZWx5ICovCisJaW5pdF9NVVRFWCgmY29uc29sZV9zZW0pOworfQorCisjaWYgZGVmaW5lZChDT05GSUdfUFJJTlRLX1RJTUUpCitzdGF0aWMgaW50IHByaW50a190aW1lID0gMTsKKyNlbHNlCitzdGF0aWMgaW50IHByaW50a190aW1lID0gMDsKKyNlbmRpZgorCitzdGF0aWMgaW50IF9faW5pdCBwcmludGtfdGltZV9zZXR1cChjaGFyICpzdHIpCit7CisJaWYgKCpzdHIpCisJCXJldHVybiAwOworCXByaW50a190aW1lID0gMTsKKwlyZXR1cm4gMTsKK30KKworX19zZXR1cCgidGltZSIsIHByaW50a190aW1lX3NldHVwKTsKKworLyoKKyAqIFRoaXMgaXMgcHJpbnRrLiAgSXQgY2FuIGJlIGNhbGxlZCBmcm9tIGFueSBjb250ZXh0LiAgV2Ugd2FudCBpdCB0byB3b3JrLgorICogCisgKiBXZSB0cnkgdG8gZ3JhYiB0aGUgY29uc29sZV9zZW0uICBJZiB3ZSBzdWNjZWVkLCBpdCdzIGVhc3kgLSB3ZSBsb2cgdGhlIG91dHB1dCBhbmQKKyAqIGNhbGwgdGhlIGNvbnNvbGUgZHJpdmVycy4gIElmIHdlIGZ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OworCWlmICgocmVsYXRpdmUgPSB5b3VuZ2VyX3NpYmxpbmcocCkpKQorCQlwcmludGsoIiU3ZCIsIHJlbGF0aXZlLT5waWQpOworCWVsc2UKKwkJcHJpbnRrKCIgICAgICAgIik7CisJaWYgKChyZWxhdGl2ZSA9IG9sZGVyX3NpYmxpbmcocCkpKQorCQlwcmludGsoIiAlNWQiLCByZWxhdGl2ZS0+cGlkKTsKKwllbHNlCisJCXByaW50aygiICAgICAgIik7CisJaWYgKCFwLT5tbSkKKwkJcHJpbnRrKCIgKEwtVExCKVxuIik7CisJZWxzZQorCQlwcmludGsoIiAoTk9UTEIpXG4iKTsKKworCWlmIChzdGF0ZSAhPSBUQVNLX1JVTk5JTkcpCisJCXNob3dfc3RhY2socCwgTlVMTCk7Cit9CisKK3ZvaWQgc2hvd19zdGF0ZSh2b2lkKQoreworCXRhc2tfdCAqZywgKnA7CisKKyNpZiAoQklUU19QRVJfTE9ORyA9PSAzMikKKwlwcmludGsoIlxuIgorCSAgICAgICAiICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzaWJsaW5nXG4iKTsKKwlwcmludGsoIiAgdGFzayAgICAgICAgICAgICBQQyAgICAgIHBpZCBmYXRoZXIgY2hpbGQgeW91bmdlciBvbGRlclxuIik7CisjZWxzZQorCXByaW50aygiXG4iCisJICAgICAgICIgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2libGluZ1xuIik7CisJcHJpbnRrKCIgIHRhc2sgICAgICAgICAgICAgICAgIFBDICAgICAgICAgIHBpZCBmYXRoZXIgY2hpbGQgeW91bmdlciBvbGRlclxuIik7CisjZW5kaWYKKwlyZWFkX2xvY2soJnRhc2tsaXN0X2xvY2spOworCWRvX2VhY2hfdGhyZWFkKGcsIHApIHsKKwkJLyoKKwkJICogcmVzZXQgdGhlIE5NSS10aW1lb3V0LCBsaXN0aW5nIGFsbCBmaWxlcyBvbiBhIHNsb3c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vcmVkdW1wIAl8CisgKgl8ICBTSUdUUkFQICAgICAgICAgICB8CWNvcmVkdW1wIAl8CisgKgl8ICBTSUdBQlJUL1NJR0lPVCAgICB8CWNvcmVkdW1wIAl8CisgKgl8ICBTSUdCVVMgICAgICAgICAgICB8CWNvcmVkdW1wIAl8CisgKgl8ICBTSUdGUEUgICAgICAgICAgICB8CWNvcmVkdW1wIAl8CisgKgl8ICBTSUdLSUxMICAgICAgICAgICB8CXRlcm1pbmF0ZSgrKQl8CisgKgl8ICBTSUdVU1IxICAgICAgICAgICB8CXRlcm1pbmF0ZQl8CisgKgl8ICBTSUdTRUdWICAgICAgICAgICB8CWNvcmVkdW1wIAl8CisgKgl8ICBTSUdVU1IyICAgICAgICAgICB8CXRlcm1pbmF0ZQl8CisgKgl8ICBTSUdQSVBFICAgICAgICAgICB8CXRlcm1pbmF0ZQl8CisgKgl8ICBTSUdBTFJNICAgICAgICAgICB8CXRlcm1pbmF0ZQl8CisgKgl8ICBTSUdURVJNICAgICAgICAgICB8CXRlcm1pbmF0ZQl8CisgKgl8ICBTSUdDSExEICAgICAgICAgICB8CWlnbm9yZSAgIAl8CisgKgl8ICBTSUdDT05UICAgICAgICAgICB8CWlnbm9yZSgqKQl8CisgKgl8ICBTSUdTVE9QICAgICAgICAgICB8CXN0b3AoKikoKykgIAl8CisgKgl8ICBTSUdUU1RQICAgICAgICAgICB8CXN0b3AoKikgIAl8CisgKgl8ICBTSUdUVElOICAgICAgICAgICB8CXN0b3AoKikgIAl8CisgKgl8ICBTSUdUVE9VICAgICAgICAgICB8CXN0b3AoKikgIAl8CisgKgl8ICBTSUdVUkcgICAgICAgICAgICB8CWlnbm9yZSAgIAl8CisgKgl8ICBTSUdYQ1BVICAgICAgICAgICB8CWNvcmVkdW1wIAl8CisgKgl8ICBTSUdYRlNaICAgICAgICAgICB8CWNvcmVkdW1wIAl8CisgKgl8ICBTSUdWVEFMUk0gICAgICAgICB8CXRlcm1pbmF0ZQl8CisgKgl8ICBTSU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zbmFtZS5ub2RlbmFtZVtsZW5dID0gMDsKKwkJZXJybm8gPSAwOworCX0KKwl1cF93cml0ZSgmdXRzX3NlbSk7CisJcmV0dXJuIGVycm5vOworfQorCisjaWZkZWYgX19BUkNIX1dBTlRfU1lTX0dFVEhPU1ROQU1FCisKK2FzbWxpbmthZ2UgbG9uZyBzeXNfZ2V0aG9zdG5hbWUoY2hhciBfX3VzZXIgKm5hbWUsIGludCBsZW4pCit7CisJaW50IGksIGVycm5vOworCisJaWYgKGxlbiA8IDApCisJCXJldHVybiAtRUlOVkFMOworCWRvd25fcmVhZCgmdXRzX3NlbSk7CisJaSA9IDEgKyBzdHJsZW4oc3lzdGVtX3V0c25hbWUubm9kZW5hbWUpOworCWlmIChpID4gbGVuKQorCQlpID0gbGVuOworCWVycm5vID0gMDsKKwlpZiAoY29weV90b191c2VyKG5hbWUsIHN5c3RlbV91dHNuYW1lLm5vZGVuYW1lLCBpKSkKKwkJZXJybm8gPSAtRUZBVUxUOworCXVwX3JlYWQoJnV0c19zZW0pOworCXJldHVybiBlcnJubzsKK30KKworI2VuZGlmCisKKy8qCisgKiBPbmx5IHNldGRvbWFpbm5hbWU7IGdldGRvbWFpbm5hbWUgY2FuIGJlIGltcGxlbWVudGVkIGJ5IGNhbGxpbmcKKyAqIHVuYW1lKCkKKyAqLworYXNtbGlua2FnZSBsb25nIHN5c19zZXRkb21haW5uYW1lKGNoYXIgX191c2VyICpuYW1lLCBpbnQgbGVuKQoreworCWludCBlcnJubzsKKwljaGFyIHRtcFtfX05FV19VVFNfTEVOXTsKKworCWlmICghY2FwYWJsZShDQVBfU1lTX0FETUlOKSkKKwkJcmV0dXJuIC1FUEVSTTsKKwlpZiAobGVuIDwgMCB8fCBsZW4gPiBfX05FV19VVFNfTEVOKQorCQlyZXR1cm4gLUVJTlZBTDsKKworCWRvd25fd3JpdGUoJnV0c19zZW0pOworCWVycm5vID0gLUVGQVVMVDsKKwlpZiAoIWNvcHlfZnJvbV91c2VyKHRtcCw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GhpZ2gybG93Z2lkKEdST1VQX0FUKGdyb3VwX2luZm8sIGkpKTsKKwkJaWYgKHB1dF91c2VyKGdyb3VwLCBncm91cGxpc3QraSkpCisJCQlyZXR1cm4gLUVGQVVMVDsKKwl9CisKKwlyZXR1cm4gMDsKK30KKworc3RhdGljIGludCBncm91cHMxNl9mcm9tX3VzZXIoc3RydWN0IGdyb3VwX2luZm8gKmdyb3VwX2luZm8sCisgICAgb2xkX2dpZF90IF9fdXNlciAqZ3JvdXBsaXN0KQoreworCWludCBpOworCW9sZF9naWRfdCBncm91cDsKKworCWZvciAoaSA9IDA7IGkgPCBncm91cF9pbmZvLT5uZ3JvdXBzOyBpKyspIHsKKwkJaWYgKGdldF91c2VyKGdyb3VwLCBncm91cGxpc3QraSkpCisJCQlyZXR1cm4gIC1FRkFVTFQ7CisJCUdST1VQX0FUKGdyb3VwX2luZm8sIGkpID0gbG93MmhpZ2hnaWQoZ3JvdXApOworCX0KKworCXJldHVybiAwOworfQorCithc21saW5rYWdlIGxvbmcgc3lzX2dldGdyb3VwczE2KGludCBnaWRzZXRzaXplLCBvbGRfZ2lkX3QgX191c2VyICpncm91cGxpc3QpCit7CisJaW50IGkgPSAwOworCisJaWYgKGdpZHNldHNpemUgPCAwKQorCQlyZXR1cm4gLUVJTlZBTDsKKworCWdldF9ncm91cF9pbmZvKGN1cnJlbnQtPmdyb3VwX2luZm8pOworCWkgPSBjdXJyZW50LT5ncm91cF9pbmZvLT5uZ3JvdXBzOworCWlmIChnaWRzZXRzaXplKSB7CisJCWlmIChpID4gZ2lkc2V0c2l6ZSkgeworCQkJaSA9IC1FSU5WQUw7CisJCQlnb3RvIG91dDsKKwkJfQorCQlpZiAoZ3JvdXBzMTZfdG9fdXNlcihncm91cGxpc3QsIGN1cnJlbnQtPmdyb3VwX2luZm8pKSB7CisJCQlpID0gLUVGQVVMVDsKKwkJCWdvdG8gb3V0OworCQl9CisJfQorb3V0OgorCXB1dF9ncm91cF9pbmZvKGN1cnJlbnQ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