// File: /workspace/github_cpp_makefile_star2_O1/ipatix[P]wav2agb/wav_file.cpp
// Function: wav_file::readData(unsigned long, double*, unsigned long)
void wav_file::readData(size_t location, double *data, size_t len)
{
    while (len-- > 0) {
        if (loadedChunk != location - (location % loadChunkSize)) {
            loadedChunk = location - (location % loadChunkSize);

            std::streampos blockpos = this->dataChunkPos + std::streampos(loadedChunk * fmt_size());
            std::streampos endblockpos = this->dataChunkEndPos;
            size_t actualChunkSize = std::min(loadChunkSize, static_cast<size_t>(endblockpos - blockpos) / fmt_size());

            if (actualChunkSize == 0) {
                std::fill(loadBuffer.begin(), loadBuffer.end(), 0.0);
                goto load_sample;
            }

            ifs.seekg(blockpos, ifs.beg);
            std::vector<uint8_t> ld(actualChunkSize * fmt_size());
            ifs.read(reinterpret_cast<char *>(ld.data()), ld.size());

            if (fmt == format_type::u8) {
                for (size_t i = 0; i < actualChunkSize; i++) {
                    loadBuffer[i] = (double(ld[i]) - 128.0) / 128.0;
                }
            } else if (fmt == format_type::s16) {
                for (size_t i = 0; i < actualChunkSize; i++) {
                    int32_t s =
                        (ld[i * fmt_size() + 0] << 0) |
                        (ld[i * fmt_size() + 1] << 8);
                    s <<= 16;
                    s >>= 16;
                    loadBuffer[i] = double(s) / 32768.0;
                }
            } else if (fmt == format_type::s24) {
                for (size_t i = 0; i < actualChunkSize; i++) {
                    int32_t s =
                        (ld[i * fmt_size() + 0] << 0) |
                        (ld[i * fmt_size() + 1] << 8) |
                        (ld[i * fmt_size() + 2] << 16);
                    s <<= 8;
                    s >>= 8;
                    loadBuffer[i] = double(s) / 8388608.0;
                }
            } else if (fmt == format_type::s32) {
                for (size_t i = 0; i < actualChunkSize; i++) {
                    int32_t s =
                        (ld[i * fmt_size() + 0] << 0) |
                        (ld[i * fmt_size() + 1] << 8) |
                        (ld[i * fmt_size() + 2] << 16) |
                        (ld[i * fmt_size() + 3] << 24);
                    loadBuffer[i] = double(s) / 2147483648.0;
                }
            } else if (fmt == format_type::f32) {
                for (size_t i = 0; i < actualChunkSize; i++) {
                    union {
                        uint32_t s;
                        float f;
                    } u;
                    u.s = 
                        (ld[i * fmt_size() + 0] << 0) |
                        (ld[i * fmt_size() + 1] << 8) |
                        (ld[i * fmt_size() + 2] << 16) |
                        (ld[i * fmt_size() + 3] << 24);
                    loadBuffer[i] = u.f;
                }
            } else if (fmt == format_type::f64) {
                for (size_t i = 0; i < actualChunkSize; i++) {
                    union {
                        uint64_t s;
                        double d;
                    } u;
                    u.s = 
                        (uint64_t(ld[i * fmt_size() + 0]) << 0) |
                        (uint64_t(ld[i * fmt_size() + 1]) << 8) |
                        (uint64_t(ld[i * fmt_size() + 2]) << 16) |
                        (uint64_t(ld[i * fmt_size() + 3]) << 24) |
                        (uint64_t(ld[i * fmt_size() + 4]) << 32) |
                        (uint64_t(ld[i * fmt_size() + 5]) << 40) |
                        (uint64_t(ld[i * fmt_size() + 6]) << 48) |
                        (uint64_t(ld[i * fmt_size() + 7]) << 56);
                    loadBuffer[i] = u.d;
                }
            }
            for (size_t i = actualChunkSize; i < loadChunkSize; i++) {
                loadBuffer[i] = 0.0;
            }
        }
load_sample:
        *data++ = loadBuffer[location % loadChunkSize];
        location++;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
testq %rcx, %rcx
je 0x56b9
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %rbp
movq %rbx, %r15
andq $-0x800, %r15           # imm = 0xF800
cmpq %r15, 0x228(%rbp)
je 0x568d
movq %rbx, 0x48(%rsp)
movq %r15, 0x228(%rbp)
movq %rbp, %rdi
callq 0x3e88
movl %eax, %eax
movq %rax, 0x20(%rsp)
imulq %rax, %r15
movq 0x208(%rbp), %rax
movq 0x218(%rbp), %rbx
movq %rax, 0x28(%rsp)
addq %rax, %r15
movq %rbx, 0x30(%rsp)
subq %r15, %rbx
movq %rbp, %rdi
callq 0x3e88
movl %eax, %esi
movq %rbx, %rax
xorl %edx, %edx
divq %rsi
movq %rax, %rcx
movl $0x800, %eax            # imm = 0x800
cmpq %rax, %rcx
movl $0x800, %r13d           # imm = 0x800
movq %rcx, 0x70(%rsp)
cmovbq %rcx, %r13
cmpq %rsi, %rbx
jae 0x5099
movq 0x230(%rbp), %rdi
movq 0x238(%rbp), %rdx
cmpq %rdx, %rdi
movq 0x48(%rsp), %rbx
je 0x568d
subq %rdi, %rdx
addq $-0x8, %rdx
andq $-0x8, %rdx
addq $0x8, %rdx
xorl %esi, %esi
callq 0x2140
jmp 0x568d
movq %rsi, 0x68(%rsp)
movq %r12, 0x58(%rsp)
movq %r14, 0x60(%rsp)
movq %rbp, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x22d0
movq %rbp, %rdi
callq 0x3e88
movl %eax, %esi
movq %r13, 0x50(%rsp)
imulq %r13, %rsi
leaq 0x8(%rsp), %rdi
leaq 0x47(%rsp), %rdx
callq 0x5a76
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
subq %rsi, %rdx
movq %rbp, %rdi
callq 0x22b0
movq %rbp, %r12
movl 0x250(%rbp), %ecx
cmpq $0x5, %rcx
movq 0x68(%rsp), %rdi
ja 0x563a
movq 0x48(%rsp), %r8
shrq $0xb, %r8
leaq 0x159c(%rip), %rsi      # 0x66b0
movslq (%rsi,%rcx,4), %rcx
addq %rsi, %rcx
jmpq *%rcx
cmpq %rdi, %rbx
jb 0x563a
movq 0x8(%rsp), %rcx
movq 0x230(%r12), %rsi
imulq 0x20(%rsp), %r8
shlq $0xb, %r8
movq 0x30(%rsp), %rax
subq %r8, %rax
subq 0x28(%rsp), %rax
xorl %edx, %edx
divq %rdi
xorl %edx, %edx
movzbl (%rcx,%rdx), %edi
xorps %xmm0, %xmm0
cvtsi2sd %edi, %xmm0
addsd 0xecc(%rip), %xmm0      # 0x6030
mulsd 0x153c(%rip), %xmm0     # 0x66a8
movsd %xmm0, (%rsi,%rdx,8)
incq %rdx
movl $0x800, %edi            # imm = 0x800
cmpq %rdi, %rax
cmovbq %rax, %rdi
cmpq $0x1, %rdi
adcq $0x0, %rdi
cmpq %rdx, %rdi
jne 0x5151
jmp 0x563a
cmpq %rdi, %rbx
jb 0x563a
imulq 0x20(%rsp), %r8
shlq $0xb, %r8
movq 0x30(%rsp), %rax
subq %r8, %rax
subq 0x28(%rsp), %rax
xorl %edx, %edx
divq %rdi
movq %rax, %rbp
xorl %ebx, %ebx
movq %r12, %rdi
callq 0x3e88
movq %r12, %r13
movl %eax, %eax
imulq %rbx, %rax
movq 0x8(%rsp), %rcx
movzbl (%rcx,%rax), %r14d
movq %r12, %rdi
callq 0x3e88
movl %eax, %eax
imulq %rbx, %rax
movq 0x8(%rsp), %rcx
movzbl 0x1(%rcx,%rax), %r15d
movq %r13, %rdi
callq 0x3e88
movl %eax, %eax
imulq %rbx, %rax
movq 0x8(%rsp), %rcx
movzbl 0x2(%rcx,%rax), %r12d
movq %r13, %rdi
callq 0x3e88
shll $0x8, %r15d
orl %r14d, %r15d
shll $0x10, %r12d
orl %r15d, %r12d
movl %eax, %eax
imulq %rbx, %rax
movq 0x8(%rsp), %rcx
movzbl 0x3(%rcx,%rax), %eax
shll $0x18, %eax
orl %r12d, %eax
movd %eax, %xmm0
cvtss2sd %xmm0, %xmm0
movq 0x230(%r13), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
movl $0x800, %eax            # imm = 0x800
cmpq %rax, %rbp
cmovbq %rbp, %rax
cmpq $0x1, %rax
adcq $0x0, %rax
cmpq %rbx, %rax
movq %r13, %r12
jne 0x51bc
jmp 0x563a
cmpq %rdi, %rbx
jb 0x563a
imulq 0x20(%rsp), %r8
shlq $0xb, %r8
movq 0x30(%rsp), %rax
subq %r8, %rax
subq 0x28(%rsp), %rax
xorl %edx, %edx
divq %rdi
movq %rax, %rbp
xorl %ebx, %ebx
movq %r12, %rdi
callq 0x3e88
movl %eax, %eax
imulq %rbx, %rax
movq 0x8(%rsp), %rcx
movzbl (%rcx,%rax), %r14d
movq %r12, %rdi
callq 0x3e88
movl %eax, %eax
imulq %rbx, %rax
movq 0x8(%rsp), %rcx
movzbl 0x1(%rcx,%rax), %r15d
movq %r12, %rdi
callq 0x3e88
movl %eax, %eax
imulq %rbx, %rax
movq 0x8(%rsp), %rcx
movzbl 0x2(%rcx,%rax), %eax
shll $0x18, %eax
shll $0x10, %r15d
shll $0x8, %r14d
orl %r15d, %r14d
orl %eax, %r14d
sarl $0x8, %r14d
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
mulsd 0x138f(%rip), %xmm0     # 0x6698
movq 0x230(%r12), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
movl $0x800, %eax            # imm = 0x800
cmpq %rax, %rbp
cmovbq %rbp, %rax
cmpq $0x1, %rax
adcq $0x0, %rax
cmpq %rbx, %rax
jne 0x529b
jmp 0x563a
cmpq %rdi, %rbx
jb 0x563a
imulq 0x20(%rsp), %r8
shlq $0xb, %r8
movq 0x30(%rsp), %rax
subq %r8, %rax
subq 0x28(%rsp), %rax
xorl %edx, %edx
divq %rdi
movq %rax, %rbp
xorl %ebx, %ebx
movq %r12, %rdi
callq 0x3e88
movq %r12, %r13
movl %eax, %eax
imulq %rbx, %rax
movq 0x8(%rsp), %rcx
movzbl (%rcx,%rax), %r14d
movq %r12, %rdi
callq 0x3e88
movl %eax, %eax
imulq %rbx, %rax
movq 0x8(%rsp), %rcx
movzbl 0x1(%rcx,%rax), %r15d
movq %r13, %rdi
callq 0x3e88
movl %eax, %eax
imulq %rbx, %rax
movq 0x8(%rsp), %rcx
movzbl 0x2(%rcx,%rax), %r12d
movq %r13, %rdi
callq 0x3e88
shll $0x8, %r15d
orl %r14d, %r15d
shll $0x10, %r12d
orl %r15d, %r12d
movl %eax, %eax
imulq %rbx, %rax
movq 0x8(%rsp), %rcx
movzbl 0x3(%rcx,%rax), %eax
shll $0x18, %eax
orl %r12d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x12a3(%rip), %xmm0     # 0x6690
movq 0x230(%r13), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
movl $0x800, %eax            # imm = 0x800
cmpq %rax, %rbp
cmovbq %rbp, %rax
cmpq $0x1, %rax
adcq $0x0, %rax
cmpq %rbx, %rax
movq %r13, %r12
jne 0x5365
jmp 0x563a
cmpq %rdi, %rbx
jb 0x563a
imulq 0x20(%rsp), %r8
shlq $0xb, %r8
movq 0x30(%rsp), %rax
subq %r8, %rax
subq 0x28(%rsp), %rax
xorl %edx, %edx
divq %rdi
movq %rax, %r13
xorl %ebx, %ebx
movq %r12, %rdi
callq 0x3e88
movl %eax, %eax
imulq %rbx, %rax
movq 0x8(%rsp), %rcx
movzbl (%rcx,%rax), %ebp
movq %r12, %rdi
callq 0x3e88
movl %eax, %eax
imulq %rbx, %rax
movq 0x8(%rsp), %rcx
movzbl 0x1(%rcx,%rax), %eax
shll $0x18, %eax
shll $0x10, %ebp
orl %eax, %ebp
sarl $0x10, %ebp
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
mulsd 0x120c(%rip), %xmm0     # 0x66a0
movq 0x230(%r12), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
movl $0x800, %eax            # imm = 0x800
cmpq %rax, %r13
cmovbq %r13, %rax
cmpq $0x1, %rax
adcq $0x0, %rax
cmpq %rbx, %rax
jne 0x544b
jmp 0x563a
cmpq %rdi, %rbx
jb 0x563a
imulq 0x20(%rsp), %r8
shlq $0xb, %r8
movq 0x30(%rsp), %rax
subq %r8, %rax
subq 0x28(%rsp), %rax
xorl %edx, %edx
divq %rdi
movq %rax, 0x20(%rsp)
xorl %r15d, %r15d
movq %r12, 0x38(%rsp)
movq %r12, %rdi
callq 0x3e88
movl %eax, %eax
imulq %r15, %rax
movq 0x8(%rsp), %rcx
movzbl (%rcx,%rax), %eax
movq %rax, 0x30(%rsp)
movq 0x38(%rsp), %rdi
callq 0x3e88
movl %eax, %eax
imulq %r15, %rax
movq 0x8(%rsp), %rcx
movzbl 0x1(%rcx,%rax), %eax
movq %rax, 0x28(%rsp)
movq 0x38(%rsp), %rdi
callq 0x3e88
movl %eax, %eax
imulq %r15, %rax
movq 0x8(%rsp), %rcx
movzbl 0x2(%rcx,%rax), %ebp
movq 0x38(%rsp), %rdi
callq 0x3e88
movl %eax, %eax
imulq %r15, %rax
movq 0x8(%rsp), %rcx
movzbl 0x3(%rcx,%rax), %r14d
movq 0x38(%rsp), %rdi
callq 0x3e88
movl %eax, %eax
imulq %r15, %rax
movq 0x8(%rsp), %rcx
movzbl 0x4(%rcx,%rax), %ebx
movq 0x38(%rsp), %rdi
callq 0x3e88
movl %eax, %eax
imulq %r15, %rax
movq 0x8(%rsp), %rcx
movzbl 0x5(%rcx,%rax), %r12d
movq 0x38(%rsp), %rdi
callq 0x3e88
movl %eax, %eax
imulq %r15, %rax
movq 0x8(%rsp), %rcx
movzbl 0x6(%rcx,%rax), %r13d
movq 0x38(%rsp), %rdi
callq 0x3e88
movq 0x28(%rsp), %rcx
shll $0x8, %ecx
addq 0x30(%rsp), %rcx
shll $0x10, %ebp
orq %rcx, %rbp
shll $0x18, %r14d
orq %rbp, %r14
shlq $0x20, %rbx
orq %r14, %rbx
shlq $0x28, %r12
orq %rbx, %r12
shlq $0x30, %r13
orq %r12, %r13
movl %eax, %eax
imulq %r15, %rax
movq 0x8(%rsp), %rcx
movzbl 0x7(%rcx,%rax), %eax
shlq $0x38, %rax
orq %r13, %rax
movq 0x38(%rsp), %r12
movq 0x230(%r12), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
movl $0x800, %eax            # imm = 0x800
movq 0x20(%rsp), %rcx
cmpq %rax, %rcx
cmovbq %rcx, %rax
cmpq $0x1, %rax
adcq $0x0, %rax
cmpq %r15, %rax
jne 0x54f4
cmpq $0x7ff, 0x70(%rsp)      # imm = 0x7FF
movq %r12, %rbp
ja 0x5667
movq 0x50(%rsp), %rdi
shlq $0x3, %rdi
movl $0x4000, %edx           # imm = 0x4000
subq %rdi, %rdx
addq 0x230(%rbp), %rdi
xorl %esi, %esi
callq 0x2140
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
movq 0x60(%rsp), %r14
movq 0x58(%rsp), %r12
movq 0x48(%rsp), %rbx
je 0x568d
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
decq %r14
movl %ebx, %eax
andl $0x7ff, %eax            # imm = 0x7FF
movq 0x230(%rbp), %rcx
movsd (%rcx,%rax,8), %xmm0
movsd %xmm0, (%r12)
addq $0x8, %r12
incq %rbx
testq %r14, %r14
jne 0x4fdd
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x56d2
jmp 0x56d2
jmp 0x56d2
jmp 0x56d2
jmp 0x56d2
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x56ec
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
movq %rbx, %rdi
callq 0x23c0