// File: /workspace/github_cpp_makefile_star2_O3/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, 0x58(%rsp)
movq %r8, %r14
movl %ecx, %ebp
movsd %xmm0, 0x48(%rsp)
movl %edx, %r15d
movl %esi, %r13d
movq %rdi, %rbx
movq 0x8(%r8), %r12
testl %ecx, %ecx
jle 0x77f5
movl %ebp, %edx
shlq $0x3, %rdx
movq %r12, %rdi
xorl %esi, %esi
movsd %xmm1, 0x50(%rsp)
callq 0x1080
movsd 0x50(%rsp), %xmm1
movq %rbx, %rdi
movl %r13d, %esi
movl %r15d, %edx
movsd 0x48(%rsp), %xmm0
movl $0x2, %ecx
movq %r12, %r8
callq 0x7a3d
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
addsd %xmm0, %xmm0
divsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
callq 0x4b8c
xorpd %xmm0, %xmm0
testl %eax, %eax
js 0x787a
movsd %xmm0, 0x48(%rsp)
movq $-0x1, %rbx
movq 0x8(%r14), %rax
movsd 0x8(%rax,%rbx,8), %xmm0
mulsd %xmm0, %xmm0
movsd 0x48(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x48(%rsp)
movsd 0x50(%rsp), %xmm0
callq 0x4b8c
addl %eax, %eax
cltq
incq %rbx
cmpq %rax, %rbx
jl 0x7843
jmp 0x7880
movsd %xmm0, 0x48(%rsp)
movsd 0x50(%rsp), %xmm0
callq 0x4b8c
testl %eax, %eax
movsd 0x48(%rsp), %xmm0
js 0x78fb
movq $-0x1, %rbx
xorps %xmm1, %xmm1
sqrtsd %xmm0, %xmm1
movsd %xmm1, 0x60(%rsp)
movsd %xmm0, 0x48(%rsp)
ucomisd 0x7891(%rip), %xmm0     # 0xf148
movsd 0x60(%rsp), %xmm0
jae 0x78ca
movsd 0x48(%rsp), %xmm0
callq 0x1090
movq 0x8(%r14), %rax
movsd 0x8(%rax,%rbx,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rax,%rbx,8)
movsd 0x50(%rsp), %xmm0
callq 0x4b8c
addl %eax, %eax
cltq
incq %rbx
cmpq %rax, %rbx
movsd 0x48(%rsp), %xmm0
jl 0x78af
leaq 0x18(%r14), %rsi
movl $0x9, %ecx
movq %rsp, %rdi
movq %rsi, 0x48(%rsp)
rep  movsq (%rsi), %es:(%rdi)
callq 0x8792
movl %ebp, %r13d
shrl $0x1f, %ebp
addl %r13d, %ebp
sarl %ebp
movslq %ebp, %rax
cmpl $-0x3, %r13d
leaq 0x8(,%rax,8), %rax
movq $-0x1, %rbx
cmovgeq %rax, %rbx
movq %rbx, %rdi
callq 0x1030
movq %rax, %r15
movq %rbx, %rdi
callq 0x1030
movq %rax, %r12
cmpl $-0x2, %r13d
jg 0x796f
movl $0x9, %ecx
movq %rsp, %rdi
movq 0x48(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x8792
jmp 0x7a1f
movl %r13d, %edx
movq 0x48(%rsp), %rsi
incl %ebp
movq 0x10(%r14), %rax
movl %ebp, %ebx
addq $0x8, %rax
xorl %ecx, %ecx
movsd -0x8(%rax), %xmm0
movsd %xmm0, (%r15,%rcx,8)
movsd (%rax), %xmm0
movsd %xmm0, (%r12,%rcx,8)
incq %rcx
addq $0x10, %rax
cmpq %rcx, %rbx
jne 0x7985
movl %edx, %ebp
testl %edx, %edx
jle 0x79d1
movq 0x8(%r14), %rax
movl %ebp, %ecx
xorl %edx, %edx
leaq 0x1(%rdx), %rdi
xorps %xmm0, %xmm0
cvtsi2sd %edi, %xmm0
mulsd (%rax,%rdx,8), %xmm0
movsd %xmm0, (%rax,%rdx,8)
movq %rdi, %rdx
cmpq %rdi, %rcx
jne 0x79b4
movl $0x9, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
callq 0x8792
cmpl $-0x1, %ebp
movq 0x58(%rsp), %rdx
jl 0x7a1f
movq 0x10(%r14), %rax
addq $0x8, %rax
xorl %ecx, %ecx
movsd (%r12,%rcx,8), %xmm0
mulsd (%rax), %xmm0
movsd -0x8(%rax), %xmm1
mulsd (%r15,%rcx,8), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rdx,%rcx,8)
incq %rcx
addq $0x10, %rax
cmpq %rcx, %rbx
jne 0x79f5
movq %r15, %rdi
callq 0x1110
movq %r12, %rdi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1110