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

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl 0x5bc5bf(%rip), %eax    # 0x5bde54
movl %eax, -0x10(%rbp)
movl 0x5bc5ba(%rip), %eax    # 0x5bde58
movl %eax, -0x14(%rbp)
movl 0x5bc591(%rip), %eax    # 0x5bde38
movl $0xfa0, %ecx            # imm = 0xFA0
cltd
idivl %ecx
movl %eax, -0x28(%rbp)
cmpl $0x1, -0x28(%rbp)
jne 0x18d7
movq -0x8(%rbp), %rdi
movl -0x10(%rbp), %esi
movl -0x14(%rbp), %edx
leaq -0x18(%rbp), %rcx
leaq -0x1c(%rbp), %r8
callq 0x1bf0
movl %eax, -0x24(%rbp)
jmp 0x1978
movq -0x8(%rbp), %rdi
callq 0x1d80
movl -0x10(%rbp), %eax
cltd
idivl -0x28(%rbp)
movl %eax, %esi
movl -0x14(%rbp), %eax
cltd
idivl -0x28(%rbp)
movl %eax, %edx
leaq 0x37bb(%rip), %rdi      # 0x50b4
addq $0x3d0900, %rdi         # imm = 0x3D0900
leaq -0x18(%rbp), %rcx
leaq -0x1c(%rbp), %r8
callq 0x1bf0
movl %eax, -0x24(%rbp)
movl -0x28(%rbp), %eax
imull -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl -0x28(%rbp), %ecx
shll $0x2, %ecx
subl %ecx, %eax
movl %eax, -0x10(%rbp)
movl -0x24(%rbp), %eax
movl -0x28(%rbp), %ecx
shll $0x2, %ecx
addl %ecx, %eax
movl %eax, -0x14(%rbp)
movl -0x10(%rbp), %eax
cmpl 0x5bc515(%rip), %eax    # 0x5bde54
jge 0x194a
movl 0x5bc50d(%rip), %eax    # 0x5bde54
movl %eax, -0x10(%rbp)
movl -0x14(%rbp), %eax
cmpl 0x5bc505(%rip), %eax    # 0x5bde58
jle 0x195e
movl 0x5bc4fd(%rip), %eax    # 0x5bde58
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rdi
movl -0x10(%rbp), %esi
movl -0x14(%rbp), %edx
leaq -0x18(%rbp), %rcx
leaq -0x1c(%rbp), %r8
callq 0x1bf0
movl %eax, -0x24(%rbp)
movl -0x18(%rbp), %edi
movl -0x1c(%rbp), %esi
movl -0xc(%rbp), %edx
callq 0x1e30
cmpl $0x0, %eax
je 0x1996
movl 0x5bc4bb(%rip), %eax    # 0x5bde4c
movl %eax, -0x20(%rbp)
jmp 0x199c
movl -0x24(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x18(%rbp), %eax
movl %eax, 0x5bc4ab(%rip)    # 0x5bde50
movl -0x24(%rbp), %eax
movl %eax, 0x5bc49e(%rip)    # 0x5bde4c
movl -0x20(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)