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iAgICBpZiAoc2VjdCA+IGRydi0+bGFzdF9zZWN0KSB7CiAgICAgICAgRkxPUFBZX0RQUklOVEYoInRyeSB0byByZWFkICVkICUwMnggJTAyeCAobWF4PSVkICVkICUwMnggJTAyeClcbiIsCiAgICAgICAgICAgICAgICAgICAgICAgaGVhZCwgdHJhY2ssIHNlY3QsIDEsCiAgICAgICAgICAgICAgICAgICAgICAgKGRydi0+ZmxhZ3MgJiBGRElTS19EQkxfU0lERVMpID09IDAgPyAwIDogMSwKICAgICAgICAgICAgICAgICAgICAgICBkcnYtPm1heF90cmFjaywgZHJ2LT5sYXN0X3NlY3QpOwogICAgICAgIHJldHVybiAzOwogICAgfQogICAgc2VjdG9yID0gX2ZkX3NlY3RvcihoZWFkLCB0cmFjaywgc2VjdCwgZHJ2LT5sYXN0X3NlY3QpOwogICAgcmV0ID0gMDsKICAgIGlmIChzZWN0b3IgIT0gZmRfc2VjdG9yKGRydikpIHsKI2lmIDAKICAgICAgICBpZiAoIWVuYWJsZV9zZWVrKSB7CiAgICAgICAgICAgIEZMT1BQWV9FUlJPUigibm8gaW1wbGljaXQgc2VlayAlZCAlMDJ4ICUwMnggKG1heD0lZCAlMDJ4ICUwMngpXG4iLAogICAgICAgICAgICAgICAgICAgICAgICAgaGVhZCwgdHJhY2ssIHNlY3QsIDEsIGRydi0+bWF4X3RyYWNrLCBkcnYtPmxhc3Rfc2VjdCk7CiAgICAgICAgICAgIHJldHVybiA0OwogICAgICAgIH0KI2VuZGlmCiAgICAgICAgZHJ2LT5oZWFkID0gaGVhZDsKICAgICAgICBpZiAoZHJ2LT50cmFjayAhPSB0cmFjaykKICAgICAgICAgICAgcmV0ID0gMTsKICAgICAgICBkcnYtPnRyYWNrID0gdHJhY2s7CiAgICAgICAgZHJ2LT5zZWN0ID0gc2VjdDsKICAgIH0KCiAgICByZXR1cm4gcmV0Owp9CgovKiBTZXQgZHJpdmUgYmFjayB0byB0cmFjayAwICovCnN0YXRpYyB2b2lkIGZkX3JlY2F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AgICAgICBpZiAoZHJ2LT5kcml2ZSA9PSBwYXJzZS0+ZHJpdmUgfHwKICAgICAgICAgICAgICAgICAgICBkcnYtPmRyaXZlID09IEZEUklWRV9EUlZfTk9ORSkgewogICAgICAgICAgICAgICAgICAgIHNpemUgPSAocGFyc2UtPm1heF9oZWFkICsgMSkgKiBwYXJzZS0+bWF4X3RyYWNrICoKICAgICAgICAgICAgICAgICAgICAgICAgcGFyc2UtPmxhc3Rfc2VjdDsKICAgICAgICAgICAgICAgICAgICBpZiAobmJfc2VjdG9ycyA9PSBzaXplKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIG1hdGNoID0gaTsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChmaXJzdF9tYXRjaCA9PSAtMSkKICAgICAgICAgICAgICAgICAgICAgICAgZmlyc3RfbWF0Y2ggPSBpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChtYXRjaCA9PSAtMSkgewogICAgICAgICAgICAgICAgaWYgKGZpcnN0X21hdGNoID09IC0xKQogICAgICAgICAgICAgICAgICAgIG1hdGNoID0gMTsKICAgICAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgICAgICBtYXRjaCA9IGZpcnN0X21hdGNoOwogICAgICAgICAgICAgICAgcGFyc2UgPSAmZmRfZm9ybWF0c1ttYXRjaF07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbmJfaGVhZHMgPSBwYXJzZS0+bWF4X2hlYWQgKyAxOwogICAgICAgICAgICBtYXhfdHJhY2sgPSBwYXJzZS0+bWF4X3RyYWNrOwogICAgICAgICAgICBsYXN0X3NlY3QgPSBwYXJzZS0+bGFzdF9zZWN0OwogICAgICAgICAgICBkcnYtPmRyaXZlID0gcGFyc2UtPmRyaXZlOwogICAgICAgICAgICBGTE9QUFlfRFBSSU5URigiJXMgZmxvcHB5IGRpc2sgKCVkIGggJWQgdCAlZCBzKSAlc1xuIiwgcGFyc2UtPnN0ciwKICAgICAgICAgICAgICAgICAgICAgICAgICAgbmJfaGVhZHMsIG1heF90cmFjaywgbGFzdF9zZWN0LCBybyA/ICJybyIgOiAicnciKTsKICAgICAgICB9CiAgICAgICAgaWYgKG5iX2hlYWRzID09IDEpIHsKICAgICAgICAgICAgZHJ2LT5mbGFncyAmPSB+RkRJU0tfREJMX1NJREVTOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGRydi0+ZmxhZ3MgfD0gRkRJU0tfREJMX1NJREVTOwogICAgICAgIH0KICAgICAgICBkcnYtPm1heF90cmFjayA9IG1heF90cmFjazsKICAgICAgICBkcnYtPmxhc3Rfc2VjdCA9IGxhc3Rfc2VjdDsKICAgICAgICBkcnYtPnJvID0gcm87CiAgICB9IGVsc2UgewogICAgICAgIEZMT1BQWV9EUFJJTlRGKCJObyBkaXNrIGluIGRyaXZlXG4iKTsKICAgICAgICBkcnYtPmxhc3Rfc2VjdCA9IDA7CiAgICAgICAgZHJ2LT5tYXhfdHJhY2sgPSAwOwogICAgICAgIGRydi0+ZmxhZ3MgJj0gfkZESVNLX0RCTF9TSURFUzsKICAgIH0KfQoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwovKiBJbnRlbCA4MjA3OCBmbG9wcHkgZGlzayBjb250cm9sbGVyIGVtdWxhdGlvbiAgICAgICAgICAqLwoKc3RhdGljIHZvaWQgZmRjdHJsX3Jlc2V0IChmZGN0cmxfdCAqZmRjdHJsLCBpbnQgZG9faXJxKTsKc3RhdGljIHZvaWQgZmRjdHJsX3Jlc2V0X2ZpZm8gKGZkY3RybF90ICpmZGN0cmwpOwpzdGF0aWMgaW50IGZkY3RybF90cmFuc2Zlcl9oYW5kbGVyICh2b2lkICpvcGFxdWUsIGludCBuY2hhbiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaW50IGRtYV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FQTVQgICAgPSAweDEwLAogICAgRkRfU1IwX1NFRUsgICAgID0gMHgyMCwKICAgIEZEX1NSMF9BQk5URVJNICA9IDB4NDAsCiAgICBGRF9TUjBfSU5WQ01EICAgPSAweDgwLAogICAgRkRfU1IwX1JEWUNIRyAgID0gMHhjMCwKfTsKCmVudW0gewogICAgRkRfU1IxX0VDICAgICAgID0gMHg4MCwgLyogRW5kIG9mIGN5bGluZGVyICovCn07CgplbnVtIHsKICAgIEZEX1NSMl9TTlMgICAgICA9IDB4MDQsIC8qIFNjYW4gbm90IHNhdGlzZmllZCAqLwogICAgRkRfU1IyX1NFSCAgICAgID0gMHgwOCwgLyogU2NhbiBlcXVhbCBoaXQgKi8KfTsKCmVudW0gewogICAgRkRfU1JBX0RJUiAgICAgID0gMHgwMSwKICAgIEZEX1NSQV9uV1AgICAgICA9IDB4MDIsCiAgICBGRF9TUkFfbklORFggICAgPSAweDA0LAogICAgRkRfU1JBX0hEU0VMICAgID0gMHgwOCwKICAgIEZEX1NSQV9uVFJLMCAgICA9IDB4MTAsCiAgICBGRF9TUkFfU1RFUCAgICAgPSAweDIwLAogICAgRkRfU1JBX25EUlYyICAgID0gMHg0MCwKICAgIEZEX1NSQV9JTlRQRU5EICA9IDB4ODAsCn07CgplbnVtIHsKICAgIEZEX1NSQl9NVFIwICAgICA9IDB4MDEsCiAgICBGRF9TUkJfTVRSMSAgICAgPSAweDAyLAogICAgRkRfU1JCX1dHQVRFICAgID0gMHgwNCwKICAgIEZEX1NSQl9SREFUQSAgICA9IDB4MDgsCiAgICBGRF9TUkJfV0RBVEEgICAgPSAweDEwLAogICAgRkRfU1JCX0RSMCAgICAgID0gMHgyMCwKfTsKCmVudW0gewojaWYgTUFYX0ZEID09IDQKICAgIEZEX0RPUl9TRUxNQVNLICA9IDB4MDMsCiNlbHNlCiAgICBGRF9ET1JfU0VMTUFTSyAgPSAweDAxLAojZW5kaWYKICAgIEZEX0RPUl9uUkVTRVQgICA9IDB4MDQsCiAgICBGR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IHVpbnQ4X3QgdmVyc2lvbjsKICAgIC8qIEhXICovCiAgICBxZW11X2lycSBpcnE7CiAgICBpbnQgZG1hX2NoYW5uOwogICAgLyogQ29udHJvbGxlciBzdGF0ZSAqLwogICAgUUVNVVRpbWVyICpyZXN1bHRfdGltZXI7CiAgICB1aW50OF90IHNyYTsKICAgIHVpbnQ4X3Qgc3JiOwogICAgdWludDhfdCBkb3I7CiAgICB1aW50OF90IGRvcl92bXN0YXRlOyAvKiBvbmx5IHVzZWQgYXMgdGVtcCBkdXJpbmcgdm1zdGF0ZSAqLwogICAgdWludDhfdCB0ZHI7CiAgICB1aW50OF90IGRzcjsKICAgIHVpbnQ4X3QgbXNyOwogICAgdWludDhfdCBjdXJfZHJ2OwogICAgdWludDhfdCBzdGF0dXMwOwogICAgdWludDhfdCBzdGF0dXMxOwogICAgdWludDhfdCBzdGF0dXMyOwogICAgLyogQ29tbWFuZCBGSUZPICovCiAgICB1aW50OF90ICpmaWZvOwogICAgaW50MzJfdCBmaWZvX3NpemU7CiAgICB1aW50MzJfdCBkYXRhX3BvczsKICAgIHVpbnQzMl90IGRhdGFfbGVuOwogICAgdWludDhfdCBkYXRhX3N0YXRlOwogICAgdWludDhfdCBkYXRhX2RpcjsKICAgIHVpbnQ4X3QgZW90OyAvKiBsYXN0IHdhbnRlZCBzZWN0b3IgKi8KICAgIC8qIFN0YXRlcyBrZXB0IG9ubHkgdG8gYmUgcmV0dXJuZWQgYmFjayAqLwogICAgLyogVGltZXJzIHN0YXRlICovCiAgICB1aW50OF90IHRpbWVyMDsKICAgIHVpbnQ4X3QgdGltZXIxOwogICAgLyogcHJlY29tcGVuc2F0aW9uICovCiAgICB1aW50OF90IHByZWNvbXBfdHJrOwogICAgdWludDhfdCBjb25maWc7CiAgICB1aW50OF90IGxvY2s7CiAgICAvKiBQb3dlciBkb3duIGNvbmZpZyAoYWxzbyB3aXRoIHN0YXR1cyByZWdCIGFjY2VzcyBtb2RlICovCiAgICB1aW50OF90IHB3cm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ZHJ2LT5sYXN0X3NlY3Qgc2hvdWxkIGJlIGFuCiAgICAgICBlcnJvciBpbiBmYWN0ICovCiAgICBpZiAoY3VyX2Rydi0+c2VjdCA+PSBjdXJfZHJ2LT5sYXN0X3NlY3QgfHwKICAgICAgICBjdXJfZHJ2LT5zZWN0ID09IGZkY3RybC0+ZW90KSB7CiAgICAgICAgY3VyX2Rydi0+c2VjdCA9IDE7CiAgICAgICAgaWYgKEZEX01VTFRJX1RSQUNLKGZkY3RybC0+ZGF0YV9zdGF0ZSkpIHsKICAgICAgICAgICAgaWYgKGN1cl9kcnYtPmhlYWQgPT0gMCAmJgogICAgICAgICAgICAgICAgKGN1cl9kcnYtPmZsYWdzICYgRkRJU0tfREJMX1NJREVTKSAhPSAwKSB7CiAgICAgICAgICAgICAgICBjdXJfZHJ2LT5oZWFkID0gMTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGN1cl9kcnYtPmhlYWQgPSAwOwogICAgICAgICAgICAgICAgY3VyX2Rydi0+dHJhY2srKzsKICAgICAgICAgICAgICAgIGlmICgoY3VyX2Rydi0+ZmxhZ3MgJiBGRElTS19EQkxfU0lERVMpID09IDApCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjdXJfZHJ2LT50cmFjaysrOwogICAgICAgICAgICByZXR1cm4gMDsKICAgICAgICB9CiAgICAgICAgRkxPUFBZX0RQUklOVEYoInNlZWsgdG8gbmV4dCB0cmFjayAoJWQgJTAyeCAlMDJ4ID0+ICVkKVxuIiwKICAgICAgICAgICAgICAgICAgICAgICBjdXJfZHJ2LT5oZWFkLCBjdXJfZHJ2LT50cmFjaywKICAgICAgICAgICAgICAgICAgICAgICBjdXJfZHJ2LT5zZWN0LCBmZF9zZWN0b3IoY3VyX2RydikpOwogICAgfSBlbHNlIHsKICAgICAgICBjdXJfZHJ2LT5zZWN0Kys7CiAgICB9CiAg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mIDM7CiAgICAgICAgRkxPUFBZX0RQUklOVEYoImRtYV9tb2RlPSVkIGRpcmVjdGlvbj0lZCAoJWQgLSAlZClcbiIsCiAgICAgICAgICAgICAgICAgICAgICAgZG1hX21vZGUsIGRpcmVjdGlvbiwKICAgICAgICAgICAgICAgICAgICAgICAoMTI4IDw8IGZkY3RybC0+Zmlmb1s1XSkgKgogICAgICAgICAgICAgICAgICAgICAgIChjdXJfZHJ2LT5sYXN0X3NlY3QgLSBrcyArIDEpLCBmZGN0cmwtPmRhdGFfbGVuKTsKICAgICAgICBpZiAoKChkaXJlY3Rpb24gPT0gRkRfRElSX1NDQU5FIHx8IGRpcmVjdGlvbiA9PSBGRF9ESVJfU0NBTkwgfHwKICAgICAgICAgICAgICBkaXJlY3Rpb24gPT0gRkRfRElSX1NDQU5IKSAmJiBkbWFfbW9kZSA9PSAwKSB8fAogICAgICAgICAgICAoZGlyZWN0aW9uID09IEZEX0RJUl9XUklURSAmJiBkbWFfbW9kZSA9PSAyKSB8fAogICAgICAgICAgICAoZGlyZWN0aW9uID09IEZEX0RJUl9SRUFEICYmIGRtYV9tb2RlID09IDEpKSB7CiAgICAgICAgICAgIC8qIE5vIGFjY2VzcyBpcyBhbGxvd2VkIHVudGlsIERNQSB0cmFuc2ZlciBoYXMgY29tcGxldGVkICovCiAgICAgICAgICAgIGZkY3RybC0+bXNyICY9IH5GRF9NU1JfUlFNOwogICAgICAgICAgICAvKiBOb3csIHdlIGp1c3QgaGF2ZSB0byB3YWl0IGZvciB0aGUgRE1BIGNvbnRyb2xsZXIgdG8KICAgICAgICAgICAgICogcmVjYWxsIHVzLi4uCiAgICAgICAgICAgICAqLwogICAgICAgICAgICBETUFfaG9sZF9EUkVRKGZkY3RybC0+ZG1hX2NoYW5uKTsKICAgICAgICAgICAgRE1BX3NjaGVkdWxlKGZkY3RybC0+ZG1hX2NoYW5uKTsKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIE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jdXJfZHJ2KSwKICAgICAgICAgICAgICAgICAgICAgICAgICBmZGN0cmwtPmZpZm8sIDEpIDwgMCkgewogICAgICAgICAgICAgICAgRkxPUFBZX0RQUklOVEYoIkZsb3BweTogZXJyb3IgZ2V0dGluZyBzZWN0b3IgJWRcbiIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmZF9zZWN0b3IoY3VyX2RydikpOwogICAgICAgICAgICAgICAgLyogU3VyZSwgaW1hZ2Ugc2l6ZSBpcyB0b28gc21hbGwuLi4gKi8KICAgICAgICAgICAgICAgIG1lbXNldChmZGN0cmwtPmZpZm8sIDAsIEZEX1NFQ1RPUl9MRU4pOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHN3aXRjaCAoZmRjdHJsLT5kYXRhX2RpcikgewogICAgICAgIGNhc2UgRkRfRElSX1JFQUQ6CiAgICAgICAgICAgIC8qIFJFQUQgY29tbWFuZHMgKi8KICAgICAgICAgICAgRE1BX3dyaXRlX21lbW9yeSAobmNoYW4sIGZkY3RybC0+ZmlmbyArIHJlbF9wb3MsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZkY3RybC0+ZGF0YV9wb3MsIGxlbik7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgRkRfRElSX1dSSVRFOgogICAgICAgICAgICAvKiBXUklURSBjb21tYW5kcyAqLwogICAgICAgICAgICBETUFfcmVhZF9tZW1vcnkgKG5jaGFuLCBmZGN0cmwtPmZpZm8gKyByZWxfcG9zLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZkY3RybC0+ZGF0YV9wb3MsIGxlbik7CiAgICAgICAgICAgIGlmIChiZHJ2X3dyaXRlKGN1cl9kcnYtPmJzLCBmZF9zZWN0b3IoY3VyX2RydiksCiAgICAgICAgICAgICAgICAgICAgICAgICAgIGZkY3RybC0+ZmlmbywgMSkgPCAwKSB7CiAgICAgICAgICAgICAgICBGTE9QUFlfRVJST1IoIndyaXRpbmcgc2VjdG9yICVkXG4iLCBmZF9zZWN0b3IoY3VyX2RydikpOwogICAgICAgICAgICAgICAgZmRjdHJsX3N0b3BfdHJhbnNmZXIoZmRjdHJsLCBGRF9TUjBfQUJOVEVSTSB8IEZEX1NSMF9TRUVLLCAweDAwLCAweDAwKTsKICAgICAgICAgICAgICAgIGdvdG8gdHJhbnNmZXJfZXJyb3I7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgLyogU0NBTiBjb21tYW5kcyAqLwogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICB1aW50OF90IHRtcGJ1ZltGRF9TRUNUT1JfTEVOXTsKICAgICAgICAgICAgICAgIGludCByZXQ7CiAgICAgICAgICAgICAgICBETUFfcmVhZF9tZW1vcnkgKG5jaGFuLCB0bXBidWYsIGZkY3RybC0+ZGF0YV9wb3MsIGxlbik7CiAgICAgICAgICAgICAgICByZXQgPSBtZW1jbXAodG1wYnVmLCBmZGN0cmwtPmZpZm8gKyByZWxfcG9zLCBsZW4pOwogICAgICAgICAgICAgICAgaWYgKHJldCA9PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgc3RhdHVzMiA9IEZEX1NSMl9TRUg7CiAgICAgICAgICAgICAgICAgICAgZ290byBlbmRfdHJhbnNmZXI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoKHJldCA8IDAgJiYgZmRjdHJsLT5kYXRhX2RpciA9PSBGRF9ESVJfU0NBTkwpIHx8CiAgICAgICAgICAgICAgICAgICAgKHJldCA+IDAgJiYgZmRjdHJsLT5kYXRhX2RpciA9PSBGRF9ESVJfU0NBTkgpKSB7CiAgICAgICAgICAgICAgICAgICAgc3RhdHVzMiA9IDB4MDA7CiAgICAgICAgICAgICAgICAgICAgZ290byBlbmRfdHJhbnNmZXI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgf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X2RhdGEgKGZkY3RybF90ICpmZGN0cmwpCnsKICAgIGZkcml2ZV90ICpjdXJfZHJ2OwogICAgdWludDMyX3QgcmV0dmFsID0gMDsKICAgIGludCBwb3M7CgogICAgY3VyX2RydiA9IGdldF9jdXJfZHJ2KGZkY3RybCk7CiAgICBmZGN0cmwtPmRzciAmPSB+RkRfRFNSX1BXUkRPV047CiAgICBpZiAoIShmZGN0cmwtPm1zciAmIEZEX01TUl9SUU0pIHx8ICEoZmRjdHJsLT5tc3IgJiBGRF9NU1JfRElPKSkgewogICAgICAgIEZMT1BQWV9FUlJPUigiY29udHJvbGxlciBub3QgcmVhZHkgZm9yIHJlYWRpbmdcbiIpOwogICAgICAgIHJldHVybiAwOwogICAgfQogICAgcG9zID0gZmRjdHJsLT5kYXRhX3BvczsKICAgIGlmIChmZGN0cmwtPm1zciAmIEZEX01TUl9OT05ETUEpIHsKICAgICAgICBwb3MgJT0gRkRfU0VDVE9SX0xFTjsKICAgICAgICBpZiAocG9zID09IDApIHsKICAgICAgICAgICAgaWYgKGZkY3RybC0+ZGF0YV9wb3MgIT0gMCkKICAgICAgICAgICAgICAgIGlmICghZmRjdHJsX3NlZWtfdG9fbmV4dF9zZWN0KGZkY3RybCwgY3VyX2RydikpIHsKICAgICAgICAgICAgICAgICAgICBGTE9QUFlfRFBSSU5URigiZXJyb3Igc2Vla2luZyB0byBuZXh0IHNlY3RvciAlZFxuIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmZF9zZWN0b3IoY3VyX2RydikpOwogICAgICAgICAgICAgICAgICAgIHJldHVybiAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoYmRydl9yZWFkKGN1cl9kcnYtPmJzLCBmZF9zZWN0b3IoY3VyX2RydiksIGZkY3RybC0+ZmlmbywgMSkgPCAwKSB7CiAgICAgICAgICAgICAgICBGTE9QUFlfRFBSSU5URigiZXJyb3IgZ2V0dGluZyBzZWN0b3IgJWRcbiIsCiAgICAgICAg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GZkY3RybCk7CiAgICAgICAgICAgIGlmIChiZHJ2X3dyaXRlKGN1cl9kcnYtPmJzLCBmZF9zZWN0b3IoY3VyX2RydiksIGZkY3RybC0+ZmlmbywgMSkgPCAwKSB7CiAgICAgICAgICAgICAgICBGTE9QUFlfRVJST1IoIndyaXRpbmcgc2VjdG9yICVkXG4iLCBmZF9zZWN0b3IoY3VyX2RydikpOwogICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICghZmRjdHJsX3NlZWtfdG9fbmV4dF9zZWN0KGZkY3RybCwgY3VyX2RydikpIHsKICAgICAgICAgICAgICAgIEZMT1BQWV9EUFJJTlRGKCJlcnJvciBzZWVraW5nIHRvIG5leHQgc2VjdG9yICVkXG4iLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZmRfc2VjdG9yKGN1cl9kcnYpKTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAvKiBTd2l0Y2ggZnJvbSB0cmFuc2ZlciBtb2RlIHRvIHN0YXR1cyBtb2RlCiAgICAgICAgICogdGhlbiBmcm9tIHN0YXR1cyBtb2RlIHRvIGNvbW1hbmQgbW9kZQogICAgICAgICAqLwogICAgICAgIGlmIChmZGN0cmwtPmRhdGFfcG9zID09IGZkY3RybC0+ZGF0YV9sZW4pCiAgICAgICAgICAgIGZkY3RybF9zdG9wX3RyYW5zZmVyKGZkY3RybCwgRkRfU1IwX1NFRUssIDB4MDAsIDB4MDApOwogICAgICAgIHJldHVybjsKICAgIH0KICAgIGlmIChmZGN0cmwtPmRhdGFfcG9zID09IDApIHsKICAgICAgICAvKiBDb21tYW5kICovCiAgICAgICAgcG9zID0gY29tbWFuZF90b19oYW5kbGVyW3ZhbHVlICYgMHhmZl07CiAgICAgICAgRkxPUFBZX0RQUklOVEYoIiVzIGNvbW1hbmRcbiIsIGhhbmRsZXJzW3Bvc10ubmFtZSk7CiAgICAgICAgZmR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SwgaW50IGRtYV9jaGFubiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0YXJnZXRfcGh5c19hZGRyX3QgbW1pb19iYXNlLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgIERyaXZlSW5mbyAqKmZkcykKewogICAgZmRjdHJsX3QgKmZkY3RybDsKICAgIERldmljZVN0YXRlICpkZXY7CiAgICBmZGN0cmxfc3lzYnVzX3QgKnN5czsKCiAgICBkZXYgPSBxZGV2X2NyZWF0ZShOVUxMLCAic3lzYnVzLWZkYyIpOwogICAgc3lzID0gRE9fVVBDQVNUKGZkY3RybF9zeXNidXNfdCwgYnVzZGV2LnFkZXYsIGRldik7CiAgICBmZGN0cmwgPSAmc3lzLT5zdGF0ZTsKICAgIGZkY3RybC0+ZG1hX2NoYW5uID0gZG1hX2NoYW5uOyAvKiBGSVhNRSAqLwogICAgcWRldl9wcm9wX3NldF9kcml2ZShkZXYsICJkcml2ZUEiLCBmZHNbMF0pOwogICAgcWRldl9wcm9wX3NldF9kcml2ZShkZXYsICJkcml2ZUIiLCBmZHNbMV0pOwogICAgcWRldl9pbml0X25vZmFpbChkZXYpOwogICAgc3lzYnVzX2Nvbm5lY3RfaXJxKCZzeXMtPmJ1c2RldiwgMCwgaXJxKTsKICAgIHN5c2J1c19tbWlvX21hcCgmc3lzLT5idXNkZXYsIDAsIG1taW9fYmFzZSk7CgogICAgcmV0dXJuIGZkY3RybDsKfQoKZmRjdHJsX3QgKnN1bjRtX2ZkY3RybF9pbml0IChxZW11X2lycSBpcnEsIHRhcmdldF9waHlzX2FkZHJfdCBpb19iYXNlLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgIERyaXZlSW5mbyAqKmZkcywgcWVtdV9pcnEgKmZkY190YykKewogICAgRGV2aWNlU3RhdGUgKmRldjsKICAgIGZkY3RybF9zeXNidXNfdCAqc3lzOwogICAgZmRjdHJsX3QgKmZkY3RybDsKCiAgICBkZXYgPSBxZGV2X2NyZWF0ZShOVUxMLCAiU1VOVyxmZHR3byIpOwogICAgcWRldl9wcm9wX3NldF9kcml2ZShkZXYsICJkcml2ZSIsIGZkc1swXSk7CiAgICBxZGV2X2luaXRfbm9mYWlsKGRldik7CiAgICBzeXMgPSBET19VUENBU1QoZmRjdHJsX3N5c2J1c190LCBidXNkZXYucWRldiwgZGV2KTsKICAgIGZkY3RybCA9ICZzeXMtPnN0YXRlOwogICAgc3lzYnVzX2Nvbm5lY3RfaXJxKCZzeXMtPmJ1c2RldiwgMCwgaXJxKTsKICAgIHN5c2J1c19tbWlvX21hcCgmc3lzLT5idXNkZXYsIDAsIGlvX2Jhc2UpOwogICAgKmZkY190YyA9IHFkZXZfZ2V0X2dwaW9faW4oZGV2LCAwKTsKCiAgICByZXR1cm4gZmRjdHJsOwp9CgpzdGF0aWMgaW50IGZkY3RybF9pbml0X2NvbW1vbihmZGN0cmxfdCAqZmRjdHJsKQp7CiAgICBpbnQgaSwgajsKICAgIHN0YXRpYyBpbnQgY29tbWFuZF90YWJsZXNfaW5pdGVkID0gMDsKCiAgICAvKiBGaWxsICdjb21tYW5kX3RvX2hhbmRsZXInIGxvb2t1cCB0YWJsZSAqLwogICAgaWYgKCFjb21tYW5kX3RhYmxlc19pbml0ZWQpIHsKICAgICAgICBjb21tYW5kX3RhYmxlc19pbml0ZWQgPSAxOwogICAgICAgIGZvciAoaSA9IEFSUkFZX1NJWkUoaGFuZGxlcnMpIC0gMTsgaSA+PSAwOyBpLS0pIHsKICAgICAgICAgICAgZm9yIChqID0gMDsgaiA8IHNpemVvZihjb21tYW5kX3RvX2hhbmRsZXIpOyBqKyspIHsKICAgICAgICAgICAgICAgIGlmICgoaiAmIGhhbmRsZXJzW2ldLm1hc2spID09IGhhbmRsZXJzW2ldLnZhbHVlKSB7CiAgICAgICAgICAgICAgICAgICAgY29tbWFuZF90b19oYW5kbGVyW2pdID0gaTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KCiAgICBGTE9QUFlfRFBS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