// File: /workspace/github_cpp_makefile_star2_O1/Sleepwalking[P]world-octave/test.cpp
// Function: main
int main(int argc, char *argv[]) {
  if (argc != 2 && argc != 3 && argc != 4 && argc != 5) {
    printf("error\n");
    return 0;
  }
  int fs, nbit, x_length;
  double *x = wavread(argv[1], &fs, &nbit, &x_length);

  if (CheckLoadedFile(x, fs, nbit, x_length) == false) {
    printf("error: File not found.\n");
    return 0;
  }

  // Allocate memories
  // The number of samples for F0
  int f0_length = GetSamplesForDIO(fs, x_length, FRAMEPERIOD);
  double *f0 = new double[f0_length];
  double *time_axis = new double[f0_length];

  // FFT size for CheapTrick
  int fft_size = GetFFTSizeForCheapTrick(fs);
  double **spectrogram = new double *[f0_length];
  double **aperiodicity = new double *[f0_length];
  for (int i = 0; i < f0_length; ++i) {
    spectrogram[i] = new double[fft_size / 2 + 1];
    aperiodicity[i] = new double[fft_size / 2 + 1];
  }

  // F0 estimation
  F0Estimation(x, x_length, fs, f0_length, f0, time_axis);

  // Spectral envelope estimation
  SpectralEnvelopeEstimation(x, x_length, fs, time_axis, f0, f0_length,
      spectrogram);

  // Aperiodicity estimation by D4C
  AperiodicityEstimation(x, x_length, fs, time_axis, f0, f0_length,
      fft_size, aperiodicity);

  // Note that F0 must not be changed until all parameters are estimated.
  ParameterModification(argc, argv, fs, f0, f0_length, spectrogram);

  // The length of the output waveform
  int y_length =
    static_cast<int>((f0_length - 1) * FRAMEPERIOD / 1000.0 * fs) + 1;
  double *y = new double[y_length];
  // Synthesis
  WaveformSynthesis(f0, f0_length, spectrogram, aperiodicity, fft_size,
      FRAMEPERIOD, fs, y_length, y);

  // Output
  wavwrite(y, y_length, fs, 16, argv[2]);

  printf("complete.\n");

  delete[] x;
  delete[] time_axis;
  delete[] f0;
  delete[] y;
  for (int i = 0; i < f0_length; ++i) {
    delete[] spectrogram[i];
    delete[] aperiodicity[i];
  }
  delete[] spectrogram;
  delete[] aperiodicity;

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
leal -0x6(%rdi), %eax
cmpl $-0x5, %eax
ja 0xe198
leaq 0x134c(%rip), %rdi      # 0xf4df
jmp 0xeb13
movq %rsi, %r15
movq %rdi, 0x68(%rsp)
movq 0x8(%rsi), %rdi
leaq 0x3c(%rsp), %rsi
leaq 0xb4(%rsp), %rdx
leaq 0x40(%rsp), %rcx
callq 0x4ce8
movq %rax, %r12
testq %rax, %rax
je 0xe21f
movl 0x40(%rsp), %ebx
movl 0xb4(%rsp), %ebp
movl 0x3c(%rsp), %r14d
leaq 0x130b(%rip), %rdi      # 0xf4e5
callq 0x1150
leaq 0x1252(%rip), %rdi      # 0xf438
movl %r14d, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1040
leaq 0x1258(%rip), %rdi      # 0xf451
movl %ebx, %esi
xorl %eax, %eax
callq 0x1040
cvtsi2sd %ebx, %xmm0
cvtsi2sd %r14d, %xmm1
divsd %xmm1, %xmm0
leaq 0x124f(%rip), %rdi      # 0xf465
movb $0x1, %al
callq 0x1040
jmp 0xe22b
leaq 0x12d0(%rip), %rdi      # 0xf4f6
callq 0x1150
testq %r12, %r12
je 0xeb0c
movq %r12, 0x90(%rsp)
movq %r15, 0xc0(%rsp)
movl 0x3c(%rsp), %edi
movl 0x40(%rsp), %esi
movsd 0x11dc(%rip), %xmm0     # 0xf430
callq 0x1c84
movq %rax, 0x48(%rsp)
movslq %eax, %rbx
leaq (,%rbx,8), %r14
testl %ebx, %ebx
movq $-0x1, %r15
cmovsq %r15, %r14
movq %r14, %rdi
callq 0x1030
movq %rax, 0x80(%rsp)
movq %r14, %rdi
callq 0x1030
movq %rax, 0x78(%rsp)
movl 0x3c(%rsp), %edi
callq 0x512c
movl %eax, 0x44(%rsp)
movq %r14, %rdi
callq 0x1030
movq %rax, %r12
movq %r14, %rdi
callq 0x1030
movq %rax, %r13
movl %ebx, %ebp
movq %rbx, 0x70(%rsp)
testl %ebx, %ebx
jle 0xe303
movl 0x44(%rsp), %ecx
movl %ecx, %eax
shrl $0x1f, %eax
addl %ecx, %eax
sarl %eax
cltq
leaq 0x8(,%rax,8), %rbx
cmpl $-0x3, %ecx
cmovlq %r15, %rbx
xorl %r15d, %r15d
movq %rbx, %rdi
callq 0x1030
movq %rax, (%r12,%r15,8)
movq %rbx, %rdi
callq 0x1030
movq %rax, (%r13,%r15,8)
incq %r15
cmpq %r15, %rbp
jne 0xe2e2
movq %rbp, 0x88(%rsp)
movq %r13, 0xb8(%rsp)
movq %r12, 0x58(%rsp)
movl 0x40(%rsp), %r12d
movl %r12d, 0x50(%rsp)
movl 0x3c(%rsp), %ebp
movq %r14, %rdi
callq 0x1030
movq %rax, 0x60(%rsp)
leaq 0xe8(%rsp), %rbx
movq %rbx, %rdi
callq 0x3196
movabsq $0x4014000000000000, %rax # imm = 0x4014000000000000
movq %rax, 0x18(%rbx)
movl $0x1, 0x20(%rbx)
movabsq $0x4051c00000000000, %rax # imm = 0x4051C00000000000
movq %rax, (%rbx)
movabsq $0x3fb999999999999a, %rax # imm = 0x3FB999999999999A
movq %rax, 0x28(%rbx)
leaq 0x1193(%rip), %rdi      # 0xf50d
callq 0x1150
leaq 0xd8(%rsp), %r13
movq %r13, %rdi
xorl %esi, %esi
callq 0x1160
movabsq $-0x20c49ba5e353f7cf, %rax # imm = 0xDF3B645A1CAC0831
imulq 0x8(%r13)
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x7, %rdx
addl %edx, %eax
movl (%r13), %r15d
movl $0xfffffc18, %ecx       # imm = 0xFFFFFC18
imull %ecx, %r15d
addl %eax, %r15d
movupd (%rbx), %xmm0
movupd 0x10(%rbx), %xmm1
movupd 0x20(%rbx), %xmm2
movupd %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq 0x90(%rsp), %rbx
movq %rbx, %rdi
movl %r12d, %esi
movl %ebp, %edx
movq 0x78(%rsp), %r12
movq %r12, %rcx
movq 0x80(%rsp), %r14
movq %r14, %r8
callq 0x1ca3
leaq 0xd8(%rsp), %r13
movq %r13, %rdi
xorl %esi, %esi
callq 0x1160
movabsq $0x20c49ba5e353f7cf, %rax # imm = 0x20C49BA5E353F7CF
imulq 0x8(%r13)
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x7, %rdx
addl %edx, %eax
imull $0x3e8, (%r13), %esi    # imm = 0x3E8
addl %eax, %esi
addl %r15d, %esi
leaq 0x1032(%rip), %rdi      # 0xf476
xorl %eax, %eax
callq 0x1040
leaq 0xd8(%rsp), %r13
movq %r13, %rdi
xorl %esi, %esi
callq 0x1160
movabsq $-0x20c49ba5e353f7cf, %rax # imm = 0xDF3B645A1CAC0831
imulq 0x8(%r13)
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x7, %rdx
addl %edx, %eax
movl (%r13), %r15d
movq %r14, %r13
movq 0x60(%rsp), %r14
movl $0xfffffc18, %ecx       # imm = 0xFFFFFC18
imull %ecx, %r15d
addl %eax, %r15d
movq %r14, (%rsp)
movq %rbx, %rdi
movl 0x50(%rsp), %esi
movl %ebp, %edx
movq %r12, %rcx
movq %r13, %r8
movq 0x70(%rsp), %r9
callq 0x5a58
leaq 0xd8(%rsp), %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0x1160
movabsq $0x20c49ba5e353f7cf, %rax # imm = 0x20C49BA5E353F7CF
imulq 0x8(%r12)
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x7, %rdx
addl %edx, %eax
imull $0x3e8, (%r12), %esi    # imm = 0x3E8
addl %eax, %esi
addl %r15d, %esi
leaq 0xf97(%rip), %rdi       # 0xf486
xorl %eax, %eax
callq 0x1040
cmpl $0x0, 0x48(%rsp)
jle 0xe518
movq 0x88(%rsp), %rax
leaq (,%rax,8), %rdx
movq %r13, %rdi
movq %r14, %rsi
callq 0x10b0
movq %r14, %rdi
callq 0x1110
movl 0x40(%rsp), %ebx
movl 0x3c(%rsp), %ebp
leaq 0xe8(%rsp), %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0x1160
movabsq $-0x20c49ba5e353f7cf, %r14 # imm = 0xDF3B645A1CAC0831
movq %r14, %rax
imulq 0x8(%r12)
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x7, %rdx
addl %edx, %eax
movl (%r12), %r15d
movl $0xfffffc18, %ecx       # imm = 0xFFFFFC18
imull %ecx, %r15d
addl %eax, %r15d
movq 0x58(%rsp), %rax
movq %rax, (%rsp)
movq 0x90(%rsp), %r12
movq %r12, %rdi
movl %ebx, %esi
movl %ebp, %edx
movq 0x78(%rsp), %rcx
movq %r13, %r8
movq 0x70(%rsp), %r9
callq 0x5171
leaq 0xe8(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1160
movabsq $0x20c49ba5e353f7cf, %rax # imm = 0x20C49BA5E353F7CF
imulq 0x8(%rbx)
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x7, %rdx
addl %edx, %eax
imull $0x3e8, (%rbx), %esi    # imm = 0x3E8
addl %eax, %esi
addl %r15d, %esi
leaq 0xeca(%rip), %rdi       # 0xf49c
xorl %eax, %eax
callq 0x1040
movl 0x40(%rsp), %ebx
movl 0x3c(%rsp), %ebp
leaq 0xe8(%rsp), %r13
movq %r13, %rdi
xorl %esi, %esi
callq 0x1160
movq %r14, %rax
imulq 0x8(%r13)
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x7, %rdx
addl %edx, %eax
movl (%r13), %r14d
movq 0x80(%rsp), %r13
movl $0xfffffc18, %ecx       # imm = 0xFFFFFC18
imull %ecx, %r14d
addl %eax, %r14d
movq 0xb8(%rsp), %rax
movq %rax, 0x8(%rsp)
movl 0x44(%rsp), %eax
movl %eax, (%rsp)
movq %r12, %rdi
movl %ebx, %esi
movl %ebp, %edx
movq 0x78(%rsp), %rcx
movq %r13, %r8
movq 0x70(%rsp), %r9
callq 0x6540
leaq 0xe8(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1160
movabsq $0x20c49ba5e353f7cf, %rax # imm = 0x20C49BA5E353F7CF
imulq 0x8(%rbx)
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x7, %rdx
addl %edx, %eax
imull $0x3e8, (%rbx), %esi    # imm = 0x3E8
addl %eax, %esi
addl %r14d, %esi
leaq 0xe28(%rip), %rdi       # 0xf4b3
xorl %eax, %eax
callq 0x1040
movl 0x3c(%rsp), %r14d
movl %r14d, %edi
callq 0x512c
movl %eax, 0x60(%rsp)
movq 0x68(%rsp), %r15
cmpl $0x4, %r15d
movq 0xc0(%rsp), %r12
movq 0x88(%rsp), %rbx
jl 0xe6eb
movq 0x18(%r12), %rdi
callq 0x1100
cmpl $0x0, 0x48(%rsp)
jle 0xe6eb
xorl %eax, %eax
movsd (%r13,%rax,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%r13,%rax,8)
incq %rax
cmpq %rax, %rbx
jne 0xe6d1
cmpl $0x5, %r15d
movq 0x58(%rsp), %r13
jl 0xe94c
movq 0x20(%r12), %rdi
callq 0x1100
movsd %xmm0, 0x98(%rsp)
movslq 0x60(%rsp), %rbx
leaq (,%rbx,8), %rax
testl %ebx, %ebx
movq $-0x1, %r12
cmovnsq %rax, %r12
movq %r12, %rdi
callq 0x1030
movq %rax, %r15
movq %r12, %rdi
callq 0x1030
movq %rax, %r13
movq %r12, %rdi
callq 0x1030
movq %rax, 0x68(%rsp)
movq %r12, %rdi
callq 0x1030
movsd 0x98(%rsp), %xmm4
movl %ebx, %edi
shrl $0x1f, %edi
addl %ebx, %edi
sarl %edi
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
cmpl $-0x1, %ebx
jl 0xe7b1
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
leal 0x1(%rdi), %ecx
xorl %edx, %edx
xorps %xmm2, %xmm2
cvtsi2sd %edx, %xmm2
movapd %xmm4, %xmm3
mulsd %xmm2, %xmm3
divsd %xmm0, %xmm3
mulsd %xmm1, %xmm3
movsd %xmm3, (%r15,%rdx,8)
divsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
movsd %xmm2, (%r13,%rdx,8)
incq %rdx
cmpq %rdx, %rcx
jne 0xe77d
movq %rax, 0xa0(%rsp)
movq %r13, 0xa8(%rsp)
movq %r15, 0x50(%rsp)
cmpl $0x0, 0x48(%rsp)
movq 0x68(%rsp), %rsi
jle 0xe91b
movsd 0x832(%rip), %xmm1      # 0xf010
ucomisd %xmm4, %xmm1
setbe %cl
mulsd 0x89b(%rip), %xmm0      # 0xf088
leal 0x1(%rdi), %r14d
mulsd %xmm4, %xmm0
cvttsd2si %xmm0, %edx
cmpl %edx, %edi
setl %al
movslq %edx, %rdx
movq %rdx, 0xd0(%rsp)
orb %cl, %al
movb %al, 0x98(%rsp)
movl %r14d, %r13d
subl %edx, %r13d
leaq (,%rdx,8), %rax
movq %rax, 0xc8(%rsp)
xorl %r15d, %r15d
movq 0x58(%rsp), %rbp
movq 0xa0(%rsp), %rbx
cmpl $-0x1, 0x60(%rsp)
jge 0xe861
movq 0x50(%rsp), %rdi
movl %r14d, %edx
movq 0xa8(%rsp), %rcx
movl %r14d, %r8d
movq 0xa0(%rsp), %r9
callq 0x41a9
jmp 0xe8ca
xorl %r12d, %r12d
movq (%rbp,%r15,8), %rax
movsd (%rax,%r12,8), %xmm0
callq 0x10a0
movq 0x68(%rsp), %rsi
movsd %xmm0, (%rsi,%r12,8)
incq %r12
cmpq %r12, %r14
jne 0xe864
movq 0x50(%rsp), %rdi
movl %r14d, %edx
movq 0xa8(%rsp), %rcx
movl %r14d, %r8d
movq %rbx, %r9
callq 0x41a9
cmpl $-0x1, 0x60(%rsp)
jl 0xe8ca
xorl %r12d, %r12d
movsd (%rbx,%r12,8), %xmm0
callq 0x11a0
movq (%rbp,%r15,8), %rax
movsd %xmm0, (%rax,%r12,8)
incq %r12
cmpq %r12, %r14
jne 0xe8ac
cmpb $0x0, 0x98(%rsp)
movq 0xd0(%rsp), %rsi
jne 0xe905
movq 0x58(%rsp), %rax
movq (%rax,%r15,8), %rax
movq 0xc8(%rsp), %rcx
addq %rax, %rcx
xorl %edx, %edx
movsd -0x8(%rax,%rsi,8), %xmm0
movsd %xmm0, (%rcx,%rdx,8)
incq %rdx
cmpl %edx, %r13d
jne 0xe8f2
incq %r15
cmpq 0x88(%rsp), %r15
movq 0x68(%rsp), %rsi
jne 0xe838
movq %rsi, %rdi
callq 0x1110
movq 0xa0(%rsp), %rdi
callq 0x1110
movq 0x50(%rsp), %rdi
callq 0x1110
movq 0xa8(%rsp), %rdi
callq 0x1110
movq 0x58(%rsp), %r13
movq 0x48(%rsp), %rax
decl %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0xace(%rip), %xmm1      # 0xf430
mulsd %xmm1, %xmm0
divsd 0x712(%rip), %xmm0      # 0xf080
movl 0x3c(%rsp), %r14d
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %ebp
movslq %ebp, %rax
incl %ebp
cmpl $-0x1, %eax
leaq 0x8(,%rax,8), %rax
movq $-0x1, %rdi
cmovgeq %rax, %rdi
callq 0x1030
movq %rax, %rbx
leaq 0xb6a(%rip), %rdi       # 0xf517
callq 0x1150
leaq 0xe8(%rsp), %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0x1160
movabsq $-0x20c49ba5e353f7cf, %rax # imm = 0xDF3B645A1CAC0831
imulq 0x8(%r12)
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x7, %rdx
addl %edx, %eax
movl $0xfffffc18, %r15d      # imm = 0xFFFFFC18
imull (%r12), %r15d
addl %eax, %r15d
movq %rbx, 0x8(%rsp)
movl %ebp, (%rsp)
movq 0x80(%rsp), %rdi
movq 0x70(%rsp), %rsi
movq %r13, %rdx
movq 0xb8(%rsp), %r12
movq %r12, %rcx
movl 0x44(%rsp), %r8d
movsd 0xa12(%rip), %xmm0      # 0xf430
movl %r14d, %r9d
callq 0x3430
leaq 0xe8(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x1160
movabsq $0x20c49ba5e353f7cf, %rax # imm = 0x20C49BA5E353F7CF
imulq 0x8(%r14)
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x7, %rdx
addl %edx, %eax
imull $0x3e8, (%r14), %esi    # imm = 0x3E8
addl %eax, %esi
addl %r15d, %esi
leaq 0xa5d(%rip), %rdi       # 0xf4c3
xorl %eax, %eax
callq 0x1040
movl 0x3c(%rsp), %edx
movq 0xc0(%rsp), %rax
movq 0x10(%rax), %r8
movq %rbx, %rdi
movl %ebp, %esi
movq 0x88(%rsp), %r15
movl $0x10, %ecx
callq 0x4a9d
leaq 0xa3a(%rip), %rdi       # 0xf4d5
callq 0x1150
movq 0x90(%rsp), %rdi
callq 0x1110
movq 0x78(%rsp), %rdi
callq 0x1110
movq 0x80(%rsp), %rdi
callq 0x1110
movq %rbx, %rdi
callq 0x1110
cmpl $0x0, 0x48(%rsp)
jle 0xeafa
xorl %ebx, %ebx
movq (%r13,%rbx,8), %rdi
testq %rdi, %rdi
je 0xeae4
callq 0x1110
movq (%r12,%rbx,8), %rdi
testq %rdi, %rdi
je 0xeaf2
callq 0x1110
incq %rbx
cmpq %rbx, %r15
jne 0xead5
movq %r13, %rdi
callq 0x1110
movq %r12, %rdi
callq 0x1110
jmp 0xeb18
leaq 0x9e3(%rip), %rdi       # 0xf4f6
callq 0x1150
xorl %eax, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq