// File: Sleepwalking[P]world-octave/cheaptrick.cpp
// Function: (anonymous namespace)::SetParametersForGetWindowedWaveform(int, int, double, int, double, 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, 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 average = 0.0;
  double position;
  double bias = temporal_position * fs - matlab_round(temporal_position * fs);
  for (int i = 0; i <= half_window_length * 2; ++i) {
    position = (static_cast<double>(base_index[i]) / 1.5 + bias) / fs;
    window[i] = 0.5 * cos(world::kPi * position * current_f0) + 0.5;
    average += window[i] * window[i];
  }
  average = sqrt(average);
  for (int i = 0; i <= half_window_length * 2; ++i) window[i] /= average;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
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)
movq %r9, -0x38(%rbp)
xorl %eax, %eax
subl -0x4(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x4(%rbp), %eax
jg 0x90b8
movl -0x3c(%rbp), %edx
movq -0x28(%rbp), %rax
movl -0x3c(%rbp), %ecx
addl -0x4(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x9092
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movl -0x4(%rbp), %ecx
shll %ecx
cmpl %ecx, %eax
jg 0x9123
movl -0x8(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x64(%rbp)
movsd -0x10(%rbp), %xmm0
cvtsi2sdl -0x14(%rbp), %xmm2
movq -0x28(%rbp), %rax
movslq -0x40(%rbp), %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x72e0
movl %eax, %esi
xorl %edi, %edi
callq 0x4f80
movl -0x64(%rbp), %edi
movl %eax, %esi
callq 0x4fb0
movl %eax, %edx
movq -0x30(%rbp), %rax
movslq -0x40(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x90bf
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
cvtsi2sdl -0x14(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x10(%rbp), %xmm0
cvtsi2sdl -0x14(%rbp), %xmm1
mulsd %xmm1, %xmm0
callq 0x72e0
movsd -0x78(%rbp), %xmm0
movsd -0x70(%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, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movl -0x4(%rbp), %ecx
shll %ecx
cmpl %ecx, %eax
jg 0x9235
movq -0x28(%rbp), %rax
movslq -0x5c(%rbp), %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm0
movsd 0x13208(%rip), %xmm1    # 0x1c3b8
divsd %xmm1, %xmm0
addsd -0x58(%rbp), %xmm0
cvtsi2sdl -0x14(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd 0x12ee9(%rip), %xmm0    # 0x1c0b8
mulsd -0x50(%rbp), %xmm0
mulsd -0x20(%rbp), %xmm0
callq 0x11a0
movsd 0x12e42(%rip), %xmm1    # 0x1c028
mulsd %xmm1, %xmm0
addsd %xmm1, %xmm0
movq -0x38(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x38(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
movsd -0x48(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x918b
movsd -0x48(%rbp), %xmm0
callq 0x1090
movsd %xmm0, -0x48(%rbp)
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
movl -0x4(%rbp), %ecx
shll %ecx
cmpl %ecx, %eax
jg 0x927d
movsd -0x48(%rbp), %xmm1
movq -0x38(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x924b
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)