// File: Sleepwalking[P]world-octave/cheaptrick.cpp
// Function: CheapTrick(double*, int, int, double*, double*, int, double**)
void CheapTrick(double *x, int x_length, int fs, double *time_axis, double *f0,
    int f0_length, double **spectrogram) {
  int fft_size = GetFFTSizeForCheapTrick(fs);
  double *spectral_envelope = new double[fft_size];

  ForwardRealFFT forward_real_fft = {0};
  InitializeForwardRealFFT(fft_size, &forward_real_fft);
  InverseRealFFT inverse_real_fft = {0};
  InitializeInverseRealFFT(fft_size, &inverse_real_fft);

  double current_f0;
  for (int i = 0; i < f0_length; ++i) {
    current_f0 = f0[i] <= world::kFloorF0 ? world::kDefaultF0 : f0[i];
    CheapTrickGeneralBody(x, x_length, fs, current_f0, fft_size,
        time_axis[i], &forward_real_fft, &inverse_real_fft, spectral_envelope);
    for (int j = 0; j <= fft_size / 2; ++j)
      spectrogram[i][j] = spectral_envelope[j];
  }

  DestroyForwardRealFFT(&forward_real_fft);
  DestroyInverseRealFFT(&inverse_real_fft);
  delete[] spectral_envelope;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
movl -0x10(%rbp), %edi
callq 0x84a0
movl %eax, -0x28(%rbp)
movslq -0x28(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x1030
movq %rax, -0x30(%rbp)
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
movl $0x60, %edx
callq 0x1080
movl -0x28(%rbp), %edi
leaq -0x90(%rbp), %rsi
callq 0x1ba0
leaq -0xf0(%rbp), %rdi
xorl %esi, %esi
movl $0x60, %edx
callq 0x1080
movl -0x28(%rbp), %edi
leaq -0xf0(%rbp), %rsi
callq 0x1d00
movl $0x0, -0xfc(%rbp)
movl -0xfc(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x86da
movq -0x20(%rbp), %rax
movslq -0xfc(%rbp), %rcx
movsd 0x13ab7(%rip), %xmm0    # 0x1c090
ucomisd (%rax,%rcx,8), %xmm0
jb 0x85f2
movsd 0x13b08(%rip), %xmm0    # 0x1c0f0
movsd %xmm0, -0x108(%rbp)
jmp 0x860a
movq -0x20(%rbp), %rax
movslq -0xfc(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x108(%rbp)
movsd -0x108(%rbp), %xmm0
movsd %xmm0, -0xf8(%rbp)
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movsd -0xf8(%rbp), %xmm0
movl -0x28(%rbp), %ecx
movq -0x18(%rbp), %rax
movslq -0xfc(%rbp), %r8
movsd (%rax,%r8,8), %xmm1
movq -0x30(%rbp), %rax
leaq -0x90(%rbp), %r8
leaq -0xf0(%rbp), %r9
movq %rax, (%rsp)
callq 0x8720
movl $0x0, -0x100(%rbp)
movl -0x100(%rbp), %eax
movl %eax, -0x10c(%rbp)
movl -0x28(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x10c(%rbp), %eax
cmpl %ecx, %eax
jg 0x86c4
movq -0x30(%rbp), %rax
movslq -0x100(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x10(%rbp), %rax
movslq -0xfc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x100(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x100(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x100(%rbp)
jmp 0x8665
jmp 0x86c6
movl -0xfc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xfc(%rbp)
jmp 0x85b7
leaq -0x90(%rbp), %rdi
callq 0x1c60
leaq -0xf0(%rbp), %rdi
callq 0x1dc0
movq -0x30(%rbp), %rax
movq %rax, -0x118(%rbp)
cmpq $0x0, %rax
je 0x870f
movq -0x118(%rbp), %rdi
callq 0x1110
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopl (%rax,%rax)