// File: Sleepwalking[P]world-octave/synthesis.cpp
// Function: (anonymous namespace)::GetTimeBase(double*, int, int, double, int, double*, int*, double*)
int GetTimeBase(double *f0, int f0_length, int fs,
    double frame_period, int y_length, double *pulse_locations,
    int *pulse_locations_index, double *interpolated_vuv) {
  double *time_axis = new double[y_length];
  double *coarse_time_axis = new double[f0_length + 1];
  double *coarse_f0 = new double[f0_length + 1];
  double *coarse_vuv = new double[f0_length + 1];
  GetTemporalParametersForTimeBase(f0, f0_length, fs, y_length, frame_period,
      time_axis, coarse_time_axis, coarse_f0, coarse_vuv);

  double *interpolated_f0 = new double[y_length];
  interp1(coarse_time_axis, coarse_f0, f0_length + 1,
      time_axis, y_length, interpolated_f0);
  interp1(coarse_time_axis, coarse_vuv, f0_length + 1,
      time_axis, y_length, interpolated_vuv);
  for (int i = 0; i < y_length; ++i)
    interpolated_vuv[i] = interpolated_vuv[i] > 0.5 ? 1.0 : 0.0;

  for (int i = 0; i < y_length; ++i)
    interpolated_f0[i] =
      interpolated_vuv[i] == 0.0 ? world::kDefaultF0 : interpolated_f0[i];

  int number_of_pulses = GetPulseLocationsForTimeBase(interpolated_f0,
      time_axis, y_length, fs, pulse_locations, pulse_locations_index);

  delete[] coarse_vuv;
  delete[] coarse_f0;
  delete[] coarse_time_axis;
  delete[] time_axis;
  delete[] interpolated_f0;

  return number_of_pulses;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movslq -0x1c(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x1030
movq %rax, -0x38(%rbp)
movl -0xc(%rbp), %eax
addl $0x1, %eax
cltq
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x1030
movq %rax, -0x40(%rbp)
movl -0xc(%rbp), %eax
addl $0x1, %eax
cltq
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x1030
movq %rax, -0x48(%rbp)
movl -0xc(%rbp), %eax
addl $0x1, %eax
cltq
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x1030
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movl -0x1c(%rbp), %ecx
movsd -0x18(%rbp), %xmm0
movq -0x38(%rbp), %r8
movq -0x40(%rbp), %r9
movq -0x48(%rbp), %r10
movq -0x50(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x5930
movslq -0x1c(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x1030
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl -0xc(%rbp), %edx
addl $0x1, %edx
movq -0x38(%rbp), %rcx
movl -0x1c(%rbp), %r8d
movq -0x58(%rbp), %r9
callq 0x68d0
movq -0x40(%rbp), %rdi
movq -0x50(%rbp), %rsi
movl -0xc(%rbp), %edx
addl $0x1, %edx
movq -0x38(%rbp), %rcx
movl -0x1c(%rbp), %r8d
movq 0x10(%rbp), %r9
callq 0x68d0
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x55cb
movq 0x10(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd 0x16a7c(%rip), %xmm3    # 0x1c010
xorps %xmm2, %xmm2
movsd 0x16a89(%rip), %xmm0    # 0x1c028
cmpltsd %xmm1, %xmm0
movaps %xmm0, %xmm1
andpd %xmm3, %xmm1
andnpd %xmm2, %xmm0
orpd %xmm1, %xmm0
movq 0x10(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x5577
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x5630
movq 0x10(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x5601
jp 0x5601
movsd 0x16af6(%rip), %xmm0    # 0x1c0f0
movsd %xmm0, -0x70(%rbp)
jmp 0x5613
movq -0x58(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x70(%rbp), %xmm0
movq -0x58(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x55d2
movq -0x58(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x1c(%rbp), %edx
movl -0x10(%rbp), %ecx
movq -0x28(%rbp), %r8
movq -0x30(%rbp), %r9
callq 0x5b00
movl %eax, -0x64(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, %rax
je 0x5665
movq -0x78(%rbp), %rdi
callq 0x1110
movq -0x48(%rbp), %rax
movq %rax, -0x80(%rbp)
cmpq $0x0, %rax
je 0x567c
movq -0x80(%rbp), %rdi
callq 0x1110
movq -0x40(%rbp), %rax
movq %rax, -0x88(%rbp)
cmpq $0x0, %rax
je 0x5699
movq -0x88(%rbp), %rdi
callq 0x1110
movq -0x38(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, %rax
je 0x56b6
movq -0x90(%rbp), %rdi
callq 0x1110
movq -0x58(%rbp), %rax
movq %rax, -0x98(%rbp)
cmpq $0x0, %rax
je 0x56d3
movq -0x98(%rbp), %rdi
callq 0x1110
movl -0x64(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nop