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GViLAogICAgbGVkX3dyaXRldywKICAgIGxlZF93cml0ZWwsCn07CgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCi8qIGphenpfbGVkIGRpc3BsYXkgKi8KCnN0YXRpYyB2b2lkIGRyYXdfaG9yaXpvbnRhbF9saW5lKERpc3BsYXlTdGF0ZSAqZHMsIGludCBwb3N5LCBpbnQgcG9zeDEsIGludCBwb3N4MiwgdWludDMyX3QgY29sb3IpCnsKICAgIHVpbnQ4X3QgKmQ7CiAgICBpbnQgeCwgYnBwOwoKICAgIGJwcCA9IChkcy0+ZGVwdGggKyA3KSA+PiAzOwogICAgZCA9IGRzLT5kYXRhICsgZHMtPmxpbmVzaXplICogcG9zeSArIGJwcCAqIHBvc3gxOwogICAgc3dpdGNoKGJwcCkgewogICAgICAgIGNhc2UgMToKICAgICAgICAgICAgZm9yICh4ID0gcG9zeDE7IHggPD0gcG9zeDI7IHgrKykgewogICAgICAgICAgICAgICAgKigodWludDhfdCAqKWQpID0gY29sb3I7CiAgICAgICAgICAgICAgICBkKys7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSAyOgogICAgICAgICAgICBmb3IgKHggPSBwb3N4MTsgeCA8PSBwb3N4MjsgeCsrKSB7CiAgICAgICAgICAgICAgICAqKCh1aW50MTZfdCAqKWQpID0gY29sb3I7CiAgICAgICAgICAgICAgICBkICs9IDI7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSA0OgogICAgICAgICAgICBmb3IgKHggPSBwb3N4MTsgeCA8PSBwb3N4MjsgeCsrKSB7CiAgICAgICAgICAgICAgICAqKCh1aW50MzJfdCAqKWQpID0gY29sb3I7CiAgICAgICAgICAgICAgICBkICs9IDQ7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYnJlYWs7CiAgICB9Cn0KCnN0YXRpYyB2b2lkIGRyYXdfdmVydGljYWxfbGluZShEaXNwbGF5U3RhdGUgKmRzLCBpbnQgcG9zeCwgaW50IHBvc3kxLCBpbnQgcG9zeTIsIHVpbnQzMl90IGNvbG9yKQp7CiAgICB1aW50OF90ICpkOwogICAgaW50IHksIGJwcDsKCiAgICBicHAgPSAoZHMtPmRlcHRoICsgNykgPj4gMzsKICAgIGQgPSBkcy0+ZGF0YSArIGRzLT5saW5lc2l6ZSAqIHBvc3kxICsgYnBwICogcG9zeDsKICAgIHN3aXRjaChicHApIHsKICAgICAgICBjYXNlIDE6CiAgICAgICAgICAgIGZvciAoeSA9IHBvc3kxOyB5IDw9IHBvc3kyOyB5KyspIHsKICAgICAgICAgICAgICAgICooKHVpbnQ4X3QgKilkKSA9IGNvbG9yOwogICAgICAgICAgICAgICAgZCArPSBkcy0+bGluZXNpemU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSAyOgogICAgICAgICAgICBmb3IgKHkgPSBwb3N5MTsgeSA8PSBwb3N5MjsgeSsrKSB7CiAgICAgICAgICAgICAgICAqKCh1aW50MTZfdCAqKWQpID0gY29sb3I7CiAgICAgICAgICAgICAgICBkICs9IGRzLT5saW5lc2l6ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIDQ6CiAgICAgICAgICAgIGZvciAoeSA9IHBvc3kxOyB5IDw9IHBvc3kyOyB5KyspIHsKICAgICAgICAgICAgICAgICooKHVpbnQzMl90ICopZCkgPSBjb2xvcjsKICAgICAgICAgICAgICAgIGQgKz0gZHMtPmxpbmVzaXplOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJyZWFrOwogICAgfQp9CgpzdGF0aWMgdm9pZCBqYXp6X2xlZF91cGRhdGVfZGlzcGxheSh2b2lkICpvcGFxdWUpCnsKICAgIExlZFN0YXRlICpzID0gb3BhcXVlOwogICAgRGlzcGxheVN0YXRlICpkcyA9IHMtPmRzOwogICAgdWludDhfdCAqZDE7CiAgICB1aW50MzJfdCBjb2xvcl9zZWdtZW50LCBjb2xvcl9sZWQ7CiAgICBpbnQgeSwgYnBwOwoKICAgIGlmIChzLT5zdGF0ZSAmIFJFRFJBV19CQUNLR1JPVU5EKSB7CiAgICAgICAgLyogY2xlYXIgc2NyZWVuICovCiAgICAgICAgYnBwID0gKGRzLT5kZXB0aCArIDcpID4+IDM7CiAgICAgICAgZDEgPSBkcy0+ZGF0YTsKICAgICAgICBmb3IgKHkgPSAwOyB5IDwgZHMtPmhlaWdodDsgeSsrKSB7CiAgICAgICAgICAgIG1lbXNldChkMSwgMHgwMCwgZHMtPndpZHRoICogYnBwKTsKICAgICAgICAgICAgZDEgKz0gZHMtPmxpbmVzaXplOwogICAgICAgIH0KICAgIH0KCiAgICBpZiAocy0+c3RhdGUgJiBSRURSQVdfU0VHTUVOVFMpIHsKICAgICAgICAvKiBzZXQgY29sb3JzIGFjY29yZGluZyB0byBicHAgKi8KICAgICAgICBzd2l0Y2ggKGRzLT5kZXB0aCkgewogICAgICAgICAgICBjYXNlIDg6CiAgICAgICAgICAgICAgICBjb2xvcl9zZWdtZW50ID0gcmdiX3RvX3BpeGVsOCgweGFhLCAweGFhLCAweGFhKTsKICAgICAgICAgICAgICAgIGNvbG9yX2xlZCA9IHJnYl90b19waXhlbDgoMHgwMCwgMHhmZiwgMHgwMCk7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgY2FzZSAxNToKICAgICAgICAgICAgICAgIGNvbG9yX3NlZ21lbnQgPSByZ2JfdG9fcGl4ZWwxNSgweGFhLCAweGFhLCAweGFhKTsKICAgICAgICAgICAgICAgIGNvbG9yX2xlZCA9IHJnYl90b19waXhlbDE1KDB4MDAsIDB4ZmYsIDB4MDApOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMTY6CiAgICAgICAgICAgICAgICBjb2xvcl9zZWdtZW50ID0gcmdiX3RvX3BpeGVsMTYoMHhhYSwgMHhhYSwgMHhhYSk7CiAgICAgICAgICAgICAgICBjb2xvcl9sZWQgPSByZ2JfdG9fcGl4ZWwxNigweDAwLCAweGZmLCAweDAwKTsKICAgICAgICAgICAgY2FzZSAyNDoKICAgICAgICAgICAgICAgIGNvbG9yX3NlZ21lbnQgPSByZ2JfdG9fcGl4ZWwyNCgweGFhLCAweGFhLCAweGFhKTsKICAgICAgICAgICAgICAgIGNvbG9yX2xlZCA9IHJnYl90b19waXhlbDI0KDB4MDAsIDB4ZmYsIDB4MDApOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMzI6CiAgICAgICAgICAgICAgICBjb2xvcl9zZWdtZW50ID0gcmdiX3RvX3BpeGVsMzIoMHhhYSwgMHhhYSwgMHhhYSk7CiAgICAgICAgICAgICAgICBjb2xvcl9sZWQgPSByZ2JfdG9fcGl4ZWwzMigweDAwLCAweGZmLCAweDAwKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgIH0KCiAgICAgICAgLyogZGlzcGxheSBzZWdtZW50cyAqLwogICAgICAgIGRyYXdfaG9yaXpvbnRhbF9saW5lKGRzLCA0MCwgMTAsIDQwLCAocy0+c2VnbWVudHMgJiAweDAyKSA/IGNvbG9yX3NlZ21lbnQgOiAwKTsKICAgICAgICBkcmF3X3ZlcnRpY2FsX2xpbmUoZHMsIDEwLCAxMCwgNDAsIChzLT5zZWdtZW50cyAmIDB4MDQpID8gY29sb3Jfc2VnbWVudCA6IDApOwogICAgICAgIGRyYXdfdmVydGljYWxfbGluZShkcywgMTAsIDQwLCA3MCwgKHMtPnNlZ21lbnRzICYgMHgwOCkgPyBjb2xvcl9zZWdtZW50IDogMCk7CiAgICAgICAgZHJhd19ob3Jpem9udGFsX2xpbmUoZHMsIDcwLCAxMCwgNDAsIChzLT5zZWdtZW50cyAmIDB4MTApID8gY29sb3Jfc2VnbWVudCA6IDApOwogICAgICAgIGRyYXdfdmVydGljYWxfbGluZShkcywgNDAsIDQwLCA3MCwgKHMtPnNlZ21lbnRzICYgMHgyMCkgPyBjb2xvcl9zZWdtZW50IDogMCk7CiAgICAgICAgZHJhd192ZXJ0aWNhbF9saW5lKGRzLCA0MCwgMTAsIDQwLCAocy0+c2VnbWVudHMgJiAweDQwKSA/IGNvbG9yX3NlZ21lbnQgOiAwKTsKICAgICAgICBkcmF3X2hvcml6b250YWxfbGluZShkcywgMTAsIDEwLCA0MCwgKHMtPnNlZ21lbnRzICYgMHg4MCkgPyBjb2xvcl9zZWdtZW50IDogMCk7CgogICAgICAgIC8qIGRpc3BsYXkgbGVkICovCiAgICAgICAgaWYgKCEocy0+c2VnbWVudHMgJiAweDAxKSkKICAgICAgICAgICAgY29sb3JfbGVkID0gMDsgLyogYmxhY2sgKi8KICAgICAgICBkcmF3X2hvcml6b250YWxfbGluZShkcywgNjgsIDUwLCA1MCwgY29sb3JfbGVkKTsKICAgICAgICBkcmF3X2hvcml6b250YWxfbGluZShkcywgNjksIDQ5LCA1MSwgY29sb3JfbGVkKTsKICAgICAgICBkcmF3X2hvcml6b250YWxfbGluZShkcywgNzAsIDQ4LCA1MiwgY29sb3JfbGVkKTsKICAgICAgICBkcmF3X2hvcml6b250YWxfbGluZShkcywgNzEsIDQ5LCA1MSwgY29sb3JfbGVkKTsKICAgICAgICBkcmF3X2hvcml6b250YWxfbGluZShkcywgNzIsIDUwLCA1MCwgY29sb3JfbGVkKTsKICAgIH0KCiAgICBzLT5zdGF0ZSA9IFJFRFJBV19OT05FOwogICAgZHB5X3VwZGF0ZShkcywgMCwgMCwgZHMtPndpZHRoLCBkcy0+aGVpZ2h0KTsKfQoKc3RhdGljIHZvaWQgamF6el9sZWRfaW52YWxpZGF0ZV9kaXNwbGF5KHZvaWQgKm9wYXF1ZSkKewogICAgTGVkU3RhdGUgKnMgPSBvcGFxdWU7CiAgICBzLT5zdGF0ZSB8PSBSRURSQVdfU0VHTUVOVFMgfCBSRURSQVdf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