// File: /workspace/github_c_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x202f
movq %rax, (%rbx)
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x2062
cltq
movq %rax, 0x20(%rbx)
movq %r14, %rdi
callq 0x202f
movq %rax, 0x8(%rbx)
leaq 0x1768(%rip), %r15      # 0x3621
leaq 0x1766(%rip), %r12      # 0x3626
pushq $0x1
popq %r13
movq %r14, %rdi
callq 0x1100
testl %eax, %eax
jne 0x1f06
movq %r14, %rdi
movq %r15, %rsi
callq 0x2088
testl %eax, %eax
jne 0x1efb
movq %r14, %rdi
movq %r12, %rsi
callq 0x2088
testl %eax, %eax
jne 0x1efb
movq %r14, %rdi
movq %r13, %rsi
callq 0x20fb
jmp 0x1ec4
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x20fb
pushq $0x4
popq %r15
movq %r14, %rdi
movl %r15d, %esi
callq 0x2062
cltq
movq %rax, 0x28(%rbx)
pushq $0x2
popq %rbp
movq %r14, %rdi
movl %ebp, %esi
callq 0x2062
movl %eax, 0x30(%rbx)
movq %r14, %rdi
movl %ebp, %esi
callq 0x2062
cmpl $0x1, %eax
adcl $0x0, %eax
movl %eax, 0x34(%rbx)
movq %r14, %rdi
movl %r15d, %esi
callq 0x2062
movl %eax, 0x38(%rbx)
movq %r14, %rdi
movl %r15d, %esi
callq 0x2062
movl %eax, 0x3c(%rbx)
movq %r14, %rdi
movl %ebp, %esi
callq 0x2062
movl %eax, 0x40(%rbx)
movq %r14, %rdi
movl %ebp, %esi
callq 0x2062
testl %eax, %eax
pushq $0x10
popq %rcx
cmovnel %eax, %ecx
movl %ecx, 0x44(%rbx)
leaq 0x16a8(%rip), %r15      # 0x362b
leaq 0x131b(%rip), %r12      # 0x32a5
pushq $0x1
popq %r13
movq %r14, %rdi
callq 0x1100
testl %eax, %eax
jne 0x1fd0
movq %r14, %rdi
movq %r15, %rsi
callq 0x2088
testl %eax, %eax
jne 0x1fc5
movq %r14, %rdi
movq %r12, %rsi
callq 0x2088
testl %eax, %eax
jne 0x1fc5
movq %r14, %rdi
movq %r13, %rsi
callq 0x20fb
jmp 0x1f8e
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x20fb
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x2062
movslq %eax, %rcx
movq %rcx, 0x48(%rbx)
movl 0x44(%rbx), %edi
pushq $0x8
popq %rsi
movl %edi, %eax
cltd
idivl %esi
movslq %eax, %rsi
movq %rcx, %rax
cqto
idivq %rsi
movslq 0x34(%rbx), %rcx
cqto
idivq %rcx
movl %eax, 0x78(%rbx)
movl %esi, 0x7c(%rbx)
decl %edi
movsd 0xff7(%rip), %xmm0      # 0x3008
callq 0x1040
cvttsd2si %xmm0, %eax
movl %eax, 0x80(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq