// File: /workspace/github_c_makefile_star2_O0/waywardgeek[P]sonic/sonic.c
// Function: findPitchPeriodInRange
static int findPitchPeriodInRange(short* samples, int minPeriod, int maxPeriod,
                                  int* retMinDiff, int* retMaxDiff) {
  int period, bestPeriod = 0, worstPeriod = 255;
  short* s;
  short* p;
  short sVal, pVal;
  unsigned long diff, minDiff = 1, maxDiff = 0;
  int i;

  for (period = minPeriod; period <= maxPeriod; period++) {
    diff = 0;
    s = samples;
    p = samples + period;
    for (i = 0; i < period; i++) {
      sVal = *s++;
      pVal = *p++;
      diff += sVal >= pVal ? (unsigned short)(sVal - pVal)
                           : (unsigned short)(pVal - sVal);
    }
    /* Note that the highest number of samples we add into diff will be less
       than 256, since we skip samples.  Thus, diff is a 24 bit number, and
       we can safely multiply by numSamples without overflow */
    if (bestPeriod == 0 || diff * bestPeriod < minDiff * period) {
      minDiff = diff;
      bestPeriod = period;
    }
    if (diff * worstPeriod > maxDiff * period) {
      maxDiff = diff;
      worstPeriod = period;
    }
  }
  *retMinDiff = minDiff / bestPeriod;
  *retMaxDiff = maxDiff / worstPeriod;
  return bestPeriod;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movl $0x0, -0x28(%rbp)
movl $0xff, -0x2c(%rbp)
movq $0x1, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x10(%rbp), %eax
jg 0x34e5
movq $0x0, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x3479
movq -0x38(%rbp), %rax
movq %rax, %rcx
addq $0x2, %rcx
movq %rcx, -0x38(%rbp)
movw (%rax), %ax
movw %ax, -0x42(%rbp)
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $0x2, %rcx
movq %rcx, -0x40(%rbp)
movw (%rax), %ax
movw %ax, -0x44(%rbp)
movswl -0x42(%rbp), %eax
movswl -0x44(%rbp), %ecx
cmpl %ecx, %eax
jl 0x3451
movswl -0x42(%rbp), %eax
movswl -0x44(%rbp), %ecx
subl %ecx, %eax
movzwl %ax, %eax
movl %eax, -0x68(%rbp)
jmp 0x3461
movswl -0x44(%rbp), %eax
movswl -0x42(%rbp), %ecx
subl %ecx, %eax
movzwl %ax, %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %eax
cltq
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x33ff
cmpl $0x0, -0x28(%rbp)
je 0x349c
movq -0x50(%rbp), %rax
movslq -0x28(%rbp), %rcx
imulq %rcx, %rax
movq -0x58(%rbp), %rcx
movslq -0x24(%rbp), %rdx
imulq %rdx, %rcx
cmpq %rcx, %rax
jae 0x34aa
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x50(%rbp), %rax
movslq -0x2c(%rbp), %rcx
imulq %rcx, %rax
movq -0x60(%rbp), %rcx
movslq -0x24(%rbp), %rdx
imulq %rdx, %rcx
cmpq %rcx, %rax
jbe 0x34d5
movq -0x50(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x34d7
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x33ca
movq -0x58(%rbp), %rax
movslq -0x28(%rbp), %rcx
xorl %edx, %edx
divq %rcx
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x60(%rbp), %rax
movslq -0x2c(%rbp), %rcx
xorl %edx, %edx
divq %rcx
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x28(%rbp), %eax
popq %rbp
retq
nopw %cs:(%rax,%rax)