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0ZVszXSA9IHsKICAgIGxlZF93cml0ZWIsCiAgICBsZWRfd3JpdGV3LAogICAgbGVkX3dyaXRlbCwKfTsKCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KLyogamF6el9sZWQgZGlzcGxheSAqLwoKc3RhdGljIHZvaWQgZHJhd19ob3Jpem9udGFsX2xpbmUoRGlzcGxheVN0YXRlICpkcywgaW50IHBvc3ksIGludCBwb3N4MSwgaW50IHBvc3gyLCB1aW50MzJfdCBjb2xvcikKewogICAgdWludDhfdCAqZDsKICAgIGludCB4LCBicHA7CgogICAgYnBwID0gKGRzLT5kZXB0aCArIDcpID4+IDM7CiAgICBkID0gZHMtPmRhdGEgKyBkcy0+bGluZXNpemUgKiBwb3N5ICsgYnBwICogcG9zeDE7CiAgICBzd2l0Y2goYnBwKSB7CiAgICAgICAgY2FzZSAxOgogICAgICAgICAgICBmb3IgKHggPSBwb3N4MTsgeCA8PSBwb3N4MjsgeCsrKSB7CiAgICAgICAgICAgICAgICAqKCh1aW50OF90ICopZCkgPSBjb2xvcjsKICAgICAgICAgICAgICAgIGQrKzsKICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIDI6CiAgICAgICAgICAgIGZvciAoeCA9IHBvc3gxOyB4IDw9IHBvc3gyOyB4KyspIHsKICAgICAgICAgICAgICAgICooKHVpbnQxNl90ICopZCkgPSBjb2xvcjsKICAgICAgICAgICAgICAgIGQgKz0gMjsKICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIDQ6CiAgICAgICAgICAgIGZvciAoeCA9IHBvc3gxOyB4IDw9IHBvc3gyOyB4KyspIHsKICAgICAgICAgICAgICAgICooKHVpbnQzMl90ICopZCkgPSBjb2xvcjsKICAgICAgICAgICAgICAgIGQgKz0gNDsKICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgIH0KfQoKc3RhdGljIHZvaWQgZHJhd192ZXJ0aWNhbF9saW5lKERpc3BsYXlTdGF0ZSAqZHMsIGludCBwb3N4LCBpbnQgcG9zeTEsIGludCBwb3N5MiwgdWludDMyX3QgY29sb3IpCnsKICAgIHVpbnQ4X3QgKmQ7CiAgICBpbnQgeSwgYnBwOwoKICAgIGJwcCA9IChkcy0+ZGVwdGggKyA3KSA+PiAzOwogICAgZCA9IGRzLT5kYXRhICsgZHMtPmxpbmVzaXplICogcG9zeTEgKyBicHAgKiBwb3N4OwogICAgc3dpdGNoKGJwcCkgewogICAgICAgIGNhc2UgMToKICAgICAgICAgICAgZm9yICh5ID0gcG9zeTE7IHkgPD0gcG9zeTI7IHkrKykgewogICAgICAgICAgICAgICAgKigodWludDhfdCAqKWQpID0gY29sb3I7CiAgICAgICAgICAgICAgICBkICs9IGRzLT5saW5lc2l6ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIDI6CiAgICAgICAgICAgIGZvciAoeSA9IHBvc3kxOyB5IDw9IHBvc3kyOyB5KyspIHsKICAgICAgICAgICAgICAgICooKHVpbnQxNl90ICopZCkgPSBjb2xvcjsKICAgICAgICAgICAgICAgIGQgKz0gZHMtPmxpbmVzaXplOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgNDoKICAgICAgICAgICAgZm9yICh5ID0gcG9zeTE7IHkgPD0gcG9zeTI7IHkrKykgewogICAgICAgICAgICAgICAgKigodWludDMyX3QgKilkKSA9IGNvbG9yOwogICAgICAgICAgICAgICAgZCArPSBkcy0+bGluZXNpemU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYnJlYWs7CiAgICB9Cn0KCnN0YXRpYyB2b2lkIGphenpfbGVkX3VwZGF0ZV9kaXNwbGF5KHZvaWQgKm9wYXF1ZSkKewogICAgTGVkU3RhdGUgKnMgPSBvcGFxdWU7CiAgICBEaXNwbGF5U3RhdGUgKmRzID0gcy0+ZHM7CiAgICB1aW50OF90ICpkMTsKICAgIHVpbnQzMl90IGNvbG9yX3NlZ21lbnQsIGNvbG9yX2xlZDsKICAgIGludCB5LCBicHA7CgogICAgaWYgKHMtPnN0YXRlICYgUkVEUkFXX0JBQ0tHUk9VTkQpIHsKICAgICAgICAvKiBjbGVhciBzY3JlZW4gKi8KICAgICAgICBicHAgPSAoZHMtPmRlcHRoICsgNykgPj4gMzsKICAgICAgICBkMSA9IGRzLT5kYXRhOwogICAgICAgIGZvciAoeSA9IDA7IHkgPCBkcy0+aGVpZ2h0OyB5KyspIHsKICAgICAgICAgICAgbWVtc2V0KGQxLCAweDAwLCBkcy0+d2lkdGggKiBicHApOwogICAgICAgICAgICBkMSArPSBkcy0+bGluZXNpemU7CiAgICAgICAgfQogICAgfQoKICAgIGlmIChzLT5zdGF0ZSAmIFJFRFJBV19TRUdNRU5UUykgewogICAgICAgIC8qIHNldCBjb2xvcnMgYWNjb3JkaW5nIHRvIGJwcCAqLwogICAgICAgIHN3aXRjaCAoZHMtPmRlcHRoKSB7CiAgICAgICAgICAgIGNhc2UgODoKICAgICAgICAgICAgICAgIGNvbG9yX3NlZ21lbnQgPSByZ2JfdG9fcGl4ZWw4KDB4YWEsIDB4YWEsIDB4YWEpOwogICAgICAgICAgICAgICAgY29sb3JfbGVkID0gcmdiX3RvX3BpeGVsOCgweDAwLCAweGZmLCAweDAwKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDE1OgogICAgICAgICAgICAgICAgY29sb3Jfc2VnbWVudCA9IHJnYl90b19waXhlbDE1KDB4YWEsIDB4YWEsIDB4YWEpOwogICAgICAgICAgICAgICAgY29sb3JfbGVkID0gcmdiX3RvX3BpeGVsMTUoMHgwMCwgMHhmZiwgMHgwMCk7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgY2FzZSAxNjoKICAgICAgICAgICAgICAgIGNvbG9yX3NlZ21lbnQgPSByZ2JfdG9fcGl4ZWwxNigweGFhLCAweGFhLCAweGFhKTsKICAgICAgICAgICAgICAgIGNvbG9yX2xlZCA9IHJnYl90b19waXhlbDE2KDB4MDAsIDB4ZmYsIDB4MDApOwogICAgICAgICAgICBjYXNlIDI0OgogICAgICAgICAgICAgICAgY29sb3Jfc2VnbWVudCA9IHJnYl90b19waXhlbDI0KDB4YWEsIDB4YWEsIDB4YWEpOwogICAgICAgICAgICAgICAgY29sb3JfbGVkID0gcmdiX3RvX3BpeGVsMjQoMHgwMCwgMHhmZiwgMHgwMCk7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgY2FzZSAzMjoKICAgICAgICAgICAgICAgIGNvbG9yX3NlZ21lbnQgPSByZ2JfdG9fcGl4ZWwzMigweGFhLCAweGFhLCAweGFhKTsKICAgICAgICAgICAgICAgIGNvbG9yX2xlZCA9IHJnYl90b19waXhlbDMyKDB4MDAsIDB4ZmYsIDB4MDApOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgfQoKICAgICAgICAvKiBkaXNwbGF5IHNlZ21lbnRzICovCiAgICAgICAgZHJhd19ob3Jpem9udGFsX2xpbmUoZHMsIDQwLCAxMCwgNDAsIChzLT5zZWdtZW50cyAmIDB4MDIpID8gY29sb3Jfc2VnbWVudCA6IDApOwogICAgICAgIGRyYXdfdmVydGljYWxfbGluZShkcywgMTAsIDEwLCA0MCwgKHMtPnNlZ21lbnRzICYgMHgwNCkgPyBjb2xvcl9zZWdtZW50IDogMCk7CiAgICAgICAgZHJhd192ZXJ0aWNhbF9saW5lKGRzLCAxMCwgNDAsIDcwLCAocy0+c2VnbWVudHMgJiAweDA4KSA/IGNvbG9yX3NlZ21lbnQgOiAwKTsKICAgICAgICBkcmF3X2hvcml6b250YWxfbGluZShkcywgNzAsIDEwLCA0MCwgKHMtPnNlZ21lbnRzICYgMHgxMCkgPyBjb2xvcl9zZWdtZW50IDogMCk7CiAgICAgICAgZHJh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