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GVmIGtleV90eXBlICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdmFsdWVfdHlwZTsKICAgIHR5cGVkZWYgX0NvbXBhcmUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBrZXlfY29tcGFyZTsKICAgIHR5cGVkZWYga2V5X2NvbXBhcmUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB2YWx1ZV9jb21wYXJlOwogICAgdHlwZWRlZiBfQWxsb2NhdG9yICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGFsbG9jYXRvcl90eXBlOwogICAgdHlwZWRlZiB2YWx1ZV90eXBlJiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlZmVyZW5jZTsKICAgIHR5cGVkZWYgY29uc3QgdmFsdWVfdHlwZSYgICAgICAgICAgICAgICAgICAgICAgICBjb25zdF9yZWZlcmVuY2U7Cgpwcml2YXRlOgogICAgdHlwZWRlZiBfX3RyZWU8dmFsdWVfdHlwZSwgdmFsdWVfY29tcGFyZSwgYWxsb2NhdG9yX3R5cGU+IF9fYmFzZTsKICAgIHR5cGVkZWYgYWxsb2NhdG9yX3RyYWl0czxhbGxvY2F0b3JfdHlwZT4gICAgICAgICAgICAgICAgICBfX2FsbG9jX3RyYWl0czsKICAgIHR5cGVkZWYgdHlwZW5hbWUgX19iYXNlOjpfX25vZGVfaG9sZGVyICAgICAgICAgICAgICAgICAgICBfX25vZGVfaG9sZGVyOwoKICAgIF9fYmFzZSBfX3RyZWVfOwoKcHVibGljOgogICAgdHlwZWRlZiB0eXBlbmFtZSBfX2Jhc2U6OnBvaW50ZXIgICAgICAgICAgICAgICBwb2ludGVyOwogICAgdHlwZWRlZiB0eXBlbmFtZSBfX2Jhc2U6OmNvbnN0X3BvaW50ZXIgICAgICAgICBjb25zdF9wb2ludGVyOwogICAgdHlwZWRlZiB0eXBlbmFtZSBfX2Jhc2U6OnNpemVfdHlwZSAgICAgICAgICAgICBzaXplX3R5cGU7CiAgICB0eXBlZGVmI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zZXQgb3BlcmF0aW9uczoKICAgIGl0ZXJhdG9yIGZpbmQoY29uc3Qga2V5X3R5cGUmIF9faykgICAgICAgICAgICAge3JldHVybiBfX3RyZWVfLmZpbmQoX19rKTt9CiAgICBjb25zdF9pdGVyYXRvciBmaW5kKGNvbnN0IGtleV90eXBlJiBfX2spIGNvbnN0IHtyZXR1cm4gX190cmVlXy5maW5kKF9fayk7fQogICAgc2l6ZV90eXBlICAgICAgY291bnQoY29uc3Qga2V5X3R5cGUmIF9faykgY29uc3QKICAgICAgICB7cmV0dXJuIF9fdHJlZV8uX19jb3VudF91bmlxdWUoX19rKTt9CiAgICBpdGVyYXRvciBsb3dlcl9ib3VuZChjb25zdCBrZXlfdHlwZSYgX19rKQogICAgICAgIHtyZXR1cm4gX190cmVlXy5sb3dlcl9ib3VuZChfX2spO30KICAgIGNvbnN0X2l0ZXJhdG9yIGxvd2VyX2JvdW5kKGNvbnN0IGtleV90eXBlJiBfX2spIGNvbnN0CiAgICAgICAge3JldHVybiBfX3RyZWVfLmxvd2VyX2JvdW5kKF9fayk7fQogICAgaXRlcmF0b3IgdXBwZXJfYm91bmQoY29uc3Qga2V5X3R5cGUmIF9faykKICAgICAgICB7cmV0dXJuIF9fdHJlZV8udXBwZXJfYm91bmQoX19rKTt9CiAgICBjb25zdF9pdGVyYXRvciB1cHBlcl9ib3VuZChjb25zdCBrZXlfdHlwZSYgX19rKSBjb25zdAogICAgICAgIHtyZXR1cm4gX190cmVlXy51cHBlcl9ib3VuZChfX2spO30KICAgIHBhaXI8aXRlcmF0b3IsaXRlcmF0b3I+IGVxdWFsX3JhbmdlKGNvbnN0IGtleV90eXBlJiBfX2spCiAgICAgICAge3JldHVybiBfX3RyZWVfLl9fZXF1YWxfcmFuZ2VfdW5pcXVlKF9fayk7fQogICAgcGFpcjxjb25zdF9pdGVyYXRvcixjb25zdF9pdGVyYXRvcj4gZXF1YWxfcmFuZ2UoY29uc3Qga2V5X3R5cGUmIF9faykgY29uc3QKICAgICA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H0KCiAgICBtdWx0aXNldChjb25zdCBtdWx0aXNldCYgX19zKQogICAgICAgIDogX190cmVlXyhfX3MuX190cmVlXy52YWx1ZV9jb21wKCksCiAgICAgICAgICBfX2FsbG9jX3RyYWl0czo6c2VsZWN0X29uX2NvbnRhaW5lcl9jb3B5X2NvbnN0cnVjdGlvbihfX3MuX190cmVlXy5fX2FsbG9jKCkpKQogICAgICAgIHsKICAgICAgICAgICAgaW5zZXJ0KF9fcy5iZWdpbigpLCBfX3MuZW5kKCkpOwogICAgICAgIH0KCiNpZmRlZiBfTElCQ1BQX01PVkUKICAgIG11bHRpc2V0KG11bHRpc2V0JiYgX19zKQogICAgICAgIDogX190cmVlXyhfU1REOjptb3ZlKF9fcy5fX3RyZWVfKSkge30KI2VuZGlmCiAgICBleHBsaWNpdCBtdWx0aXNldChjb25zdCBhbGxvY2F0b3JfdHlwZSYgX19hKQogICAgICAgIDogX190cmVlXyhfX2EpIHt9CiAgICBtdWx0aXNldChjb25zdCBtdWx0aXNldCYgX19zLCBjb25zdCBhbGxvY2F0b3JfdHlwZSYgX19hKQogICAgICAgIDogX190cmVlXyhfX3MuX190cmVlXy52YWx1ZV9jb21wKCksIF9fYSkKICAgICAgICB7CiAgICAgICAgICAgIGluc2VydChfX3MuYmVnaW4oKSwgX19zLmVuZCgpKTsKICAgICAgICB9CiNpZmRlZiBfTElCQ1BQX01PVkUKICAgIG11bHRpc2V0KG11bHRpc2V0JiYgX19zLCBjb25zdCBhbGxvY2F0b3JfdHlwZSYgX19hKTsKI2VuZGlmCgogICAgbXVsdGlzZXQoaW5pdGlhbGl6ZXJfbGlzdDx2YWx1ZV90eXBlPiBfX2lsLCBjb25zdCB2YWx1ZV9jb21wYXJlJiBfX2NvbXAgPSB2YWx1ZV9jb21wYXJlKCkpCiAgICAgICAgOiBfX3RyZWVfKF9fY29tcCkKICAgICAgICB7CiAgICAgICAgICAgIGluc2VydChfX2lsLmJlZ2luKCksIF9faWwuZW5kKCkpOwogICAgICAgIH0KCiAgICBtdWx0aXNldChpbml0aWFsaXplcl9saXN0PHZhbHVlX3R5cGU+IF9faWwsIGNvbnN0IHZhbHVlX2NvbXBhcmUmIF9fY29tcCwKICAgICAgICBjb25zdCBhbGxvY2F0b3JfdHlwZSYgX19hKQogICAgICAgIDogX190cmVlXyhfX2NvbXAsIF9fYSkKICAgICAgICB7CiAgICAgICAgICAgIGluc2VydChfX2lsLmJlZ2luKCksIF9faWwuZW5kKCkpOwogICAgICAgIH0KCiAgICBtdWx0aXNldCYgb3BlcmF0b3I9KGluaXRpYWxpemVyX2xpc3Q8dmFsdWVfdHlwZT4gX19pbCkKICAgICAgICB7CiAgICAgICAgICAgIF9fdHJlZV8uX19hc3NpZ25fbXVsdGkoX19pbC5iZWdpbigpLCBfX2lsLmVuZCgpKTsKICAgICAgICAgICAgcmV0dXJuICp0aGlzOwogICAgICAgIH0KCiNpZmRlZiBfTElCQ1BQX01PVkUKICAgIG11bHRpc2V0JiBvcGVyYXRvcj0obXVsdGlzZXQmJiBfX3MpCiAgICAgICAgewogICAgICAgICAgICBfX3RyZWVfID0gX1NURDo6bW92ZShfX3MuX190cmVlXyk7CiAgICAgICAgICAgIHJldHVybiAqdGhpczsKICAgICAgICB9CiNlbmRpZgoKICAgICAgICAgIGl0ZXJhdG9yIGJlZ2luKCkgICAgICAge3JldHVybiBfX3RyZWVfLmJlZ2luKCk7fQogICAgY29uc3RfaXRlcmF0b3IgYmVnaW4oKSBjb25zdCB7cmV0dXJuIF9fdHJlZV8uYmVnaW4oKTt9CiAgICAgICAgICBpdGVyYXRvciBlbmQoKSAgICAgICAgIHtyZXR1cm4gX190cmVlXy5lbmQoKTt9CiAgICBjb25zdF9pdGVyYXRvciBlbmQoKSAgIGNvbnN0IHtyZXR1cm4gX190cmVlXy5lbmQoKTt9CgogICAgICAgICAgcmV2ZXJzZV9pdGVyYXRvciByYmVnaW4oKSAgICAgICB7cmV0dXJuICAgICAgIHJldmVyc2VfaXRlcmF0b3IoZW5kKCkp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V0dXJuIF9fdHJlZV8uZmluZChfX2spO30KICAgIGNvbnN0X2l0ZXJhdG9yIGZpbmQoY29uc3Qga2V5X3R5cGUmIF9faykgY29uc3Qge3JldHVybiBfX3RyZWVfLmZpbmQoX19rKTt9CiAgICBzaXplX3R5cGUgICAgICBjb3VudChjb25zdCBrZXlfdHlwZSYgX19rKSBjb25zdAogICAgICAgIHtyZXR1cm4gX190cmVlXy5fX2NvdW50X211bHRpKF9fayk7fQogICAgaXRlcmF0b3IgbG93ZXJfYm91bmQoY29uc3Qga2V5X3R5cGUmIF9faykKICAgICAgICB7cmV0dXJuIF9fdHJlZV8ubG93ZXJfYm91bmQoX19rKTt9CiAgICBjb25zdF9pdGVyYXRvciBsb3dlcl9ib3VuZChjb25zdCBrZXlfdHlwZSYgX19rKSBjb25zdAogICAgICAgICAgICB7cmV0dXJuIF9fdHJlZV8ubG93ZXJfYm91bmQoX19rKTt9CiAgICBpdGVyYXRvciB1cHBlcl9ib3VuZChjb25zdCBrZXlfdHlwZSYgX19rKQogICAgICAgICAgICB7cmV0dXJuIF9fdHJlZV8udXBwZXJfYm91bmQoX19rKTt9CiAgICBjb25zdF9pdGVyYXRvciB1cHBlcl9ib3VuZChjb25zdCBrZXlfdHlwZSYgX19rKSBjb25zdAogICAgICAgICAgICB7cmV0dXJuIF9fdHJlZV8udXBwZXJfYm91bmQoX19rKTt9CiAgICBwYWlyPGl0ZXJhdG9yLGl0ZXJhdG9yPiAgICAgICAgICAgICBlcXVhbF9yYW5nZShjb25zdCBrZXlfdHlwZSYgX19rKQogICAgICAgICAgICB7cmV0dXJuIF9fdHJlZV8uX19lcXVhbF9yYW5nZV9tdWx0aShfX2spO30KICAgIHBhaXI8Y29uc3RfaXRlcmF0b3IsY29uc3RfaXRlcmF0b3I+IGVxdWFsX3JhbmdlKGNvbnN0IGtleV90eXBlJiBfX2spIGNvbnN0CiAgICAgICAgICAgIHtyZXR1cm4gX190cmVlXy5fX2VxdWFsX3JhbmdlX211bHRpKF9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