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X19pbmxpbmVfXyBpbnQKdmFyX3RvX3JlZnJlc2goY29uc3Qgc3RydWN0IGZiX3Zhcl9zY3JlZW5pbmZvICp2YXIpCnsKCWludCB4dG90ID0gdmFyLT54cmVzICsgdmFyLT5sZWZ0X21hcmdpbiArIHZhci0+cmlnaHRfbWFyZ2luICsKCQkgICB2YXItPmhzeW5jX2xlbjsKCWludCB5dG90ID0gdmFyLT55cmVzICsgdmFyLT51cHBlcl9tYXJnaW4gKyB2YXItPmxvd2VyX21hcmdpbiArCgkJICAgdmFyLT52c3luY19sZW47CgoJcmV0dXJuICgxMDAwMDAwMDAwIC8gdmFyLT5waXhjbG9jayAqIDEwMDAgKyA1MDApIC8geHRvdCAvIHl0b3Q7Cn0KCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKICogICAgICAgICAgICAgICAgVmFyaW91cyBpbnRpYWxpc2F0aW9uIGZ1bmN0aW9ucyAgICAgICAgICAgICAgKgogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwoKc3RhdGljIHZvaWQgX19kZXZpbml0CmdldF9pbml0aWFsX21vZGUoc3RydWN0IGludGVsZmJfaW5mbyAqZGluZm8pCnsKCXN0cnVjdCBmYl92YXJfc2NyZWVuaW5mbyAqdmFyOwoJaW50IHh0b3QsIHl0b3Q7CgoJREJHX01TRygiZ2V0X2luaXRpYWxfbW9kZVxuIik7CgoJZGluZm8tPmluaXRpYWxfdmdhID0gMTsKCWRpbmZvLT5pbml0aWFsX2ZiX2Jhc2UgPSBzY3JlZW5faW5mby5sZmJfYmFzZTsKCWRpbmZvLT5pbml0aWFsX3ZpZGVvX3JhbSA9IHNjcmVlbl9pbmZvLmxmYl9zaXplICogS0IoNjQpOwoJZGluZm8tPmluaXRpYWxfcGl0Y2ggPSBzY3JlZW5faW5mby5sZmJfbGluZWxlbmd0aDsKCgl2YXIgPSAmZG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