// File: /workspace/github_cpp_makefile_star2_O2/Sleepwalking[P]world-octave/d4c.cpp
// Function: D4C(double*, int, int, double*, double*, int, int, double**)
void D4C(double *x, int x_length, int fs, double *time_axis, double *f0,
    int f0_length, int fft_size, double **aperiodicity) {
  int fft_size_d4c = static_cast<int>(pow(2.0, 1.0 +
      static_cast<int>(log(4.0 * fs / world::kFloorF0 + 1) / world::kLog2)));

  ForwardRealFFT forward_real_fft = {0};
  InitializeForwardRealFFT(fft_size_d4c, &forward_real_fft);

  int number_of_aperiodicities =
    static_cast<int>(MyMin(world::kUpperLimit, fs / 2.0 -
      world::kFrequencyInterval) / world::kFrequencyInterval);
  // Since the window function is common in D4CGeneralBody(),
  // it is designed here to speed up.
  int window_length =
    static_cast<int>(world::kFrequencyInterval * fft_size_d4c / fs) * 2 + 1;
  double *window =  new double[window_length];
  NuttallWindow(window_length, window);

  double *coarse_aperiodicity = new double[number_of_aperiodicities + 2];
  coarse_aperiodicity[0] = -60.0;
  coarse_aperiodicity[number_of_aperiodicities + 1] = 0.0;
  double *coarse_frequency_axis = new double[number_of_aperiodicities + 2];
  for (int i = 0; i <= number_of_aperiodicities; ++i)
    coarse_frequency_axis[i] =
      static_cast<double>(i) * world::kFrequencyInterval;
  coarse_frequency_axis[number_of_aperiodicities + 1] = fs / 2.0;

  double *frequency_axis = new double[fft_size / 2 + 1];
  for (int i = 0; i <= fft_size / 2; ++i)
    frequency_axis[i] = static_cast<double>(i) * fs / fft_size;
  for (int i = 0; i < f0_length; ++i) {
    if (f0[i] == 0) {
      for (int j = 0; j <= fft_size / 2; ++j) aperiodicity[i][j] = 0.0;
      continue;
    }
//    D4CGeneralBody(x, x_length, fs, f0[i], fft_size_d4c, time_axis[i],
    D4CGeneralBody(x, x_length, fs, MyMax(f0[i], world::kFloorF0),
        fft_size_d4c, time_axis[i], number_of_aperiodicities, window,
        window_length, &forward_real_fft, &coarse_aperiodicity[1]);
    // Linear interpolation to convert the coarse aperiodicity into its
    // spectral representation.
    interp1(coarse_frequency_axis, coarse_aperiodicity,
        number_of_aperiodicities + 2, frequency_axis, fft_size / 2 + 1,
        aperiodicity[i]);
    for (int j = 0; j <= fft_size / 2; ++j)
      aperiodicity[i][j] = pow(10.0, aperiodicity[i][j] / 20.0);
  }

  DestroyForwardRealFFT(&forward_real_fft);
  delete[] coarse_frequency_axis;
  delete[] coarse_aperiodicity;
  delete[] window;
  delete[] frequency_axis;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movq %r9, 0x98(%rsp)
movq %r8, 0x118(%rsp)
movq %rcx, 0x110(%rsp)
movl %esi, 0x64(%rsp)
movq %rdi, 0xb0(%rsp)
movl %edx, 0x4c(%rsp)
cvtsi2sd %edx, %xmm1
movapd %xmm1, 0xf0(%rsp)
movsd 0x769e(%rip), %xmm0     # 0xd430
mulsd %xmm1, %xmm0
divsd 0x760a(%rip), %xmm0     # 0xd3a8
addsd 0x726a(%rip), %xmm0     # 0xd010
callq 0x10a0
divsd 0x7255(%rip), %xmm0     # 0xd008
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
addsd 0x724d(%rip), %xmm0     # 0xd010
callq 0x10b0
movapd %xmm0, 0x80(%rsp)
cvttsd2si %xmm0, %edi
xorpd %xmm0, %xmm0
leaq 0x150(%rsp), %rsi
movapd %xmm0, 0x50(%rsi)
movapd %xmm0, 0x40(%rsi)
movapd %xmm0, 0x30(%rsi)
movapd %xmm0, 0x20(%rsi)
movapd %xmm0, 0x10(%rsi)
movapd %xmm0, (%rsi)
movl %edi, 0x48(%rsp)
callq 0x17c6
movsd 0x72b1(%rip), %xmm1     # 0xd0c0
movapd 0xf0(%rsp), %xmm3
mulsd %xmm3, %xmm1
movsd 0x7614(%rip), %xmm0     # 0xd438
movsd %xmm1, 0x58(%rsp)
addsd %xmm1, %xmm0
movsd 0x760a(%rip), %xmm1     # 0xd440
cvttpd2dq 0x80(%rsp), %xmm2
cvtdq2pd %xmm2, %xmm2
minsd %xmm0, %xmm1
movapd %xmm2, 0x140(%rsp)
movapd %xmm2, %xmm0
mulsd 0x75ec(%rip), %xmm0     # 0xd448
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
movapd 0x7608(%rip), %xmm0     # 0xd470
unpcklpd %xmm3, %xmm0            # xmm0 = xmm0[0],xmm3[0]
divpd %xmm0, %xmm1
cvttpd2dq %xmm1, %xmm1
movapd %xmm1, 0x80(%rsp)
pshufd $0x55, %xmm1, %xmm0     # xmm0 = xmm1[1,1,1,1]
movd %xmm0, %eax
leal 0x1(%rax,%rax), %r15d
movslq %r15d, %rbx
leaq (,%rbx,8), %rdi
pshufd $0x50, %xmm1, %xmm0     # xmm0 = xmm1[0,0,1,1]
pcmpgtd 0x75dd(%rip), %xmm0     # 0xd480
movmskpd %xmm0, %r13d
xorl $0x3, %r13d
testb $0x2, %r13b
pushq $-0x1
popq %rbp
cmovneq %rbp, %rdi
callq 0x1030
movq %rax, %r14
movl %ebx, %edi
movq %rax, %rsi
callq 0x1705
movdqa 0x80(%rsp), %xmm0
movd %xmm0, %eax
leal 0x2(%rax), %ecx
movl %ecx, 0xcc(%rsp)
movq %rax, 0x80(%rsp)
movslq %eax, %r12
leaq 0x10(,%r12,8), %rbx
testb $0x1, %r13b
cmovneq %rbp, %rbx
movq %rbx, %rdi
callq 0x1030
movabsq $-0x3fb2000000000000, %rcx # imm = 0xC04E000000000000
movq %rcx, (%rax)
leaq 0x1(%r12), %r13
movq %rax, 0x78(%rsp)
andq $0x0, 0x8(%rax,%r12,8)
movq %rbx, %rdi
callq 0x1030
xorl %ecx, %ecx
cmpq %r12, %rcx
jg 0x5f45
cvtsi2sd %ecx, %xmm0
mulsd 0x750d(%rip), %xmm0     # 0xd448
movsd %xmm0, (%rax,%rcx,8)
incq %rcx
jmp 0x5f2a
movq %rax, 0xd8(%rsp)
movsd 0x58(%rsp), %xmm0
movsd %xmm0, (%rax,%r13,8)
pushq $0x2
popq %rbx
movl 0x1f0(%rsp), %r12d
movl %r12d, %eax
cltd
idivl %ebx
movl %eax, %ebp
cltq
incl %ebp
cmpl $-0x3, %r12d
leaq 0x8(,%rax,8), %rdi
pushq $-0x1
popq %rax
cmovlq %rax, %rdi
callq 0x1030
cvtsi2sd %r12d, %xmm0
xorl %ecx, %ecx
testl %ebp, %ebp
movl $0x0, %esi
movl %ebp, 0xc8(%rsp)
cmovgl %ebp, %esi
cmpq %rcx, %rsi
je 0x5fc0
cvtsi2sd %ecx, %xmm1
mulsd 0xf0(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rax,%rcx,8)
incq %rcx
jmp 0x5fa0
movq %rax, 0xd0(%rsp)
movl 0x48(%rsp), %ecx
movl %ecx, %eax
cltd
idivl %ebx
leal 0x1(%rax), %edi
cmpl $-0x3, %ecx
movslq %eax, %r13
leaq 0x8(,%r13,8), %rdx
pushq $-0x1
popq %rax
cmovlq %rax, %rdx
movq %rdx, 0xa0(%rsp)
xorl %r8d, %r8d
testl %edi, %edi
cmovlel %r8d, %edi
testl %ecx, %ecx
movl $0x0, %edx
cmovgl %ecx, %edx
movq %rdx, 0xe0(%rsp)
testq %r13, %r13
cmovnsq %r13, %rax
incq %rax
movq %rax, 0x108(%rsp)
movsd 0x742a(%rip), %xmm1     # 0xd450
mulsd 0x140(%rsp), %xmm1
cvtsi2sd %r15d, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x100(%rsp)
movl %r15d, %eax
cltd
idivl %ebx
movq 0x80(%rsp), %rcx
testl %ecx, %ecx
cmovlel %r8d, %ecx
movq %rcx, 0x80(%rsp)
movq 0x98(%rsp), %r15
testl %r15d, %r15d
cmovlel %r8d, %r15d
movq %rax, 0x120(%rsp)
leal 0x1(,%rax,2), %r12d
testl %r12d, %r12d
cmovlel %r8d, %r12d
movq %rdi, 0xa8(%rsp)
leaq (,%rdi,8), %rbp
movq 0x1f8(%rsp), %rdx
movq %r15, 0x98(%rsp)
movq %rsi, 0x138(%rsp)
cmpq %r15, %r8
je 0x665c
movq 0x118(%rsp), %rax
movsd (%rax,%r8,8), %xmm0
ucomisd 0x702e(%rip), %xmm0     # 0xd0f8
jne 0x60e7
jp 0x60e7
xorl %eax, %eax
cmpq %rax, %rsi
je 0x6654
movq (%rdx,%r8,8), %rcx
andq $0x0, (%rcx,%rax,8)
incq %rax
jmp 0x60d0
maxsd 0x72b9(%rip), %xmm0     # 0xd3a8
movsd %xmm0, 0x50(%rsp)
movq 0x110(%rsp), %rax
movq %r8, 0xe8(%rsp)
movsd (%rax,%r8,8), %xmm1
movsd %xmm1, 0x58(%rsp)
movq 0xa0(%rsp), %r15
movq %r15, %rdi
callq 0x1030
movq %rax, 0xb8(%rsp)
movq %r15, %rdi
callq 0x1030
movq %rax, 0x70(%rsp)
movq %r15, %rdi
callq 0x1030
movq %rax, 0x68(%rsp)
movq %r15, %rdi
callq 0x1030
movq %rax, %rbx
movq %r15, %rdi
callq 0x1030
movq %rax, %r15
movsd 0x6f7f(%rip), %xmm2     # 0xd0e0
movsd 0x50(%rsp), %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, 0xc0(%rsp)
movsd 0x58(%rsp), %xmm1
subsd %xmm2, %xmm1
movq 0xb0(%rsp), %rdi
movl 0x64(%rsp), %esi
movl 0x4c(%rsp), %edx
movl 0x48(%rsp), %ecx
leaq 0x150(%rsp), %r8
movq %rbx, %r9
callq 0x66a7
movsd 0xc0(%rsp), %xmm1
addsd 0x58(%rsp), %xmm1
movq 0xb0(%rsp), %rdi
movl 0x64(%rsp), %esi
movl 0x4c(%rsp), %edx
movsd 0x50(%rsp), %xmm0
movl 0x48(%rsp), %ecx
leaq 0x150(%rsp), %r8
movq %r15, %r9
callq 0x66a7
movq 0xb8(%rsp), %rdi
xorl %eax, %eax
movq 0xa8(%rsp), %rcx
cmpq %rax, %rcx
je 0x6207
movsd (%rbx,%rax,8), %xmm0
addsd (%r15,%rax,8), %xmm0
movsd %xmm0, (%rdi,%rax,8)
incq %rax
jmp 0x61ed
movsd 0x50(%rsp), %xmm0
movl 0x4c(%rsp), %esi
movl 0x48(%rsp), %edx
movq %rdi, %rcx
callq 0x12f9
movq %rbx, %rdi
callq 0x1110
movq %r15, %rdi
callq 0x1110
movq 0x158(%rsp), %r8
xorl %eax, %eax
movq 0xe0(%rsp), %rcx
movq 0x70(%rsp), %rbx
cmpq %rax, %rcx
je 0x6253
andq $0x0, (%r8,%rax,8)
incq %rax
jmp 0x6244
movq 0xb0(%rsp), %rdi
movl 0x64(%rsp), %esi
movl 0x4c(%rsp), %edx
movsd 0x50(%rsp), %xmm0
movsd 0x58(%rsp), %xmm1
pushq $0x1
popq %rcx
callq 0x68b0
pushq $0x9
popq %rcx
movq %rsp, %rdi
leaq 0x168(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x752b
movq 0x160(%rsp), %rax
addq $0x8, %rax
xorl %ecx, %ecx
movq 0x108(%rsp), %rdx
cmpq %rcx, %rdx
je 0x62cb
movsd -0x8(%rax), %xmm0
movsd (%rax), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rbx,%rcx,8)
incq %rcx
addq $0x10, %rax
jmp 0x62a3
movq %rbx, %rdi
movsd 0x50(%rsp), %xmm0
movl 0x4c(%rsp), %ebx
movl %ebx, %esi
movl 0x48(%rsp), %r15d
movl %r15d, %edx
movq 0x70(%rsp), %rcx
callq 0x12f9
movq 0x70(%rsp), %rdi
movsd 0x50(%rsp), %xmm0
movl %ebx, %esi
movq 0x70(%rsp), %rbx
movl %r15d, %edx
movq %rbx, %rcx
callq 0x1412
xorl %eax, %eax
movq 0xa8(%rsp), %rcx
movq 0xb8(%rsp), %rdx
movq 0x68(%rsp), %rdi
cmpq %rax, %rcx
je 0x6339
movsd (%rdx,%rax,8), %xmm0
divsd (%rbx,%rax,8), %xmm0
movsd %xmm0, (%rdi,%rax,8)
incq %rax
jmp 0x6320
movsd 0x50(%rsp), %xmm0
mulsd 0x6d79(%rip), %xmm0     # 0xd0c0
movl 0x4c(%rsp), %r15d
movl %r15d, %esi
movl 0x48(%rsp), %edx
movq 0x68(%rsp), %rcx
callq 0x1412
movq 0xa0(%rsp), %rdi
callq 0x1030
movq %rax, %rbx
movq 0x68(%rsp), %rdi
movsd 0x50(%rsp), %xmm0
movl %r15d, %esi
movq 0x68(%rsp), %r15
movl 0x48(%rsp), %edx
movq %rax, %rcx
callq 0x1412
movq 0xa8(%rsp), %rcx
xorl %eax, %eax
cmpq %rax, %rcx
je 0x63b1
movsd (%r15,%rax,8), %xmm0
subsd (%rbx,%rax,8), %xmm0
movsd %xmm0, (%r15,%rax,8)
incq %rax
jmp 0x6396
movq %rbx, %rdi
callq 0x1110
movsd 0x100(%rsp), %xmm0
callq 0x419e
movl %eax, %ebx
movq 0xa0(%rsp), %rdi
callq 0x1030
movq %rax, %r15
movq 0x158(%rsp), %rax
xorl %ecx, %ecx
movq 0xe0(%rsp), %rdx
cmpq %rcx, %rdx
je 0x63fa
andq $0x0, (%rax,%rcx,8)
incq %rcx
jmp 0x63eb
leaq (%r15,%r13,8), %rax
movq %rax, 0xc0(%rsp)
leaq (%r15,%r13,8), %rax
addq $0x8, %rax
movq %rax, 0x130(%rsp)
notl %ebx
addl %r13d, %ebx
movslq %ebx, %rax
movq %rax, 0x128(%rsp)
xorl %ebx, %ebx
cmpq 0x80(%rsp), %rbx
je 0x654b
leaq 0x1(%rbx), %rax
movq %rax, 0x58(%rsp)
cvtsi2sd %eax, %xmm0
mulsd 0x6ffd(%rip), %xmm0     # 0xd448
mulsd 0x140(%rsp), %xmm0
divsd 0xf0(%rsp), %xmm0
cvttsd2si %xmm0, %eax
subl 0x120(%rsp), %eax
cltq
movq 0x68(%rsp), %rcx
leaq (%rcx,%rax,8), %rax
movq 0x158(%rsp), %rcx
xorl %edx, %edx
cmpq %rdx, %r12
je 0x6497
movsd (%rax,%rdx,8), %xmm0
mulsd (%r14,%rdx,8), %xmm0
movsd %xmm0, (%rcx,%rdx,8)
incq %rdx
jmp 0x647d
pushq $0x9
popq %rcx
movq %rsp, %rdi
leaq 0x168(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x752b
movq 0x160(%rsp), %rax
xorl %ecx, %ecx
cmpq %rcx, %rbp
je 0x64df
movsd (%rax,%rcx,2), %xmm0
movsd 0x8(%rax,%rcx,2), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%r15,%rcx)
addq $0x8, %rcx
jmp 0x64b7
movq %r15, %rdi
movq 0x130(%rsp), %rsi
callq 0x6b65
pushq $0x1
popq %rax
cmpq %r13, %rax
jg 0x650f
movsd -0x8(%r15,%rax,8), %xmm0
addsd (%r15,%rax,8), %xmm0
movsd %xmm0, (%r15,%rax,8)
incq %rax
jmp 0x64f2
movq 0x128(%rsp), %rax
movsd (%r15,%rax,8), %xmm0
movq 0xc0(%rsp), %rax
divsd (%rax), %xmm0
callq 0x1070
mulsd 0x6f22(%rip), %xmm0     # 0xd458
movq 0x78(%rsp), %rax
movsd %xmm0, 0x8(%rax,%rbx,8)
movq 0x58(%rsp), %rbx
jmp 0x6428
movq %r15, %rdi
callq 0x1110
movsd 0x50(%rsp), %xmm2
addsd 0x6eff(%rip), %xmm2     # 0xd460
divsd 0x6b5f(%rip), %xmm2     # 0xd0c8
xorl %eax, %eax
movq 0xb8(%rsp), %rdi
movq 0x70(%rsp), %rbx
movq 0x68(%rsp), %r15
cmpq %rax, 0x80(%rsp)
je 0x65a9
movq 0x78(%rsp), %rcx
movsd 0x8(%rcx,%rax,8), %xmm0
addsd %xmm2, %xmm0
xorpd %xmm1, %xmm1
minsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rcx,%rax,8)
incq %rax
jmp 0x657d
callq 0x1110
movq %rbx, %rdi
callq 0x1110
movq %r15, %rdi
callq 0x1110
movq 0x1f8(%rsp), %rbx
movq 0xe8(%rsp), %r15
movq (%rbx,%r15,8), %r9
movq 0xd8(%rsp), %rdi
movq 0x78(%rsp), %rsi
movl 0xcc(%rsp), %edx
movq 0xd0(%rsp), %rcx
movl 0xc8(%rsp), %r8d
callq 0x3dbc
movq %r15, %r8
movq %rbx, %rdx
xorl %ebx, %ebx
movq 0x98(%rsp), %r15
movq 0x138(%rsp), %rsi
cmpq %rbx, %rsi
je 0x6654
movq (%rdx,%r8,8), %rax
movsd (%rax,%rbx,8), %xmm1
divsd 0x6e3f(%rip), %xmm1     # 0xd468
movsd 0x6e27(%rip), %xmm0     # 0xd458
callq 0x1190
movq 0xe8(%rsp), %r8
movq 0x1f8(%rsp), %rdx
movq (%rdx,%r8,8), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
jmp 0x660b
incq %r8
jmp 0x60ab
leaq 0x150(%rsp), %rdi
callq 0x1842
movq 0xd8(%rsp), %rdi
callq 0x1110
movq 0x78(%rsp), %rdi
callq 0x1110
movq %r14, %rdi
callq 0x1110
movq 0xd0(%rsp), %rdi
callq 0x1110
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq