// File: Sleepwalking[P]world-octave/d4c.cpp
// Function: (anonymous namespace)::SetParametersForGetWindowedWaveform(int, int, double, int, double, int*, int*, int, double*)
void SetParametersForGetWindowedWaveform(int half_window_length, int x_length,
    double temporal_position, int fs, double current_f0, int *base_index,
    int *index, int window_type, double *window) {
  for (int i = -half_window_length; i <= half_window_length; ++i)
    base_index[i + half_window_length] = i;
  for (int i = 0; i <= half_window_length * 2; ++i)
    index[i] = MyMin(x_length - 1, MyMax(0,
        matlab_round(temporal_position * fs + base_index[i])));

  // Designing of the window function
  double position;
  double bias = temporal_position * fs - matlab_round(temporal_position * fs);
  if (window_type == world::kHanning) {  // Hanning window
    for (int i = 0; i <= half_window_length * 2; ++i) {
      position = (static_cast<double>(base_index[i]) / 2.0 + bias) / fs;
      window[i] = 0.5 * cos(world::kPi * position * current_f0) + 0.5;
    }
  } else {  // Blackman window
    for (int i = 0; i <= half_window_length * 2; ++i) {
      position = (static_cast<double>(base_index[i]) / 2.0 + bias) / fs;
      window[i] = 0.42 + 0.5 * cos(world::kPi * position * current_f0) +
        0.08 * cos(world::kPi * position * current_f0 * 2);
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq 0x10(%rbp), %rax
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movsd %xmm0, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movsd %xmm1, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
xorl %eax, %eax
subl -0x4(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x4(%rbp), %eax
jg 0xbd0c
movl -0x38(%rbp), %edx
movq -0x28(%rbp), %rax
movl -0x38(%rbp), %ecx
addl -0x4(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0xbce6
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl -0x4(%rbp), %ecx
shll %ecx
cmpl %ecx, %eax
jg 0xbd77
movl -0x8(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x5c(%rbp)
movsd -0x10(%rbp), %xmm0
cvtsi2sdl -0x14(%rbp), %xmm2
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x72e0
movl %eax, %esi
xorl %edi, %edi
callq 0x4f80
movl -0x5c(%rbp), %edi
movl %eax, %esi
callq 0x4fb0
movl %eax, %edx
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xbd13
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
cvtsi2sdl -0x14(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x10(%rbp), %xmm0
cvtsi2sdl -0x14(%rbp), %xmm1
mulsd %xmm1, %xmm0
callq 0x72e0
movsd -0x70(%rbp), %xmm0
movsd -0x68(%rbp), %xmm2
cvtsi2sd %eax, %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
cmpl $0x1, -0x34(%rbp)
jne 0xbe5d
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl -0x4(%rbp), %ecx
shll %ecx
cmpl %ecx, %eax
jg 0xbe58
movq -0x28(%rbp), %rax
movslq -0x54(%rbp), %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm0
movsd 0x10206(%rip), %xmm1    # 0x1c008
divsd %xmm1, %xmm0
addsd -0x50(%rbp), %xmm0
cvtsi2sdl -0x14(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd 0x10297(%rip), %xmm0    # 0x1c0b8
mulsd -0x48(%rbp), %xmm0
mulsd -0x20(%rbp), %xmm0
callq 0x11a0
movsd 0x101f0(%rip), %xmm1    # 0x1c028
mulsd %xmm1, %xmm0
addsd %xmm1, %xmm0
movq 0x10(%rbp), %rax
movslq -0x54(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0xbde1
jmp 0xbf29
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
movl -0x4(%rbp), %ecx
shll %ecx
cmpl %ecx, %eax
jg 0xbf27
movq -0x28(%rbp), %rax
movslq -0x58(%rbp), %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm0
movsd 0x1017f(%rip), %xmm1    # 0x1c008
divsd %xmm1, %xmm0
addsd -0x50(%rbp), %xmm0
cvtsi2sdl -0x14(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd 0x10210(%rip), %xmm0    # 0x1c0b8
mulsd -0x48(%rbp), %xmm0
mulsd -0x20(%rbp), %xmm0
callq 0x11a0
movsd 0x10169(%rip), %xmm1    # 0x1c028
mulsd %xmm1, %xmm0
movsd 0x10535(%rip), %xmm1    # 0x1c400
addsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd 0x101dc(%rip), %xmm0    # 0x1c0b8
mulsd -0x48(%rbp), %xmm0
mulsd -0x20(%rbp), %xmm0
movsd 0x1011a(%rip), %xmm1    # 0x1c008
mulsd %xmm1, %xmm0
callq 0x11a0
movsd -0x78(%rbp), %xmm1
movsd 0x104f4(%rip), %xmm2    # 0x1c3f8
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x10(%rbp), %rax
movslq -0x58(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0xbe64
jmp 0xbf29
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)