// File: /workspace/github_cpp_makefile_star2_O2/Sleepwalking[P]world-octave/matlabfunctions.cpp
// Function: fast_fftfilt(double*, int, double*, int, int, ForwardRealFFT*, InverseRealFFT*, double*)
void fast_fftfilt(double *x, int x_length, double *h, int h_length,
    int fft_size, ForwardRealFFT *forward_real_fft,
    InverseRealFFT *inverse_real_fft, double *y) {
  fft_complex *x_spectrum = new fft_complex[fft_size];

  for (int i = 0; i < x_length; ++i)
    forward_real_fft->waveform[i] = x[i] / fft_size;
  for (int i = x_length; i < fft_size; ++i)
    forward_real_fft->waveform[i] = 0.0;
  fft_execute(forward_real_fft->forward_fft);
  for (int i = 0; i <= fft_size / 2; ++i) {
    x_spectrum[i][0] = forward_real_fft->spectrum[i][0];
    x_spectrum[i][1] = forward_real_fft->spectrum[i][1];
  }

  for (int i = 0; i < h_length; ++i)
    forward_real_fft->waveform[i] = h[i] / fft_size;
  for (int i = h_length; i < fft_size; ++i)
    forward_real_fft->waveform[i] = 0.0;
  fft_execute(forward_real_fft->forward_fft);

  for (int i = 0; i <= fft_size / 2; ++i) {
    inverse_real_fft->spectrum[i][0] =
      x_spectrum[i][0] * forward_real_fft->spectrum[i][0] -
      x_spectrum[i][1] * forward_real_fft->spectrum[i][1];
    inverse_real_fft->spectrum[i][1] =
      x_spectrum[i][0] * forward_real_fft->spectrum[i][1] +
      x_spectrum[i][1] * forward_real_fft->spectrum[i][0];
  }
  fft_execute(inverse_real_fft->inverse_fft);

  for (int i = 0; i < fft_size; ++i)
    y[i] = inverse_real_fft->waveform[i];

  delete[] x_spectrum;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r9, %r15
movl %r8d, %ebx
movl %ecx, 0x54(%rsp)
movq %rdx, %r12
movl %esi, %r14d
movq %rdi, %rbp
movq 0xb8(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0xb0(%rsp), %r13
movl %r8d, %eax
shlq $0x4, %rax
testl %r8d, %r8d
pushq $-0x1
popq %rdi
cmovnsq %rax, %rdi
callq 0x1030
movl %r14d, %esi
movq %rax, %r14
cvtsi2sd %ebx, %xmm1
xorl %eax, %eax
testl %esi, %esi
movl $0x0, %ecx
cmovgl %esi, %ecx
cmpq %rax, %rcx
je 0x4418
movsd (%rbp,%rax,8), %xmm0
divsd %xmm1, %xmm0
movq 0x8(%r15), %rdx
movsd %xmm0, (%rdx,%rax,8)
incq %rax
jmp 0x43fb
movslq %esi, %rax
movq %rbx, 0x58(%rsp)
movslq %ebx, %rbx
cmpq %rbx, %rax
jge 0x4436
movq 0x8(%r15), %rcx
andq $0x0, (%rcx,%rax,8)
incq %rax
jmp 0x4423
leaq 0x18(%r15), %rsi
pushq $0x9
popq %rcx
movq %rsp, %rdi
movq %rsi, 0x60(%rsp)
rep  movsq (%rsi), %es:(%rdi)
movsd %xmm1, 0x68(%rsp)
callq 0x752b
movsd 0x68(%rsp), %xmm1
pushq $0x2
popq %rcx
movq 0x58(%rsp), %rax
cltd
idivl %ecx
testl %eax, %eax
pushq $-0x1
popq %rbp
cmovnsl %eax, %ebp
incl %ebp
shlq $0x4, %rbp
xorl %eax, %eax
movl 0x54(%rsp), %esi
cmpq %rax, %rbp
je 0x449f
movq 0x10(%r15), %rcx
movsd (%rcx,%rax), %xmm0
movsd %xmm0, (%r14,%rax)
movsd 0x8(%rcx,%rax), %xmm0
movsd %xmm0, 0x8(%r14,%rax)
addq $0x10, %rax
jmp 0x4478
xorl %eax, %eax
testl %esi, %esi
movl $0x0, %ecx
cmovgl %esi, %ecx
cmpq %rax, %rcx
je 0x44c8
movsd (%r12,%rax,8), %xmm0
divsd %xmm1, %xmm0
movq 0x8(%r15), %rdx
movsd %xmm0, (%rdx,%rax,8)
incq %rax
jmp 0x44ab
movslq %esi, %rax
cmpq %rbx, %rax
jge 0x44de
movq 0x8(%r15), %rcx
andq $0x0, (%rcx,%rax,8)
incq %rax
jmp 0x44cb
pushq $0x9
popq %rcx
movq %rsp, %rdi
movq 0x60(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x752b
xorl %eax, %eax
movq 0x58(%rsp), %rbx
cmpq %rax, %rbp
je 0x4549
movq 0x10(%r15), %rcx
movsd (%r14,%rax), %xmm0
movsd 0x8(%r14,%rax), %xmm1
movsd 0x8(%rcx,%rax), %xmm2
mulsd %xmm1, %xmm2
movsd (%rcx,%rax), %xmm3
mulsd %xmm0, %xmm3
subsd %xmm2, %xmm3
movq 0x10(%r13), %rdx
movsd %xmm3, (%rdx,%rax)
mulsd (%rcx,%rax), %xmm1
mulsd 0x8(%rcx,%rax), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rdx,%rax)
addq $0x10, %rax
jmp 0x44f8
leaq 0x18(%r13), %rsi
pushq $0x9
popq %rcx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
callq 0x752b
xorl %eax, %eax
testl %ebx, %ebx
cmovlel %eax, %ebx
movq 0x70(%rsp), %rdx
cmpq %rax, %rbx
je 0x457f
movq 0x8(%r13), %rcx
movsd (%rcx,%rax,8), %xmm0
movsd %xmm0, (%rdx,%rax,8)
incq %rax
jmp 0x4567
movq %r14, %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1110