// File: Sleepwalking[P]world-octave/stonemask.cpp
// Function: (anonymous namespace)::GetTentativeF0(double*, double*, int, int, double)
double GetTentativeF0(double *power_spectrum, double *numerator_i,
    int fft_size, int fs, double f0_initial) {
  double power_list[6];
  double fixp_list[6];
  int index;
  for (int i = 0; i < 2; ++i) {
    index = matlab_round(f0_initial * fft_size / fs * (i + 1));

    fixp_list[i] = static_cast<double>(index) * fs / fft_size +
      numerator_i[index] / power_spectrum[index] * fs / 2.0 / world::kPi;
    power_list[i] = power_spectrum[index];
  }

  double tmp1 = 0.0;
  double tmp2 = 0.0;
  for (int i = 0; i < 2; ++i) {
    tmp1 += power_list[i] * fixp_list[i] / (i + 1);
    tmp2 += power_list[i];
  }
  f0_initial = tmp1 / tmp2;

  for (int i = 0; i < 6; ++i) {
    index = matlab_round(f0_initial * fft_size / fs * (i + 1));
    fixp_list[i] = static_cast<double>(index) * fs / fft_size +
      numerator_i[index] / power_spectrum[index] * fs / 2.0 / world::kPi;
    power_list[i] = sqrt(power_spectrum[index]);
  }
  for (int i = 0; i < 6; ++i) {
    tmp1 += power_list[i] * fixp_list[i];
    tmp2 += power_list[i] * (i + 1);
  }

  return tmp1 / tmp2;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movsd %xmm0, -0x20(%rbp)
movl $0x0, -0x88(%rbp)
cmpl $0x2, -0x88(%rbp)
jge 0xa235
movsd -0x20(%rbp), %xmm0
cvtsi2sdl -0x14(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvtsi2sdl -0x18(%rbp), %xmm1
divsd %xmm1, %xmm0
movl -0x88(%rbp), %eax
addl $0x1, %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm1, %xmm0
callq 0x72e0
movl %eax, -0x84(%rbp)
cvtsi2sdl -0x84(%rbp), %xmm0
cvtsi2sdl -0x18(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvtsi2sdl -0x14(%rbp), %xmm1
divsd %xmm1, %xmm0
movq -0x10(%rbp), %rax
movslq -0x84(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq -0x8(%rbp), %rax
movslq -0x84(%rbp), %rcx
divsd (%rax,%rcx,8), %xmm1
cvtsi2sdl -0x18(%rbp), %xmm2
mulsd %xmm2, %xmm1
movsd 0x11e25(%rip), %xmm2    # 0x1c008
divsd %xmm2, %xmm1
movsd 0x11ec9(%rip), %xmm2    # 0x1c0b8
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movslq -0x88(%rbp), %rax
movsd %xmm0, -0x80(%rbp,%rax,8)
movq -0x8(%rbp), %rax
movslq -0x84(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movslq -0x88(%rbp), %rax
movsd %xmm0, -0x50(%rbp,%rax,8)
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0xa158
xorps %xmm0, %xmm0
movsd %xmm0, -0x90(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x98(%rbp)
movl $0x0, -0x9c(%rbp)
cmpl $0x2, -0x9c(%rbp)
jge 0xa2c7
movslq -0x9c(%rbp), %rax
movsd -0x50(%rbp,%rax,8), %xmm0
movslq -0x9c(%rbp), %rax
mulsd -0x80(%rbp,%rax,8), %xmm0
movl -0x9c(%rbp), %eax
addl $0x1, %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
addsd -0x90(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
movslq -0x9c(%rbp), %rax
movsd -0x50(%rbp,%rax,8), %xmm0
addsd -0x98(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0xa255
movsd -0x90(%rbp), %xmm0
divsd -0x98(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
movl $0x0, -0xa0(%rbp)
cmpl $0x6, -0xa0(%rbp)
jge 0xa3c8
movsd -0x20(%rbp), %xmm0
cvtsi2sdl -0x14(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvtsi2sdl -0x18(%rbp), %xmm1
divsd %xmm1, %xmm0
movl -0xa0(%rbp), %eax
addl $0x1, %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm1, %xmm0
callq 0x72e0
movl %eax, -0x84(%rbp)
cvtsi2sdl -0x84(%rbp), %xmm0
cvtsi2sdl -0x18(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvtsi2sdl -0x14(%rbp), %xmm1
divsd %xmm1, %xmm0
movq -0x10(%rbp), %rax
movslq -0x84(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq -0x8(%rbp), %rax
movslq -0x84(%rbp), %rcx
divsd (%rax,%rcx,8), %xmm1
cvtsi2sdl -0x18(%rbp), %xmm2
mulsd %xmm2, %xmm1
movsd 0x11c97(%rip), %xmm2    # 0x1c008
divsd %xmm2, %xmm1
movsd 0x11d3b(%rip), %xmm2    # 0x1c0b8
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movslq -0xa0(%rbp), %rax
movsd %xmm0, -0x80(%rbp,%rax,8)
movq -0x8(%rbp), %rax
movslq -0x84(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
callq 0x1090
movslq -0xa0(%rbp), %rax
movsd %xmm0, -0x50(%rbp,%rax,8)
movl -0xa0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa0(%rbp)
jmp 0xa2e6
movl $0x0, -0xa4(%rbp)
cmpl $0x6, -0xa4(%rbp)
jge 0xa450
movslq -0xa4(%rbp), %rax
movsd -0x50(%rbp,%rax,8), %xmm0
movslq -0xa4(%rbp), %rax
movsd -0x80(%rbp,%rax,8), %xmm2
movsd -0x90(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x90(%rbp)
movslq -0xa4(%rbp), %rax
movsd -0x50(%rbp,%rax,8), %xmm0
movl -0xa4(%rbp), %eax
addl $0x1, %eax
cvtsi2sd %eax, %xmm2
movsd -0x98(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x98(%rbp)
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0xa3d2
movsd -0x90(%rbp), %xmm0
divsd -0x98(%rbp), %xmm0
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax)