// File: Sleepwalking[P]world-octave/common.cpp
// Function: GetMinimumPhaseSpectrum(MinimumPhaseAnalysis*)
void GetMinimumPhaseSpectrum(MinimumPhaseAnalysis *minimum_phase) {
  // Mirroring
  for (int i = minimum_phase->fft_size / 2 + 1;
      i < minimum_phase->fft_size; ++i)
    minimum_phase->log_spectrum[i] =
    minimum_phase->log_spectrum[minimum_phase->fft_size - i];

  // This fft_plan carries out "forward" FFT.
  // To carriy out the Inverse FFT, the sign of imaginary part
  // is inverted after FFT.
  fft_execute(minimum_phase->inverse_fft);
  minimum_phase->cepstrum[0][1] *= -1.0;
  for (int i = 1; i < minimum_phase->fft_size / 2; ++i) {
    minimum_phase->cepstrum[i][0] *= 2.0;
    minimum_phase->cepstrum[i][1] *= -2.0;
  }
  minimum_phase->cepstrum[minimum_phase->fft_size / 2][1] *= -1.0;
  for (int i = minimum_phase->fft_size / 2 + 1;
      i < minimum_phase->fft_size; ++i) {
    minimum_phase->cepstrum[i][0] = 0.0;
    minimum_phase->cepstrum[i][1] = 0.0;
  }

  fft_execute(minimum_phase->forward_fft);

  // Since x is complex number, calculation of exp(x) is as following.
  // Note: This FFT library does not keep the aliasing.
  double tmp;
  for (int i = 0; i <= minimum_phase->fft_size / 2; ++i) {
    tmp = exp(minimum_phase->minimum_phase_spectrum[i][0] /
      minimum_phase->fft_size);
    minimum_phase->minimum_phase_spectrum[i][0] = tmp *
      cos(minimum_phase->minimum_phase_spectrum[i][1] /
      minimum_phase->fft_size);
    minimum_phase->minimum_phase_spectrum[i][1] = tmp *
      sin(minimum_phase->minimum_phase_spectrum[i][1] /
      minimum_phase->fft_size);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
addl $0x1, %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x1ff3
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movl (%rcx), %ecx
subl -0xc(%rbp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0xc(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x1fb3
movq -0x8(%rbp), %rsi
addq $0x20, %rsi
leaq -0x58(%rbp), %rdi
movl $0x48, %edx
callq 0x10b0
movq -0x18(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x40(%rax)
movups -0x58(%rbp), %xmm0
movups -0x48(%rbp), %xmm1
movups -0x38(%rbp), %xmm2
movups -0x28(%rbp), %xmm3
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0xd500
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movsd 0x1a020(%rip), %xmm0    # 0x1c068
mulsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%rax)
movl $0x1, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0xb8(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0xb8(%rbp), %eax
cmpl %ecx, %eax
jge 0x20cf
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x5c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x19f71(%rip), %xmm0    # 0x1c008
mulsd (%rax), %xmm0
movsd %xmm0, (%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x5c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x19fb6(%rip), %xmm0    # 0x1c070
mulsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%rax)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x2059
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0xc0(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0xc0(%rbp), %rax
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x19f61(%rip), %xmm0    # 0x1c068
mulsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%rax)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
addl $0x1, %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x2170
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x60(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x60(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x8(%rax)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x2125
movq -0x8(%rbp), %rsi
addq $0x68, %rsi
leaq -0xa8(%rbp), %rdi
movl $0x48, %edx
callq 0x10b0
movq -0x68(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x40(%rax)
movups -0xa8(%rbp), %xmm0
movups -0x98(%rbp), %xmm1
movups -0x88(%rbp), %xmm2
movups -0x78(%rbp), %xmm3
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0xd500
movl $0x0, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
movl %eax, -0xc4(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0xc4(%rbp), %eax
cmpl %ecx, %eax
jg 0x2307
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xb4(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movq -0x8(%rbp), %rax
cvtsi2sdl (%rax), %xmm1
divsd %xmm1, %xmm0
callq 0x1190
movsd %xmm0, -0xb0(%rbp)
movsd -0xb0(%rbp), %xmm0
movsd %xmm0, -0xd8(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xb4(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movq -0x8(%rbp), %rax
cvtsi2sdl (%rax), %xmm1
divsd %xmm1, %xmm0
callq 0x11a0
movaps %xmm0, %xmm1
movsd -0xd8(%rbp), %xmm0
mulsd %xmm1, %xmm0
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xb4(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, (%rax)
movsd -0xb0(%rbp), %xmm0
movsd %xmm0, -0xd0(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xb4(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movq -0x8(%rbp), %rax
cvtsi2sdl (%rax), %xmm1
divsd %xmm1, %xmm0
callq 0x1060
movaps %xmm0, %xmm1
movsd -0xd0(%rbp), %xmm0
mulsd %xmm1, %xmm0
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xb4(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x21cb
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq