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ZGLCAweDFGMDAsIDB4MDAwMCwgMHgwNTAxLCAweDAxMDEsIDB4MDEwMSwgMHgwMTAxLCAweDAwMDAsCgkJMHgwMDAwLCAweDAwMDAsIDB4MDAwMCwgMHgwMjAxLCAweDA0MDMsIDB4MDYwNSwgMHgwODA3LCAweDBBMDksCgkJMHhGRjBCLAoJCTB4QzRGRiwgMHgxRjAwLCAweDAwMDEsIDB4MDEwMywgMHgwMTAxLCAweDAxMDEsIDB4MDEwMSwgMHgwMTAxLAoJCTB4MDAwMCwgMHgwMDAwLCAweDAwMDAsIDB4MDIwMSwgMHgwNDAzLCAweDA2MDUsIDB4MDgwNywgMHgwQTA5LAoJCTB4RkYwQgoJfTsKCgkqbGVuZ3RoID0gQVJSQVlfU0laRSh0YWJsZXMpOwoJcmV0dXJuIHRhYmxlczsKfQoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCi8qIE1DSElQIGxvdy1sZXZlbCBmdW5jdGlvbnMgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAqLwovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KCi8qIHJldHVybnMgdGhlIGhvcml6b250YWwgY2FwdHVyZSBzaXplICovCnN0YXRpYyBpbmxpbmUgaW50IG1jaGlwX2hzaXplKHZvaWQpCnsKCXJldHVybiBtZXllLnBhcmFtcy5zdWJzYW1wbGUgPyAzMjAgOiA2NDA7Cn0KCi8qIHJldHVybnMgdGhlIHZlcnRpY2FsIGNhcHR1cmUgc2l6ZSAqLwpzdGF0aWMgaW5saW5lIGludCBtY2hpcF92c2l6ZSh2b2lkKQp7CglyZXR1cm4gbWV5ZS5wYXJhbXMuc3Vic2FtcGxlID8gMjQwIDogNDgwOwp9CgovKiB3YWl0cyBmb3IgYSByZWdpc3RlciB0byBi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ioqKioqKioqKioqKioqKioqKiovCi8qIEludGVycnVwdCBoYW5kbGluZyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAqLwovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KCnN0YXRpYyBpcnFyZXR1cm5fdCBtZXllX2lycShpbnQgaXJxLCB2b2lkICpkZXZfaWQsIHN0cnVjdCBwdF9yZWdzICpyZWdzKQp7Cgl1MzIgdjsKCWludCByZXFucjsKCXN0YXRpYyBpbnQgc2VxdWVuY2UgPSAwOwoKCXYgPSBtY2hpcF9yZWFkKE1DSElQX01NX0lOVEEpOwoKCWlmIChtZXllLm1jaGlwX21vZGUgIT0gTUNISVBfSElDX01PREVfQ09OVF9PVVQgJiYKCSAgICBtZXllLm1jaGlwX21vZGUgIT0gTUNISVBfSElDX01PREVfQ09OVF9DT01QKQoJCXJldHVybiBJUlFfTk9ORTsKCmFnYWluOgoJdiA9IG1jaGlwX2dldF9mcmFtZSgpOwoJaWYgKCEodiAmIE1DSElQX01NX0ZJUl9SRFkpKQoJCXJldHVybiBJUlFfSEFORExFRDsKCglpZiAobWV5ZS5tY2hpcF9tb2RlID09IE1DSElQX0hJQ19NT0RFX0NPTlRfT1VUKSB7CgkJaWYgKGtmaWZvX2dldChtZXllLmdyYWJxLCAodW5zaWduZWQgY2hhciAqKSZyZXFuciwKCQkJICAgICAgc2l6ZW9mKGludCkpICE9IHNpemVvZihpbnQpKSB7CgkJCW1jaGlwX2ZyZWVfZnJhbWUoKTsKCQkJcmV0dXJuIElSUV9IQU5ETEVEOwoJCX0KCQltY2hpcF9jb250X3JlYWRfZnJhbWUodiwgbWV5ZS5ncmFiX2ZidWZmZXIgKyBnYnVmc2l6ZSAqIHJlcW5yLAoJCQkJICAgICAgbWNoaXBfaHNpemUoKSAqIG1jaGlwX3ZzaXplKCkgKiAyKTsKCQltZXllLmd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S5ncmFiX2J1ZmZlcltyZXFucl0udGltZXN0YW1wKTsKCQltZXllLmdyYWJfYnVmZmVyW3JlcW5yXS5zZXF1ZW5jZSA9IHNlcXVlbmNlKys7CgkJa2ZpZm9fcHV0KG1leWUuZG9uZXEsICh1bnNpZ25lZCBjaGFyICopJnJlcW5yLCBzaXplb2YoaW50KSk7CgkJd2FrZV91cF9pbnRlcnJ1cHRpYmxlKCZtZXllLnByb2NfbGlzdCk7Cgl9CgltY2hpcF9mcmVlX2ZyYW1lKCk7Cglnb3RvIGFnYWluOwp9CgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KLyogdmlkZW80bGludXggaW50ZWdyYXRpb24gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICovCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwoKc3RhdGljIGludCBtZXllX29wZW4oc3RydWN0IGlub2RlICppbm9kZSwgc3RydWN0IGZpbGUgKmZpbGUpCnsKCWludCBpLCBlcnI7CgoJZXJyID0gdmlkZW9fZXhjbHVzaXZlX29wZW4oaW5vZGUsIGZpbGUpOwoJaWYgKGVyciA8IDApCgkJcmV0dXJuIGVycjsKCgltY2hpcF9oaWNfc3RvcCgpOwoKCWlmIChtY2hpcF9kbWFfYWxsb2MoKSkgewoJCXByaW50ayhLRVJOX0VSUiAibWV5ZTogbWNoaXAgZnJhbWVidWZmZXIgYWxsb2NhdGlvbiBmYWlsZWRcbiIpOwoJCXZpZGVvX2V4Y2x1c2l2ZV9yZWxlYXNlKGlub2RlLCBmaWxlKTsKCQlyZXR1cm4gLUVOT0JVRlM7Cgl9CgoJZm9yIChpID0gMDsgaSA8IE1FWUVfTUFYX0JVRk5CUlM7IGkrKykKCQltZXllLmdyYWJfYnVmZmVyW2ldLnN0YXR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