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