// File: /workspace/github_cpp_makefile_star2_O1/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 $0x78, %rsp
movq %r9, 0x68(%rsp)
movq %r8, %r14
movsd %xmm0, 0x50(%rsp)
movl %edx, %r15d
movl %esi, %r12d
movq %rdi, %r13
movl %ecx, %ebp
movl %ecx, 0x5c(%rsp)
testl %ecx, %ecx
jle 0x6f96
movq 0x8(%r14), %rdi
leaq (,%rbp,8), %rdx
xorl %esi, %esi
movsd %xmm1, 0x60(%rsp)
callq 0x1080
movsd 0x60(%rsp), %xmm1
movq 0x8(%r14), %r8
movq %r13, %rdi
movl %r12d, %esi
movl %r15d, %edx
movsd 0x50(%rsp), %xmm0
movl $0x2, %ecx
callq 0x71d0
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
addsd %xmm0, %xmm0
divsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
callq 0x45c3
xorpd %xmm0, %xmm0
testl %eax, %eax
js 0x701d
movsd %xmm0, 0x50(%rsp)
movq $-0x1, %r15
movq 0x8(%r14), %rax
movsd 0x8(%rax,%r15,8), %xmm0
mulsd %xmm0, %xmm0
movsd 0x50(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x50(%rsp)
movsd 0x60(%rsp), %xmm0
callq 0x45c3
addl %eax, %eax
cltq
incq %r15
cmpq %rax, %r15
jl 0x6fe5
jmp 0x7023
movsd %xmm0, 0x50(%rsp)
movsd 0x60(%rsp), %xmm0
callq 0x45c3
testl %eax, %eax
movsd 0x50(%rsp), %xmm0
js 0x70a0
movq $-0x1, %r15
xorps %xmm1, %xmm1
sqrtsd %xmm0, %xmm1
movsd %xmm1, 0x70(%rsp)
movsd %xmm0, 0x50(%rsp)
ucomisd 0x805e(%rip), %xmm0     # 0xf0b8
movsd 0x70(%rsp), %xmm0
jae 0x706d
movsd 0x50(%rsp), %xmm0
callq 0x1090
movq 0x8(%r14), %rax
movsd 0x8(%rax,%r15,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rax,%r15,8)
movsd 0x60(%rsp), %xmm0
callq 0x45c3
addl %eax, %eax
cltq
incq %r15
cmpq %rax, %r15
movsd 0x50(%rsp), %xmm0
jl 0x7052
leaq 0x18(%r14), %rsi
movl $0x9, %ecx
movq %rsp, %rdi
movq %rsi, 0x50(%rsp)
rep  movsq (%rsi), %es:(%rdi)
callq 0x7f1a
movl 0x5c(%rsp), %ebx
movl %ebx, %r13d
shrl $0x1f, %r13d
addl %ebx, %r13d
sarl %r13d
movslq %r13d, %rax
leaq 0x8(,%rax,8), %rax
cmpl $-0x3, %ebx
movq $-0x1, %r12
cmovgeq %rax, %r12
movq %r12, %rdi
callq 0x1030
movq %rax, %r15
movq %r12, %rdi
callq 0x1030
movq %rax, %r12
cmpl $-0x1, %ebx
jl 0x712d
movq 0x10(%r14), %rax
leal 0x1(%r13), %ecx
addq $0x8, %rax
xorl %edx, %edx
movsd -0x8(%rax), %xmm0
movsd %xmm0, (%r15,%rdx,8)
movsd (%rax), %xmm0
movsd %xmm0, (%r12,%rdx,8)
incq %rdx
addq $0x10, %rax
cmpq %rdx, %rcx
jne 0x710c
cmpl $0x0, 0x5c(%rsp)
jle 0x715a
movq 0x8(%r14), %rax
xorl %ecx, %ecx
leaq 0x1(%rcx), %rdx
movl %edx, %esi
xorps %xmm0, %xmm0
cvtsi2sd %rsi, %xmm0
mulsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq %rdx, %rcx
cmpq %rdx, %rbp
jne 0x713a
movl $0x9, %ecx
movq %rsp, %rdi
movq 0x50(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x7f1a
cmpl $-0x1, 0x5c(%rsp)
movq 0x68(%rsp), %rdx
jl 0x71b2
movq 0x10(%r14), %rax
incl %r13d
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, %r13
jne 0x7188
movq %r15, %rdi
callq 0x1110
movq %r12, %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1110