// File: /workspace/github_cpp_makefile_star2_O2/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 $0xe8, %rsp
movl %edi, %ebx
leal -0x6(%rbx), %eax
cmpl $-0x5, %eax
ja 0xc6d1
leaq 0xe93(%rip), %rdi       # 0xd55f
jmp 0xca7f
movq %rsi, %r12
movq 0x8(%rsi), %rdi
leaq 0x3c(%rsp), %rsi
leaq 0xa4(%rsp), %rdx
leaq 0x44(%rsp), %rcx
callq 0x4828
movq %rax, 0x98(%rsp)
testq %rax, %rax
je 0xca6d
movq %rbx, 0x70(%rsp)
movl 0x44(%rsp), %ebx
movl 0xa4(%rsp), %r15d
movl 0x3c(%rsp), %r14d
leaq 0xe48(%rip), %rdi       # 0xd565
callq 0x1150
leaq 0xd8f(%rip), %rdi       # 0xd4b8
xorl %ebp, %ebp
movl %r14d, %esi
movl %r15d, %edx
xorl %eax, %eax
callq 0x1040
leaq 0xd92(%rip), %rdi       # 0xd4d1
movl %ebx, %esi
xorl %eax, %eax
callq 0x1040
cvtsi2sd %ebx, %xmm0
cvtsi2sd %r14d, %xmm1
divsd %xmm1, %xmm0
leaq 0xd89(%rip), %rdi       # 0xd4e5
movb $0x1, %al
callq 0x1040
movl 0x3c(%rsp), %edi
movl 0x44(%rsp), %esi
movsd 0xd3d(%rip), %xmm0      # 0xd4b0
callq 0x1bd8
movl %eax, %ebx
shlq $0x3, %rbx
testl %eax, %eax
pushq $-0x1
popq %rcx
cmovsq %rcx, %rbx
movl $0x0, %r15d
movl %eax, 0x5c(%rsp)
cmovgl %eax, %r15d
movq %rbx, %rdi
callq 0x1030
movq %rax, 0x60(%rsp)
movq %rbx, %rdi
callq 0x1030
movq %rax, 0x90(%rsp)
movl 0x3c(%rsp), %edi
callq 0x4bec
movl %eax, %r13d
movq %rbx, %rdi
callq 0x1030
movq %rax, 0x50(%rsp)
movq %rbx, %rdi
callq 0x1030
movq %rax, 0x78(%rsp)
pushq $0x2
popq %rcx
movl %r13d, %eax
cltd
idivl %ecx
cltq
leaq 0x8(,%rax,8), %r14
movl %r13d, 0x84(%rsp)
cmpl $-0x3, %r13d
pushq $-0x1
popq %rax
cmovlq %rax, %r14
cmpq %rbp, %r15
je 0xc82a
movq %r14, %rdi
callq 0x1030
movq 0x50(%rsp), %rcx
movq %rax, (%rcx,%rbp,8)
movq %r14, %rdi
callq 0x1030
movq 0x78(%rsp), %rcx
movq %rax, (%rcx,%rbp,8)
incq %rbp
jmp 0xc7fe
movq %r12, 0x88(%rsp)
movl 0x44(%rsp), %r12d
movl %r12d, 0x68(%rsp)
movl 0x3c(%rsp), %r13d
movl %r13d, 0x48(%rsp)
movq %rbx, %rdi
callq 0x1030
movq %rax, %rbx
leaq 0xb8(%rsp), %r14
movq %r14, %rdi
callq 0x2ede
movabsq $0x4014000000000000, %rax # imm = 0x4014000000000000
movq %rax, 0x18(%r14)
movl $0x1, 0x20(%r14)
movabsq $0x4051c00000000000, %rax # imm = 0x4051C00000000000
movq %rax, (%r14)
movabsq $0x3fb999999999999a, %rax # imm = 0x3FB999999999999A
movq %rax, 0x28(%r14)
leaq 0xcf4(%rip), %rdi       # 0xd58d
callq 0x1150
callq 0xc67c
movl %eax, 0x40(%rsp)
movupd (%r14), %xmm0
movupd 0x10(%r14), %xmm1
movupd 0x20(%r14), %xmm2
movupd %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq 0x98(%rsp), %rbp
movq %rbp, %rdi
movl %r12d, %esi
movl %r13d, %edx
movq 0x90(%rsp), %r13
movq %r13, %rcx
movq 0x60(%rsp), %r12
movq %r12, %r8
callq 0x1c03
callq 0xc67c
subl 0x40(%rsp), %eax
leaq 0xbf4(%rip), %rdi       # 0xd4f6
xorl %r14d, %r14d
movl %eax, %esi
xorl %eax, %eax
callq 0x1040
callq 0xc67c
movl %eax, 0x40(%rsp)
movq %rbx, (%rsp)
movq %rbp, %rdi
movl 0x68(%rsp), %esi
movl 0x48(%rsp), %edx
movq %r13, %rcx
movq %r12, %r8
movl 0x5c(%rsp), %r9d
callq 0x5354
callq 0xc67c
subl 0x40(%rsp), %eax
leaq 0xbc0(%rip), %rdi       # 0xd506
movl %eax, %esi
xorl %eax, %eax
callq 0x1040
cmpq %r14, %r15
je 0xc965
movsd (%rbx,%r14,8), %xmm0
movsd %xmm0, (%r12,%r14,8)
incq %r14
jmp 0xc94f
movq %rbx, %rdi
callq 0x1110
movl 0x44(%rsp), %ebx
movl 0x3c(%rsp), %ebp
callq 0xc67c
movl %eax, 0x48(%rsp)
movq 0x50(%rsp), %rax
movq %rax, (%rsp)
movq 0x98(%rsp), %r14
movq %r14, %rdi
movl %ebx, %esi
movl %ebp, %edx
movq 0x90(%rsp), %r13
movq %r13, %rcx
movq %r12, %r8
movl 0x5c(%rsp), %r12d
movl %r12d, %r9d
callq 0x4c31
callq 0xc67c
subl 0x48(%rsp), %eax
leaq 0xb5b(%rip), %rdi       # 0xd51c
movl %eax, %esi
xorl %eax, %eax
callq 0x1040
movl 0x44(%rsp), %ebx
movl 0x3c(%rsp), %ebp
callq 0xc67c
movl %eax, 0x48(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0x8(%rsp)
movl 0x84(%rsp), %eax
movl %eax, (%rsp)
movq %r14, %rdi
movl %ebx, %esi
movl %ebp, %edx
movq %r13, %rcx
movq 0x60(%rsp), %r8
movl %r12d, %r9d
callq 0x5d44
callq 0xc67c
subl 0x48(%rsp), %eax
leaq 0xb1d(%rip), %rdi       # 0xd533
movl %eax, %esi
xorl %eax, %eax
callq 0x1040
movl 0x3c(%rsp), %r14d
movl %r14d, %edi
callq 0x4bec
movq 0x70(%rsp), %rbx
cmpl $0x4, %ebx
jl 0xcc5b
movl %eax, %r12d
movq 0x88(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x1100
xorl %eax, %eax
movq 0x60(%rsp), %rcx
cmpq %rax, %r15
je 0xca89
movsd (%rcx,%rax,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%rcx,%rax,8)
incq %rax
jmp 0xca55
leaq 0xb02(%rip), %rbx       # 0xd576
movq %rbx, %rdi
callq 0x1150
movq %rbx, %rdi
callq 0x1150
jmp 0xcda5
cmpl $0x4, %ebx
je 0xcc5b
movq 0x88(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0x1100
movsd %xmm0, 0x70(%rsp)
movl %r12d, %ebp
shlq $0x3, %rbp
testl %r12d, %r12d
pushq $-0x1
popq %rax
cmovsq %rax, %rbp
movq %rbp, %rdi
callq 0x1030
movq %rax, 0x48(%rsp)
movq %rbp, %rdi
callq 0x1030
movq %rax, 0x68(%rsp)
movq %rbp, %rdi
callq 0x1030
movq %rax, %rbx
movq %rbp, %rdi
callq 0x1030
movq %rax, %rbp
movl %r12d, %eax
cltd
cvtsi2sd %r12d, %xmm0
cvtsi2sd %r14d, %xmm1
pushq $0x2
popq %rcx
idivl %ecx
leal 0x1(%rax), %edx
xorl %ecx, %ecx
testl %edx, %edx
movl $0x0, %r14d
movl %edx, 0x40(%rsp)
cmovgl %edx, %r14d
cmpq %rcx, %r14
je 0xcb4e
cvtsi2sd %ecx, %xmm2
movsd 0x70(%rsp), %xmm3
mulsd %xmm2, %xmm3
divsd %xmm0, %xmm3
mulsd %xmm1, %xmm3
movq 0x48(%rsp), %rdx
movsd %xmm3, (%rdx,%rcx,8)
divsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
movq 0x68(%rsp), %rdx
movsd %xmm2, (%rdx,%rcx,8)
incq %rcx
jmp 0xcb12
mulsd 0x56a(%rip), %xmm0      # 0xd0c0
mulsd 0x70(%rsp), %xmm0
cvttsd2si %xmm0, %ecx
movslq %ecx, %r13
movslq %eax, %rdx
xorl %r12d, %r12d
movq %r15, 0xb0(%rsp)
movq %rdx, 0xa8(%rsp)
cmpq %r15, %r12
je 0xcc37
xorl %r15d, %r15d
cmpq %r15, %r14
je 0xcba9
movq 0x50(%rsp), %rax
movq (%rax,%r12,8), %rax
movsd (%rax,%r15,8), %xmm0
callq 0x10a0
movsd %xmm0, (%rbx,%r15,8)
incq %r15
jmp 0xcb85
movq 0x48(%rsp), %rdi
movq %rbx, %rsi
movl 0x40(%rsp), %edx
movq 0x68(%rsp), %rcx
movl %edx, %r8d
movq %rbp, %r9
callq 0x3dbc
xorl %r15d, %r15d
cmpq %r15, %r14
je 0xcbed
movsd (%rbp,%r15,8), %xmm0
callq 0x11a0
movq 0x50(%rsp), %rax
movq (%rax,%r12,8), %rax
movsd %xmm0, (%rax,%r15,8)
incq %r15
jmp 0xcbc8
movsd 0x41b(%rip), %xmm0      # 0xd010
ucomisd 0x70(%rsp), %xmm0
movq %r13, %rax
movq 0xa8(%rsp), %rdx
jbe 0xcc27
cmpq %rdx, %rax
jg 0xcc27
movq 0x50(%rsp), %rcx
movq (%rcx,%r12,8), %rcx
movsd -0x8(%rcx,%r13,8), %xmm0
movsd %xmm0, (%rcx,%rax,8)
incq %rax
jmp 0xcc08
incq %r12
movq 0xb0(%rsp), %r15
jmp 0xcb79
movq %rbx, %rdi
callq 0x1110
movq %rbp, %rdi
callq 0x1110
movq 0x48(%rsp), %rdi
callq 0x1110
movq 0x68(%rsp), %rdi
callq 0x1110
movl 0x5c(%rsp), %r13d
movl %r13d, %eax
decl %eax
cvtsi2sd %eax, %xmm0
movsd 0x83f(%rip), %xmm1      # 0xd4b0
mulsd %xmm1, %xmm0
divsd 0x45b(%rip), %xmm0      # 0xd0d8
movl 0x3c(%rsp), %r14d
cvtsi2sd %r14d, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %ebp
movslq %ebp, %rax
incl %ebp
cmpl $-0x1, %eax
leaq 0x8(,%rax,8), %rdi
pushq $-0x1
popq %rax
cmovlq %rax, %rdi
callq 0x1030
movq %rax, %r12
leaq 0x8e2(%rip), %rdi       # 0xd597
callq 0x1150
callq 0xc67c
movl %eax, %ebx
movq %r12, 0x8(%rsp)
movl %ebp, (%rsp)
movq 0x60(%rsp), %rdi
movl %r13d, %esi
movq 0x50(%rsp), %rdx
movq 0x78(%rsp), %rcx
movl 0x84(%rsp), %r8d
movsd 0x7c5(%rip), %xmm0      # 0xd4b0
movl %r14d, %r9d
callq 0x3130
callq 0xc67c
subl %ebx, %eax
leaq 0x842(%rip), %rdi       # 0xd543
xorl %ebx, %ebx
movl %eax, %esi
xorl %eax, %eax
callq 0x1040
movl 0x3c(%rsp), %edx
movq 0x88(%rsp), %rax
movq 0x10(%rax), %r8
pushq $0x10
popq %rcx
movq %r12, %rdi
movl %ebp, %esi
callq 0x45fa
leaq 0x825(%rip), %rdi       # 0xd555
callq 0x1150
movq 0x98(%rsp), %rdi
callq 0x1110
movq 0x90(%rsp), %rdi
callq 0x1110
movq 0x60(%rsp), %rdi
callq 0x1110
movq %r12, %rdi
callq 0x1110
cmpq %rbx, %r15
je 0xcd91
movq 0x50(%rsp), %rax
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0xcd79
callq 0x1110
movq 0x78(%rsp), %rax
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0xcd8c
callq 0x1110
incq %rbx
jmp 0xcd61
movq 0x50(%rsp), %rdi
callq 0x1110
movq 0x78(%rsp), %rdi
callq 0x1110
xorl %eax, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq