// File: Sleepwalking[P]world-octave/dio.cpp
// Function: (anonymous namespace)::GetFilteredSignal(int, int, double (*) [2], int, double*)
void GetFilteredSignal(int half_average_length, int fft_size,
    fft_complex *y_spectrum, int y_length, double *filtered_signal) {
  double *low_pass_filter = new double[fft_size];
  // Nuttall window is used as a low-pass filter.
  // Cutoff frequency depends on the window length.
  NuttallWindow(half_average_length * 4, low_pass_filter);
  for (int i = half_average_length * 4; i < fft_size; ++i)
    low_pass_filter[i] = 0.0;

  fft_complex *low_pass_filter_spectrum = new fft_complex[fft_size];
  fft_plan forwardFFT = fft_plan_dft_r2c_1d(fft_size, low_pass_filter,
      low_pass_filter_spectrum, FFT_ESTIMATE);
  fft_execute(forwardFFT);

  // Convolution
  double tmp = y_spectrum[0][0] * low_pass_filter_spectrum[0][0] -
    y_spectrum[0][1] * low_pass_filter_spectrum[0][1];
  low_pass_filter_spectrum[0][1] =
    y_spectrum[0][0] * low_pass_filter_spectrum[0][1] +
    y_spectrum[0][1] * low_pass_filter_spectrum[0][0];
  low_pass_filter_spectrum[0][0] = tmp;
  for (int i = 1; i <= fft_size / 2; ++i) {
    tmp = y_spectrum[i][0] * low_pass_filter_spectrum[i][0] -
      y_spectrum[i][1] * low_pass_filter_spectrum[i][1];
    low_pass_filter_spectrum[i][1] =
      y_spectrum[i][0] * low_pass_filter_spectrum[i][1] +
      y_spectrum[i][1] * low_pass_filter_spectrum[i][0];
    low_pass_filter_spectrum[i][0] = tmp;
    low_pass_filter_spectrum[fft_size - i - 1][0] =
      low_pass_filter_spectrum[i][0];
    low_pass_filter_spectrum[fft_size - i - 1][1] =
      low_pass_filter_spectrum[i][1];
  }

  fft_plan inverseFFT = fft_plan_dft_c2r_1d(fft_size,
      low_pass_filter_spectrum, filtered_signal, FFT_ESTIMATE);
  fft_execute(inverseFFT);

  // Compensation of the delay.
  int index_bias = half_average_length * 2;
  for (int i = 0; i < y_length; ++i)
    filtered_signal[i] = filtered_signal[i + index_bias];

  fft_destroy_plan(inverseFFT);
  fft_destroy_plan(forwardFFT);
  delete[] low_pass_filter_spectrum;
  delete[] low_pass_filter;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x260, %rsp            # imm = 0x260
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq %r8, -0x20(%rbp)
movslq -0x8(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x1030
movq %rax, -0x28(%rbp)
movl -0x4(%rbp), %edi
shll $0x2, %edi
movq -0x28(%rbp), %rsi
callq 0x1ac0
movl -0x4(%rbp), %eax
shll $0x2, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x3750
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x372d
movslq -0x8(%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, -0x38(%rbp)
movl -0x8(%rbp), %esi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq -0x80(%rbp), %rdi
movl $0x3, %r8d
callq 0xd3b0
leaq -0xc8(%rbp), %rdi
leaq -0x80(%rbp), %rsi
movl $0x48, %edx
callq 0x10b0
movq -0x88(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x40(%rax)
movups -0xc8(%rbp), %xmm0
movups -0xb8(%rbp), %xmm1
movups -0xa8(%rbp), %xmm2
movups -0x98(%rbp), %xmm3
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0xd500
movq -0x10(%rbp), %rax
movsd (%rax), %xmm0
movq -0x38(%rbp), %rax
movsd (%rax), %xmm2
movq -0x10(%rbp), %rax
movsd 0x8(%rax), %xmm1
movq -0x38(%rbp), %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
movsd %xmm0, -0xd0(%rbp)
movq -0x10(%rbp), %rax
movsd (%rax), %xmm0
movq -0x38(%rbp), %rax
movsd 0x8(%rax), %xmm2
movq -0x10(%rbp), %rax
movsd 0x8(%rax), %xmm1
movq -0x38(%rbp), %rax
mulsd (%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq -0x38(%rbp), %rax
movsd %xmm0, 0x8(%rax)
movsd -0xd0(%rbp), %xmm0
movq -0x38(%rbp), %rax
movsd %xmm0, (%rax)
movl $0x1, -0xd4(%rbp)
movl -0xd4(%rbp), %eax
movl %eax, -0x204(%rbp)
movl -0x8(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x204(%rbp), %eax
cmpl %ecx, %eax
jg 0x3a39
movq -0x10(%rbp), %rax
movslq -0xd4(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movq -0x38(%rbp), %rax
movslq -0xd4(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm2
movq -0x10(%rbp), %rax
movslq -0xd4(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm1
movq -0x38(%rbp), %rax
movslq -0xd4(%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
movsd %xmm0, -0xd0(%rbp)
movq -0x10(%rbp), %rax
movslq -0xd4(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movq -0x38(%rbp), %rax
movslq -0xd4(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm2
movq -0x10(%rbp), %rax
movslq -0xd4(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm1
movq -0x38(%rbp), %rax
movslq -0xd4(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
mulsd (%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq -0x38(%rbp), %rax
movslq -0xd4(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movsd -0xd0(%rbp), %xmm0
movq -0x38(%rbp), %rax
movslq -0xd4(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, (%rax)
movq -0x38(%rbp), %rax
movslq -0xd4(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movq -0x38(%rbp), %rax
movl -0x8(%rbp), %ecx
subl -0xd4(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, (%rax)
movq -0x38(%rbp), %rax
movslq -0xd4(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movq -0x38(%rbp), %rax
movl -0x8(%rbp), %ecx
subl -0xd4(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movl -0xd4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd4(%rbp)
jmp 0x387c
movl -0x8(%rbp), %esi
movq -0x38(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq -0x120(%rbp), %rdi
movl $0x3, %r8d
callq 0xd150
leaq -0x168(%rbp), %rdi
leaq -0x120(%rbp), %rsi
movl $0x48, %edx
callq 0x10b0
movq -0x128(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x40(%rax)
movups -0x168(%rbp), %xmm0
movups -0x158(%rbp), %xmm1
movups -0x148(%rbp), %xmm2
movups -0x138(%rbp), %xmm3
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0xd500
movl -0x4(%rbp), %eax
shll %eax
movl %eax, -0x16c(%rbp)
movl $0x0, -0x170(%rbp)
movl -0x170(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x3b05
movq -0x20(%rbp), %rax
movl -0x170(%rbp), %ecx
addl -0x16c(%rbp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x20(%rbp), %rax
movslq -0x170(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x170(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x170(%rbp)
jmp 0x3ac1
leaq -0x1b8(%rbp), %rdi
leaq -0x120(%rbp), %rsi
movl $0x48, %edx
callq 0x10b0
movq -0x178(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x40(%rax)
movups -0x1b8(%rbp), %xmm0
movups -0x1a8(%rbp), %xmm1
movups -0x198(%rbp), %xmm2
movups -0x188(%rbp), %xmm3
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0xda70
leaq -0x200(%rbp), %rdi
leaq -0x80(%rbp), %rsi
movl $0x48, %edx
callq 0x10b0
movq -0x1c0(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x40(%rax)
movups -0x200(%rbp), %xmm0
movups -0x1f0(%rbp), %xmm1
movups -0x1e0(%rbp), %xmm2
movups -0x1d0(%rbp), %xmm3
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0xda70
movq -0x38(%rbp), %rax
movq %rax, -0x210(%rbp)
cmpq $0x0, %rax
je 0x3bcb
movq -0x210(%rbp), %rdi
callq 0x1110
movq -0x28(%rbp), %rax
movq %rax, -0x218(%rbp)
cmpq $0x0, %rax
je 0x3be8
movq -0x218(%rbp), %rdi
callq 0x1110
addq $0x260, %rsp            # imm = 0x260
popq %rbp
retq
nopw %cs:(%rax,%rax)