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