// File: /workspace/github_cpp_makefile_star2_O1/Sleepwalking[P]world-octave/d4c.cpp
// Function: (anonymous namespace)::GetWindowedWaveform(double*, int, int, double, double, int, double, double*)
void GetWindowedWaveform(double *x, int x_length, int fs, double current_f0,
    double temporal_position, int window_type, double window_length_ratio,
    double *waveform) {
  int half_window_length =
    matlab_round(window_length_ratio * fs / current_f0 / 2.0);

  int *base_index = new int[half_window_length * 2 + 1];
  int *index = new int[half_window_length * 2 + 1];
  double *window  = new double[half_window_length * 2 + 1];

  SetParametersForGetWindowedWaveform(half_window_length, x_length,
      temporal_position, fs, current_f0, base_index, index, window_type,
      window);

  // F0-adaptive windowing
  for (int i = 0; i <= half_window_length * 2; ++i)
    waveform[i] =
      x[index[i]] * window[i] + randn() * world::kMySafeGuardMinimum;

  double tmp_weight1 = 0;
  double tmp_weight2 = 0;
  for (int i = 0; i <= half_window_length * 2; ++i) {
    tmp_weight1 += waveform[i];
    tmp_weight2 += window[i];
  }
  double weighting_coefficient = tmp_weight1 / tmp_weight2;
  for (int i = 0; i <= half_window_length * 2; ++i)
    waveform[i] -= window[i] * weighting_coefficient;

  delete[] base_index;
  delete[] index;
  delete[] window;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, %rbx
movl %ecx, 0x44(%rsp)
movsd %xmm1, 0x10(%rsp)
movapd %xmm0, %xmm1
movl %esi, %ebp
movq %rdi, 0x50(%rsp)
cvtsi2sd %edx, %xmm2
movsd 0x81de(%rip), %xmm0     # 0xf3e0
movsd %xmm2, 0x8(%rsp)
mulsd %xmm2, %xmm0
movsd %xmm1, 0x28(%rsp)
divsd %xmm1, %xmm0
mulsd 0x7e6a(%rip), %xmm0     # 0xf088
callq 0x45c3
movl %eax, %r13d
leal (,%r13,2), %eax
movq %rax, 0x20(%rsp)
leal 0x1(,%r13,2), %eax
movslq %eax, %r12
leaq (,%r12,4), %r15
shlq $0x3, %r12
testl %r13d, %r13d
movq $-0x1, %rax
cmovsq %rax, %r15
cmovsq %rax, %r12
movq %r15, %rdi
callq 0x1030
movq %rax, %r14
movq %r15, %rdi
callq 0x1030
movq %rax, 0x30(%rsp)
movq %r12, %rdi
callq 0x1030
movq %rax, %r12
movl 0x20(%rsp), %eax
movq %rax, 0x48(%rsp)
movq %r13, 0x18(%rsp)
testl %r13d, %r13d
js 0x7331
movq 0x18(%rsp), %rcx
movl %ecx, %eax
negl %eax
movl %ecx, %edx
shlq $0x2, %rdx
movslq %ecx, %rcx
shlq $0x2, %rcx
subq %rcx, %rdx
movq %r14, %rcx
addq %rdx, %rcx
movq 0x48(%rsp), %rdx
incq %rdx
xorl %esi, %esi
leal (%rax,%rsi), %edi
movl %edi, (%rcx,%rsi,4)
incq %rsi
cmpl %esi, %edx
jne 0x72bf
cmpl $0x0, 0x18(%rsp)
js 0x7331
decl %ebp
xorl %r13d, %r13d
movq 0x20(%rsp), %rax
testl %eax, %eax
movl $0x0, %r15d
cmovgl %eax, %r15d
incq %r15
movsd 0x10(%rsp), %xmm0
mulsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl (%r14,%r13,4), %xmm0
addsd 0x38(%rsp), %xmm0
callq 0x45c3
testl %eax, %eax
jg 0x7318
xorl %eax, %eax
movl %ebp, %ecx
cmpl %eax, %ebp
jl 0x7320
movl %eax, %ecx
movq 0x30(%rsp), %rax
movl %ecx, (%rax,%r13,4)
incq %r13
cmpq %r13, %r15
jne 0x72fe
movsd 0x10(%rsp), %xmm0
mulsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
callq 0x45c3
movsd 0x10(%rsp), %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
subsd %xmm0, %xmm1
cmpl $0x1, 0x44(%rsp)
movsd %xmm1, 0x10(%rsp)
jne 0x73fc
cmpl $0x0, 0x18(%rsp)
movsd 0x28(%rsp), %xmm2
movsd 0x8(%rsp), %xmm3
js 0x74b5
xorl %r15d, %r15d
movq 0x20(%rsp), %rax
testl %eax, %eax
movl $0x0, %r13d
cmovgl %eax, %r13d
orl $0x1, %r13d
xorps %xmm0, %xmm0
cvtsi2sdl (%r14,%r15,4), %xmm0
movsd 0x7cde(%rip), %xmm4     # 0xf088
mulsd %xmm4, %xmm0
addsd %xmm1, %xmm0
divsd %xmm3, %xmm0
mulsd 0x7cda(%rip), %xmm0     # 0xf098
mulsd %xmm2, %xmm0
callq 0x11b0
movsd 0x8(%rsp), %xmm3
movsd 0x28(%rsp), %xmm2
movsd 0x10(%rsp), %xmm1
movsd 0x7ca7(%rip), %xmm4     # 0xf088
mulsd %xmm4, %xmm0
addsd %xmm4, %xmm0
movsd %xmm0, (%r12,%r15,8)
incq %r15
cmpq %r15, %r13
jne 0x7399
jmp 0x74b5
cmpl $0x0, 0x18(%rsp)
movsd 0x28(%rsp), %xmm4
movsd 0x8(%rsp), %xmm2
js 0x74b5
xorl %ebp, %ebp
movq 0x20(%rsp), %rax
testl %eax, %eax
movl $0x0, %r13d
cmovgl %eax, %r13d
orl $0x1, %r13d
xorps %xmm0, %xmm0
cvtsi2sdl (%r14,%rbp,4), %xmm0
movsd 0x7c4d(%rip), %xmm3     # 0xf088
mulsd %xmm3, %xmm0
addsd %xmm1, %xmm0
divsd %xmm2, %xmm0
mulsd 0x7c49(%rip), %xmm0     # 0xf098
mulsd %xmm4, %xmm0
movsd %xmm0, 0x18(%rsp)
callq 0x11b0
mulsd 0x7c22(%rip), %xmm0     # 0xf088
addsd 0x7f5a(%rip), %xmm0     # 0xf3c8
movsd %xmm0, 0x38(%rsp)
movsd 0x18(%rsp), %xmm0
addsd %xmm0, %xmm0
callq 0x11b0
movsd 0x8(%rsp), %xmm2
movsd 0x10(%rsp), %xmm1
mulsd 0x7f39(%rip), %xmm0     # 0xf3d0
addsd 0x38(%rsp), %xmm0
movsd %xmm0, (%r12,%rbp,8)
movsd 0x28(%rsp), %xmm4
incq %rbp
cmpq %rbp, %r13
jne 0x742a
movq %r14, 0x8(%rsp)
movq 0x20(%rsp), %r13
testl %r13d, %r13d
movq 0x30(%rsp), %rcx
movq 0x50(%rsp), %r14
movq 0x48(%rsp), %rbp
js 0x7515
incq %rbp
xorl %r15d, %r15d
movslq (%rcx,%r15,4), %rax
movsd (%r14,%rax,8), %xmm0
mulsd (%r12,%r15,8), %xmm0
movsd %xmm0, 0x10(%rsp)
callq 0x476c
movq 0x30(%rsp), %rcx
mulsd 0x7baf(%rip), %xmm0     # 0xf0b0
addsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rbx,%r15,8)
incq %r15
cmpq %r15, %rbp
jne 0x74d9
testl %r13d, %r13d
js 0x7548
movl %r13d, %eax
orl $0x1, %eax
xorpd %xmm1, %xmm1
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
movq 0x8(%rsp), %rdi
addsd (%rbx,%rcx,8), %xmm0
addsd (%r12,%rcx,8), %xmm1
incq %rcx
cmpq %rcx, %rax
jne 0x752f
divsd %xmm1, %xmm0
jmp 0x7555
movsd 0x7e38(%rip), %xmm0     # 0xf388
movq 0x8(%rsp), %rdi
testl %r13d, %r13d
js 0x7580
orl $0x1, %r13d
xorl %eax, %eax
movsd (%rbx,%rax,8), %xmm1
movsd (%r12,%rax,8), %xmm2
mulsd %xmm0, %xmm2
subsd %xmm2, %xmm1
movsd %xmm1, (%rbx,%rax,8)
incq %rax
cmpq %rax, %r13
jne 0x7560
callq 0x1110
movq 0x30(%rsp), %rdi
callq 0x1110
movq %r12, %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1110