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QkgKiBidXQgZG8gbm90IGVycm9yIG91dCB5ZXQgaWYgd2UgZmFpbCB0byBmaW5kIGl0Li4uICovCgkJaWYgKHVuYW1lKCZteXVuYW1lKSA9PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgY2hhciAqbW9kdWxlX2RpcjsKICAgICAgICAgICAgICAgICAgICAgICBjaGFyICp0bWRuOwoJCQljaGFyIHJlYWxfbW9kdWxlX2RpcltGSUxFTkFNRV9NQVhdOwoKICAgICAgICAgICAgICAgICAgICAgICB0bWRuID0gY29uY2F0X3BhdGhfZmlsZShfUEFUSF9NT0RVTEVTLCBteXVuYW1lLnJlbGVhc2UpOwoJCQkvKiBKdW1wIHRocm91Z2ggaG9vcHMgaW4gY2FzZSAvbGliL21vZHVsZXMvYHVuYW1lIC1yYAoJCQkgKiBpcyBhIHN5bWxpbmsuICBXZSBkbyBub3Qgd2FudCByZWN1cnNpdmVfYWN0aW9uIHRvCgkJCSAqIGZvbGxvdyBzeW1saW5rcywgYnV0IHdlIGRvIHdhbnQgdG8gZm9sbG93IHRoZQoJCQkgKiAvbGliL21vZHVsZXMvYHVuYW1lIC1yYCBkaXIsIFNvIHJlc29sdmUgaXQgb3Vyc2VsdmVzCgkJCSAqIGlmIGl0IGlzIGEgbGluay4uLiAqLwogICAgICAgICAgICAgICAgICAgICAgIGlmIChyZWFscGF0aCAodG1kbiwgcmVhbF9tb2R1bGVfZGlyKSA9PSBOVUxMKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbW9kdWxlX2RpciA9IHRtZG47CiAgICAgICAgICAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbW9kdWxlX2RpciA9IHJlYWxfbW9kdWxlX2RpcjsKICAgICAgICAgICAgICAgICAgICAgICByZWN1cnNpdmVfYWN0aW9uKG1vZHVsZV9kaXIsIFRSVUUsIEZBTFNFLCBGQUxTRSwKCQkJCQljaGVja19tb2R1bGVfbmFtZV9tYXRjaCwgMCw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