// File: /workspace/github_cpp_makefile_star2_O3/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, 0x48(%rsp)
movl %r8d, %r15d
movq %rcx, 0x60(%rsp)
movq %rdx, %r12
movl %esi, %r13d
movq %rdi, %r14
movq 0xb8(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x68(%rsp)
movl %r8d, %ebp
movq %rbp, %rax
shlq $0x4, %rax
testl %r8d, %r8d
movq $-0x1, %rdi
cmovnsq %rax, %rdi
callq 0x1030
movq %rax, %rbx
movl %r15d, 0x54(%rsp)
cvtsi2sd %r15d, %xmm1
testl %r13d, %r13d
jle 0x4e52
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movl %r13d, %ecx
xorl %edx, %edx
movsd (%r14,%rdx,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rdx,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x4e3b
movsd %xmm1, 0x58(%rsp)
movl 0x54(%rsp), %r15d
cmpl %r15d, %r13d
jge 0x4e87
movslq %r13d, %rdi
shlq $0x3, %rdi
movq 0x48(%rsp), %rax
addq 0x8(%rax), %rdi
notl %r13d
addl %r15d, %r13d
leaq 0x8(,%r13,8), %rdx
xorl %esi, %esi
callq 0x1080
movq 0x48(%rsp), %rax
leaq 0x18(%rax), %r13
movl $0x9, %ecx
movq %rsp, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x8792
movl %r15d, %r14d
shrl $0x1f, %r14d
addl %r15d, %r14d
sarl %r14d
cmpl $-0x1, %r15d
jl 0x4ee8
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rax
leal 0x1(%r14), %ecx
shlq $0x4, %rcx
xorl %edx, %edx
movsd (%rax,%rdx), %xmm0
movsd %xmm0, (%rbx,%rdx)
movsd 0x8(%rax,%rdx), %xmm0
movsd %xmm0, 0x8(%rbx,%rdx)
addq $0x10, %rdx
cmpq %rdx, %rcx
jne 0x4ec9
movq 0x60(%rsp), %rsi
testl %esi, %esi
movsd 0x58(%rsp), %xmm1
jle 0x4f1b
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movl %esi, %ecx
xorl %edx, %edx
movsd (%r12,%rdx,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rdx,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x4f04
movl 0x54(%rsp), %r15d
cmpl %r15d, %esi
jge 0x4f49
movslq %esi, %rdi
shlq $0x3, %rdi
movq 0x48(%rsp), %rax
addq 0x8(%rax), %rdi
notl %esi
addl %r15d, %esi
leaq 0x8(,%rsi,8), %rdx
xorl %esi, %esi
callq 0x1080
movl $0x9, %ecx
movq %rsp, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x8792
cmpl $-0x1, %r15d
movq 0x68(%rsp), %r12
jl 0x4fc7
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%r12), %rcx
movl %r14d, %edx
shlq $0x4, %rdx
addq $0x10, %rdx
xorl %esi, %esi
movsd (%rbx,%rsi), %xmm0
movsd 0x8(%rbx,%rsi), %xmm1
movsd 0x8(%rax,%rsi), %xmm2
mulsd %xmm1, %xmm2
movsd (%rax,%rsi), %xmm3
mulsd %xmm0, %xmm3
subsd %xmm2, %xmm3
movsd %xmm3, (%rcx,%rsi)
mulsd (%rax,%rsi), %xmm1
mulsd 0x8(%rax,%rsi), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rcx,%rsi)
addq $0x10, %rsi
cmpq %rsi, %rdx
jne 0x4f82
leaq 0x18(%r12), %rsi
movl $0x9, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
callq 0x8792
testl %r15d, %r15d
movq 0x70(%rsp), %rdx
jle 0x4fff
movq 0x8(%r12), %rax
xorl %ecx, %ecx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rdx,%rcx,8)
incq %rcx
cmpq %rcx, %rbp
jne 0x4fed
movq %rbx, %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1110