// File: ipatix[P]wav2agb/wav_file.cpp
// Function: wav_file::wav_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
wav_file::wav_file(const std::string& path) : loadBuffer(loadChunkSize)
{
    ifs.exceptions(std::ios::badbit | std::ios::eofbit);
    ifs.open(path, std::ios::binary);
    if (!ifs.good())
        throw std::runtime_error("failed to open file: " + path + ", reason: " + strerror(errno));
    if (!ifs.is_open())
        throw std::runtime_error("failed to open file: " + path + ", reason: " + strerror(errno));

    ifs.seekg(0, ifs.end);
    std::streampos len = ifs.tellg();
    ifs.seekg(0, ifs.beg);

    std::string chunkId = read_str(ifs, 4);
    if (chunkId != "RIFF")
        throw std::runtime_error("RIFF ID invalid");
    uint32_t mainChunkLen = read_u32(ifs);
    if (mainChunkLen + 8 != len)
        throw std::runtime_error("RIFF chunk len (=" +
                std::to_string(mainChunkLen) +
                ") doesn't match file len (=" +
                std::to_string(len) +
                ")");
    std::string riffType = read_str(ifs, 4);
    if (riffType != "WAVE")
        throw std::runtime_error("WAVE ID invalid");

    bool dataChunkFound = false;
    bool fmtChunkFound = false;
    // search all chunks
    std::streampos curPos;
    while ((curPos = ifs.tellg()) + std::streampos(8) <= len) {
        chunkId = read_str(ifs, 4);
        uint32_t chunkLen = read_u32(ifs);
        if (curPos + std::streampos(8) + std::streampos(chunkLen) > len)
            throw std::runtime_error("ERROR: chunk goes beyond end of file: offset=" + std::to_string(curPos));

        if (chunkId == "fmt ") {
            fmtChunkFound = true;
            std::vector<uint8_t> fmtChunk = read_arr(ifs, chunkLen);
            uint16_t fmtTag = arr_u16(fmtChunk, 0);
            uint16_t numChannels = arr_u16(fmtChunk, 2);
            if (numChannels != 1)
                throw std::runtime_error("ERROR: input file is NOT mono");
            this->sampleRate = arr_u32(fmtChunk, 4);
            uint16_t block_align = arr_u16(fmtChunk, 12);
            uint16_t bits_per_sample = arr_u16(fmtChunk, 14);
            if (fmtTag == 1) {
                // integer
                if (block_align == 1 && bits_per_sample == 8)
                    this->fmt = format_type::u8;
                else if (block_align == 2 && bits_per_sample == 16)
                    this->fmt = format_type::s16;
                else if (block_align == 3 && bits_per_sample == 24)
                    this->fmt = format_type::s24;
                else if (block_align == 4 && bits_per_sample == 32)
                    this->fmt = format_type::s32;
                else
                    throw std::runtime_error("ERROR: unsupported integer format combination");
            } else if (fmtTag == 3) {
                // float
                if (block_align == 4 && bits_per_sample == 32)
                    this->fmt = format_type::f32;
                else if (block_align == 8 && bits_per_sample == 64)
                    this->fmt = format_type::f64;
                else
                    throw std::runtime_error("ERROR: unsupported float format combination");
            } else {
                throw std::runtime_error("ERROR: unsupported format code: " + std::to_string(fmtTag));
            }
        } else if (chunkId == "data") {
            dataChunkFound = true;
            dataChunkPos = ifs.tellg();
            dataChunkEndPos = dataChunkPos + std::streampos(chunkLen);
            ifs.seekg(chunkLen, ifs.cur);
        } else if (chunkId == "smpl") {
            std::vector<uint8_t> smplChunk = read_arr(ifs, chunkLen);
            uint32_t midiUnityNote = arr_u32(smplChunk, 12);
            this->midiKey = static_cast<uint8_t>(std::min(midiUnityNote, 127u));
            uint32_t midiPitchFraction = arr_u32(smplChunk, 16);
            // the values below convert the uint32_t range to 0.0 to 100.0 range
            this->tuning = static_cast<double>(midiPitchFraction) / (4294967296.0 * 100.0);
            uint32_t numLoops = arr_u32(smplChunk, 28);
            if (numLoops > 1)
                throw std::runtime_error("ERROR: too many loops in smpl chunk");
            if (numLoops == 1) {
                uint32_t loopType = arr_u32(smplChunk, 36 + 4);
                if (loopType != 0)
                    throw std::runtime_error("ERROR: loop type not supported: " + std::to_string(loopType));
                this->loopStart = arr_u32(smplChunk, 36 + 8);
                // sampler chunks tell the last sample to be played (so including rather than excluding), thus +1
                this->loopEnd = arr_u32(smplChunk, 36 + 12) + 1;
                this->loopEnabled = true;
            }
        } else {
            //fprintf(stderr, "WARNING: ignoring unknown chunk type: <%s>\n", chunkId.c_str());
            ifs.seekg(chunkLen, ifs.cur);
        }

        /* https://en.wikipedia.org/wiki/Resource_Interchange_File_Format#Explanation
         * If chunk size is odd, skip the pad byte */
        if ((chunkLen % 2) == 1)
            ifs.seekg(1, ifs.cur);
    }

    if (!fmtChunkFound)
        throw std::runtime_error("ERROR: fmt chunk not found");
    if (!dataChunkFound)
        throw std::runtime_error("ERROR: data chunk not found");

    uint32_t numSamples = static_cast<uint32_t>(dataChunkEndPos - dataChunkPos) / fmt_size();
    this->loopEnd = std::min(this->loopEnd, numSamples);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x630, %rsp            # imm = 0x630
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x428(%rbp)
movq %rdi, %rax
movq %rax, -0x430(%rbp)
callq 0x3320
movq -0x428(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
callq 0x9320
jmp 0x6ae2
movq -0x430(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
callq 0x9320
jmp 0x6af7
movq -0x430(%rbp), %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rcx, 0x228(%rax)
addq $0x230, %rax            # imm = 0x230
movq %rax, -0x440(%rbp)
leaq -0x1d(%rbp), %rdi
movq %rdi, -0x438(%rbp)
callq 0x9350
movq -0x440(%rbp), %rdi
movq -0x438(%rbp), %rdx
movl $0x800, %esi            # imm = 0x800
callq 0x9370
jmp 0x6b41
leaq -0x1d(%rbp), %rdi
callq 0x93e0
callq 0x9400
movq %rax, %rcx
movq -0x430(%rbp), %rax
movq %rcx, 0x248(%rax)
movl $0x0, 0x254(%rax)
callq 0x9410
movl %eax, %ecx
movq -0x430(%rbp), %rax
movl %ecx, 0x258(%rax)
movb $0x0, 0x25c(%rax)
movq $0x0, 0x260(%rax)
movb $0x3c, 0x268(%rax)
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x450(%rbp)
movl $0x1, %edi
movl $0x2, %esi
callq 0x9420
movl %eax, -0x444(%rbp)
jmp 0x6bbf
movl -0x444(%rbp), %esi
movq -0x450(%rbp), %rdi
callq 0x30d0
jmp 0x6bd3
movq -0x430(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x4, %edx
callq 0x3270
jmp 0x6bea
movq -0x430(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3490
movb %al, -0x451(%rbp)
jmp 0x6c08
movb -0x451(%rbp), %al
testb $0x1, %al
jne 0x6d5b
jmp 0x6c18
movb $0x1, -0x81(%rbp)
movl $0x10, %edi
callq 0x3160
movq %rax, -0x460(%rbp)
movq -0x10(%rbp), %rdx
leaq 0x5a81(%rip), %rsi      # 0xc6bc
leaq -0x80(%rbp), %rdi
callq 0x9440
jmp 0x6c46
leaq 0x5a85(%rip), %rdx      # 0xc6d2
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x61c0
jmp 0x6c5c
callq 0x3040
movl (%rax), %edi
callq 0x30e0
movq %rax, %rdx
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x61c0
jmp 0x6c7a
movq -0x460(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x3450
jmp 0x6c8c
movq -0x460(%rbp), %rdi
movb $0x0, -0x81(%rbp)
movq 0xa357(%rip), %rsi      # 0x10ff8
movq 0xa320(%rip), %rdx      # 0x10fc8
callq 0x34a0
jmp 0x8104
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x80ef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x1d(%rbp), %rdi
callq 0x93e0
jmp 0x80ef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x80e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x6d3f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x6d36
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x6d2d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x3578
leaq -0x60(%rbp), %rdi
callq 0x3578
leaq -0x80(%rbp), %rdi
callq 0x3578
testb $0x1, -0x81(%rbp)
jne 0x6d4a
jmp 0x6d56
movq -0x460(%rbp), %rdi
callq 0x3210
jmp 0x80e3
movq -0x430(%rbp), %rdi
callq 0x3440
movb %al, -0x461(%rbp)
jmp 0x6d6f
movb -0x461(%rbp), %al
testb $0x1, %al
jne 0x6ea1
jmp 0x6d7f
movb $0x1, -0xe9(%rbp)
movl $0x10, %edi
callq 0x3160
movq %rax, -0x470(%rbp)
movq -0x10(%rbp), %rdx
leaq 0x591a(%rip), %rsi      # 0xc6bc
leaq -0xe8(%rbp), %rdi
callq 0x9440
jmp 0x6db0
leaq 0x591b(%rip), %rdx      # 0xc6d2
leaq -0xc8(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x61c0
jmp 0x6dcc
callq 0x3040
movl (%rax), %edi
callq 0x30e0
movq %rax, %rdx
leaq -0xa8(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x61c0
jmp 0x6df0
movq -0x470(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x3450
jmp 0x6e05
movq -0x470(%rbp), %rdi
movb $0x0, -0xe9(%rbp)
movq 0xa1de(%rip), %rsi      # 0x10ff8
movq 0xa1a7(%rip), %rdx      # 0x10fc8
callq 0x34a0
jmp 0x8104
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x6e85
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x6e79
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x6e6d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x3578
leaq -0xc8(%rbp), %rdi
callq 0x3578
leaq -0xe8(%rbp), %rdi
callq 0x3578
testb $0x1, -0xe9(%rbp)
jne 0x6e90
jmp 0x6e9c
movq -0x470(%rbp), %rdi
callq 0x3210
jmp 0x80e3
movq -0x430(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x3390
jmp 0x6eb8
movq -0x430(%rbp), %rdi
callq 0x34c0
movq %rdx, -0x480(%rbp)
movq %rax, -0x478(%rbp)
jmp 0x6ed4
movq -0x430(%rbp), %rdi
movq -0x480(%rbp), %rax
movq -0x478(%rbp), %rcx
movq %rcx, -0x100(%rbp)
movq %rax, -0xf8(%rbp)
xorl %edx, %edx
movl %edx, %esi
callq 0x3390
jmp 0x6f02
movq -0x430(%rbp), %rsi
leaq -0x120(%rbp), %rdi
movl $0x4, %edx
callq 0x8110
jmp 0x6f1c
leaq 0x57ba(%rip), %rsi      # 0xc6dd
leaq -0x120(%rbp), %rdi
callq 0x9550
movb %al, -0x481(%rbp)
jmp 0x6f37
movb -0x481(%rbp), %al
testb $0x1, %al
jne 0x6f43
jmp 0x6fb5
movl $0x10, %edi
callq 0x3160
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x490(%rbp)
leaq 0x5781(%rip), %rsi      # 0xc6e2
callq 0x3110
jmp 0x6f68
movq -0x490(%rbp), %rdi
movq 0xa082(%rip), %rsi      # 0x10ff8
movq 0xa04b(%rip), %rdx      # 0x10fc8
callq 0x34a0
jmp 0x8104
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x80d7
movq -0x490(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x3210
jmp 0x80d7
movq -0x430(%rbp), %rdi
callq 0x8260
movl %eax, -0x494(%rbp)
jmp 0x6fc9
movl -0x494(%rbp), %eax
movl %eax, -0x124(%rbp)
movl -0x124(%rbp), %eax
addl $0x8, %eax
movq %rax, -0x4a8(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x9580
movq %rax, -0x4a0(%rbp)
jmp 0x6ffa
movq -0x4a8(%rbp), %rax
movq -0x4a0(%rbp), %rcx
cmpq %rcx, %rax
je 0x71dc
movb $0x1, -0x1e9(%rbp)
movl $0x10, %edi
callq 0x3160
movq %rax, -0x4b0(%rbp)
movl -0x124(%rbp), %esi
leaq -0x1c8(%rbp), %rdi
callq 0x96c0
jmp 0x703d
leaq 0x56ae(%rip), %rsi      # 0xc6f2
leaq -0x1a8(%rbp), %rdi
leaq -0x1c8(%rbp), %rdx
callq 0x9670
jmp 0x7059
leaq 0x56a4(%rip), %rdx      # 0xc704
leaq -0x188(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
callq 0x61c0
jmp 0x7075
leaq -0x100(%rbp), %rdi
callq 0x9580
movq %rax, -0x4b8(%rbp)
jmp 0x708a
movq -0x4b8(%rbp), %rsi
leaq -0x1e8(%rbp), %rdi
callq 0x97a0
jmp 0x709f
leaq -0x168(%rbp), %rdi
leaq -0x188(%rbp), %rsi
leaq -0x1e8(%rbp), %rdx
callq 0x95a0
jmp 0x70bb
leaq 0x5583(%rip), %rdx      # 0xc645
leaq -0x148(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x61c0
jmp 0x70d7
movq -0x4b0(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x3450
jmp 0x70ec
movq -0x4b0(%rbp), %rdi
movb $0x0, -0x1e9(%rbp)
movq 0x9ef7(%rip), %rsi      # 0x10ff8
movq 0x9ec0(%rip), %rdx      # 0x10fc8
callq 0x34a0
jmp 0x8104
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x71c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x71b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x71a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x719c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x7190
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x7184
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x3578
leaq -0x168(%rbp), %rdi
callq 0x3578
leaq -0x1e8(%rbp), %rdi
callq 0x3578
leaq -0x188(%rbp), %rdi
callq 0x3578
leaq -0x1a8(%rbp), %rdi
callq 0x3578
leaq -0x1c8(%rbp), %rdi
callq 0x3578
testb $0x1, -0x1e9(%rbp)
jne 0x71cb
jmp 0x71d7
movq -0x4b0(%rbp), %rdi
callq 0x3210
jmp 0x80d7
movq -0x430(%rbp), %rsi
leaq -0x210(%rbp), %rdi
movl $0x4, %edx
callq 0x8110
jmp 0x71f6
leaq 0x5523(%rip), %rsi      # 0xc720
leaq -0x210(%rbp), %rdi
callq 0x9550
movb %al, -0x4b9(%rbp)
jmp 0x7211
movb -0x4b9(%rbp), %al
testb $0x1, %al
jne 0x721d
jmp 0x728f
movl $0x10, %edi
callq 0x3160
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x4c8(%rbp)
leaq 0x54ea(%rip), %rsi      # 0xc725
callq 0x3110
jmp 0x7242
movq -0x4c8(%rbp), %rdi
movq 0x9da8(%rip), %rsi      # 0x10ff8
movq 0x9d71(%rip), %rdx      # 0x10fc8
callq 0x34a0
jmp 0x8104
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x80cb
movq -0x4c8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x3210
jmp 0x80cb
movb $0x0, -0x211(%rbp)
movb $0x0, -0x212(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x9320
jmp 0x72ab
jmp 0x72ad
movq -0x430(%rbp), %rdi
callq 0x34c0
movq %rdx, -0x4d8(%rbp)
movq %rax, -0x4d0(%rbp)
jmp 0x72c9
movq -0x4d8(%rbp), %rax
movq -0x4d0(%rbp), %rcx
movq %rcx, -0x250(%rbp)
movq %rax, -0x248(%rbp)
movups -0x250(%rbp), %xmm0
movaps %xmm0, -0x230(%rbp)
leaq -0x260(%rbp), %rdi
movl $0x8, %esi
callq 0x9910
jmp 0x7306
leaq -0x260(%rbp), %rdi
callq 0x9580
movq %rax, -0x4e0(%rbp)
jmp 0x731b
movq -0x4e0(%rbp), %rsi
leaq -0x230(%rbp), %rdi
callq 0x98d0
movq %rdx, -0x4f0(%rbp)
movq %rax, -0x4e8(%rbp)
jmp 0x733e
movq -0x4f0(%rbp), %rax
movq -0x4e8(%rbp), %rcx
movq %rcx, -0x240(%rbp)
movq %rax, -0x238(%rbp)
leaq -0x240(%rbp), %rdi
callq 0x9580
movq %rax, -0x4f8(%rbp)
jmp 0x736f
leaq -0x100(%rbp), %rdi
callq 0x9580
movq %rax, -0x500(%rbp)
jmp 0x7384
movq -0x4f8(%rbp), %rax
movq -0x500(%rbp), %rcx
cmpq %rcx, %rax
jg 0x7f40
movq -0x430(%rbp), %rsi
leaq -0x280(%rbp), %rdi
movl $0x4, %edx
callq 0x8110
jmp 0x73b5
leaq -0x120(%rbp), %rdi
leaq -0x280(%rbp), %rsi
movq %rsi, -0x510(%rbp)
callq 0x3350
movq -0x510(%rbp), %rdi
callq 0x3578
movq -0x430(%rbp), %rdi
callq 0x8260
movl %eax, -0x504(%rbp)
jmp 0x73ef
movl -0x504(%rbp), %eax
movl %eax, -0x284(%rbp)
leaq -0x2b8(%rbp), %rdi
movl $0x8, %esi
callq 0x9910
jmp 0x740e
leaq -0x2b8(%rbp), %rdi
callq 0x9580
movq %rax, -0x518(%rbp)
jmp 0x7423
movq -0x518(%rbp), %rsi
leaq -0x230(%rbp), %rdi
callq 0x98d0
movq %rdx, -0x528(%rbp)
movq %rax, -0x520(%rbp)
jmp 0x7446
movq -0x528(%rbp), %rax
movq -0x520(%rbp), %rcx
movq %rcx, -0x2a8(%rbp)
movq %rax, -0x2a0(%rbp)
movl -0x284(%rbp), %eax
movl %eax, %esi
leaq -0x2c8(%rbp), %rdi
callq 0x9910
jmp 0x7478
leaq -0x2c8(%rbp), %rdi
callq 0x9580
movq %rax, -0x530(%rbp)
jmp 0x748d
movq -0x530(%rbp), %rsi
leaq -0x2a8(%rbp), %rdi
callq 0x98d0
movq %rdx, -0x540(%rbp)
movq %rax, -0x538(%rbp)
jmp 0x74b0
movq -0x540(%rbp), %rax
movq -0x538(%rbp), %rcx
movq %rcx, -0x298(%rbp)
movq %rax, -0x290(%rbp)
leaq -0x298(%rbp), %rdi
callq 0x9580
movq %rax, -0x548(%rbp)
jmp 0x74e1
leaq -0x100(%rbp), %rdi
callq 0x9580
movq %rax, -0x550(%rbp)
jmp 0x74f6
movq -0x548(%rbp), %rax
movq -0x550(%rbp), %rcx
cmpq %rcx, %rax
jle 0x7602
movb $0x1, -0x309(%rbp)
movl $0x10, %edi
callq 0x3160
movq %rax, -0x560(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x9580
movq %rax, -0x558(%rbp)
jmp 0x753a
movq -0x558(%rbp), %rsi
leaq -0x308(%rbp), %rdi
callq 0x97a0
jmp 0x754f
leaq 0x51df(%rip), %rsi      # 0xc735
leaq -0x2e8(%rbp), %rdi
leaq -0x308(%rbp), %rdx
callq 0x9670
jmp 0x756b
movq -0x560(%rbp), %rdi
leaq -0x2e8(%rbp), %rsi
callq 0x3450
jmp 0x7580
movq -0x560(%rbp), %rdi
movb $0x0, -0x309(%rbp)
movq 0x9a63(%rip), %rsi      # 0x10ff8
movq 0x9a2c(%rip), %rdx      # 0x10fc8
callq 0x34a0
jmp 0x8104
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x75e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x75da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x2e8(%rbp), %rdi
callq 0x3578
leaq -0x308(%rbp), %rdi
callq 0x3578
testb $0x1, -0x309(%rbp)
jne 0x75f1
jmp 0x75fd
movq -0x560(%rbp), %rdi
callq 0x3210
jmp 0x80cb
leaq 0x515a(%rip), %rsi      # 0xc763
leaq -0x120(%rbp), %rdi
callq 0x60d0
movb %al, -0x561(%rbp)
jmp 0x761d
movb -0x561(%rbp), %al
testb $0x1, %al
jne 0x762c
jmp 0x7a9c
movq -0x430(%rbp), %rsi
movb $0x1, -0x212(%rbp)
movl -0x284(%rbp), %eax
movl %eax, %edx
leaq -0x328(%rbp), %rdi
callq 0x82b0
jmp 0x7650
xorl %eax, %eax
movl %eax, %esi
leaq -0x328(%rbp), %rdi
callq 0x8390
movw %ax, -0x564(%rbp)
jmp 0x7669
movw -0x564(%rbp), %ax
movw %ax, -0x32a(%rbp)
leaq -0x328(%rbp), %rdi
movl $0x2, %esi
callq 0x8390
movw %ax, -0x566(%rbp)
jmp 0x7691
movw -0x566(%rbp), %ax
movw %ax, -0x32c(%rbp)
movzwl -0x32c(%rbp), %eax
cmpl $0x1, %eax
je 0x771d
movl $0x10, %edi
callq 0x3160
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x570(%rbp)
leaq 0x509f(%rip), %rsi      # 0xc768
callq 0x3110
jmp 0x76d0
movq -0x570(%rbp), %rdi
movq 0x991a(%rip), %rsi      # 0x10ff8
movq 0x98e3(%rip), %rdx      # 0x10fc8
callq 0x34a0
jmp 0x8104
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x7a8b
movq -0x570(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x3210
jmp 0x7a8b
leaq -0x328(%rbp), %rdi
movl $0x4, %esi
callq 0x83e0
movl %eax, -0x574(%rbp)
jmp 0x7736
movq -0x430(%rbp), %rax
movl -0x574(%rbp), %ecx
movl %ecx, 0x26c(%rax)
leaq -0x328(%rbp), %rdi
movl $0xc, %esi
callq 0x8390
movw %ax, -0x576(%rbp)
jmp 0x7763
movw -0x576(%rbp), %ax
movw %ax, -0x32e(%rbp)
leaq -0x328(%rbp), %rdi
movl $0xe, %esi
callq 0x8390
movw %ax, -0x578(%rbp)
jmp 0x778b
movw -0x578(%rbp), %ax
movw %ax, -0x330(%rbp)
movzwl -0x32a(%rbp), %eax
cmpl $0x1, %eax
jne 0x78ca
movzwl -0x32e(%rbp), %eax
cmpl $0x1, %eax
jne 0x77d7
movzwl -0x330(%rbp), %eax
cmpl $0x8, %eax
jne 0x77d7
movq -0x430(%rbp), %rax
movl $0x0, 0x250(%rax)
jmp 0x78c5
movzwl -0x32e(%rbp), %eax
cmpl $0x2, %eax
jne 0x7805
movzwl -0x330(%rbp), %eax
cmpl $0x10, %eax
jne 0x7805
movq -0x430(%rbp), %rax
movl $0x1, 0x250(%rax)
jmp 0x78c3
movzwl -0x32e(%rbp), %eax
cmpl $0x3, %eax
jne 0x7833
movzwl -0x330(%rbp), %eax
cmpl $0x18, %eax
jne 0x7833
movq -0x430(%rbp), %rax
movl $0x2, 0x250(%rax)
jmp 0x78c1
movzwl -0x32e(%rbp), %eax
cmpl $0x4, %eax
jne 0x785e
movzwl -0x330(%rbp), %eax
cmpl $0x20, %eax
jne 0x785e
movq -0x430(%rbp), %rax
movl $0x3, 0x250(%rax)
jmp 0x78bf
movl $0x10, %edi
callq 0x3160
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x580(%rbp)
leaq 0x4f0a(%rip), %rsi      # 0xc786
callq 0x3110
jmp 0x7883
movq -0x580(%rbp), %rdi
movq 0x9767(%rip), %rsi      # 0x10ff8
movq 0x9730(%rip), %rdx      # 0x10fc8
callq 0x34a0
jmp 0x8104
movq -0x580(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x3210
jmp 0x7a8b
jmp 0x78c1
jmp 0x78c3
jmp 0x78c5
jmp 0x7a7a
movzwl -0x32a(%rbp), %eax
cmpl $0x3, %eax
jne 0x799b
movzwl -0x32e(%rbp), %eax
cmpl $0x4, %eax
jne 0x7908
movzwl -0x330(%rbp), %eax
cmpl $0x20, %eax
jne 0x7908
movq -0x430(%rbp), %rax
movl $0x4, 0x250(%rax)
jmp 0x7996
movzwl -0x32e(%rbp), %eax
cmpl $0x8, %eax
jne 0x7933
movzwl -0x330(%rbp), %eax
cmpl $0x40, %eax
jne 0x7933
movq -0x430(%rbp), %rax
movl $0x5, 0x250(%rax)
jmp 0x7994
movl $0x10, %edi
callq 0x3160
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x588(%rbp)
leaq 0x4e63(%rip), %rsi      # 0xc7b4
callq 0x3110
jmp 0x7958
movq -0x588(%rbp), %rdi
movq 0x9692(%rip), %rsi      # 0x10ff8
movq 0x965b(%rip), %rdx      # 0x10fc8
callq 0x34a0
jmp 0x8104
movq -0x588(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x3210
jmp 0x7a8b
jmp 0x7996
jmp 0x7a78
movb $0x1, -0x371(%rbp)
movl $0x10, %edi
callq 0x3160
movq %rax, -0x590(%rbp)
movzwl -0x32a(%rbp), %esi
leaq -0x370(%rbp), %rdi
callq 0x9950
jmp 0x79c8
leaq 0x4e11(%rip), %rsi      # 0xc7e0
leaq -0x350(%rbp), %rdi
leaq -0x370(%rbp), %rdx
callq 0x9670
jmp 0x79e4
movq -0x590(%rbp), %rdi
leaq -0x350(%rbp), %rsi
callq 0x3450
jmp 0x79f9
movq -0x590(%rbp), %rdi
movb $0x0, -0x371(%rbp)
movq 0x95ea(%rip), %rsi      # 0x10ff8
movq 0x95b3(%rip), %rdx      # 0x10fc8
callq 0x34a0
jmp 0x8104
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x7a5f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x7a53
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x350(%rbp), %rdi
callq 0x3578
leaq -0x370(%rbp), %rdi
callq 0x3578
testb $0x1, -0x371(%rbp)
jne 0x7a6a
jmp 0x7a76
movq -0x590(%rbp), %rdi
callq 0x3210
jmp 0x7a8b
jmp 0x7a7a
leaq -0x328(%rbp), %rdi
callq 0x9a70
jmp 0x7f13
leaq -0x328(%rbp), %rdi
callq 0x9a70
jmp 0x80cb
leaq 0x4d5e(%rip), %rsi      # 0xc801
leaq -0x120(%rbp), %rdi
callq 0x60d0
movb %al, -0x591(%rbp)
jmp 0x7ab7
movb -0x591(%rbp), %al
testb $0x1, %al
jne 0x7ac6
jmp 0x7bc3
movq -0x430(%rbp), %rdi
movb $0x1, -0x211(%rbp)
callq 0x34c0
movq %rdx, -0x5a8(%rbp)
movq %rax, -0x5a0(%rbp)
jmp 0x7ae9
movq -0x430(%rbp), %rax
movq -0x5a8(%rbp), %rcx
movq -0x5a0(%rbp), %rdx
movq %rdx, -0x388(%rbp)
movq %rcx, -0x380(%rbp)
movq %rax, %rcx
addq $0x208, %rcx            # imm = 0x208
movq %rcx, -0x5b0(%rbp)
movups -0x388(%rbp), %xmm0
movups %xmm0, 0x208(%rax)
movl -0x284(%rbp), %eax
movl %eax, %esi
leaq -0x3a8(%rbp), %rdi
callq 0x9910
jmp 0x7b41
leaq -0x3a8(%rbp), %rdi
callq 0x9580
movq %rax, -0x5b8(%rbp)
jmp 0x7b56
movq -0x5b8(%rbp), %rsi
movq -0x5b0(%rbp), %rdi
callq 0x98d0
movq %rdx, -0x5c8(%rbp)
movq %rax, -0x5c0(%rbp)
jmp 0x7b79
movq -0x430(%rbp), %rdi
movq -0x5c8(%rbp), %rax
movq -0x5c0(%rbp), %rcx
movq %rcx, -0x398(%rbp)
movq %rax, -0x390(%rbp)
movups -0x398(%rbp), %xmm0
movups %xmm0, 0x218(%rdi)
movl -0x284(%rbp), %eax
movl %eax, %esi
movl $0x1, %edx
callq 0x3390
jmp 0x7bbe
jmp 0x7f11
leaq 0x4c3c(%rip), %rsi      # 0xc806
leaq -0x120(%rbp), %rdi
callq 0x60d0
movb %al, -0x5c9(%rbp)
jmp 0x7bde
movb -0x5c9(%rbp), %al
testb $0x1, %al
jne 0x7bed
jmp 0x7ef2
movq -0x430(%rbp), %rsi
movl -0x284(%rbp), %eax
movl %eax, %edx
leaq -0x3c0(%rbp), %rdi
callq 0x82b0
jmp 0x7c0a
leaq -0x3c0(%rbp), %rdi
movl $0xc, %esi
callq 0x83e0
movl %eax, -0x5d0(%rbp)
jmp 0x7c23
movl -0x5d0(%rbp), %eax
movl %eax, -0x3c4(%rbp)
movl $0x7f, -0x3c8(%rbp)
leaq -0x3c4(%rbp), %rdi
leaq -0x3c8(%rbp), %rsi
callq 0x4610
movq %rax, -0x5d8(%rbp)
jmp 0x7c55
movq -0x430(%rbp), %rax
movq -0x5d8(%rbp), %rcx
movb (%rcx), %cl
movb %cl, 0x268(%rax)
leaq -0x3c0(%rbp), %rdi
movl $0x10, %esi
callq 0x83e0
movl %eax, -0x5dc(%rbp)
jmp 0x7c84
movq -0x430(%rbp), %rax
movl -0x5dc(%rbp), %ecx
movl %ecx, -0x3cc(%rbp)
movl -0x3cc(%rbp), %ecx
cvtsi2sd %rcx, %xmm0
movsd 0x49ce(%rip), %xmm1     # 0xc678
divsd %xmm1, %xmm0
movsd %xmm0, 0x260(%rax)
leaq -0x3c0(%rbp), %rdi
movl $0x1c, %esi
callq 0x83e0
movl %eax, -0x5e0(%rbp)
jmp 0x7ccf
movl -0x5e0(%rbp), %eax
movl %eax, -0x3d0(%rbp)
cmpl $0x1, -0x3d0(%rbp)
jbe 0x7d56
movl $0x10, %edi
callq 0x3160
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x5e8(%rbp)
leaq 0x4b09(%rip), %rsi      # 0xc80b
callq 0x3110
jmp 0x7d09
movq -0x5e8(%rbp), %rdi
movq 0x92e1(%rip), %rsi      # 0x10ff8
movq 0x92aa(%rip), %rdx      # 0x10fc8
callq 0x34a0
jmp 0x8104
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x7ee1
movq -0x5e8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x3210
jmp 0x7ee1
cmpl $0x1, -0x3d0(%rbp)
jne 0x7ed3
leaq -0x3c0(%rbp), %rdi
movl $0x28, %esi
callq 0x83e0
movl %eax, -0x5ec(%rbp)
jmp 0x7d7c
movl -0x5ec(%rbp), %eax
movl %eax, -0x3d4(%rbp)
cmpl $0x0, -0x3d4(%rbp)
je 0x7e71
movb $0x1, -0x419(%rbp)
movl $0x10, %edi
callq 0x3160
movq %rax, -0x5f8(%rbp)
movl -0x3d4(%rbp), %esi
leaq -0x418(%rbp), %rdi
callq 0x96c0
jmp 0x7dc1
leaq 0x4a67(%rip), %rsi      # 0xc82f
leaq -0x3f8(%rbp), %rdi
leaq -0x418(%rbp), %rdx
callq 0x9670
jmp 0x7ddd
movq -0x5f8(%rbp), %rdi
leaq -0x3f8(%rbp), %rsi
callq 0x3450
jmp 0x7df2
movq -0x5f8(%rbp), %rdi
movb $0x0, -0x419(%rbp)
movq 0x91f1(%rip), %rsi      # 0x10ff8
movq 0x91ba(%rip), %rdx      # 0x10fc8
callq 0x34a0
jmp 0x8104
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x7e58
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x7e4c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x3f8(%rbp), %rdi
callq 0x3578
leaq -0x418(%rbp), %rdi
callq 0x3578
testb $0x1, -0x419(%rbp)
jne 0x7e63
jmp 0x7e6f
movq -0x5f8(%rbp), %rdi
callq 0x3210
jmp 0x7ee1
leaq -0x3c0(%rbp), %rdi
movl $0x2c, %esi
callq 0x83e0
movl %eax, -0x5fc(%rbp)
jmp 0x7e8a
movq -0x430(%rbp), %rax
movl -0x5fc(%rbp), %ecx
movl %ecx, 0x254(%rax)
leaq -0x3c0(%rbp), %rdi
movl $0x30, %esi
callq 0x83e0
movl %eax, -0x600(%rbp)
jmp 0x7eb6
movq -0x430(%rbp), %rax
movl -0x600(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, 0x258(%rax)
movb $0x1, 0x25c(%rax)
leaq -0x3c0(%rbp), %rdi
callq 0x9a70
jmp 0x7f0f
leaq -0x3c0(%rbp), %rdi
callq 0x9a70
jmp 0x80cb
movq -0x430(%rbp), %rdi
movl -0x284(%rbp), %eax
movl %eax, %esi
movl $0x1, %edx
callq 0x3390
jmp 0x7f0d
jmp 0x7f0f
jmp 0x7f11
jmp 0x7f13
movl -0x284(%rbp), %eax
andl $0x1, %eax
cmpl $0x1, %eax
jne 0x7f3b
movq -0x430(%rbp), %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x3390
jmp 0x7f39
jmp 0x7f3b
jmp 0x72ad
testb $0x1, -0x212(%rbp)
jne 0x7faa
movl $0x10, %edi
callq 0x3160
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x608(%rbp)
leaq 0x48e9(%rip), %rsi      # 0xc850
callq 0x3110
jmp 0x7f6e
movq -0x608(%rbp), %rdi
movq 0x907c(%rip), %rsi      # 0x10ff8
movq 0x9045(%rip), %rdx      # 0x10fc8
callq 0x34a0
jmp 0x8104
movq -0x608(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x3210
jmp 0x80cb
testb $0x1, -0x211(%rbp)
jne 0x8014
movl $0x10, %edi
callq 0x3160
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x610(%rbp)
leaq 0x489a(%rip), %rsi      # 0xc86b
callq 0x3110
jmp 0x7fd8
movq -0x610(%rbp), %rdi
movq 0x9012(%rip), %rsi      # 0x10ff8
movq 0x8fdb(%rip), %rdx      # 0x10fc8
callq 0x34a0
jmp 0x8104
movq -0x610(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x3210
jmp 0x80cb
movq -0x430(%rbp), %rsi
movq %rsi, %rdi
addq $0x218, %rdi            # imm = 0x218
addq $0x208, %rsi            # imm = 0x208
callq 0x9ad0
movq %rax, -0x618(%rbp)
jmp 0x803a
movq -0x430(%rbp), %rdi
movq -0x618(%rbp), %rax
movl %eax, -0x620(%rbp)
callq 0x69a0
movl %eax, -0x61c(%rbp)
jmp 0x805b
movq -0x430(%rbp), %rdi
movl -0x61c(%rbp), %ecx
movl -0x620(%rbp), %eax
xorl %edx, %edx
divl %ecx
movl %eax, -0x420(%rbp)
addq $0x258, %rdi            # imm = 0x258
leaq -0x420(%rbp), %rsi
callq 0x4610
movq %rax, -0x628(%rbp)
jmp 0x8094
movq -0x430(%rbp), %rax
movq -0x628(%rbp), %rcx
movl (%rcx), %ecx
movl %ecx, 0x258(%rax)
leaq -0x210(%rbp), %rdi
callq 0x3578
leaq -0x120(%rbp), %rdi
callq 0x3578
addq $0x630, %rsp            # imm = 0x630
popq %rbp
retq
leaq -0x210(%rbp), %rdi
callq 0x3578
leaq -0x120(%rbp), %rdi
callq 0x3578
movq -0x440(%rbp), %rdi
callq 0x9af0
movq -0x428(%rbp), %rdi
callq 0x30a0
movq -0x18(%rbp), %rdi
callq 0x34e0
nopw %cs:(%rax,%rax)