// File: /workspace/github_cpp_makefile_star2_O3/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 $0x68, %rsp
testq %rcx, %rcx
je 0x5725
movq %rcx, %r12
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r13
movq %r14, %r15
andq $-0x800, %r15           # imm = 0xF800
cmpq %r15, 0x228(%r13)
je 0x56fa
movq %r14, 0x30(%rsp)
movq %rbx, 0x38(%rsp)
movq %r15, 0x228(%r13)
movq %r13, %rdi
callq 0x3eac
movl %eax, %eax
movq %rax, 0x18(%rsp)
imulq %rax, %r15
movq 0x208(%r13), %rax
movq 0x218(%r13), %r14
movq %rax, 0x20(%rsp)
addq %rax, %r15
movq %r14, %rbp
subq %r15, %rbp
movq %r13, %rdi
callq 0x3eac
movl %eax, %esi
movq %rbp, %rax
xorl %edx, %edx
divq %rsi
movq %rax, %rcx
movl $0x800, %eax            # imm = 0x800
cmpq %rax, %rcx
movl $0x800, %ebx            # imm = 0x800
movq %rcx, 0x50(%rsp)
cmovbq %rcx, %rbx
cmpq %rsi, %rbp
jae 0x518e
movq 0x230(%r13), %rdi
movq 0x238(%r13), %rdx
cmpq %rdx, %rdi
movq 0x38(%rsp), %rbx
movq 0x30(%rsp), %r14
je 0x56fa
subq %rdi, %rdx
addq $-0x8, %rdx
andq $-0x8, %rdx
addq $0x8, %rdx
xorl %esi, %esi
callq 0x2140
jmp 0x56fa
movq %rsi, %rbp
movq %r12, 0x48(%rsp)
movq %r13, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x22d0
movq %r13, %rdi
callq 0x3eac
movl %eax, %esi
movq %rbx, 0x40(%rsp)
imulq %rbx, %rsi
movq %rsp, %rdi
leaq 0x2f(%rsp), %rdx
callq 0x5ae0
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
subq %rsi, %rdx
movq %r13, %rdi
callq 0x22b0
movl 0x250(%r13), %ecx
cmpq $0x5, %rcx
ja 0x56ab
movq 0x30(%rsp), %rax
shrq $0xb, %rax
leaq 0x14b8(%rip), %rdx      # 0x66b0
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movq (%rsp), %rcx
movq 0x230(%r13), %rsi
imulq 0x18(%rsp), %rax
shlq $0xb, %rax
subq %rax, %r14
subq 0x20(%rsp), %r14
movq %r14, %rax
xorl %edx, %edx
divq %rbp
xorl %edx, %edx
movzbl (%rcx,%rdx), %edi
xorps %xmm0, %xmm0
cvtsi2sd %edi, %xmm0
addsd 0xde5(%rip), %xmm0      # 0x6020
mulsd 0x1465(%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 0x5228
jmp 0x56ab
imulq 0x18(%rsp), %rax
shlq $0xb, %rax
subq %rax, %r14
subq 0x20(%rsp), %r14
movq %r14, %rax
xorl %edx, %edx
divq %rbp
movq %rax, %rbp
xorl %ebx, %ebx
movq %r13, %rdi
callq 0x3eac
movl %eax, %eax
imulq %rbx, %rax
movq (%rsp), %rcx
movzbl (%rcx,%rax), %r14d
movq %r13, %rdi
callq 0x3eac
movl %eax, %eax
imulq %rbx, %rax
movq (%rsp), %rcx
movzbl 0x1(%rcx,%rax), %r15d
movq %r13, %rdi
callq 0x3eac
movl %eax, %eax
imulq %rbx, %rax
movq (%rsp), %rcx
movzbl 0x2(%rcx,%rax), %r12d
movq %r13, %rdi
callq 0x3eac
shll $0x8, %r15d
orl %r14d, %r15d
shll $0x10, %r12d
orl %r15d, %r12d
movl %eax, %eax
imulq %rbx, %rax
movq (%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
jne 0x5288
jmp 0x56ab
imulq 0x18(%rsp), %rax
shlq $0xb, %rax
subq %rax, %r14
subq 0x20(%rsp), %r14
movq %r14, %rax
xorl %edx, %edx
divq %rbp
movq %rax, %rbp
xorl %ebx, %ebx
movq %r13, %rdi
callq 0x3eac
movl %eax, %eax
imulq %rbx, %rax
movq (%rsp), %rcx
movzbl (%rcx,%rax), %r14d
movq %r13, %rdi
callq 0x3eac
movl %eax, %eax
imulq %rbx, %rax
movq (%rsp), %rcx
movzbl 0x1(%rcx,%rax), %r15d
movq %r13, %rdi
callq 0x3eac
movl %eax, %eax
imulq %rbx, %rax
movq (%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 0x12db(%rip), %xmm0     # 0x6698
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
jne 0x5352
jmp 0x56ab
imulq 0x18(%rsp), %rax
shlq $0xb, %rax
subq %rax, %r14
subq 0x20(%rsp), %r14
movq %r14, %rax
xorl %edx, %edx
divq %rbp
movq %rax, %rbp
xorl %ebx, %ebx
movq %r13, %rdi
callq 0x3eac
movl %eax, %eax
imulq %rbx, %rax
movq (%rsp), %rcx
movzbl (%rcx,%rax), %r14d
movq %r13, %rdi
callq 0x3eac
movl %eax, %eax
imulq %rbx, %rax
movq (%rsp), %rcx
movzbl 0x1(%rcx,%rax), %r15d
movq %r13, %rdi
callq 0x3eac
movl %eax, %eax
imulq %rbx, %rax
movq (%rsp), %rcx
movzbl 0x2(%rcx,%rax), %r12d
movq %r13, %rdi
callq 0x3eac
shll $0x8, %r15d
orl %r14d, %r15d
shll $0x10, %r12d
orl %r15d, %r12d
movl %eax, %eax
imulq %rbx, %rax
movq (%rsp), %rcx
movzbl 0x3(%rcx,%rax), %eax
shll $0x18, %eax
orl %r12d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x1202(%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
jne 0x540d
jmp 0x56ab
imulq 0x18(%rsp), %rax
shlq $0xb, %rax
subq %rax, %r14
subq 0x20(%rsp), %r14
movq %r14, %rax
xorl %edx, %edx
divq %rbp
movq %rax, %rbp
xorl %ebx, %ebx
movq %r13, %rdi
callq 0x3eac
movl %eax, %eax
imulq %rbx, %rax
movq (%rsp), %rcx
movzbl (%rcx,%rax), %r14d
movq %r13, %rdi
callq 0x3eac
movl %eax, %eax
imulq %rbx, %rax
movq (%rsp), %rcx
movzbl 0x1(%rcx,%rax), %eax
shll $0x18, %eax
shll $0x10, %r14d
orl %eax, %r14d
sarl $0x10, %r14d
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
mulsd 0x1176(%rip), %xmm0     # 0x66a0
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
jne 0x54de
jmp 0x56ab
imulq 0x18(%rsp), %rax
shlq $0xb, %rax
subq %rax, %r14
subq 0x20(%rsp), %r14
movq %r14, %rax
xorl %edx, %edx
divq %rbp
movq %rax, 0x58(%rsp)
xorl %r14d, %r14d
movq %r13, %rdi
callq 0x3eac
movl %eax, %eax
imulq %r14, %rax
movq (%rsp), %rcx
movzbl (%rcx,%rax), %eax
movq %rax, 0x20(%rsp)
movq %r13, %rdi
callq 0x3eac
movl %eax, %eax
imulq %r14, %rax
movq (%rsp), %rcx
movzbl 0x1(%rcx,%rax), %eax
movq %rax, 0x18(%rsp)
movq %r13, %rdi
callq 0x3eac
movl %eax, %eax
imulq %r14, %rax
movq (%rsp), %rcx
movzbl 0x2(%rcx,%rax), %eax
movq %rax, 0x60(%rsp)
movq %r13, %rdi
callq 0x3eac
movl %eax, %eax
imulq %r14, %rax
movq (%rsp), %rcx
movzbl 0x3(%rcx,%rax), %ebp
movq %r13, %rdi
callq 0x3eac
movl %eax, %eax
imulq %r14, %rax
movq (%rsp), %rcx
movzbl 0x4(%rcx,%rax), %ebx
movq %r13, %rdi
callq 0x3eac
movl %eax, %eax
imulq %r14, %rax
movq (%rsp), %rcx
movzbl 0x5(%rcx,%rax), %r12d
movq %r13, %rdi
callq 0x3eac
movl %eax, %eax
imulq %r14, %rax
movq (%rsp), %rcx
movzbl 0x6(%rcx,%rax), %r15d
movq %r13, %rdi
callq 0x3eac
movq 0x18(%rsp), %rcx
shll $0x8, %ecx
addq 0x20(%rsp), %rcx
movq 0x60(%rsp), %rdx
shll $0x10, %edx
orq %rcx, %rdx
shll $0x18, %ebp
orq %rdx, %rbp
shlq $0x20, %rbx
orq %rbp, %rbx
shlq $0x28, %r12
orq %rbx, %r12
shlq $0x30, %r15
orq %r12, %r15
movl %eax, %eax
imulq %r14, %rax
movq (%rsp), %rcx
movzbl 0x7(%rcx,%rax), %eax
shlq $0x38, %rax
orq %r15, %rax
movq 0x230(%r13), %rcx
movq %rax, (%rcx,%r14,8)
incq %r14
movl $0x800, %eax            # imm = 0x800
movq 0x58(%rsp), %rcx
cmpq %rax, %rcx
cmovbq %rcx, %rax
cmpq $0x1, %rax
adcq $0x0, %rax
cmpq %r14, %rax
jne 0x5579
cmpq $0x7ff, 0x50(%rsp)      # imm = 0x7FF
ja 0x56d5
movq 0x40(%rsp), %rdi
shlq $0x3, %rdi
movl $0x4000, %edx           # imm = 0x4000
subq %rdi, %rdx
addq 0x230(%r13), %rdi
xorl %esi, %esi
callq 0x2140
movq (%rsp), %rdi
testq %rdi, %rdi
movq 0x48(%rsp), %r12
movq 0x38(%rsp), %rbx
movq 0x30(%rsp), %r14
je 0x56fa
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
decq %r12
movl %r14d, %eax
andl $0x7ff, %eax            # imm = 0x7FF
movq 0x230(%r13), %rcx
movsd (%rcx,%rax,8), %xmm0
movsd %xmm0, (%rbx)
addq $0x8, %rbx
incq %r14
testq %r12, %r12
jne 0x50cb
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x573e
jmp 0x573e
jmp 0x573e
jmp 0x573e
jmp 0x573e
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x5757
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
movq %rbx, %rdi
callq 0x23c0