// File: /workspace/github_c_makefile_star2_O3/pipde[P]deos-songlib/lib/wave.c
// Function: readWaveHeader
void
readWaveHeader(WAVE *w,FILE *in)
    {
    w->ID = readByteString(in,4,ALLOCATE);
    //fprintf(stderr,"id is %s\n",w->ID);

    w->ChunkSize = readByteInt(in,4);
    //fprintf(stderr,"chunk size is %ld\n",w->ChunkSize);

    w->Format = readByteString(in,4,ALLOCATE);
    //fprintf(stderr,"format is %s\n",w->Format);

    while (!feof(in))
        {
        if (isID(in,"FMT "))
            {
            skip(in,4);
            break;
            }
        if (isID(in,"fmt "))
            {
            skip(in,4);
            break;
            }
        skip(in,1);
        }
            
    w->Subchunk1Size = readByteInt(in,4);
    //fprintf(stderr,"subchunk 1 size is %ld\n",w->Subchunk1Size);

    w->AudioFormat = readByteInt(in,2);
    //fprintf(stderr,"audio format is %d\n",w->AudioFormat);

    w->NumChannels = readByteInt(in,2);
    //fprintf(stderr,"# channels is %d\n",w->NumChannels);

    if (w->NumChannels == 0) w->NumChannels = 1;

    w->SampleRate = readByteInt(in,4);
    //fprintf(stderr,"sample rate is %d\n",w->SampleRate);

    w->ByteRate = readByteInt(in,4);
    //fprintf(stderr,"byte rate is %d\n",w->ByteRate);

    w->BlockAlign = readByteInt(in,2);
    //fprintf(stderr,"block align is %d\n",w->BlockAlign);

    w->BitsPerSample = readByteInt(in,2);
    //fprintf(stderr,"bits per sample is %d\n",w->BitsPerSample);

    if (w->BitsPerSample == 0) w->BitsPerSample = 16;

    while (!feof(in))
        {
        if (isID(in,"DATA"))
            {
            skip(in,4);
            break;
            }
        if (isID(in,"data"))
            {
            skip(in,4);
            break;
            }
        skip(in,1);
        }

    w->Subchunk2Size = readByteInt(in,4);
    //fprintf(stderr,"subchunk 2 size is %ld\n",w->Subchunk2Size);
            
    /* derived values */

    w->sampleCount = w->Subchunk2Size / (w->BitsPerSample / 8)
        / w->NumChannels;

    //fprintf(stderr,"sample count is %d\n",w->sampleCount);

    w->sampleWidth = w->BitsPerSample / 8;
    w->maxAmp = (int) pow(2,w->BitsPerSample - 1);
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movl $0x5, %edi
callq 0x21af
movq %rax, %r15
movl $0x1, %esi
movl $0x4, %edx
movq %rax, %rdi
movq %r14, %rcx
callq 0x1070
xorl %ebp, %ebp
movb %bpl, 0x4(%r15)
movq %r15, (%rbx)
leaq 0xc(%rsp), %r15
movl $0x0, (%r15)
movl $0x1, %esi
movl $0x4, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x1070
movslq (%r15), %rax
movq %rax, 0x20(%rbx)
movl $0x5, %edi
callq 0x21af
movq %rax, %r15
movl $0x1, %esi
movl $0x4, %edx
movq %rax, %rdi
movq %r14, %rcx
callq 0x1070
movb %bpl, 0x4(%r15)
movq %r15, 0x8(%rbx)
movq %r14, %rdi
callq 0x1110
testl %eax, %eax
jne 0x2657
leaq 0x1021(%rip), %r15      # 0x3621
leaq 0x101f(%rip), %r12      # 0x3626
movq %r14, %rdi
movq %r15, %rsi
callq 0x2839
testl %eax, %eax
jne 0x2645
movq %r14, %rdi
movq %r12, %rsi
callq 0x2839
testl %eax, %eax
jne 0x2645
movl $0x1, %esi
movq %r14, %rdi
movl $0x1, %edx
callq 0x1140
movq %r14, %rdi
callq 0x1110
testl %eax, %eax
je 0x2607
jmp 0x2657
movl $0x4, %esi
movq %r14, %rdi
movl $0x1, %edx
callq 0x1140
leaq 0xc(%rsp), %r15
movl %ebp, (%r15)
movl $0x1, %esi
movl $0x4, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x1070
movslq (%r15), %rax
movq %rax, 0x28(%rbx)
movl %ebp, (%r15)
leaq 0xc(%rsp), %r15
movl $0x1, %esi
movl $0x2, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x1070
movl (%r15), %eax
movl %eax, 0x30(%rbx)
movl %ebp, (%r15)
leaq 0xc(%rsp), %r15
movl $0x1, %esi
movl $0x2, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x1070
movl (%r15), %eax
cmpl $0x1, %eax
adcl %ebp, %eax
movl %eax, 0x34(%rbx)
movl %ebp, (%r15)
leaq 0xc(%rsp), %r15
movl $0x1, %esi
movl $0x4, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x1070
movl (%r15), %eax
movl %eax, 0x38(%rbx)
movl %ebp, (%r15)
leaq 0xc(%rsp), %r15
movl $0x1, %esi
movl $0x4, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x1070
movl (%r15), %eax
movl %eax, 0x3c(%rbx)
movl %ebp, (%r15)
leaq 0xc(%rsp), %r15
movl $0x1, %esi
movl $0x2, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x1070
movl (%r15), %eax
movl %eax, 0x40(%rbx)
movl %ebp, (%r15)
leaq 0xc(%rsp), %r15
movl $0x1, %esi
movl $0x2, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x1070
movl (%r15), %eax
testl %eax, %eax
movl $0x10, %ecx
cmovnel %eax, %ecx
movl %ecx, 0x44(%rbx)
movq %r14, %rdi
callq 0x1110
testl %eax, %eax
jne 0x27c6
leaq 0xebc(%rip), %r15       # 0x362b
leaq 0xb2f(%rip), %r12       # 0x32a5
movq %r14, %rdi
movq %r15, %rsi
callq 0x2839
testl %eax, %eax
jne 0x27b4
movq %r14, %rdi
movq %r12, %rsi
callq 0x2839
testl %eax, %eax
jne 0x27b4
movl $0x1, %esi
movq %r14, %rdi
movl $0x1, %edx
callq 0x1140
movq %r14, %rdi
callq 0x1110
testl %eax, %eax
je 0x2776
jmp 0x27c6
movl $0x4, %esi
movq %r14, %rdi
movl $0x1, %edx
callq 0x1140
leaq 0xc(%rsp), %r15
movl $0x0, (%r15)
movl $0x1, %esi
movl $0x4, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x1070
movslq (%r15), %rax
movq %rax, 0x48(%rbx)
movl 0x44(%rbx), %edi
leal 0x7(%rdi), %ecx
testl %edi, %edi
cmovnsl %edi, %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
cqto
idivq %rcx
movslq 0x34(%rbx), %rsi
cqto
idivq %rsi
movl %eax, 0x78(%rbx)
movl %ecx, 0x7c(%rbx)
decl %edi
movsd 0x7eb(%rip), %xmm0      # 0x3008
callq 0x1040
cvttsd2si %xmm0, %eax
movl %eax, 0x80(%rbx)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq