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Zm10LCAuLi4pICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICBkbyB7IHByaW50ZigiRkxPUFBZOiAiIGZtdCAsICMjIF9fVkFfQVJHU19fKTsgfSB3aGlsZSAoMCkKI2Vsc2UKI2RlZmluZSBGTE9QUFlfRFBSSU5URihmbXQsIC4uLikKI2VuZGlmCgojZGVmaW5lIEZMT1BQWV9FUlJPUihmbXQsIC4uLikgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICBkbyB7IHByaW50ZigiRkxPUFBZIEVSUk9SOiAlczogIiBmbXQsIF9fZnVuY19fICwgIyMgX19WQV9BUkdTX18pOyB9IHdoaWxlICgwKQoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwovKiBGbG9wcHkgZHJpdmUgZW11bGF0aW9uICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICovCgojZGVmaW5lIEdFVF9DVVJfRFJWKGZkY3RybCkgKChmZGN0cmwpLT5jdXJfZHJ2KQojZGVmaW5lIFNFVF9DVVJfRFJWKGZkY3RybCwgZHJpdmUpICgoZmRjdHJsKS0+Y3VyX2RydiA9IChkcml2ZSkpCgovKiBXaWxsIGFsd2F5cyBiZSBhIGZpeGVkIHBhcmFtZXRlciBmb3IgdXMgKi8KI2RlZmluZSBGRF9TRUNUT1JfTEVOICAgICAgICAgIDUxMgojZGVmaW5lIEZEX1NFQ1RPUl9TQyAgICAgICAgICAgMiAgIC8qIFNlY3RvciBzaXplIGNvZGUgKi8KI2RlZmluZSBGRF9SRVNFVF9TRU5TRUlfQ09VTlQgIDQgICAvKiBOdW1iZXIgb2Ygc2Vuc2UgaW50ZXJydXB0cyBvbiBSRVNFVCAqLwoKLyogRmxvcHB5IGRpc2sgZHJpdmUgZW11bGF0aW9uICovCnR5cGVkZWYgZW51bSBGRGlza1R5cGUgewogICAgRkRSSVZFX0RJU0tfMjg4ICAgPSAweDAxLCA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FkcywgbWF4X3RyYWNrLCBsYXN0X3NlY3QsIHJvOwoKICAgIEZMT1BQWV9EUFJJTlRGKCJyZXZhbGlkYXRlXG4iKTsKICAgIGlmIChkcnYtPmJzICE9IE5VTEwgJiYgYmRydl9pc19pbnNlcnRlZChkcnYtPmJzKSkgewogICAgICAgIHJvID0gYmRydl9pc19yZWFkX29ubHkoZHJ2LT5icyk7CiAgICAgICAgYmRydl9nZXRfZ2VvbWV0cnlfaGludChkcnYtPmJzLCAmbmJfaGVhZHMsICZtYXhfdHJhY2ssICZsYXN0X3NlY3QpOwogICAgICAgIGlmIChuYl9oZWFkcyAhPSAwICYmIG1heF90cmFjayAhPSAwICYmIGxhc3Rfc2VjdCAhPSAwKSB7CiAgICAgICAgICAgIEZMT1BQWV9EUFJJTlRGKCJVc2VyIGRlZmluZWQgZGlzayAoJWQgJWQgJWQpIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgbmJfaGVhZHMgLSAxLCBtYXhfdHJhY2ssIGxhc3Rfc2VjdCk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgYmRydl9nZXRfZ2VvbWV0cnkoZHJ2LT5icywgJm5iX3NlY3RvcnMpOwogICAgICAgICAgICBtYXRjaCA9IC0xOwogICAgICAgICAgICBmaXJzdF9tYXRjaCA9IC0xOwogICAgICAgICAgICBmb3IgKGkgPSAwOzsgaSsrKSB7CiAgICAgICAgICAgICAgICBwYXJzZSA9ICZmZF9mb3JtYXRzW2ldOwogICAgICAgICAgICAgICAgaWYgKHBhcnNlLT5kcml2ZSA9PSBGRFJJVkVfRFJWX05PTkUpCiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICBpZiAoZHJ2LT5kcml2ZSA9PSBwYXJzZS0+ZHJpdmUgfHwKICAgICAgICAgICAgICAgICAgICBkcnYtPmRyaXZlID09IEZEUklWRV9EUlZfTk9ORSkgewogICAgICAgICAgICAgICAgICAgIHNpemUgPSAocGFyc2UtPm1heF9oZWFkICsgMSkgKiBwYXJzZS0+bWF4X3RyYWNrICoKICAgICAgICAgICAgICAgICAgICAgICAgcGFyc2UtPmxhc3Rfc2VjdDsKICAgICAgICAgICAgICAgICAgICBpZiAobmJfc2VjdG9ycyA9PSBzaXplKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIG1hdGNoID0gaTsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChmaXJzdF9tYXRjaCA9PSAtMSkKICAgICAgICAgICAgICAgICAgICAgICAgZmlyc3RfbWF0Y2ggPSBpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChtYXRjaCA9PSAtMSkgewogICAgICAgICAgICAgICAgaWYgKGZpcnN0X21hdGNoID09IC0xKQogICAgICAgICAgICAgICAgICAgIG1hdGNoID0gMTsKICAgICAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgICAgICBtYXRjaCA9IGZpcnN0X21hdGNoOwogICAgICAgICAgICAgICAgcGFyc2UgPSAmZmRfZm9ybWF0c1ttYXRjaF07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbmJfaGVhZHMgPSBwYXJzZS0+bWF4X2hlYWQgKyAxOwogICAgICAgICAgICBtYXhfdHJhY2sgPSBwYXJzZS0+bWF4X3RyYWNrOwogICAgICAgICAgICBsYXN0X3NlY3QgPSBwYXJzZS0+bGFzdF9zZWN0OwogICAgICAgICAgICBkcnYtPmRyaXZlID0gcGFyc2UtPmRyaXZlOwogICAgICAgICAgICBGTE9QUFlfRFBSSU5URigiJXMgZmxvcHB5IGRpc2sgKCVkIGggJWQgdCAlZCBzKSAlc1xuIiwgcGFyc2UtPnN0ciwKICAgICAgICAgICAgICAgICAgICAgICAgICAgbmJfaGVhZHMsIG1heF90cmFjaywgbGFzdF9zZWN0LCBybyA/ICJybyIgOiAicnciKTsKICAgICAgICB9CiAgICAgICAgaWYgKG5iX2hlYWRzID09IDEpIHsKICAgICAgICAgICAgZHJ2LT5mbGFncyAmPSB+RkRJU0tfREJMX1NJREVTOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGRydi0+ZmxhZ3MgfD0gRkRJU0tfREJMX1NJREVTOwogICAgICAgIH0KICAgICAgICBkcnYtPm1heF90cmFjayA9IG1heF90cmFjazsKICAgICAgICBkcnYtPmxhc3Rfc2VjdCA9IGxhc3Rfc2VjdDsKICAgICAgICBkcnYtPnJvID0gcm87CiAgICB9IGVsc2UgewogICAgICAgIEZMT1BQWV9EUFJJTlRGKCJObyBkaXNrIGluIGRyaXZlXG4iKTsKICAgICAgICBkcnYtPmxhc3Rfc2VjdCA9IDA7CiAgICAgICAgZHJ2LT5tYXhfdHJhY2sgPSAwOwogICAgICAgIGRydi0+ZmxhZ3MgJj0gfkZESVNLX0RCTF9TSURFUzsKICAgIH0KfQoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwovKiBJbnRlbCA4MjA3OCBmbG9wcHkgZGlzayBjb250cm9sbGVyIGVtdWxhdGlvbiAgICAgICAgICAqLwoKc3RhdGljIHZvaWQgZmRjdHJsX3Jlc2V0KEZEQ3RybCAqZmRjdHJsLCBpbnQgZG9faXJxKTsKc3RhdGljIHZvaWQgZmRjdHJsX3Jlc2V0X2ZpZm8oRkRDdHJsICpmZGN0cmwpOwpzdGF0aWMgaW50IGZkY3RybF90cmFuc2Zlcl9oYW5kbGVyICh2b2lkICpvcGFxdWUsIGludCBuY2hhbiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaW50IGRtYV9wb3MsIGludCBkbWFfbGVuKTsKc3RhdGljIHZvaWQgZmRjdHJsX3JhaXNlX2lycShGREN0cmwgKmZkY3RybCwgdWludDhfdCBzdGF0dXMwKTsKCnN0YXRpYyB1aW50MzJfdCBmZGN0cmxfcmVhZF9zdGF0dXNBKEZEQ3RybCAqZmRjd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N5bGluZGVyICovCn07CgplbnVtIHsKICAgIEZEX1NSMl9TTlMgICAgICA9IDB4MDQsIC8qIFNjYW4gbm90IHNhdGlzZmllZCAqLwogICAgRkRfU1IyX1NFSCAgICAgID0gMHgwOCwgLyogU2NhbiBlcXVhbCBoaXQgKi8KfTsKCmVudW0gewogICAgRkRfU1JBX0RJUiAgICAgID0gMHgwMSwKICAgIEZEX1NSQV9uV1AgICAgICA9IDB4MDIsCiAgICBGRF9TUkFfbklORFggICAgPSAweDA0LAogICAgRkRfU1JBX0hEU0VMICAgID0gMHgwOCwKICAgIEZEX1NSQV9uVFJLMCAgICA9IDB4MTAsCiAgICBGRF9TUkFfU1RFUCAgICAgPSAweDIwLAogICAgRkRfU1JBX25EUlYyICAgID0gMHg0MCwKICAgIEZEX1NSQV9JTlRQRU5EICA9IDB4ODAsCn07CgplbnVtIHsKICAgIEZEX1NSQl9NVFIwICAgICA9IDB4MDEsCiAgICBGRF9TUkJfTVRSMSAgICAgPSAweDAyLAogICAgRkRfU1JCX1dHQVRFICAgID0gMHgwNCwKICAgIEZEX1NSQl9SREFUQSAgICA9IDB4MDgsCiAgICBGRF9TUkJfV0RBVEEgICAgPSAweDEwLAogICAgRkRfU1JCX0RSMCAgICAgID0gMHgyMCwKfTsKCmVudW0gewojaWYgTUFYX0ZEID09IDQKICAgIEZEX0RPUl9TRUxNQVNLICA9IDB4MDMsCiNlbHNlCiAgICBGRF9ET1JfU0VMTUFTSyAgPSAweDAxLAojZW5kaWYKICAgIEZEX0RPUl9uUkVTRVQgICA9IDB4MDQsCiAgICBGRF9ET1JfRE1BRU4gICAgPSAweDA4LAogICAgRkRfRE9SX01PVEVOMCAgID0gMHgxMCwKICAgIEZEX0RPUl9NT1RFTjEgICA9IDB4MjAsCiAgICBGRF9ET1JfTU9URU4yICAgPSAweDQwLAogICAgRkRfRE9SX01PVEVOMyAgID0gMHg4MCwKfTsKCmVudW0gewojaWYgTUFYX0ZEID09IDQKICAgIEZEX1REUl9CT09UU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VyX2Rydi0+c2VjdCA9IDE7CiAgICAgICAgaWYgKEZEX01VTFRJX1RSQUNLKGZkY3RybC0+ZGF0YV9zdGF0ZSkpIHsKICAgICAgICAgICAgaWYgKGN1cl9kcnYtPmhlYWQgPT0gMCAmJgogICAgICAgICAgICAgICAgKGN1cl9kcnYtPmZsYWdzICYgRkRJU0tfREJMX1NJREVTKSAhPSAwKSB7CiAgICAgICAgICAgICAgICBjdXJfZHJ2LT5oZWFkID0gMTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGN1cl9kcnYtPmhlYWQgPSAwOwogICAgICAgICAgICAgICAgY3VyX2Rydi0+dHJhY2srKzsKICAgICAgICAgICAgICAgIGlmICgoY3VyX2Rydi0+ZmxhZ3MgJiBGRElTS19EQkxfU0lERVMpID09IDApCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjdXJfZHJ2LT50cmFjaysrOwogICAgICAgICAgICByZXR1cm4gMDsKICAgICAgICB9CiAgICAgICAgRkxPUFBZX0RQUklOVEYoInNlZWsgdG8gbmV4dCB0cmFjayAoJWQgJTAyeCAlMDJ4ID0+ICVkKVxuIiwKICAgICAgICAgICAgICAgICAgICAgICBjdXJfZHJ2LT5oZWFkLCBjdXJfZHJ2LT50cmFjaywKICAgICAgICAgICAgICAgICAgICAgICBjdXJfZHJ2LT5zZWN0LCBmZF9zZWN0b3IoY3VyX2RydikpOwogICAgfSBlbHNlIHsKICAgICAgICBjdXJfZHJ2LT5zZWN0Kys7CiAgICB9CiAgICByZXR1cm4gMTsKfQoKLyogQ2FsbGJhY2sgZm9yIHRyYW5zZmVyIGVuZCAoc3RvcCBvciBhYm9ydCkgKi8Kc3RhdGljIHZvaWQgZmRjdHJsX3N0b3BfdHJhbnNmZXIoRkRDdHJsICpmZGN0cmwsIHVpbnQ4X3Qgc3RhdHVzMCwKICAgICAgICAgICAgICAgICAgICA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qIFN1cmUsIGltYWdlIHNpemUgaXMgdG9vIHNtYWxsLi4uICovCiAgICAgICAgICAgICAgICBtZW1zZXQoZmRjdHJsLT5maWZvLCAwLCBGRF9TRUNUT1JfTEVOKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzd2l0Y2ggKGZkY3RybC0+ZGF0YV9kaXIpIHsKICAgICAgICBjYXNlIEZEX0RJUl9SRUFEOgogICAgICAgICAgICAvKiBSRUFEIGNvbW1hbmRzICovCiAgICAgICAgICAgIERNQV93cml0ZV9tZW1vcnkgKG5jaGFuLCBmZGN0cmwtPmZpZm8gKyByZWxfcG9zLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmZGN0cmwtPmRhdGFfcG9zLCBsZW4pOwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIEZEX0RJUl9XUklURToKICAgICAgICAgICAgLyogV1JJVEUgY29tbWFuZHMgKi8KICAgICAgICAgICAgRE1BX3JlYWRfbWVtb3J5IChuY2hhbiwgZmRjdHJsLT5maWZvICsgcmVsX3BvcywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmZGN0cmwtPmRhdGFfcG9zLCBsZW4pOwogICAgICAgICAgICBpZiAoYmRydl93cml0ZShjdXJfZHJ2LT5icywgZmRfc2VjdG9yKGN1cl9kcnYpLAogICAgICAgICAgICAgICAgICAgICAgICAgICBmZGN0cmwtPmZpZm8sIDEpIDwgMCkgewogICAgICAgICAgICAgICAgRkxPUFBZX0VSUk9SKCJ3cml0aW5nIHNlY3RvciAlZFxuIiwgZmRfc2VjdG9yKGN1cl9kcnYpKTsKICAgICAgICAgICAgICAgIGZkY3RybF9zdG9wX3RyYW5zZmVyKGZkY3RybCwgRkRfU1IwX0FCTlRFUk0gfCBGRF9TUjBfU0VFSywgMHgwMCwgMHgwMCk7CiAgICAgICAgICAgICAgICBnb3RvIHRyYW5zZmVyX2Vycm9yOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgIC8qIFNDQU4gY29tbWFuZHMgKi8KICAgICAgICAgICAgewogICAgICAgICAgICAgICAgdWludDhfdCB0bXBidWZbRkRfU0VDVE9SX0xFTl07CiAgICAgICAgICAgICAgICBpbnQgcmV0OwogICAgICAgICAgICAgICAgRE1BX3JlYWRfbWVtb3J5IChuY2hhbiwgdG1wYnVmLCBmZGN0cmwtPmRhdGFfcG9zLCBsZW4pOwogICAgICAgICAgICAgICAgcmV0ID0gbWVtY21wKHRtcGJ1ZiwgZmRjdHJsLT5maWZvICsgcmVsX3BvcywgbGVuKTsKICAgICAgICAgICAgICAgIGlmIChyZXQgPT0gMCkgewogICAgICAgICAgICAgICAgICAgIHN0YXR1czIgPSBGRF9TUjJfU0VIOwogICAgICAgICAgICAgICAgICAgIGdvdG8gZW5kX3RyYW5zZmVyOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKChyZXQgPCAwICYmIGZkY3RybC0+ZGF0YV9kaXIgPT0gRkRfRElSX1NDQU5MKSB8fAogICAgICAgICAgICAgICAgICAgIChyZXQgPiAwICYmIGZkY3RybC0+ZGF0YV9kaXIgPT0gRkRfRElSX1NDQU5IKSkgewogICAgICAgICAgICAgICAgICAgIHN0YXR1czIgPSAweDAwOwogICAgICAgICAgICAgICAgICAgIGdvdG8gZW5kX3RyYW5zZmVyOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICBmZGN0cmwtPmRhdGFfcG9zICs9IGxlbjsKICAgICAgICByZWxfcG9zID0gZmRjdHJsLT5kYXRhX3BvcyAlIEZEX1NFQ1RPUl9MRU47CiAgICAgICAgaWYgKHJlbF9wb3MgPT0gMCkgewogICAgICAgICAgICAvKiBTZWVrIHRvIG5leHQgc2VjdG9yICovCiAgICAgICAgICAgIGlmICghZmRjdHJsX3NlZWtfdG9fbmV4dF9zZWN0KGZkY3RybCwgY3VyX2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ZGN0cmwtPm1zciAmIEZEX01TUl9ESU8pKSB7CiAgICAgICAgRkxPUFBZX0VSUk9SKCJjb250cm9sbGVyIG5vdCByZWFkeSBmb3IgcmVhZGluZ1xuIik7CiAgICAgICAgcmV0dXJuIDA7CiAgICB9CiAgICBwb3MgPSBmZGN0cmwtPmRhdGFfcG9zOwogICAgaWYgKGZkY3RybC0+bXNyICYgRkRfTVNSX05PTkRNQSkgewogICAgICAgIHBvcyAlPSBGRF9TRUNUT1JfTEVOOwogICAgICAgIGlmIChwb3MgPT0gMCkgewogICAgICAgICAgICBpZiAoZmRjdHJsLT5kYXRhX3BvcyAhPSAwKQogICAgICAgICAgICAgICAgaWYgKCFmZGN0cmxfc2Vla190b19uZXh0X3NlY3QoZmRjdHJsLCBjdXJfZHJ2KSkgewogICAgICAgICAgICAgICAgICAgIEZMT1BQWV9EUFJJTlRGKCJlcnJvciBzZWVraW5nIHRvIG5leHQgc2VjdG9yICVkXG4iLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZkX3NlY3RvcihjdXJfZHJ2KSk7CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChiZHJ2X3JlYWQoY3VyX2Rydi0+YnMsIGZkX3NlY3RvcihjdXJfZHJ2KSwgZmRjdHJsLT5maWZvLCAxKSA8IDApIHsKICAgICAgICAgICAgICAgIEZMT1BQWV9EUFJJTlRGKCJlcnJvciBnZXR0aW5nIHNlY3RvciAlZFxuIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZkX3NlY3RvcihjdXJfZHJ2KSk7CiAgICAgICAgICAgICAgICAvKiBTdXJlLCBpbWFnZSBzaXplIGlzIHRvbyBzbWFsbC4uLiAqLwogICAgICAgICAgICAgICAgbWVtc2V0KGZkY3RybC0+ZmlmbywgMCwgRkRfU0VDVE9SX0xFTik7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICByZXR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ICYgRkRfTVNSX1JRTSkgfHwgKGZkY3RybC0+bXNyICYgRkRfTVNSX0RJTykpIHsKICAgICAgICBGTE9QUFlfRVJST1IoImNvbnRyb2xsZXIgbm90IHJlYWR5IGZvciB3cml0aW5nXG4iKTsKICAgICAgICByZXR1cm47CiAgICB9CiAgICBmZGN0cmwtPmRzciAmPSB+RkRfRFNSX1BXUkRPV047CiAgICAvKiBJcyBpdCB3cml0ZSBjb21tYW5kIHRpbWUgPyAqLwogICAgaWYgKGZkY3RybC0+bXNyICYgRkRfTVNSX05PTkRNQSkgewogICAgICAgIC8qIEZJRk8gZGF0YSB3cml0ZSAqLwogICAgICAgIHBvcyA9IGZkY3RybC0+ZGF0YV9wb3MrKzsKICAgICAgICBwb3MgJT0gRkRfU0VDVE9SX0xFTjsKICAgICAgICBmZGN0cmwtPmZpZm9bcG9zXSA9IHZhbHVlOwogICAgICAgIGlmIChwb3MgPT0gRkRfU0VDVE9SX0xFTiAtIDEgfHwKICAgICAgICAgICAgZmRjdHJsLT5kYXRhX3BvcyA9PSBmZGN0cmwtPmRhdGFfbGVuKSB7CiAgICAgICAgICAgIGN1cl9kcnYgPSBnZXRfY3VyX2RydihmZGN0cmwpOwogICAgICAgICAgICBpZiAoYmRydl93cml0ZShjdXJfZHJ2LT5icywgZmRfc2VjdG9yKGN1cl9kcnYpLCBmZGN0cmwtPmZpZm8sIDEpIDwgMCkgewogICAgICAgICAgICAgICAgRkxPUFBZX0VSUk9SKCJ3cml0aW5nIHNlY3RvciAlZFxuIiwgZmRfc2VjdG9yKGN1cl9kcnYpKTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoIWZkY3RybF9zZWVrX3RvX25leHRfc2VjdChmZGN0cmwsIGN1cl9kcnYpKSB7CiAgICAgICAgICAgICAgICBGTE9QUFlfRFBSSU5URigiZXJyb3Igc2Vla2luZyB0byBuZXh0IHNlY3RvciAlZFxuIiwKICAgICAgICAgICAgICAgICAg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