// File: /workspace/github_cpp_makefile_star2_O2/Sleepwalking[P]world-octave/common.cpp
// Function: LinearSmoothing(double*, double, int, int, double*)
void LinearSmoothing(double *input, double width, int fs, int fft_size,
    double *output) {
  int boundary = static_cast<int>(width * fft_size / fs) + 1;

  // These parameters are set by the other function.
  double *mirroring_spectrum = new double[fft_size / 2 + boundary * 2 + 1];
  double *mirroring_segment = new double[fft_size / 2 + boundary * 2 + 1];
  double *frequency_axis = new double[fft_size / 2 + 1];
  SetParametersForLinearSmoothing(boundary, fft_size, fs, width,
      input, mirroring_spectrum, mirroring_segment, frequency_axis);

  double *low_levels = new double[fft_size / 2 + 1];
  double *high_levels = new double[fft_size / 2 + 1];
  double origin_of_mirroring_axis =
    -(static_cast<double>(boundary) - 0.5) * fs / fft_size;
  double discrete_frequency_interval = static_cast<double>(fs) / fft_size;

  interp1Q(origin_of_mirroring_axis, discrete_frequency_interval,
      mirroring_segment, fft_size / 2 + boundary * 2 + 1, frequency_axis,
      fft_size / 2 + 1, low_levels);

  for (int i = 0; i <= fft_size / 2; ++i) frequency_axis[i] += width;

  interp1Q(origin_of_mirroring_axis, discrete_frequency_interval,
      mirroring_segment, fft_size / 2 + boundary * 2 + 1, frequency_axis,
      fft_size / 2 + 1, high_levels);

  for (int i = 0; i <= fft_size / 2; ++i)
    output[i] = (high_levels[i] - low_levels[i]) / width;

  delete[] mirroring_spectrum;
  delete[] mirroring_segment;
  delete[] frequency_axis;
  delete[] low_levels;
  delete[] high_levels;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, 0x50(%rsp)
cvtsi2sd %edx, %xmm1
movl %edx, %eax
movl %edx, 0x10(%rsp)
movsd %xmm1, 0x30(%rsp)
cvtsi2sd %esi, %xmm2
movsd %xmm0, 0x18(%rsp)
mulsd %xmm0, %xmm1
movsd %xmm2, 0x8(%rsp)
divsd %xmm2, %xmm1
cvttsd2si %xmm1, %esi
movq %rdi, %rbp
leal 0x1(%rsi), %ecx
movq %rcx, 0x20(%rsp)
pushq $0x2
popq %rcx
cltd
idivl %ecx
movl %eax, %r12d
movl %eax, %ebx
movq %rsi, 0x38(%rsp)
leal (%r12,%rsi,2), %ecx
addl $0x2, %ecx
leal 0x3(%r12,%rsi,2), %eax
movl %eax, 0x4(%rsp)
movq %rcx, 0x40(%rsp)
movslq %ecx, %r13
cmpl $-0x1, %r13d
leaq 0x8(,%r13,8), %r15
pushq $-0x1
popq %rax
cmovlq %rax, %r15
movq %r15, %rdi
callq 0x1030
movq %rax, %r14
movq %r15, %rdi
callq 0x1030
movq %rax, %r15
leal 0x1(%r12), %eax
movl %eax, (%rsp)
movq %r12, 0x48(%rsp)
movslq %r12d, %rax
cmpl $-0x3, 0x10(%rsp)
leaq 0x8(,%rax,8), %rdi
pushq $-0x1
popq %rax
cmovlq %rax, %rdi
movq %rdi, 0x10(%rsp)
callq 0x1030
movq %rax, %r12
movslq 0x20(%rsp), %rax
xorl %ecx, %ecx
testl %eax, %eax
movl $0x0, %edx
cmovgl %eax, %edx
movslq 0x38(%rsp), %rsi
leaq 0x8(,%rsi,8), %rsi
addq %rbp, %rsi
cmpq %rcx, %rdx
je 0x1517
movsd (%rsi), %xmm0
movsd %xmm0, (%r14,%rcx,8)
incq %rcx
addq $-0x8, %rsi
jmp 0x14ff
movq 0x20(%rsp), %rcx
movq 0x48(%rsp), %rsi
addl %esi, %ecx
movslq %ecx, %rcx
movq %rbp, %rdx
movsd 0x18(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
movsd 0x30(%rsp), %xmm3
cmpq %rcx, %rax
jge 0x1567
movsd (%rdx), %xmm0
movsd %xmm0, (%r14,%rax,8)
incq %rax
addq $0x8, %rdx
jmp 0x153b
movslq %ebx, %rbx
movsd (%rbp,%rbx,8), %xmm0
movsd %xmm0, (%r14,%rcx,8)
incq %rcx
decl %ebx
cmpq %r13, %rcx
jle 0x1553
movsd (%r14), %xmm0
mulsd %xmm2, %xmm0
divsd %xmm3, %xmm0
movsd %xmm0, (%r15)
xorl %eax, %eax
movq 0x40(%rsp), %rcx
testl %ecx, %ecx
cmovlel %eax, %ecx
cmpq %rax, %rcx
je 0x15b0
movsd 0x8(%r14,%rax,8), %xmm0
mulsd %xmm2, %xmm0
divsd %xmm3, %xmm0
addsd (%r15,%rax,8), %xmm0
movsd %xmm0, 0x8(%r15,%rax,8)
incq %rax
jmp 0x158a
movsd 0xba68(%rip), %xmm0     # 0xd020
mulsd %xmm1, %xmm0
testl %esi, %esi
pushq $-0x1
popq %rax
cmovnsl %esi, %eax
incl %eax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x15e8
cvtsi2sd %ecx, %xmm1
divsd %xmm3, %xmm1
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%r12,%rcx,8)
incq %rcx
jmp 0x15c8
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x1030
movq %rax, %r13
movq %rbx, %rdi
callq 0x1030
cvtsi2sdl 0x20(%rsp), %xmm0
addsd 0xba12(%rip), %xmm0     # 0xd020
xorpd 0xba4a(%rip), %xmm0     # 0xd060
movq %rax, %rbp
movsd 0x8(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x30(%rsp), %xmm2
divsd %xmm2, %xmm0
divsd %xmm2, %xmm1
movapd %xmm0, 0x20(%rsp)
movsd %xmm1, 0x8(%rsp)
movq %r15, %rdi
movl 0x4(%rsp), %esi
movq %r12, %rdx
movl (%rsp), %ebx
movl %ebx, %ecx
movq %r13, %r8
callq 0x41e4
xorl %eax, %eax
testl %ebx, %ebx
movl %ebx, %ecx
movl $0x0, %ebx
cmovgl %ecx, %ebx
movsd 0x18(%rsp), %xmm1
cmpq %rax, %rbx
je 0x1682
movsd (%r12,%rax,8), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%r12,%rax,8)
incq %rax
jmp 0x1668
movaps 0x20(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movq %r15, %rdi
movl 0x4(%rsp), %esi
movq %r12, %rdx
movl (%rsp), %ecx
movq %rbp, %r8
callq 0x41e4
movsd 0x18(%rsp), %xmm1
xorl %eax, %eax
movq 0x50(%rsp), %rcx
cmpq %rax, %rbx
je 0x16cf
movsd (%rbp,%rax,8), %xmm0
subsd (%r13,%rax,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rcx,%rax,8)
incq %rax
jmp 0x16af
movq %r14, %rdi
callq 0x1110
movq %r15, %rdi
callq 0x1110
movq %r12, %rdi
callq 0x1110
movq %r13, %rdi
callq 0x1110
movq %rbp, %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1110