// File: /workspace/github_c_makefile_star2_O0/waywardgeek[P]sonic/wave.c
// Function: readHeader
static int readHeader(waveFile file) {
  int data;

  expectString(file, "RIFF");
  data = readInt(file);          /* 04 - how big is the rest of this file? */
  expectString(file, "WAVE");    /* 08 - WAVE */
  expectString(file, "fmt ");    /* 12 - fmt */
  int chunkSize = readInt(file); /* 16 or 18 - size of this chunk */
  if (chunkSize != 16 && chunkSize != 18) {
    fprintf(stderr, "Only basic wave files are supported\n");
    return 0;
  }
  data = readShort(file); /* 20 - what is the audio format? 1 for PCM = Pulse
                             Code Modulation */
  if (data != 1) {
    fprintf(stderr, "Only PCM wave files are supported (not %d)\n", data);
    return 0;
  }
  file->numChannels =
      readShort(file); /* 22 - mono or stereo? 1 or 2?  (or 5 or ???) */
  file->sampleRate =
      readInt(file); /* 24 - samples per second (numbers per second) */
  readInt(file);     /* 28 - bytes per second */
  readShort(file);   /* 32 - # of bytes in one sample, for all channels */
  data = readShort(
      file); /* 34 - how many bits in a sample(number)?  usually 16 or 24 */
  if (data != 16) {
    fprintf(stderr, "Only 16 bit PCM wave files are supported\n");
    return 0;
  }
  if (chunkSize == 18) { /* ffmpeg writes 18, and so has 2 extra bytes here */
    data = readShort(file);
  }

  /* Read and discard chunks until we find the "data" chunk or fail */
  char chunk[5];
  chunk[4] = 0;

  while (1) {
    readExactBytes(file, chunk, 4);  /* chunk id */
    int size = readInt(file);        /* how big is this data chunk */
    if (strcmp(chunk, "data") == 0) {
      return 1;
    }
    if (fseek(file->soundFile, size, SEEK_CUR) != 0) {
      fprintf(stderr, "Failed to seek on input file.\n");
      return 0;
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x1531(%rip), %rsi      # 0x50e8
callq 0x43e0
movq -0x10(%rbp), %rdi
callq 0x4490
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x151a(%rip), %rsi      # 0x50ed
callq 0x43e0
movq -0x10(%rbp), %rdi
leaq 0x150f(%rip), %rsi      # 0x50f2
callq 0x43e0
movq -0x10(%rbp), %rdi
callq 0x4490
movl %eax, -0x18(%rbp)
cmpl $0x10, -0x18(%rbp)
je 0x3c24
cmpl $0x12, -0x18(%rbp)
je 0x3c24
movq 0x43f1(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x14e6(%rip), %rsi      # 0x50f7
movb $0x0, %al
callq 0x10f0
movl $0x0, -0x4(%rbp)
jmp 0x3d58
movq -0x10(%rbp), %rdi
callq 0x44f0
movl %eax, -0x14(%rbp)
cmpl $0x1, -0x14(%rbp)
je 0x3c5d
movq 0x43bb(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x14d2(%rip), %rsi      # 0x511c
movb $0x0, %al
callq 0x10f0
movl $0x0, -0x4(%rbp)
jmp 0x3d58
movq -0x10(%rbp), %rdi
callq 0x44f0
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rdi
callq 0x4490
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rdi
callq 0x4490
movq -0x10(%rbp), %rdi
callq 0x44f0
movq -0x10(%rbp), %rdi
callq 0x44f0
movl %eax, -0x14(%rbp)
cmpl $0x10, -0x14(%rbp)
je 0x3cc8
movq 0x434d(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x1493(%rip), %rsi      # 0x5148
movb $0x0, %al
callq 0x10f0
movl $0x0, -0x4(%rbp)
jmp 0x3d58
cmpl $0x12, -0x18(%rbp)
jne 0x3cda
movq -0x10(%rbp), %rdi
callq 0x44f0
movl %eax, -0x14(%rbp)
movb $0x0, -0x19(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x1d(%rbp), %rsi
movl $0x4, %edx
callq 0x4550
movq -0x10(%rbp), %rdi
callq 0x4490
movl %eax, -0x24(%rbp)
leaq -0x1d(%rbp), %rdi
leaq 0x146b(%rip), %rsi      # 0x5172
callq 0x10e0
cmpl $0x0, %eax
jne 0x3d1a
movl $0x1, -0x4(%rbp)
jmp 0x3d58
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movslq -0x24(%rbp), %rsi
movl $0x1, %edx
callq 0x1160
cmpl $0x0, %eax
je 0x3d56
movq 0x42bc(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x1362(%rip), %rsi      # 0x50a8
movb $0x0, %al
callq 0x10f0
movl $0x0, -0x4(%rbp)
jmp 0x3d58
jmp 0x3cde
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)