// File: /workspace/github_c_makefile_star2_O0/waywardgeek[P]sonic/sonic.c
// Function: changeSpeed
static int changeSpeed(sonicStream stream, float speed) {
  short* samples;
  int numSamples = stream->numInputSamples;
  int position = 0, period, newSamples;
  int maxRequired = stream->maxRequired;

  if (stream->numInputSamples < maxRequired) {
    return 1;
  }
  do {
    samples = stream->inputBuffer + position * stream->numChannels;
    if ((speed > 1.0f && speed < 2.0f && stream->timeError < 0.0f) ||
        (speed < 1.0f && speed > 0.5f && stream->timeError > 0.0f)) {
      /* Deal with the case where PICOLA is still copying input samples to
         output unmodified, */
      if (!copyUnmodifiedSamples(stream, samples, speed, position,
                                 &newSamples)) {
        return 0;
      }
      position += newSamples;
    } else {
      /* We are in the remaining cases, either inserting/removing a pitch period
         for speed < 2.0X, or a portion of one for speed >= 2.0X. */
      period = findPitchPeriod(stream, samples, 1);
#ifdef SONIC_SPECTROGRAM
      if (stream->spectrogram != NULL) {
        sonicAddPitchPeriodToSpectrogram(stream->spectrogram, samples, period,
                                         stream->numChannels);
        newSamples = period;
        position += period;
      } else
#endif /* SONIC_SPECTROGRAM */
        if (speed > 1.0) {
          newSamples = skipPitchPeriod(stream, samples, speed, period);
          position += period + newSamples;
          if (speed < 2.0) {
            stream->timeError += newSamples * stream->samplePeriod -
                                 (period + newSamples) * stream->inputPlayTime /
                                     stream->numInputSamples;
          }
        } else {
          newSamples = insertPitchPeriod(stream, samples, speed, period);
          position += newSamples;
          if (speed > 0.5) {
            stream->timeError +=
                (period + newSamples) * stream->samplePeriod -
                newSamples * stream->inputPlayTime / stream->numInputSamples;
          }
        }
      if (newSamples == 0) {
        return 0; /* Failed to resize output buffer */
      }
    }
  } while (position + maxRequired <= numSamples);
  removeInputSamples(stream, position);
  return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movss %xmm0, -0x14(%rbp)
movq -0x10(%rbp), %rax
movl 0x60(%rax), %eax
movl %eax, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl 0x74(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movl 0x60(%rax), %eax
cmpl -0x34(%rbp), %eax
jge 0x2754
movl $0x1, -0x4(%rbp)
jmp 0x298c
jmp 0x2756
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x28(%rbp), %ecx
movq -0x10(%rbp), %rdx
imull 0x50(%rdx), %ecx
movslq %ecx, %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movss -0x14(%rbp), %xmm0
movss 0x288e(%rip), %xmm1     # 0x5010
ucomiss %xmm1, %xmm0
jbe 0x27a2
movss 0x288d(%rip), %xmm0     # 0x501c
ucomiss -0x14(%rbp), %xmm0
jbe 0x27a2
movq -0x10(%rbp), %rax
xorps %xmm0, %xmm0
ucomiss 0x40(%rax), %xmm0
ja 0x27d3
movss 0x2866(%rip), %xmm0     # 0x5010
ucomiss -0x14(%rbp), %xmm0
jbe 0x280b
movss -0x14(%rbp), %xmm0
movss 0x285b(%rip), %xmm1     # 0x5018
ucomiss %xmm1, %xmm0
jbe 0x280b
movq -0x10(%rbp), %rax
movss 0x40(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x280b
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movss -0x14(%rbp), %xmm0
movl -0x28(%rbp), %edx
leaq -0x30(%rbp), %rcx
callq 0x2ce0
cmpl $0x0, %eax
jne 0x27fd
movl $0x0, -0x4(%rbp)
jmp 0x298c
movl -0x30(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x2968
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl $0x1, %edx
callq 0x2e10
movl %eax, -0x2c(%rbp)
movss -0x14(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x27f7(%rip), %xmm1     # 0x5028
ucomisd %xmm1, %xmm0
jbe 0x28cc
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movss -0x14(%rbp), %xmm0
movl -0x2c(%rbp), %edx
callq 0x2fc0
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %eax
addl -0x30(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movss -0x14(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x27d8(%rip), %xmm0     # 0x5048
ucomisd %xmm1, %xmm0
jbe 0x28c7
cvtsi2ssl -0x30(%rbp), %xmm0
movq -0x10(%rbp), %rax
movss 0x38(%rax), %xmm2
movl -0x2c(%rbp), %eax
addl -0x30(%rbp), %eax
cvtsi2ss %eax, %xmm1
movq -0x10(%rbp), %rax
mulss 0x3c(%rax), %xmm1
movq -0x10(%rbp), %rax
cvtsi2ssl 0x60(%rax), %xmm3
divss %xmm3, %xmm1
movd %xmm1, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movq -0x10(%rbp), %rax
addss 0x40(%rax), %xmm0
movss %xmm0, 0x40(%rax)
jmp 0x2957
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movss -0x14(%rbp), %xmm0
movl -0x2c(%rbp), %edx
callq 0x30a0
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movss -0x14(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x2742(%rip), %xmm1     # 0x5040
ucomisd %xmm1, %xmm0
jbe 0x2955
movl -0x2c(%rbp), %eax
addl -0x30(%rbp), %eax
cvtsi2ss %eax, %xmm0
movq -0x10(%rbp), %rax
movss 0x38(%rax), %xmm2
cvtsi2ssl -0x30(%rbp), %xmm1
movq -0x10(%rbp), %rax
mulss 0x3c(%rax), %xmm1
movq -0x10(%rbp), %rax
cvtsi2ssl 0x60(%rax), %xmm3
divss %xmm3, %xmm1
movd %xmm1, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movq -0x10(%rbp), %rax
addss 0x40(%rax), %xmm0
movss %xmm0, 0x40(%rax)
jmp 0x2957
cmpl $0x0, -0x30(%rbp)
jne 0x2966
movl $0x0, -0x4(%rbp)
jmp 0x298c
jmp 0x2968
jmp 0x296a
movl -0x28(%rbp), %eax
addl -0x34(%rbp), %eax
cmpl -0x24(%rbp), %eax
jle 0x2756
movq -0x10(%rbp), %rdi
movl -0x28(%rbp), %esi
callq 0x31d0
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)