// File: 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
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movslq -0x20(%rbp), %rax
movl $0x10, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x1030
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x7713
movq -0x8(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
cvtsi2sdl -0x20(%rbp), %xmm1
divsd %xmm1, %xmm0
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x34(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x76d9
movl -0xc(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x7740
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x38(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x7719
movq -0x28(%rbp), %rsi
addq $0x18, %rsi
leaq -0x80(%rbp), %rdi
movl $0x48, %edx
callq 0x10b0
movq -0x40(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x40(%rax)
movups -0x80(%rbp), %xmm0
movups -0x70(%rbp), %xmm1
movups -0x60(%rbp), %xmm2
movups -0x50(%rbp), %xmm3
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0xd500
movl $0x0, -0x84(%rbp)
movl -0x84(%rbp), %eax
movl %eax, -0x130(%rbp)
movl -0x20(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x130(%rbp), %eax
cmpl %ecx, %eax
jg 0x7828
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x84(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movq -0x30(%rbp), %rax
movslq -0x84(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, (%rax)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x84(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movq -0x30(%rbp), %rax
movslq -0x84(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x778f
movl $0x0, -0x88(%rbp)
movl -0x88(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x787b
movq -0x18(%rbp), %rax
movslq -0x88(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
cvtsi2sdl -0x20(%rbp), %xmm1
divsd %xmm1, %xmm0
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x88(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x7832
movl -0x1c(%rbp), %eax
movl %eax, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x78b7
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x8c(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x7884
movq -0x28(%rbp), %rsi
addq $0x18, %rsi
leaq -0xd8(%rbp), %rdi
movl $0x48, %edx
callq 0x10b0
movq -0x98(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x40(%rax)
movups -0xd8(%rbp), %xmm0
movups -0xc8(%rbp), %xmm1
movups -0xb8(%rbp), %xmm2
movups -0xa8(%rbp), %xmm3
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0xd500
movl $0x0, -0xdc(%rbp)
movl -0xdc(%rbp), %eax
movl %eax, -0x134(%rbp)
movl -0x20(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x134(%rbp), %eax
cmpl %ecx, %eax
jg 0x7a73
movq -0x30(%rbp), %rax
movslq -0xdc(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xdc(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm2
movq -0x30(%rbp), %rax
movslq -0xdc(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm1
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xdc(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
mulsd 0x8(%rax), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xdc(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, (%rax)
movq -0x30(%rbp), %rax
movslq -0xdc(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xdc(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm2
movq -0x30(%rbp), %rax
movslq -0xdc(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm1
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xdc(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
mulsd (%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xdc(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movl -0xdc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xdc(%rbp)
jmp 0x7918
movq 0x10(%rbp), %rsi
addq $0x18, %rsi
leaq -0x128(%rbp), %rdi
movl $0x48, %edx
callq 0x10b0
movq -0xe8(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x40(%rax)
movups -0x128(%rbp), %xmm0
movups -0x118(%rbp), %xmm1
movups -0x108(%rbp), %xmm2
movups -0xf8(%rbp), %xmm3
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0xd500
movl $0x0, -0x12c(%rbp)
movl -0x12c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x7b14
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x12c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x18(%rbp), %rax
movslq -0x12c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x12c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x12c(%rbp)
jmp 0x7ad4
movq -0x30(%rbp), %rax
movq %rax, -0x140(%rbp)
cmpq $0x0, %rax
je 0x7b31
movq -0x140(%rbp), %rdi
callq 0x1110
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
nopw (%rax,%rax)