// File: /workspace/github_c_makefile_star2_O0/waywardgeek[P]sonic/sonic.c
// Function: findPitchPeriod
static int findPitchPeriod(sonicStream stream, short* samples,
                           int preferNewPeriod) {
  int minPeriod = stream->minPeriod;
  int maxPeriod = stream->maxPeriod;
  int minDiff, maxDiff, retPeriod;
  int skip = computeSkip(stream, stream->sampleRate);
  int period;

  if (stream->numChannels == 1 && skip == 1) {
    period = findPitchPeriodInRange(samples, minPeriod, maxPeriod, &minDiff,
                                    &maxDiff);
  } else {
    downSampleInput(stream, samples, skip);
    period = findPitchPeriodInRange(stream->downSampleBuffer, minPeriod / skip,
                                    maxPeriod / skip, &minDiff, &maxDiff);
    if (skip != 1) {
      period *= skip;
      minPeriod = period - (skip << 2);
      maxPeriod = period + (skip << 2);
      if (minPeriod < stream->minPeriod) {
        minPeriod = stream->minPeriod;
      }
      if (maxPeriod > stream->maxPeriod) {
        maxPeriod = stream->maxPeriod;
      }
      if (stream->numChannels == 1) {
        period = findPitchPeriodInRange(samples, minPeriod, maxPeriod, &minDiff,
                                        &maxDiff);
      } else {
        downSampleInput(stream, samples, 1);
        period = findPitchPeriodInRange(stream->downSampleBuffer, minPeriod,
                                        maxPeriod, &minDiff, &maxDiff);
      }
    }
  }
  if (prevPeriodBetter(stream, minDiff, maxDiff, preferNewPeriod)) {
    retPeriod = stream->prevPeriod;
  } else {
    retPeriod = period;
  }
  stream->prevMinDiff = minDiff;
  stream->prevPeriod = period;
  return retPeriod;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movl 0x6c(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movl 0x70(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x7c(%rax), %esi
callq 0x2640
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x1, 0x50(%rax)
jne 0x2e79
cmpl $0x1, -0x2c(%rbp)
jne 0x2e79
movq -0x10(%rbp), %rdi
movl -0x18(%rbp), %esi
movl -0x1c(%rbp), %edx
leaq -0x20(%rbp), %rcx
leaq -0x24(%rbp), %r8
callq 0x3390
movl %eax, -0x30(%rbp)
jmp 0x2f69
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x2c(%rbp), %edx
callq 0x3520
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x18(%rbp), %eax
cltd
idivl -0x2c(%rbp)
movl %eax, %esi
movl -0x1c(%rbp), %eax
cltd
idivl -0x2c(%rbp)
movl %eax, %edx
leaq -0x20(%rbp), %rcx
leaq -0x24(%rbp), %r8
callq 0x3390
movl %eax, -0x30(%rbp)
cmpl $0x1, -0x2c(%rbp)
je 0x2f67
movl -0x2c(%rbp), %eax
imull -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl -0x2c(%rbp), %ecx
shll $0x2, %ecx
subl %ecx, %eax
movl %eax, -0x18(%rbp)
movl -0x30(%rbp), %eax
movl -0x2c(%rbp), %ecx
shll $0x2, %ecx
addl %ecx, %eax
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x6c(%rcx), %eax
jge 0x2ef9
movq -0x8(%rbp), %rax
movl 0x6c(%rax), %eax
movl %eax, -0x18(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x70(%rcx), %eax
jle 0x2f0f
movq -0x8(%rbp), %rax
movl 0x70(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x1, 0x50(%rax)
jne 0x2f35
movq -0x10(%rbp), %rdi
movl -0x18(%rbp), %esi
movl -0x1c(%rbp), %edx
leaq -0x20(%rbp), %rcx
leaq -0x24(%rbp), %r8
callq 0x3390
movl %eax, -0x30(%rbp)
jmp 0x2f65
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x1, %edx
callq 0x3520
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x18(%rbp), %esi
movl -0x1c(%rbp), %edx
leaq -0x20(%rbp), %rcx
leaq -0x24(%rbp), %r8
callq 0x3390
movl %eax, -0x30(%rbp)
jmp 0x2f67
jmp 0x2f69
movq -0x8(%rbp), %rdi
movl -0x20(%rbp), %esi
movl -0x24(%rbp), %edx
movl -0x14(%rbp), %ecx
callq 0x35d0
cmpl $0x0, %eax
je 0x2f8f
movq -0x8(%rbp), %rax
movl 0x80(%rax), %eax
movl %eax, -0x28(%rbp)
jmp 0x2f95
movl -0x30(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x20(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x84(%rax)
movl -0x30(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x80(%rax)
movl -0x28(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)