// File: /workspace/github_cpp_makefile_star2_O2/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
movq %rsi, %rbx
movq %rdi, %r12
movq %rdi, 0x18(%rsp)
subq $0x1, %rcx
jb 0x4f7d
movq %rbx, %r15
andq $-0x800, %r15           # imm = 0xF800
cmpq %r15, 0x228(%r12)
je 0x4f59
movq %rbx, 0x40(%rsp)
movq %rdx, 0x48(%rsp)
movq %rcx, 0x50(%rsp)
movq %r15, 0x228(%r12)
movq %r12, %rdi
callq 0x3c18
movl %eax, %eax
movq %rax, 0x8(%rsp)
imulq %rax, %r15
movq 0x208(%r12), %rax
movq 0x218(%r12), %r14
movq %rax, 0x10(%rsp)
addq %rax, %r15
movq %r14, %r13
subq %r15, %r13
movq %r12, %rdi
callq 0x3c18
movl %eax, %ebx
movq %r13, %rax
xorl %edx, %edx
divq %rbx
movq %rax, %rbp
movl $0x800, %eax            # imm = 0x800
cmpq %rax, %rbp
cmovaeq %rax, %rbp
cmpq %rbx, %r13
jae 0x4a21
movq 0x230(%r12), %rax
movq 0x238(%r12), %rsi
movq 0x50(%rsp), %rcx
movq 0x48(%rsp), %rdx
movq 0x40(%rsp), %rbx
cmpq %rsi, %rax
je 0x4f59
andq $0x0, (%rax)
addq $0x8, %rax
jmp 0x4a0e
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x22b0
movq %r12, %rdi
callq 0x3c18
movl %eax, %esi
movq %rbp, 0x58(%rsp)
imulq %rbp, %rsi
leaq 0x20(%rsp), %rdi
leaq 0x3f(%rsp), %rdx
callq 0x5200
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
subq %rsi, %rdx
movq %r12, %rdi
callq 0x2280
movl 0x250(%r12), %ecx
cmpq $0x5, %rcx
ja 0x4f20
movq 0x40(%rsp), %rax
shrq $0xb, %rax
leaq 0x1c31(%rip), %rdx      # 0x66b8
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movq 0x20(%rsp), %rcx
movq 0x230(%r12), %rsi
imulq 0x8(%rsp), %rax
shlq $0xb, %rax
subq %rax, %r14
subq 0x10(%rsp), %r14
movq %r14, %rax
xorl %edx, %edx
divq %rbx
xorl %edx, %edx
movl $0x800, %edi            # imm = 0x800
cmpq %rdi, %rax
cmovbq %rax, %rdi
cmpq %rdx, %rdi
je 0x4f20
movzbl (%rcx,%rdx), %edi
cvtsi2sd %edi, %xmm0
addsd 0x1542(%rip), %xmm0     # 0x6020
mulsd 0x1bca(%rip), %xmm0     # 0x66b0
movsd %xmm0, (%rsi,%rdx,8)
incq %rdx
jmp 0x4ab9
imulq 0x8(%rsp), %rax
shlq $0xb, %rax
subq %rax, %r14
subq 0x10(%rsp), %r14
movq %r14, %rax
xorl %edx, %edx
divq %rbx
movq %rax, %r13
xorl %ebx, %ebx
movl $0x800, %eax            # imm = 0x800
cmpq %rax, %r13
cmovbq %r13, %rax
cmpq %rbx, %rax
je 0x4f20
movq %r12, %rdi
callq 0x3c18
movl %eax, %eax
imulq %rbx, %rax
movq 0x20(%rsp), %rcx
movzbl (%rcx,%rax), %ebp
movq %r12, %rdi
callq 0x3c18
movl %eax, %eax
imulq %rbx, %rax
movq 0x20(%rsp), %rcx
movzbl 0x1(%rcx,%rax), %r14d
movq %r12, %rdi
callq 0x3c18
movl %eax, %eax
imulq %rbx, %rax
movq 0x20(%rsp), %rcx
movzbl 0x2(%rcx,%rax), %r15d
movq %r12, %rdi
callq 0x3c18
shll $0x8, %r14d
orl %ebp, %r14d
shll $0x10, %r15d
orl %r14d, %r15d
movl %eax, %eax
imulq %rbx, %rax
movq 0x20(%rsp), %rcx
movzbl 0x3(%rcx,%rax), %eax
shll $0x18, %eax
orl %r15d, %eax
movd %eax, %xmm0
cvtss2sd %xmm0, %xmm0
movq 0x230(%r12), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
jmp 0x4b0f
imulq 0x8(%rsp), %rax
shlq $0xb, %rax
subq %rax, %r14
subq 0x10(%rsp), %r14
movq %r14, %rax
xorl %edx, %edx
divq %rbx
movq %rax, %r13
xorl %ebx, %ebx
movl $0x800, %eax            # imm = 0x800
cmpq %rax, %r13
cmovbq %r13, %rax
cmpq %rbx, %rax
je 0x4f20
movq %r12, %rdi
callq 0x3c18
movl %eax, %eax
imulq %rbx, %rax
movq 0x20(%rsp), %rcx
movzbl (%rcx,%rax), %ebp
movq %r12, %rdi
callq 0x3c18
movl %eax, %eax
imulq %rbx, %rax
movq 0x20(%rsp), %rcx
movzbl 0x1(%rcx,%rax), %r14d
movq %r12, %rdi
callq 0x3c18
movl %eax, %eax
imulq %rbx, %rax
movq 0x20(%rsp), %rcx
movzbl 0x2(%rcx,%rax), %eax
shll $0x18, %eax
shll $0x10, %r14d
shll $0x8, %ebp
orl %r14d, %ebp
orl %eax, %ebp
sarl $0x8, %ebp
cvtsi2sd %ebp, %xmm0
mulsd 0x1a50(%rip), %xmm0     # 0x66a0
movq 0x230(%r12), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
jmp 0x4bd5
imulq 0x8(%rsp), %rax
shlq $0xb, %rax
subq %rax, %r14
subq 0x10(%rsp), %r14
movq %r14, %rax
xorl %edx, %edx
divq %rbx
movq %rax, %r13
xorl %ebx, %ebx
movl $0x800, %eax            # imm = 0x800
cmpq %rax, %r13
cmovbq %r13, %rax
cmpq %rbx, %rax
je 0x4f20
movq %r12, %rdi
callq 0x3c18
movl %eax, %eax
imulq %rbx, %rax
movq 0x20(%rsp), %rcx
movzbl (%rcx,%rax), %ebp
movq %r12, %rdi
callq 0x3c18
movl %eax, %eax
imulq %rbx, %rax
movq 0x20(%rsp), %rcx
movzbl 0x1(%rcx,%rax), %r14d
movq %r12, %rdi
callq 0x3c18
movl %eax, %eax
imulq %rbx, %rax
movq 0x20(%rsp), %rcx
movzbl 0x2(%rcx,%rax), %r15d
movq %r12, %rdi
callq 0x3c18
shll $0x8, %r14d
orl %ebp, %r14d
shll $0x10, %r15d
orl %r14d, %r15d
movl %eax, %eax
imulq %rbx, %rax
movq 0x20(%rsp), %rcx
movzbl 0x3(%rcx,%rax), %eax
shll $0x18, %eax
orl %r15d, %eax
cvtsi2sd %eax, %xmm0
mulsd 0x197e(%rip), %xmm0     # 0x6698
movq 0x230(%r12), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
jmp 0x4c84
imulq 0x8(%rsp), %rax
shlq $0xb, %rax
subq %rax, %r14
subq 0x10(%rsp), %r14
movq %r14, %rax
xorl %edx, %edx
divq %rbx
movq %rax, %r13
xorl %ebx, %ebx
movl $0x800, %eax            # imm = 0x800
cmpq %rax, %r13
cmovbq %r13, %rax
cmpq %rbx, %rax
je 0x4f20
movq %r12, %rdi
callq 0x3c18
movl %eax, %eax
imulq %rbx, %rax
movq 0x20(%rsp), %rcx
movzbl (%rcx,%rax), %ebp
movq %r12, %rdi
callq 0x3c18
movl %eax, %eax
imulq %rbx, %rax
movq 0x20(%rsp), %rcx
movzbl 0x1(%rcx,%rax), %eax
shll $0x18, %eax
shll $0x10, %ebp
orl %eax, %ebp
sarl $0x10, %ebp
cvtsi2sd %ebp, %xmm0
mulsd 0x18ff(%rip), %xmm0     # 0x66a8
movq 0x230(%r12), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
jmp 0x4d4e
imulq 0x8(%rsp), %rax
shlq $0xb, %rax
subq %rax, %r14
subq 0x10(%rsp), %r14
movq %r14, %rax
xorl %edx, %edx
divq %rbx
movq %rax, 0x60(%rsp)
xorl %r15d, %r15d
movl $0x800, %eax            # imm = 0x800
movq 0x60(%rsp), %rcx
cmpq %rax, %rcx
cmovbq %rcx, %rax
cmpq %r15, %rax
je 0x4f20
movq %r12, %rdi
callq 0x3c18
movl %eax, %eax
imulq %r15, %rax
movq 0x20(%rsp), %rcx
movzbl (%rcx,%rax), %eax
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rdi
callq 0x3c18
movl %eax, %eax
imulq %r15, %rax
movq 0x20(%rsp), %rcx
movzbl 0x1(%rcx,%rax), %eax
movq %rax, 0x8(%rsp)
movq 0x18(%rsp), %rdi
callq 0x3c18
movl %eax, %eax
imulq %r15, %rax
movq 0x20(%rsp), %rcx
movzbl 0x2(%rcx,%rax), %r13d
movq 0x18(%rsp), %rdi
callq 0x3c18
movl %eax, %eax
imulq %r15, %rax
movq 0x20(%rsp), %rcx
movzbl 0x3(%rcx,%rax), %ebx
movq 0x18(%rsp), %rdi
callq 0x3c18
movl %eax, %eax
imulq %r15, %rax
movq 0x20(%rsp), %rcx
movzbl 0x4(%rcx,%rax), %r12d
movq 0x18(%rsp), %rdi
callq 0x3c18
movl %eax, %eax
imulq %r15, %rax
movq 0x20(%rsp), %rcx
movzbl 0x5(%rcx,%rax), %ebp
movq 0x18(%rsp), %rdi
callq 0x3c18
movl %eax, %eax
imulq %r15, %rax
movq 0x20(%rsp), %rcx
movzbl 0x6(%rcx,%rax), %r14d
movq 0x18(%rsp), %rdi
callq 0x3c18
movq 0x8(%rsp), %rcx
shll $0x8, %ecx
addq 0x10(%rsp), %rcx
shll $0x10, %r13d
orq %rcx, %r13
shll $0x18, %ebx
orq %r13, %rbx
shlq $0x20, %r12
orq %rbx, %r12
shlq $0x28, %rbp
orq %r12, %rbp
shlq $0x30, %r14
orq %rbp, %r14
movl %eax, %eax
imulq %r15, %rax
movq 0x20(%rsp), %rcx
movzbl 0x7(%rcx,%rax), %eax
shlq $0x38, %rax
orq %r14, %rax
movq 0x18(%rsp), %r12
movq 0x230(%r12), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
jmp 0x4ddd
movq 0x230(%r12), %rax
movq 0x40(%rsp), %rbx
movq 0x58(%rsp), %rcx
cmpq $0x800, %rcx            # imm = 0x800
jae 0x4f45
andq $0x0, (%rax,%rcx,8)
incq %rcx
jmp 0x4f32
leaq 0x20(%rsp), %rdi
callq 0x552e
movq 0x50(%rsp), %rcx
movq 0x48(%rsp), %rdx
movl %ebx, %eax
andl $0x7ff, %eax            # imm = 0x7FF
movq 0x230(%r12), %rsi
movsd (%rsi,%rax,8), %xmm0
movsd %xmm0, (%rdx)
addq $0x8, %rdx
incq %rbx
jmp 0x495f
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4f96
jmp 0x4f96
jmp 0x4f96
jmp 0x4f96
jmp 0x4f96
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x552e
movq %rbx, %rdi
callq 0x23a0
nop