// File: /workspace/github_c_makefile_star2_O0/waywardgeek[P]sonic/main.c
// Function: runSonic
static void runSonic(char* inFileName, char* outFileName, float speed,
                     float pitch, float rate, float volume, int outputSampleRate,
                     int emulateChordPitch, int quality, int computeSpectrogram,
                     int numRows, int numCols) {
  waveFile inFile, outFile = NULL;
  sonicStream stream;
  short inBuffer[BUFFER_SIZE], outBuffer[BUFFER_SIZE];
  int sampleRate, numChannels, samplesRead, samplesWritten;

  inFile = openInputWaveFile(inFileName, &sampleRate, &numChannels);
  if (outputSampleRate != 0) {
    sampleRate = outputSampleRate;
  }
  if (inFile == NULL) {
    fprintf(stderr, "Unable to read wave file %s\n", inFileName);
    exit(1);
  }
  if (!computeSpectrogram) {
    outFile = openOutputWaveFile(outFileName, sampleRate, numChannels);
    if (outFile == NULL) {
      closeWaveFile(inFile);
      fprintf(stderr, "Unable to open wave file %s for writing\n", outFileName);
      exit(1);
    }
  }
  stream = sonicCreateStream(sampleRate, numChannels);
  sonicSetSpeed(stream, speed);
  sonicSetPitch(stream, pitch);
  sonicSetRate(stream, rate);
  sonicSetVolume(stream, volume);
  sonicSetChordPitch(stream, emulateChordPitch);
  sonicSetQuality(stream, quality);
#ifdef SONIC_SPECTROGRAM
  if (computeSpectrogram) {
    sonicComputeSpectrogram(stream);
  }
#endif  /* SONIC_SPECTROGRAM */
  do {
    samplesRead = readFromWaveFile(inFile, inBuffer, BUFFER_SIZE / numChannels);
    if (samplesRead == 0) {
      sonicFlushStream(stream);
    } else {
      sonicWriteShortToStream(stream, inBuffer, samplesRead);
    }
    if (!computeSpectrogram) {
      do {
        samplesWritten = sonicReadShortFromStream(stream, outBuffer,
                                                  BUFFER_SIZE / numChannels);
        if (samplesWritten > 0 && !computeSpectrogram) {
          writeToWaveFile(outFile, outBuffer, samplesWritten);
        }
      } while (samplesWritten > 0);
    }
  } while (samplesRead > 0);
#ifdef SONIC_SPECTROGRAM
  if (computeSpectrogram) {
    sonicSpectrogram spectrogram = sonicGetSpectrogram(stream);
    sonicBitmap bitmap =
        sonicConvertSpectrogramToBitmap(spectrogram, numRows, numCols);
    sonicWritePGM(bitmap, outFileName);
    sonicDestroyBitmap(bitmap);
  }
#endif  /* SONIC_SPECTROGRAM */
  sonicDestroyStream(stream);
  closeWaveFile(inFile);
  if (!computeSpectrogram) {
    closeWaveFile(outFile);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2060, %rsp           # imm = 0x2060
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movss %xmm0, -0x14(%rbp)
movss %xmm1, -0x18(%rbp)
movss %xmm2, -0x1c(%rbp)
movss %xmm3, -0x20(%rbp)
movl %edx, -0x24(%rbp)
movl %ecx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movl %r9d, -0x30(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x2054(%rbp), %rsi
leaq -0x2058(%rbp), %rdx
callq 0x40a0
movq %rax, -0x38(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x169d
movl -0x24(%rbp), %eax
movl %eax, -0x2054(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x16ca
movq 0x694d(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movq -0x8(%rbp), %rdx
leaq 0x3cae(%rip), %rsi      # 0x5367
movb $0x0, %al
callq 0x10c0
movl $0x1, %edi
callq 0x1130
cmpl $0x0, -0x30(%rbp)
jne 0x1721
movq -0x10(%rbp), %rdi
movl -0x2054(%rbp), %esi
movl -0x2058(%rbp), %edx
callq 0x4390
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x171f
movq -0x38(%rbp), %rdi
callq 0x4540
movq 0x68f8(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x3c76(%rip), %rsi      # 0x5384
movb $0x0, %al
callq 0x10c0
movl $0x1, %edi
callq 0x1130
jmp 0x1721
movl -0x2054(%rbp), %edi
movl -0x2058(%rbp), %esi
callq 0x1c40
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
movss -0x14(%rbp), %xmm0
callq 0x18d0
movq -0x48(%rbp), %rdi
movss -0x18(%rbp), %xmm0
callq 0x1960
movq -0x48(%rbp), %rdi
movss -0x1c(%rbp), %xmm0
callq 0x19f0
movq -0x48(%rbp), %rdi
movss -0x20(%rbp), %xmm0
callq 0x1b10
movq -0x48(%rbp), %rdi
movl -0x28(%rbp), %esi
callq 0x1a90
movq -0x48(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x1ac0
movq -0x38(%rbp), %rdi
leaq -0x1050(%rbp), %rsi
movl $0x800, %eax            # imm = 0x800
cltd
idivl -0x2058(%rbp)
movl %eax, %edx
callq 0x46d0
movl %eax, -0x205c(%rbp)
cmpl $0x0, -0x205c(%rbp)
jne 0x17be
movq -0x48(%rbp), %rdi
callq 0x23d0
jmp 0x17d4
movq -0x48(%rbp), %rdi
leaq -0x1050(%rbp), %rsi
movl -0x205c(%rbp), %edx
callq 0x25d0
cmpl $0x0, -0x30(%rbp)
jne 0x1832
jmp 0x17dc
movq -0x48(%rbp), %rdi
leaq -0x2050(%rbp), %rsi
movl $0x800, %eax            # imm = 0x800
cltd
idivl -0x2058(%rbp)
movl %eax, %edx
callq 0x21f0
movl %eax, -0x2060(%rbp)
cmpl $0x0, -0x2060(%rbp)
jle 0x1825
cmpl $0x0, -0x30(%rbp)
jne 0x1825
movq -0x40(%rbp), %rdi
leaq -0x2050(%rbp), %rsi
movl -0x2060(%rbp), %edx
callq 0x4820
jmp 0x1827
cmpl $0x0, -0x2060(%rbp)
jg 0x17dc
jmp 0x1832
jmp 0x1834
cmpl $0x0, -0x205c(%rbp)
jg 0x1786
movq -0x48(%rbp), %rdi
callq 0x1b80
movq -0x38(%rbp), %rdi
callq 0x4540
cmpl $0x0, -0x30(%rbp)
jne 0x1862
movq -0x40(%rbp), %rdi
callq 0x4540
addq $0x2060, %rsp           # imm = 0x2060
popq %rbp
retq
nopl (%rax,%rax)