// File: /workspace/github_cpp_makefile_star2_O3/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, 0x3c(%rsp)
movsd %xmm1, 0x10(%rsp)
movapd %xmm0, %xmm1
movl %esi, %ebp
movq %rdi, 0x50(%rsp)
cvtsi2sd %edx, %xmm2
movsd 0x7a21(%rip), %xmm0     # 0xf490
movsd %xmm2, 0x18(%rsp)
mulsd %xmm2, %xmm0
movsd %xmm1, 0x28(%rsp)
divsd %xmm1, %xmm0
mulsd 0x7685(%rip), %xmm0     # 0xf110
callq 0x4b8c
movl %eax, %r13d
leal (,%r13,2), %eax
movl %eax, 0xc(%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, 0x48(%rsp)
movq %r12, %rdi
callq 0x1030
movq %rax, %r12
movl 0xc(%rsp), %eax
movq %rax, 0x40(%rsp)
movq %r13, 0x20(%rsp)
testl %r13d, %r13d
js 0x7c14
movq 0x20(%rsp), %rsi
movl %esi, %eax
negl %eax
movl %esi, %edx
movq 0x40(%rsp), %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
addq $0x2, %rcx
shlq $0x2, %rdx
movslq %esi, %rsi
shlq $0x2, %rsi
subq %rsi, %rdx
addq %r14, %rdx
addq $0x4, %rdx
xorl %esi, %esi
movdqa 0x7521(%rip), %xmm1     # 0xf060
movdqa 0x7529(%rip), %xmm2     # 0xf070
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movsd 0x18(%rsp), %xmm7
movq %rsi, %xmm4
pshufd $0x44, %xmm4, %xmm4     # xmm4 = xmm4[0,1,0,1]
por %xmm1, %xmm4
pxor %xmm2, %xmm4
movdqa %xmm4, %xmm5
pcmpgtd %xmm0, %xmm5
pcmpeqd %xmm0, %xmm4
pshufd $0xf5, %xmm4, %xmm6     # xmm6 = xmm4[1,1,3,3]
pand %xmm5, %xmm6
pshufd $0xf5, %xmm5, %xmm4     # xmm4 = xmm5[1,1,3,3]
por %xmm6, %xmm4
movd %xmm4, %edi
notl %edi
testb $0x1, %dil
je 0x7b99
leaq (%rax,%rsi), %rdi
movl %edi, -0x4(%rdx,%rsi,4)
pxor %xmm3, %xmm4
pextrw $0x4, %xmm4, %edi
testb $0x1, %dil
je 0x7bb0
leal (%rax,%rsi), %edi
incl %edi
movl %edi, (%rdx,%rsi,4)
addq $0x2, %rsi
cmpq %rsi, %rcx
jne 0x7b55
decl %ebp
xorl %r13d, %r13d
movl 0xc(%rsp), %eax
testl %eax, %eax
movl $0x0, %r15d
cmovgl %eax, %r15d
incq %r15
movsd 0x10(%rsp), %xmm0
mulsd %xmm7, %xmm0
movsd %xmm0, 0x30(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl (%r14,%r13,4), %xmm0
addsd 0x30(%rsp), %xmm0
callq 0x4b8c
testl %eax, %eax
jg 0x7bfb
xorl %eax, %eax
movl %ebp, %ecx
cmpl %eax, %ebp
jl 0x7c03
movl %eax, %ecx
movq 0x48(%rsp), %rax
movl %ecx, (%rax,%r13,4)
incq %r13
cmpq %r13, %r15
jne 0x7be1
movsd 0x10(%rsp), %xmm0
mulsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
callq 0x4b8c
movsd 0x10(%rsp), %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
subsd %xmm0, %xmm1
cmpl $0x1, 0x3c(%rsp)
movsd %xmm1, 0x10(%rsp)
jne 0x7cde
cmpl $0x0, 0x20(%rsp)
movsd 0x28(%rsp), %xmm2
movsd 0x18(%rsp), %xmm3
js 0x7d96
xorl %r15d, %r15d
movl 0xc(%rsp), %eax
testl %eax, %eax
movl $0x0, %r13d
cmovgl %eax, %r13d
orl $0x1, %r13d
xorps %xmm0, %xmm0
cvtsi2sdl (%r14,%r15,4), %xmm0
movsd 0x7484(%rip), %xmm4     # 0xf110
mulsd %xmm4, %xmm0
addsd %xmm1, %xmm0
divsd %xmm3, %xmm0
mulsd 0x7480(%rip), %xmm0     # 0xf120
mulsd %xmm2, %xmm0
callq 0x11b0
movsd 0x18(%rsp), %xmm3
movsd 0x28(%rsp), %xmm2
movsd 0x10(%rsp), %xmm1
movsd 0x744d(%rip), %xmm4     # 0xf110
mulsd %xmm4, %xmm0
addsd %xmm4, %xmm0
movsd %xmm0, (%r12,%r15,8)
incq %r15
cmpq %r15, %r13
jne 0x7c7b
jmp 0x7d96
cmpl $0x0, 0x20(%rsp)
movsd 0x28(%rsp), %xmm4
movsd 0x18(%rsp), %xmm2
js 0x7d96
xorl %ebp, %ebp
movl 0xc(%rsp), %eax
testl %eax, %eax
movl $0x0, %r13d
cmovgl %eax, %r13d
orl $0x1, %r13d
xorps %xmm0, %xmm0
cvtsi2sdl (%r14,%rbp,4), %xmm0
movsd 0x73f4(%rip), %xmm3     # 0xf110
mulsd %xmm3, %xmm0
addsd %xmm1, %xmm0
divsd %xmm2, %xmm0
mulsd 0x73f0(%rip), %xmm0     # 0xf120
mulsd %xmm4, %xmm0
movsd %xmm0, 0x20(%rsp)
callq 0x11b0
mulsd 0x73c9(%rip), %xmm0     # 0xf110
addsd 0x7709(%rip), %xmm0     # 0xf458
movsd %xmm0, 0x30(%rsp)
movsd 0x20(%rsp), %xmm0
addsd %xmm0, %xmm0
callq 0x11b0
movsd 0x18(%rsp), %xmm2
movsd 0x10(%rsp), %xmm1
mulsd 0x76e8(%rip), %xmm0     # 0xf460
addsd 0x30(%rsp), %xmm0
movsd %xmm0, (%r12,%rbp,8)
movsd 0x28(%rsp), %xmm4
incq %rbp
cmpq %rbp, %r13
jne 0x7d0b
movl 0xc(%rsp), %eax
testl %eax, %eax
movq 0x48(%rsp), %r13
js 0x7e4d
movq %r14, 0x18(%rsp)
movq 0x40(%rsp), %r14
incq %r14
xorl %r15d, %r15d
movq 0x50(%rsp), %rbp
movslq (%r13,%r15,4), %rax
movsd (%rbp,%rax,8), %xmm0
mulsd (%r12,%r15,8), %xmm0
movsd %xmm0, 0x10(%rsp)
callq 0x4d40
mulsd 0x7360(%rip), %xmm0     # 0xf140
addsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rbx,%r15,8)
incq %r15
cmpq %r15, %r14
jne 0x7dbc
movl 0xc(%rsp), %edx
testl %edx, %edx
movq 0x18(%rsp), %r14
js 0x7e4d
movl %edx, %eax
orl $0x1, %eax
xorpd %xmm1, %xmm1
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
addsd (%rbx,%rcx,8), %xmm0
addsd (%r12,%rcx,8), %xmm1
incq %rcx
cmpq %rcx, %rax
jne 0x7e10
testl %edx, %edx
js 0x7e4d
divsd %xmm1, %xmm0
xorl %ecx, %ecx
movsd (%rbx,%rcx,8), %xmm1
movsd (%r12,%rcx,8), %xmm2
mulsd %xmm0, %xmm2
subsd %xmm2, %xmm1
movsd %xmm1, (%rbx,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x7e2d
movq %r14, %rdi
callq 0x1110
movq %r13, %rdi
callq 0x1110
movq %r12, %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1110