// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
movq %r9, 0x48(%rsp)
movl %r8d, %ebx
movq %rcx, 0x58(%rsp)
movq %rdx, %r13
movl %esi, %ebp
movq %rdi, %r15
movq 0xa8(%rsp), %r12
movq 0xa0(%rsp), %rax
movq %rax, 0x60(%rsp)
movslq %r8d, %rax
movq %rax, %rcx
shlq $0x4, %rcx
testl %eax, %eax
movq $-0x1, %rdi
cmovnsq %rcx, %rdi
callq 0x1030
movq %rax, %r14
cvtsi2sd %ebx, %xmm1
testl %ebp, %ebp
jle 0x487c
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movl %ebp, %ecx
xorl %edx, %edx
movsd (%r15,%rdx,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rdx,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x4865
movsd %xmm1, 0x50(%rsp)
cmpl %ebx, %ebp
jge 0x48a9
movslq %ebp, %rdi
shlq $0x3, %rdi
movq 0x48(%rsp), %rax
addq 0x8(%rax), %rdi
notl %ebp
addl %ebx, %ebp
leaq 0x8(,%rbp,8), %rdx
xorl %esi, %esi
callq 0x1080
movq 0x48(%rsp), %rax
leaq 0x18(%rax), %rbp
movl $0x9, %ecx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x7f1a
movl %ebx, %r15d
shrl $0x1f, %r15d
addl %ebx, %r15d
sarl %r15d
cmpl $-0x1, %ebx
jl 0x490b
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rax
leal 0x1(%r15), %ecx
shlq $0x4, %rcx
xorl %edx, %edx
movsd (%rax,%rdx), %xmm0
movsd %xmm0, (%r14,%rdx)
movsd 0x8(%rax,%rdx), %xmm0
movsd %xmm0, 0x8(%r14,%rdx)
addq $0x10, %rdx
cmpq %rdx, %rcx
jne 0x48ea
movq 0x58(%rsp), %rsi
testl %esi, %esi
movsd 0x50(%rsp), %xmm1
jle 0x493f
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movl %esi, %ecx
xorl %edx, %edx
movsd (%r13,%rdx,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rdx,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x4927
cmpl %ebx, %esi
jge 0x4966
movslq %esi, %rdi
shlq $0x3, %rdi
movq 0x48(%rsp), %rax
addq 0x8(%rax), %rdi
notl %esi
addl %ebx, %esi
leaq 0x8(,%rsi,8), %rdx
xorl %esi, %esi
callq 0x1080
movl $0x9, %ecx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x7f1a
cmpl $-0x1, %ebx
movq 0x60(%rsp), %r13
jl 0x49e9
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%r13), %rcx
movl %r15d, %edx
shlq $0x4, %rdx
addq $0x10, %rdx
xorl %esi, %esi
movsd (%r14,%rsi), %xmm0
movsd 0x8(%rax,%rsi), %xmm1
mulsd 0x8(%r14,%rsi), %xmm1
mulsd (%rax,%rsi), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rcx,%rsi)
movsd (%r14,%rsi), %xmm0
movsd 0x8(%r14,%rsi), %xmm1
mulsd (%rax,%rsi), %xmm1
mulsd 0x8(%rax,%rsi), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rcx,%rsi)
addq $0x10, %rsi
cmpq %rsi, %rdx
jne 0x499d
leaq 0x18(%r13), %rsi
movl $0x9, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
callq 0x7f1a
testl %ebx, %ebx
jle 0x4a1c
movq 0x8(%r13), %rax
movl %ebx, %ecx
xorl %edx, %edx
movsd (%rax,%rdx,8), %xmm0
movsd %xmm0, (%r12,%rdx,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x4a09
movq %r14, %rdi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1110