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J5cHRvX3RmbV9hbGdfdHlwZSh0Zm0pICE9IENSWVBUT19BTEdfVFlQRV9DSVBIRVIpOwoJcmV0dXJuIHRmbS0+Y3J0X2NpcGhlci5jaXRfZW5jcnlwdCh0Zm0sIGRzdCwgc3JjLCBuYnl0ZXMpOwp9ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAoKc3RhdGljIGlubGluZSBpbnQgY3J5cHRvX2NpcGhlcl9lbmNyeXB0X2l2KHN0cnVjdCBjcnlwdG9fdGZtICp0Zm0sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdHJ1Y3Qgc2NhdHRlcmxpc3QgKmRzdCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0cnVjdCBzY2F0dGVybGlzdCAqc3JjLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdW5zaWduZWQgaW50IG5ieXRlcywgdTggKml2KQp7CglCVUdfT04oY3J5cHRvX3RmbV9hbGdfdHlwZSh0Zm0pICE9IENSWVBUT19BTEdfVFlQRV9DSVBIRVIpOwoJcmV0dXJuIHRmbS0+Y3J0X2NpcGhlci5jaXRfZW5jcnlwdF9pdih0Zm0sIGRzdCwgc3JjLCBuYnl0ZXMsIGl2KTsKfSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKCnN0YXRpYyBpbmxpbmUgaW50IGNyeXB0b19jaXBoZXJfZGVjcnlwdChzdHJ1Y3QgY3J5cHRvX3RmbSAqdGZtLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RydWN0IHNjYXR0ZXJsaXN0ICpkc3QsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdHJ1Y3Qgc2NhdHRlcmxpc3QgKnNyYywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHVuc2lnbmVkIGludCBuYnl0ZXM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Y3J5cHRvX3RmbSAqdGZtLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdTggKmRzdCwgdW5zaWduZWQgaW50IGxlbikKewoJQlVHX09OKGNyeXB0b190Zm1fYWxnX3R5cGUodGZtKSAhPSBDUllQVE9fQUxHX1RZUEVfQ0lQSEVSKTsKCW1lbWNweShkc3QsIHRmbS0+Y3J0X2NpcGhlci5jaXRfaXYsIGxlbik7Cn0KCnN0YXRpYyBpbmxpbmUgaW50IGNyeXB0b19jb21wX2NvbXByZXNzKHN0cnVjdCBjcnlwdG9fdGZtICp0Zm0sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IHU4ICpzcmMsIHVuc2lnbmVkIGludCBzbGVuLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB1OCAqZHN0LCB1bnNpZ25lZCBpbnQgKmRsZW4pCnsKCUJVR19PTihjcnlwdG9fdGZtX2FsZ190eXBlKHRmbSkgIT0gQ1JZUFRPX0FMR19UWVBFX0NPTVBSRVNTKTsKCXJldHVybiB0Zm0tPmNydF9jb21wcmVzcy5jb3RfY29tcHJlc3ModGZtLCBzcmMsIHNsZW4sIGRzdCwgZGxlbik7Cn0KCnN0YXRpYyBpbmxpbmUgaW50IGNyeXB0b19jb21wX2RlY29tcHJlc3Moc3RydWN0IGNyeXB0b190Zm0gKnRmbSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zdCB1OCAqc3JjLCB1bnNpZ25lZCBpbnQgc2xlbiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB1OCAqZHN0LCB1bnNpZ25lZCBpbnQgKmRsZW4pCnsKCUJVR19PTihjcnlwdG9fdGZtX2FsZ190eXBlKHRmbSkgIT0gQ1JZUFRPX0FMR19UWVBFX0NPTVBSRVNTKTsKCXJldHVybiB0Zm0tPmNydF9jb21wcmVzcy5jb3RfZGVjb21wcmVzcy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