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IpLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBudG9ocyhzby0+c29fZnBvcnQpLCAxKTsKCQl9IGVsc2UgaWYgKHNzY2FuZihicHRyLCAiRENDIFNFTkQgJTI1NnMgJXUgJXUgJXUiLCBidWZmLCAmbGFkZHIsICZscG9ydCwgJm4xKSA9PSA0KSB7CgkJCWlmICgoc28gPSBzb2xpc3RlbigwLCBodG9ubChsYWRkciksIGh0b25zKGxwb3J0KSwgU1NfRkFDQ0VQVE9OQ0UpKSA9PSBOVUxMKQoJCQkJcmV0dXJuIDE7CgoJCQltLT5tX2xlbiA9IGJwdHIgLSBtLT5tX2RhdGE7IC8qIEFkanVzdCBsZW5ndGggKi8KICAgICAgICAgICAgICAgICAgICAgICAgbS0+bV9sZW4gKz0gc25wcmludGYoYnB0ciwgbS0+bV9oZHIubWhfc2l6ZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIkRDQyBTRU5EICVzICVsdSAldSAldSVjXG4iLCBidWZmLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAodW5zaWduZWQgbG9uZyludG9obChzby0+c29fZmFkZHIuc19hZGRyKSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbnRvaHMoc28tPnNvX2Zwb3J0KSwgbjEsIDEpOwoJCX0gZWxzZSBpZiAoc3NjYW5mKGJwdHIsICJEQ0MgTU9WRSAlMjU2cyAldSAldSAldSIsIGJ1ZmYsICZsYWRkciwgJmxwb3J0LCAmbjEpID09IDQpIHsKCQkJaWYgKChzbyA9IHNvbGlzdGVuKDAsIGh0b25sKGxhZGRyKSwgaHRvbnMobHBvcnQpLCBTU19GQUNDRVBUT05DRSkpID09IE5VTEwpCgkJCQlyZXR1cm4gMTsKCgkJCW0tPm1fbGVuID0gYnB0ciAtIG0tPm1fZGF0YTsgLyogQWRqdXN0IGxlbmd0aCAqLwogICAgICAg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