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dGlvbiAqLwogICAgdWludDhfdCBoZWFkOwogICAgdWludDhfdCB0cmFjazsKICAgIHVpbnQ4X3Qgc2VjdDsKICAgIC8qIE1lZGlhICovCiAgICBGRGlza0ZsYWdzIGZsYWdzOwogICAgdWludDhfdCBsYXN0X3NlY3Q7ICAgICAgICAvKiBOYiBzZWN0b3IgcGVyIHRyYWNrICAgICovCiAgICB1aW50OF90IG1heF90cmFjazsgICAgICAgIC8qIE5iIG9mIHRyYWNrcyAgICAgICAgICAgKi8KICAgIHVpbnQxNl90IGJwczsgICAgICAgICAgICAgLyogQnl0ZXMgcGVyIHNlY3RvciAgICAgICAqLwogICAgdWludDhfdCBybzsgICAgICAgICAgICAgICAvKiBJcyByZWFkLW9ubHkgICAgICAgICAgICovCn0gRkRyaXZlOwoKc3RhdGljIHZvaWQgZmRfaW5pdChGRHJpdmUgKmRydikKewogICAgLyogRHJpdmUgKi8KICAgIGRydi0+YnMgPSBkcnYtPmRpbmZvID8gZHJ2LT5kaW5mby0+YmRydiA6IE5VTEw7CiAgICBkcnYtPmRyaXZlID0gRkRSSVZFX0RSVl9OT05FOwogICAgZHJ2LT5wZXJwZW5kaWN1bGFyID0gMDsKICAgIC8qIERpc2sgKi8KICAgIGRydi0+bGFzdF9zZWN0ID0gMDsKICAgIGRydi0+bWF4X3RyYWNrID0gMDsKfQoKc3RhdGljIGludCBmZF9zZWN0b3JfY2FsYyh1aW50OF90IGhlYWQsIHVpbnQ4X3QgdHJhY2ssIHVpbnQ4X3Qgc2VjdCwKICAgICAgICAgICAgICAgICAgICAgICAgICB1aW50OF90IGxhc3Rfc2VjdCkKewogICAgcmV0dXJuICgoKHRyYWNrICogMikgKyBoZWFkKSAqIGxhc3Rfc2VjdCkgKyBzZWN0IC0gMTsKfQoKLyogUmV0dXJucyBjdXJyZW50IHBvc2l0aW9uLCBpbiBzZWN0b3JzLCBmb3IgZ2l2ZW4gZHJpdmUgKi8Kc3RhdGljIGludCBmZF9zZWN0b3IoRkRyaXZlICp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AgICAgICAgICAgICAgICBkcnYtPmRyaXZlID09IEZEUklWRV9EUlZfTk9ORSkgewogICAgICAgICAgICAgICAgICAgIHNpemUgPSAocGFyc2UtPm1heF9oZWFkICsgMSkgKiBwYXJzZS0+bWF4X3RyYWNrICoKICAgICAgICAgICAgICAgICAgICAgICAgcGFyc2UtPmxhc3Rfc2VjdDsKICAgICAgICAgICAgICAgICAgICBpZiAobmJfc2VjdG9ycyA9PSBzaXplKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIG1hdGNoID0gaTsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChmaXJzdF9tYXRjaCA9PSAtMSkKICAgICAgICAgICAgICAgICAgICAgICAgZmlyc3RfbWF0Y2ggPSBpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChtYXRjaCA9PSAtMSkgewogICAgICAgICAgICAgICAgaWYgKGZpcnN0X21hdGNoID09IC0xKQogICAgICAgICAgICAgICAgICAgIG1hdGNoID0gMTsKICAgICAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgICAgICBtYXRjaCA9IGZpcnN0X21hdGNoOwogICAgICAgICAgICAgICAgcGFyc2UgPSAmZmRfZm9ybWF0c1ttYXRjaF07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbmJfaGVhZHMgPSBwYXJzZS0+bWF4X2hlYWQgKyAxOwogICAgICAgICAgICBtYXhfdHJhY2sgPSBwYXJzZS0+bWF4X3RyYWNrOwogICAgICAgICAgICBsYXN0X3NlY3QgPSBwYXJzZS0+bGFzdF9zZWN0OwogICAgICAgICAgICBkcnYtPmRyaXZlID0gcGFyc2UtPmRyaXZlOwogICAgICAgICAgICBGTE9QUFlfRFBSSU5URigiJXMgZmxvcHB5IGRpc2sgKCVkIGggJWQgdCAlZCBzKSAlc1xuIiwgcGFyc2UtPnN0ciwKICAgICAgICAgICAgICAgICAgICAgICAgICAgbmJfaGVhZHMsIG1heF90cmFjaywgbGFzdF9zZWN0LCBybyA/ICJybyIgOiAicnciKTsKICAgICAgICB9CiAgICAgICAgaWYgKG5iX2hlYWRzID09IDEpIHsKICAgICAgICAgICAgZHJ2LT5mbGFncyAmPSB+RkRJU0tfREJMX1NJREVTOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGRydi0+ZmxhZ3MgfD0gRkRJU0tfREJMX1NJREVTOwogICAgICAgIH0KICAgICAgICBkcnYtPm1heF90cmFjayA9IG1heF90cmFjazsKICAgICAgICBkcnYtPmxhc3Rfc2VjdCA9IGxhc3Rfc2VjdDsKICAgICAgICBkcnYtPnJvID0gcm87CiAgICB9IGVsc2UgewogICAgICAgIEZMT1BQWV9EUFJJTlRGKCJObyBkaXNrIGluIGRyaXZlXG4iKTsKICAgICAgICBkcnYtPmxhc3Rfc2VjdCA9IDA7CiAgICAgICAgZHJ2LT5tYXhfdHJhY2sgPSAwOwogICAgICAgIGRydi0+ZmxhZ3MgJj0gfkZESVNLX0RCTF9TSURFUzsKICAgIH0KfQoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwovKiBJbnRlbCA4MjA3OCBmbG9wcHkgZGlzayBjb250cm9sbGVyIGVtdWxhdGlvbiAgICAgICAgICAqLwoKc3RhdGljIHZvaWQgZmRjdHJsX3Jlc2V0KEZEQ3RybCAqZmRjdHJsLCBpbnQgZG9faXJxKTsKc3RhdGljIHZvaWQgZmRjdHJsX3Jlc2V0X2ZpZm8oRkRDdHJsICpmZGN0cmwpOwpzdGF0aWMgaW50IGZkY3RybF90cmFuc2Zlcl9oYW5kbGVyICh2b2lkICpvcGFxdWUsIGludCBuY2hhbiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaW50IGRtYV9wb3MsIGludCBkbWFfbGVuKTsKc3RhdGljIHZvaWQgZmRjdHJsX3JhaXNlX2lycShGREN0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jdXJfZHJ2LT5zZWN0ID09IGZkY3RybC0+ZW90KSB7CiAgICAgICAgY3VyX2Rydi0+c2VjdCA9IDE7CiAgICAgICAgaWYgKEZEX01VTFRJX1RSQUNLKGZkY3RybC0+ZGF0YV9zdGF0ZSkpIHsKICAgICAgICAgICAgaWYgKGN1cl9kcnYtPmhlYWQgPT0gMCAmJgogICAgICAgICAgICAgICAgKGN1cl9kcnYtPmZsYWdzICYgRkRJU0tfREJMX1NJREVTKSAhPSAwKSB7CiAgICAgICAgICAgICAgICBjdXJfZHJ2LT5oZWFkID0gMTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGN1cl9kcnYtPmhlYWQgPSAwOwogICAgICAgICAgICAgICAgY3VyX2Rydi0+dHJhY2srKzsKICAgICAgICAgICAgICAgIGlmICgoY3VyX2Rydi0+ZmxhZ3MgJiBGRElTS19EQkxfU0lERVMpID09IDApCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjdXJfZHJ2LT50cmFjaysrOwogICAgICAgICAgICByZXR1cm4gMDsKICAgICAgICB9CiAgICAgICAgRkxPUFBZX0RQUklOVEYoInNlZWsgdG8gbmV4dCB0cmFjayAoJWQgJTAyeCAlMDJ4ID0+ICVkKVxuIiwKICAgICAgICAgICAgICAgICAgICAgICBjdXJfZHJ2LT5oZWFkLCBjdXJfZHJ2LT50cmFjaywKICAgICAgICAgICAgICAgICAgICAgICBjdXJfZHJ2LT5zZWN0LCBmZF9zZWN0b3IoY3VyX2RydikpOwogICAgfSBlbHNlIHsKICAgICAgICBjdXJfZHJ2LT5zZWN0Kys7CiAgICB9CiAgICByZXR1cm4gMTsKfQoKLyogQ2FsbGJhY2sgZm9yIHRyYW5zZmVyIGVuZCAoc3RvcCBvciBhYm9ydCkgKi8Kc3RhdGljIHZvaWQgZmRjdHJsX3N0b3BfdHJhbnNmZXIoRkRDdHJsICpmZG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jggPDwgZmRjdHJsLT5maWZvWzVdKSAqCiAgICAgICAgICAgICAgICAgICAgICAgKGN1cl9kcnYtPmxhc3Rfc2VjdCAtIGtzICsgMSksIGZkY3RybC0+ZGF0YV9sZW4pOwogICAgICAgIGlmICgoKGRpcmVjdGlvbiA9PSBGRF9ESVJfU0NBTkUgfHwgZGlyZWN0aW9uID09IEZEX0RJUl9TQ0FOTCB8fAogICAgICAgICAgICAgIGRpcmVjdGlvbiA9PSBGRF9ESVJfU0NBTkgpICYmIGRtYV9tb2RlID09IDApIHx8CiAgICAgICAgICAgIChkaXJlY3Rpb24gPT0gRkRfRElSX1dSSVRFICYmIGRtYV9tb2RlID09IDIpIHx8CiAgICAgICAgICAgIChkaXJlY3Rpb24gPT0gRkRfRElSX1JFQUQgJiYgZG1hX21vZGUgPT0gMSkpIHsKICAgICAgICAgICAgLyogTm8gYWNjZXNzIGlzIGFsbG93ZWQgdW50aWwgRE1BIHRyYW5zZmVyIGhhcyBjb21wbGV0ZWQgKi8KICAgICAgICAgICAgZmRjdHJsLT5tc3IgJj0gfkZEX01TUl9SUU07CiAgICAgICAgICAgIC8qIE5vdywgd2UganVzdCBoYXZlIHRvIHdhaXQgZm9yIHRoZSBETUEgY29udHJvbGxlciB0bwogICAgICAgICAgICAgKiByZWNhbGwgdXMuLi4KICAgICAgICAgICAgICovCiAgICAgICAgICAgIERNQV9ob2xkX0RSRVEoZmRjdHJsLT5kbWFfY2hhbm4pOwogICAgICAgICAgICBETUFfc2NoZWR1bGUoZmRjdHJsLT5kbWFfY2hhbm4pOwogICAgICAgICAgICByZXR1cm47CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgRkxPUFBZX0VSUk9SKCJkbWFfbW9kZT0lZCBkaXJlY3Rpb249JWRcbiIsIGRtYV9tb2RlLCBkaXJlY3Rpb24pOwogICAgICAgIH0KICAgIH0KICAgIEZMT1BQWV9EUFJJTlRGKCJzdGFydCBub24tRE1BIHRyYW5zZmVyXG4iKTsKICAgIG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ICAgICAgZmRfc2VjdG9yKGN1cl9kcnYpKTsKICAgICAgICAgICAgICAgIC8qIFN1cmUsIGltYWdlIHNpemUgaXMgdG9vIHNtYWxsLi4uICovCiAgICAgICAgICAgICAgICBtZW1zZXQoZmRjdHJsLT5maWZvLCAwLCBGRF9TRUNUT1JfTEVOKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzd2l0Y2ggKGZkY3RybC0+ZGF0YV9kaXIpIHsKICAgICAgICBjYXNlIEZEX0RJUl9SRUFEOgogICAgICAgICAgICAvKiBSRUFEIGNvbW1hbmRzICovCiAgICAgICAgICAgIERNQV93cml0ZV9tZW1vcnkgKG5jaGFuLCBmZGN0cmwtPmZpZm8gKyByZWxfcG9zLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmZGN0cmwtPmRhdGFfcG9zLCBsZW4pOwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIEZEX0RJUl9XUklURToKICAgICAgICAgICAgLyogV1JJVEUgY29tbWFuZHMgKi8KICAgICAgICAgICAgRE1BX3JlYWRfbWVtb3J5IChuY2hhbiwgZmRjdHJsLT5maWZvICsgcmVsX3BvcywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmZGN0cmwtPmRhdGFfcG9zLCBsZW4pOwogICAgICAgICAgICBpZiAoYmRydl93cml0ZShjdXJfZHJ2LT5icywgZmRfc2VjdG9yKGN1cl9kcnYpLAogICAgICAgICAgICAgICAgICAgICAgICAgICBmZGN0cmwtPmZpZm8sIDEpIDwgMCkgewogICAgICAgICAgICAgICAgRkxPUFBZX0VSUk9SKCJ3cml0aW5nIHNlY3RvciAlZFxuIiwgZmRfc2VjdG9yKGN1cl9kcnYpKTsKICAgICAgICAgICAgICAgIGZkY3RybF9zdG9wX3RyYW5zZmVyKGZkY3RybCwgRkRfU1IwX0FCTlRFUk0gfCBGRF9TUjBfU0VFSywgMHgwMCwgMHgwMCk7CiAgICAgICAgICAgICAgICBnb3RvIHRyYW5zZmVyX2Vycm9yOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgIC8qIFNDQU4gY29tbWFuZHMgKi8KICAgICAgICAgICAgewogICAgICAgICAgICAgICAgdWludDhfdCB0bXBidWZbRkRfU0VDVE9SX0xFTl07CiAgICAgICAgICAgICAgICBpbnQgcmV0OwogICAgICAgICAgICAgICAgRE1BX3JlYWRfbWVtb3J5IChuY2hhbiwgdG1wYnVmLCBmZGN0cmwtPmRhdGFfcG9zLCBsZW4pOwogICAgICAgICAgICAgICAgcmV0ID0gbWVtY21wKHRtcGJ1ZiwgZmRjdHJsLT5maWZvICsgcmVsX3BvcywgbGVuKTsKICAgICAgICAgICAgICAgIGlmIChyZXQgPT0gMCkgewogICAgICAgICAgICAgICAgICAgIHN0YXR1czIgPSBGRF9TUjJfU0VIOwogICAgICAgICAgICAgICAgICAgIGdvdG8gZW5kX3RyYW5zZmVyOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKChyZXQgPCAwICYmIGZkY3RybC0+ZGF0YV9kaXIgPT0gRkRfRElSX1NDQU5MKSB8fAogICAgICAgICAgICAgICAgICAgIChyZXQgPiAwICYmIGZkY3RybC0+ZGF0YV9kaXIgPT0gRkRfRElSX1NDQU5IKSkgewogICAgICAgICAgICAgICAgICAgIHN0YXR1czIgPSAweDAwOwogICAgICAgICAgICAgICAgICAgIGdvdG8gZW5kX3RyYW5zZmVyOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICBmZGN0cmwtPmRhdGFfcG9zICs9IGxlbjsKICAgICAgICByZWxfcG9zID0gZmRjdHJsLT5kYXRhX3BvcyAlIEZEX1NFQ1RPUl9MRU47CiAgICAgICAgaWYgKHJlbF9wb3MgPT0gMCkgewogICAgICAgICAgICAvKiBTZWVrIHRvIG5leHQgc2VjdG9yICovCiAgICAgICAgICAgIGl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sKICAgIGlmICghKGZkY3RybC0+bXNyICYgRkRfTVNSX1JRTSkgfHwgIShmZGN0cmwtPm1zciAmIEZEX01TUl9ESU8pKSB7CiAgICAgICAgRkxPUFBZX0VSUk9SKCJjb250cm9sbGVyIG5vdCByZWFkeSBmb3IgcmVhZGluZ1xuIik7CiAgICAgICAgcmV0dXJuIDA7CiAgICB9CiAgICBwb3MgPSBmZGN0cmwtPmRhdGFfcG9zOwogICAgaWYgKGZkY3RybC0+bXNyICYgRkRfTVNSX05PTkRNQSkgewogICAgICAgIHBvcyAlPSBGRF9TRUNUT1JfTEVOOwogICAgICAgIGlmIChwb3MgPT0gMCkgewogICAgICAgICAgICBpZiAoZmRjdHJsLT5kYXRhX3BvcyAhPSAwKQogICAgICAgICAgICAgICAgaWYgKCFmZGN0cmxfc2Vla190b19uZXh0X3NlY3QoZmRjdHJsLCBjdXJfZHJ2KSkgewogICAgICAgICAgICAgICAgICAgIEZMT1BQWV9EUFJJTlRGKCJlcnJvciBzZWVraW5nIHRvIG5leHQgc2VjdG9yICVkXG4iLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZkX3NlY3RvcihjdXJfZHJ2KSk7CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChiZHJ2X3JlYWQoY3VyX2Rydi0+YnMsIGZkX3NlY3RvcihjdXJfZHJ2KSwgZmRjdHJsLT5maWZvLCAxKSA8IDApIHsKICAgICAgICAgICAgICAgIEZMT1BQWV9EUFJJTlRGKCJlcnJvciBnZXR0aW5nIHNlY3RvciAlZFxuIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZkX3NlY3RvcihjdXJfZHJ2KSk7CiAgICAgICAgICAgICAgICAvKiBTdXJlLCBpbWFnZSBzaXplIGlzIHRvbyBzbWFsbC4uLiAqLwogICAgICAgICAgICAgICAgbWVtc2V0KGZkY3RybC0+ZmlmbywgMCwgRkRfU0VDV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IpOwogICAgICAgIHJldHVybjsKICAgIH0KICAgIGlmICghKGZkY3RybC0+bXNyICYgRkRfTVNSX1JRTSkgfHwgKGZkY3RybC0+bXNyICYgRkRfTVNSX0RJTykpIHsKICAgICAgICBGTE9QUFlfRVJST1IoImNvbnRyb2xsZXIgbm90IHJlYWR5IGZvciB3cml0aW5nXG4iKTsKICAgICAgICByZXR1cm47CiAgICB9CiAgICBmZGN0cmwtPmRzciAmPSB+RkRfRFNSX1BXUkRPV047CiAgICAvKiBJcyBpdCB3cml0ZSBjb21tYW5kIHRpbWUgPyAqLwogICAgaWYgKGZkY3RybC0+bXNyICYgRkRfTVNSX05PTkRNQSkgewogICAgICAgIC8qIEZJRk8gZGF0YSB3cml0ZSAqLwogICAgICAgIHBvcyA9IGZkY3RybC0+ZGF0YV9wb3MrKzsKICAgICAgICBwb3MgJT0gRkRfU0VDVE9SX0xFTjsKICAgICAgICBmZGN0cmwtPmZpZm9bcG9zXSA9IHZhbHVlOwogICAgICAgIGlmIChwb3MgPT0gRkRfU0VDVE9SX0xFTiAtIDEgfHwKICAgICAgICAgICAgZmRjdHJsLT5kYXRhX3BvcyA9PSBmZGN0cmwtPmRhdGFfbGVuKSB7CiAgICAgICAgICAgIGN1cl9kcnYgPSBnZXRfY3VyX2RydihmZGN0cmwpOwogICAgICAgICAgICBpZiAoYmRydl93cml0ZShjdXJfZHJ2LT5icywgZmRfc2VjdG9yKGN1cl9kcnYpLCBmZGN0cmwtPmZpZm8sIDEpIDwgMCkgewogICAgICAgICAgICAgICAgRkxPUFBZX0VSUk9SKCJ3cml0aW5nIHNlY3RvciAlZFxuIiwgZmRfc2VjdG9yKGN1cl9kcnYpKTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoIWZkY3RybF9zZWVrX3RvX25leHRfc2VjdChmZGN0cmwsIGN1cl9kcnYpKSB7CiAgICAgICAgICAgICAgICBGTE9QUFlfRFBSSU5URigiZXJyb3Igc2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24oRkRDdHJsICpmZGN0cmwsIHRhcmdldF9waHlzX2FkZHJfdCBpb19iYXNlKQp7CiAgICBpbnQgaSwgajsKICAgIHN0YXRpYyBpbnQgY29tbWFuZF90YWJsZXNfaW5pdGVkID0gMDsKCiAgICAvKiBGaWxsICdjb21tYW5kX3RvX2hhbmRsZXInIGxvb2t1cCB0YWJsZSAqLwogICAgaWYgKCFjb21tYW5kX3RhYmxlc19pbml0ZWQpIHsKICAgICAgICBjb21tYW5kX3RhYmxlc19pbml0ZWQgPSAxOwogICAgICAgIGZvciAoaSA9IEFSUkFZX1NJWkUoaGFuZGxlcnMpIC0gMTsgaSA+PSAwOyBpLS0pIHsKICAgICAgICAgICAgZm9yIChqID0gMDsgaiA8IHNpemVvZihjb21tYW5kX3RvX2hhbmRsZXIpOyBqKyspIHsKICAgICAgICAgICAgICAgIGlmICgoaiAmIGhhbmRsZXJzW2ldLm1hc2spID09IGhhbmRsZXJzW2ldLnZhbHVlKSB7CiAgICAgICAgICAgICAgICAgICAgY29tbWFuZF90b19oYW5kbGVyW2pdID0gaTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KCiAgICBGTE9QUFlfRFBSSU5URigiaW5pdCBjb250cm9sbGVyXG4iKTsKICAgIGZkY3RybC0+ZmlmbyA9IHFlbXVfbWVtYWxpZ24oNTEyLCBGRF9TRUNUT1JfTEVOKTsKICAgIGZkY3RybC0+Zmlmb19zaXplID0gNTEyOwogICAgZmRjdHJsLT5yZXN1bHRfdGltZXIgPSBxZW11X25ld190aW1lcih2bV9jbG9jaywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZmRjdHJsX3Jlc3VsdF90aW1lciwgZmRjdHJsKTsKCiAgICBmZGN0cmwtPnZlcnNpb24gPSAweDkwOyAvKiBJbnRlbCA4MjA3OCBjb250cm9sbGVyICovCiAgICBmZGN0cmwtPmNvbmZpZyA9IEZEX0NPTkZJR19FSVMgfCBGRF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