// File: /workspace/github_cpp_makefile_star2_O3/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
movl %edi, %r14d
leal -0x6(%r14), %eax
cmpl $-0x5, %eax
ja 0xdee0
leaq 0x16e4(%rip), %rdi      # 0xf5bf
jmp 0xe895
movq %rsi, %rbx
movq 0x8(%rsi), %rdi
leaq 0x30(%rsp), %rsi
leaq 0xa4(%rsp), %rdx
leaq 0x34(%rsp), %rcx
callq 0x52d1
testq %rax, %rax
je 0xe883
movq %r14, 0x38(%rsp)
movq %rax, 0x90(%rsp)
movq %rbx, 0x80(%rsp)
movl 0x34(%rsp), %ebx
movl 0xa4(%rsp), %ebp
movl 0x30(%rsp), %r14d
leaq 0x1692(%rip), %rdi      # 0xf5c5
callq 0x1150
leaq 0x15d9(%rip), %rdi      # 0xf518
movl %r14d, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1040
leaq 0x15df(%rip), %rdi      # 0xf531
movl %ebx, %esi
xorl %eax, %eax
callq 0x1040
cvtsi2sd %ebx, %xmm0
cvtsi2sd %r14d, %xmm1
divsd %xmm1, %xmm0
leaq 0x15d6(%rip), %rdi      # 0xf545
movb $0x1, %al
callq 0x1040
movl 0x30(%rsp), %edi
movl 0x34(%rsp), %esi
movsd 0x158a(%rip), %xmm0     # 0xf510
callq 0x1e18
movl %eax, %ebx
movl %eax, %r12d
leaq (,%r12,8), %rbp
testl %eax, %eax
movq $-0x1, %r14
movq %rbp, 0x50(%rsp)
cmovsq %r14, %rbp
movq %rbp, %rdi
callq 0x1030
movq %rax, 0xa8(%rsp)
movq %rbp, %rdi
callq 0x1030
movq %rax, 0x68(%rsp)
movl 0x30(%rsp), %edi
callq 0x56f0
movl %eax, 0x44(%rsp)
movq %rbp, %rdi
callq 0x1030
movq %rax, %r15
movq %rbp, %rdi
callq 0x1030
movq %rax, %r13
testl %ebx, %ebx
jle 0xe030
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 %r14, %rbx
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0x1030
movq %rax, (%r15,%r14,8)
movq %rbx, %rdi
callq 0x1030
movq %rax, (%r13,%r14,8)
incq %r14
cmpq %r14, %r12
jne 0xe00f
movq %r13, 0x88(%rsp)
movq %r15, 0x78(%rsp)
movl 0x34(%rsp), %r14d
movl %r14d, 0x58(%rsp)
movl 0x30(%rsp), %r13d
movl %r13d, 0x60(%rsp)
movq %rbp, %rdi
callq 0x1030
movq %rax, 0x70(%rsp)
leaq 0xd0(%rsp), %rbp
movq %rbp, %rdi
callq 0x34f2
movabsq $0x4014000000000000, %rax # imm = 0x4014000000000000
movq %rax, 0x18(%rbp)
movl $0x1, 0x20(%rbp)
movabsq $0x4051c00000000000, %rax # imm = 0x4051C00000000000
movq %rax, (%rbp)
movabsq $0x3fb999999999999a, %rax # imm = 0x3FB999999999999A
movq %rax, 0x28(%rbp)
leaq 0x1547(%rip), %rdi      # 0xf5ed
callq 0x1150
leaq 0xc0(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1160
movabsq $-0x20c49ba5e353f7cf, %rax # imm = 0xDF3B645A1CAC0831
imulq 0x8(%rbx)
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x7, %rdx
addl %edx, %eax
movl $0xfffffc18, %ecx       # imm = 0xFFFFFC18
movq %r12, 0x48(%rsp)
movl (%rbx), %r15d
imull %ecx, %r15d
addl %eax, %r15d
movupd (%rbp), %xmm0
movupd 0x10(%rbp), %xmm1
movupd 0x20(%rbp), %xmm2
movupd %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq 0x90(%rsp), %r12
movq %r12, %rdi
movl %r14d, %esi
movl %r13d, %edx
movq 0x68(%rsp), %r14
movq %r14, %rcx
movq 0xa8(%rsp), %r13
movq %r13, %r8
callq 0x1e43
leaq 0xc0(%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
movq 0x70(%rsp), %r15
leaq 0x13dd(%rip), %rdi      # 0xf556
xorl %eax, %eax
callq 0x1040
leaq 0xc0(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1160
movabsq $-0x20c49ba5e353f7cf, %rax # imm = 0xDF3B645A1CAC0831
imulq 0x8(%rbx)
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x7, %rdx
addl %edx, %eax
movl (%rbx), %ebp
movl $0xfffffc18, %ecx       # imm = 0xFFFFFC18
imull %ecx, %ebp
addl %eax, %ebp
movq %r15, (%rsp)
movq %r12, %rdi
movl 0x58(%rsp), %esi
movl 0x60(%rsp), %edx
movq %r14, %rcx
movq %r13, %r8
movq 0x48(%rsp), %r14
movl %r14d, %r9d
callq 0x6068
leaq 0xc0(%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 %ebp, %esi
leaq 0x134d(%rip), %rdi      # 0xf566
xorl %eax, %eax
callq 0x1040
testl %r14d, %r14d
jle 0xe235
movq %r13, %rdi
movq %r15, %rsi
movq 0x50(%rsp), %rdx
callq 0x10b0
movq %r15, %rdi
callq 0x1110
movl 0x34(%rsp), %ebp
movl 0x30(%rsp), %r14d
leaq 0xd0(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1160
movabsq $-0x20c49ba5e353f7cf, %rax # imm = 0xDF3B645A1CAC0831
imulq 0x8(%rbx)
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x7, %rdx
addl %edx, %eax
movl (%rbx), %r15d
movl $0xfffffc18, %ecx       # imm = 0xFFFFFC18
imull %ecx, %r15d
addl %eax, %r15d
movq 0x78(%rsp), %rax
movq %rax, (%rsp)
movq 0x90(%rsp), %r12
movq %r12, %rdi
movl %ebp, %esi
movl %r14d, %edx
movq 0x68(%rsp), %rcx
movq %r13, %r8
movq 0x48(%rsp), %r14
movl %r14d, %r9d
callq 0x5735
leaq 0xd0(%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
movq %r14, %r15
leaq 0x128a(%rip), %rdi      # 0xf57c
xorl %eax, %eax
callq 0x1040
movl 0x34(%rsp), %ebx
movl 0x30(%rsp), %ebp
leaq 0xd0(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x1160
movabsq $-0x20c49ba5e353f7cf, %rax # imm = 0xDF3B645A1CAC0831
imulq 0x8(%r14)
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x7, %rdx
addl %edx, %eax
movl (%r14), %r14d
movl $0xfffffc18, %ecx       # imm = 0xFFFFFC18
imull %ecx, %r14d
addl %eax, %r14d
movq 0x88(%rsp), %rax
movq %rax, 0x8(%rsp)
movl 0x44(%rsp), %eax
movl %eax, (%rsp)
movq %r12, %rdi
movl %ebx, %esi
movl %ebp, %edx
movq 0x68(%rsp), %rcx
movq %r13, %r8
movl %r15d, %r9d
callq 0x6c14
leaq 0xd0(%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 0x11ec(%rip), %rdi      # 0xf593
xorl %eax, %eax
callq 0x1040
movl 0x30(%rsp), %ebp
movl %ebp, %edi
callq 0x56f0
movl %eax, 0x70(%rsp)
movq 0x38(%rsp), %rbx
cmpl $0x4, %ebx
jl 0xe6c8
movq 0x80(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x1100
testl %r15d, %r15d
jle 0xe3fd
xorl %eax, %eax
movsd (%r13,%rax,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%r13,%rax,8)
incq %rax
cmpq %rax, %r15
jne 0xe3e3
cmpl $0x4, %ebx
je 0xe6c8
movl %ebp, %ebx
movq 0x80(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0x1100
movsd %xmm0, 0x98(%rsp)
movl 0x70(%rsp), %ebp
movl %ebp, %eax
shlq $0x3, %rax
testl %ebp, %ebp
movq $-0x1, %r14
cmovnsq %rax, %r14
movq %r14, %rdi
callq 0x1030
movq %rax, %r12
movq %r14, %rdi
callq 0x1030
movq %rax, %r13
movq %r14, %rdi
callq 0x1030
movq %rax, 0x38(%rsp)
movq %r14, %rdi
callq 0x1030
movsd 0x98(%rsp), %xmm4
movl %ebp, %edi
shrl $0x1f, %edi
addl %ebp, %edi
sarl %edi
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
cmpl $-0x1, %ebp
jl 0xe4c2
xorps %xmm1, %xmm1
cvtsi2sd %ebx, %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, (%r12,%rdx,8)
divsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
movsd %xmm2, (%r13,%rdx,8)
incq %rdx
cmpq %rdx, %rcx
jne 0xe48e
movq %rax, 0x50(%rsp)
movq %r13, 0x58(%rsp)
movq %r12, 0x60(%rsp)
testl %r15d, %r15d
movq 0x38(%rsp), %rsi
jle 0xe695
movsd 0xb29(%rip), %xmm1      # 0xf010
ucomisd %xmm4, %xmm1
setbe %cl
leal 0x1(%rdi), %r14d
mulsd 0xc16(%rip), %xmm0      # 0xf110
mulsd %xmm4, %xmm0
cvttsd2si %xmm0, %edx
subl %edx, %edi
setl %al
movslq %edx, %rdx
orb %cl, %al
movb %al, 0x98(%rsp)
leaq 0x2(%rdi), %r13
andq $-0x2, %r13
movq %rdi, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movq %rdx, 0xb8(%rsp)
leaq 0x8(,%rdx,8), %rax
movq %rax, 0xb0(%rsp)
xorl %r15d, %r15d
pxor 0xb28(%rip), %xmm0      # 0xf070
movdqa %xmm0, 0x100(%rsp)
movq 0x78(%rsp), %rbp
movq 0x50(%rsp), %rbx
cmpl $-0x2, 0x70(%rsp)
jg 0xe57e
movq 0x60(%rsp), %rdi
movl %r14d, %edx
movq 0x58(%rsp), %rcx
movl %r14d, %r8d
movq 0x50(%rsp), %r9
callq 0x4733
jmp 0xe5dd
xorl %r12d, %r12d
movq (%rbp,%r15,8), %rax
movq (%rax,%r12,8), %xmm0
callq 0x10a0
movq 0x38(%rsp), %rsi
movq %xmm0, (%rsi,%r12,8)
incq %r12
cmpq %r12, %r14
jne 0xe581
movq 0x60(%rsp), %rdi
movl %r14d, %edx
movq 0x58(%rsp), %rcx
movl %r14d, %r8d
movq %rbx, %r9
callq 0x4733
xorl %r12d, %r12d
movq (%rbx,%r12,8), %xmm0
callq 0x11a0
movq (%rbp,%r15,8), %rax
movq %xmm0, (%rax,%r12,8)
incq %r12
cmpq %r12, %r14
jne 0xe5bf
cmpb $0x0, 0x98(%rsp)
movq 0x38(%rsp), %rsi
movdqa 0x100(%rsp), %xmm4
movdqa 0xa65(%rip), %xmm5      # 0xf060
movdqa 0xa6d(%rip), %xmm6      # 0xf070
pcmpeqd %xmm7, %xmm7
jne 0xe687
movq 0x78(%rsp), %rax
movq (%rax,%r15,8), %rax
movq 0xb8(%rsp), %rcx
movq -0x8(%rax,%rcx,8), %xmm0
addq 0xb0(%rsp), %rax
xorl %ecx, %ecx
movq %rcx, %xmm1
pshufd $0x44, %xmm1, %xmm1     # xmm1 = xmm1[0,1,0,1]
por %xmm5, %xmm1
pxor %xmm6, %xmm1
movdqa %xmm1, %xmm2
pcmpgtd %xmm4, %xmm2
pcmpeqd %xmm4, %xmm1
pshufd $0xf5, %xmm1, %xmm3     # xmm3 = xmm1[1,1,3,3]
pand %xmm2, %xmm3
pshufd $0xf5, %xmm2, %xmm1     # xmm1 = xmm2[1,1,3,3]
por %xmm3, %xmm1
movd %xmm1, %edx
notl %edx
testb $0x1, %dl
je 0xe66b
movq %xmm0, -0x8(%rax,%rcx,8)
pxor %xmm7, %xmm1
pextrw $0x4, %xmm1, %edx
testb $0x1, %dl
je 0xe67e
movq %xmm0, (%rax,%rcx,8)
addq $0x2, %rcx
cmpq %rcx, %r13
jne 0xe62a
incq %r15
cmpq 0x48(%rsp), %r15
jne 0xe55b
movq %rsi, %rdi
callq 0x1110
movq 0x50(%rsp), %rdi
callq 0x1110
movq 0x60(%rsp), %rdi
callq 0x1110
movq 0x58(%rsp), %rdi
callq 0x1110
movq 0x48(%rsp), %r15
movq 0xa8(%rsp), %r13
leal -0x1(%r15), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0xe35(%rip), %xmm1      # 0xf510
mulsd %xmm1, %xmm0
divsd 0xa41(%rip), %xmm0      # 0xf128
movl 0x30(%rsp), %eax
movl %eax, 0x38(%rsp)
xorps %xmm1, %xmm1
cvtsi2sd %eax, %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, %r14
movq %rax, 0x48(%rsp)
leaq 0xeca(%rip), %rdi       # 0xf5f7
callq 0x1150
leaq 0xd0(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1160
movabsq $-0x20c49ba5e353f7cf, %rax # imm = 0xDF3B645A1CAC0831
imulq 0x8(%rbx)
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x7, %rdx
addl %edx, %eax
movl $0xfffffc18, %r12d      # imm = 0xFFFFFC18
imull (%rbx), %r12d
addl %eax, %r12d
movq %r14, 0x8(%rsp)
movl %ebp, (%rsp)
movq %r13, %rdi
movl %r15d, %esi
movq 0x78(%rsp), %r14
movq %r14, %rdx
movq 0x88(%rsp), %rcx
movl 0x44(%rsp), %r8d
movsd 0xd79(%rip), %xmm0      # 0xf510
movl 0x38(%rsp), %r9d
callq 0x375c
leaq 0xd0(%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 %r12d, %esi
leaq 0xdc3(%rip), %rdi       # 0xf5a3
xorl %eax, %eax
callq 0x1040
movl 0x30(%rsp), %edx
movq 0x80(%rsp), %rax
movq 0x10(%rax), %r8
movq 0x48(%rsp), %rbx
movq %rbx, %rdi
movl %ebp, %esi
movl $0x10, %ecx
callq 0x5086
leaq 0xda3(%rip), %rdi       # 0xf5b5
callq 0x1150
movq 0x90(%rsp), %rdi
movq 0x88(%rsp), %r12
callq 0x1110
movq 0x68(%rsp), %rdi
callq 0x1110
movq %r13, %rdi
callq 0x1110
movq %rbx, %rdi
callq 0x1110
testl %r15d, %r15d
jle 0xe871
xorl %ebx, %ebx
movq (%r14,%rbx,8), %rdi
testq %rdi, %rdi
je 0xe85b
callq 0x1110
movq (%r12,%rbx,8), %rdi
testq %rdi, %rdi
je 0xe869
callq 0x1110
incq %rbx
cmpq %rbx, %r15
jne 0xe84d
movq %r14, %rdi
callq 0x1110
movq %r12, %rdi
callq 0x1110
jmp 0xe89a
leaq 0xd4c(%rip), %rbx       # 0xf5d6
movq %rbx, %rdi
callq 0x1150
movq %rbx, %rdi
callq 0x1150
xorl %eax, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq