// File: /workspace/github_cpp_makefile_star2_O2/Sleepwalking[P]world-octave/d4c.cpp
// Function: (anonymous namespace)::GetCentroid(double*, int, int, double, int, double, ForwardRealFFT*, double*)
void GetCentroid(double *x, int x_length, int fs, double current_f0,
    int fft_size, double temporal_position, ForwardRealFFT *forward_real_fft,
    double *centroid) {
  for (int i = 0; i < fft_size; ++i) forward_real_fft->waveform[i] = 0.0;
  GetWindowedWaveform(x, x_length, fs, current_f0,
      temporal_position, world::kBlackman, 4.0, forward_real_fft->waveform);
  double power = 0.0;
  for (int i = 0; i <= matlab_round(2.0 * fs / current_f0) * 2; ++i)
    power += forward_real_fft->waveform[i] * forward_real_fft->waveform[i];
  for (int i = 0; i <= matlab_round(2.0 * fs / current_f0) * 2; ++i)
    forward_real_fft->waveform[i] /= sqrt(power);

  fft_execute(forward_real_fft->forward_fft);
  double *tmp_real = new double[fft_size / 2 + 1];
  double *tmp_imag = new double[fft_size / 2 + 1];
  for (int i = 0; i <= fft_size / 2; ++i) {
    tmp_real[i] = forward_real_fft->spectrum[i][0];
    tmp_imag[i] = forward_real_fft->spectrum[i][1];
  }

  for (int i = 0; i < fft_size; ++i)
    forward_real_fft->waveform[i] *= i + 1.0;
  fft_execute(forward_real_fft->forward_fft);
  for (int i = 0; i <= fft_size / 2; ++i)
    centroid[i] = forward_real_fft->spectrum[i][0] * tmp_real[i] +
      tmp_imag[i] * forward_real_fft->spectrum[i][1];

  delete[] tmp_real;
  delete[] tmp_imag;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, %rbx
movq %r8, %r14
movl %ecx, %ebp
movl %edx, %r12d
xorl %eax, %eax
testl %ecx, %ecx
movl $0x0, %r13d
cmovgl %ecx, %r13d
movq 0x8(%r8), %r8
cmpq %rax, %r13
je 0x66e1
andq $0x0, (%r8,%rax,8)
incq %rax
jmp 0x66d2
pushq $0x2
popq %r15
movl %r12d, %edx
movsd %xmm0, 0x50(%rsp)
movl %r15d, %ecx
callq 0x68b0
cvtsi2sd %r12d, %xmm0
addsd %xmm0, %xmm0
divsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x50(%rsp)
xorl %r12d, %r12d
movsd 0x58(%rsp), %xmm0
callq 0x419e
addl %eax, %eax
cltq
cmpq %rax, %r12
jg 0x674f
movq 0x8(%r14), %rax
movsd (%rax,%r12,8), %xmm0
mulsd %xmm0, %xmm0
movsd 0x50(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x50(%rsp)
incq %r12
jmp 0x6718
xorl %r12d, %r12d
sqrtsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movsd 0x58(%rsp), %xmm0
callq 0x419e
addl %eax, %eax
cltq
cmpq %rax, %r12
jg 0x67ac
movsd 0x50(%rsp), %xmm0
ucomisd 0x6978(%rip), %xmm0     # 0xd0f8
movsd 0x60(%rsp), %xmm0
jae 0x6793
movsd 0x50(%rsp), %xmm0
callq 0x1090
movq 0x8(%r14), %rax
movsd (%rax,%r12,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rax,%r12,8)
incq %r12
jmp 0x675e
leaq 0x18(%r14), %rsi
pushq $0x9
popq %rcx
movq %rsp, %rdi
movq %rsi, 0x50(%rsp)
rep  movsq (%rsi), %es:(%rdi)
callq 0x752b
movl %ebp, %eax
cltd
idivl %r15d
movl %eax, %r15d
cltq
incl %r15d
cmpl $-0x3, %ebp
leaq 0x8(,%rax,8), %rax
pushq $-0x1
popq %rbp
cmovgeq %rax, %rbp
movq %rbp, %rdi
callq 0x1030
movq %rax, %r12
movq %rbp, %rdi
callq 0x1030
movq %rax, %rbp
xorl %eax, %eax
testl %r15d, %r15d
cmovlel %eax, %r15d
shlq $0x3, %r15
cmpq %rax, %r15
je 0x682c
movq 0x10(%r14), %rcx
movsd (%rcx,%rax,2), %xmm0
movsd %xmm0, (%r12,%rax)
movsd 0x8(%rcx,%rax,2), %xmm0
movsd %xmm0, (%rbp,%rax)
addq $0x8, %rax
jmp 0x6806
xorl %eax, %eax
cmpq %rax, %r13
je 0x684e
leaq 0x1(%rax), %rcx
cvtsi2sd %ecx, %xmm0
movq 0x8(%r14), %rdx
mulsd (%rdx,%rax,8), %xmm0
movsd %xmm0, (%rdx,%rax,8)
movq %rcx, %rax
jmp 0x682e
pushq $0x9
popq %rcx
movq %rsp, %rdi
movq 0x50(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x752b
xorl %eax, %eax
cmpq %rax, %r15
je 0x6892
movq 0x10(%r14), %rcx
movsd (%rcx,%rax,2), %xmm0
movsd (%rbp,%rax), %xmm1
mulsd 0x8(%rcx,%rax,2), %xmm1
mulsd (%r12,%rax), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rbx,%rax)
addq $0x8, %rax
jmp 0x6863
movq %r12, %rdi
callq 0x1110
movq %rbp, %rdi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1110