// File: Sleepwalking[P]world-octave/dio.cpp
// Function: (anonymous namespace)::DioGeneralBody(double*, int, int, double, double, double, double, int, double, double*, double*)
void DioGeneralBody(double *x, int x_length, int fs, double frame_period,
    double f0_floor, double f0_ceil, double channels_in_octave, int speed,
    double allowed_range, double *time_axis, double *f0) {
  int number_of_bands = 1 + static_cast<int>(log(f0_ceil / f0_floor) /
    world::kLog2 * channels_in_octave);
  double * boundary_f0_list = new double[number_of_bands];
  for (int i = 0; i < number_of_bands; ++i)
    boundary_f0_list[i] = f0_floor * pow(2.0, (i + 1) / channels_in_octave);

  // normalization
  int decimation_ratio = MyMax(MyMin(speed, 12), 1);
  int y_length = (1 + static_cast<int>(x_length / decimation_ratio));
  double actual_fs = static_cast<double>(fs) / decimation_ratio;
  int fft_size = GetSuitableFFTSize(y_length +
      (4 * static_cast<int>(1.0 + actual_fs / boundary_f0_list[0] / 2.0)));

  // Calculation of the spectrum used for the f0 estimation
  fft_complex *y_spectrum = new fft_complex[fft_size];
  GetSpectrumForEstimation(x, x_length, y_length, actual_fs, fft_size,
      decimation_ratio, y_spectrum);

  // f0map represents all F0 candidates. We can modify them.
  double **f0_candidate_map = new double *[number_of_bands];
  double **f0_stability_map = new double *[number_of_bands];
  int f0_length = GetSamplesForDIO(fs, x_length, frame_period);
  for (int i = 0; i < number_of_bands; ++i) {
    f0_candidate_map[i] = new double[f0_length];
    f0_stability_map[i] = new double[f0_length];
  }

  for (int i = 0; i < f0_length; ++i)
    time_axis[i] = i * frame_period / 1000.0;

  GetF0CandidateAndStabilityMap(boundary_f0_list, number_of_bands,
      actual_fs, y_length, time_axis, f0_length, y_spectrum,
      fft_size, f0_floor, f0_ceil, f0_candidate_map, f0_stability_map);

  // Selection of the best value based on fundamental-ness.
  double *best_f0_contour = new double[f0_length];
  GetBestF0Contour(f0_length, f0_candidate_map, f0_stability_map,
      number_of_bands, best_f0_contour);

  // Postprocessing to find the best f0-contour.
  FixF0Contour(frame_period, number_of_bands, fs, f0_candidate_map,
      best_f0_contour, f0_length, f0_floor, allowed_range, f0);

  delete[] best_f0_contour;
  delete[] y_spectrum;
  for (int i = 0; i < number_of_bands; ++i) {
    delete[] f0_stability_map[i];
    delete[] f0_candidate_map[i];
  }
  delete[] f0_stability_map;
  delete[] f0_candidate_map;
  delete[] boundary_f0_list;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movsd %xmm1, -0x20(%rbp)
movsd %xmm2, -0x28(%rbp)
movsd %xmm3, -0x30(%rbp)
movl %ecx, -0x34(%rbp)
movsd %xmm4, -0x40(%rbp)
movq %r8, -0x48(%rbp)
movq %r9, -0x50(%rbp)
movsd -0x28(%rbp), %xmm0
divsd -0x20(%rbp), %xmm0
callq 0x10a0
movsd 0x19b08(%rip), %xmm1    # 0x1c018
divsd %xmm1, %xmm0
mulsd -0x30(%rbp), %xmm0
cvttsd2si %xmm0, %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movslq -0x54(%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, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x54(%rbp), %eax
jge 0x25ab
movsd -0x20(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
cvtsi2sd %eax, %xmm1
divsd -0x30(%rbp), %xmm1
movsd 0x19a89(%rip), %xmm0    # 0x1c008
callq 0x1180
movaps %xmm0, %xmm1
movsd -0xc0(%rbp), %xmm0
mulsd %xmm1, %xmm0
movq -0x60(%rbp), %rax
movslq -0x64(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x2553
movl -0x34(%rbp), %edi
movl $0xc, %esi
callq 0x4fb0
movl %eax, %edi
movl $0x1, %esi
callq 0x4f80
movl %eax, -0x68(%rbp)
movl -0xc(%rbp), %eax
cltd
idivl -0x68(%rbp)
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
cvtsi2sdl -0x10(%rbp), %xmm0
cvtsi2sdl -0x68(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movl -0x6c(%rbp), %edi
movsd -0x78(%rbp), %xmm1
movq -0x60(%rbp), %rax
divsd (%rax), %xmm1
movsd 0x19a09(%rip), %xmm0    # 0x1c008
divsd %xmm0, %xmm1
movsd 0x19a05(%rip), %xmm0    # 0x1c010
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
shll $0x2, %eax
addl %eax, %edi
callq 0x12c0
movl %eax, -0x7c(%rbp)
movslq -0x7c(%rbp), %rax
movl $0x10, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x1030
movq %rax, -0x88(%rbp)
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x6c(%rbp), %edx
movsd -0x78(%rbp), %xmm0
movl -0x7c(%rbp), %ecx
movl -0x68(%rbp), %r8d
movq -0x88(%rbp), %r9
callq 0x2a40
movslq -0x54(%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, -0x90(%rbp)
movslq -0x54(%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, -0x98(%rbp)
movl -0x10(%rbp), %edi
movl -0xc(%rbp), %esi
movsd -0x18(%rbp), %xmm0
callq 0x2420
movl %eax, -0x9c(%rbp)
movl $0x0, -0xa0(%rbp)
movl -0xa0(%rbp), %eax
cmpl -0x54(%rbp), %eax
jge 0x2783
movslq -0x9c(%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, %rdx
movq -0x90(%rbp), %rax
movslq -0xa0(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movslq -0x9c(%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, %rdx
movq -0x98(%rbp), %rax
movslq -0xa0(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0xa0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa0(%rbp)
jmp 0x26e6
movl $0x0, -0xa4(%rbp)
movl -0xa4(%rbp), %eax
cmpl -0x9c(%rbp), %eax
jge 0x27d5
cvtsi2sdl -0xa4(%rbp), %xmm0
mulsd -0x18(%rbp), %xmm0
movsd 0x198c8(%rip), %xmm1    # 0x1c078
divsd %xmm1, %xmm0
movq -0x48(%rbp), %rax
movslq -0xa4(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x278d
movq -0x60(%rbp), %rdi
movl -0x54(%rbp), %esi
movsd -0x78(%rbp), %xmm0
movl -0x6c(%rbp), %edx
movq -0x48(%rbp), %rcx
movl -0x9c(%rbp), %r8d
movq -0x88(%rbp), %r9
movl -0x7c(%rbp), %r11d
movsd -0x20(%rbp), %xmm1
movsd -0x28(%rbp), %xmm2
movq -0x90(%rbp), %r10
movq -0x98(%rbp), %rax
movl %r11d, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x2f00
movslq -0x9c(%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, -0xb0(%rbp)
movl -0x9c(%rbp), %edi
movq -0x90(%rbp), %rsi
movq -0x98(%rbp), %rdx
movl -0x54(%rbp), %ecx
movq -0xb0(%rbp), %r8
callq 0x30a0
movsd -0x18(%rbp), %xmm0
movl -0x54(%rbp), %edi
movl -0x10(%rbp), %esi
movq -0x90(%rbp), %rdx
movq -0xb0(%rbp), %rcx
movl -0x9c(%rbp), %r8d
movsd -0x20(%rbp), %xmm1
movsd -0x40(%rbp), %xmm2
movq -0x50(%rbp), %r9
callq 0x3190
movq -0xb0(%rbp), %rax
movq %rax, -0xc8(%rbp)
cmpq $0x0, %rax
je 0x28ca
movq -0xc8(%rbp), %rdi
callq 0x1110
movq -0x88(%rbp), %rax
movq %rax, -0xd0(%rbp)
cmpq $0x0, %rax
je 0x28ea
movq -0xd0(%rbp), %rdi
callq 0x1110
movl $0x0, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
cmpl -0x54(%rbp), %eax
jge 0x2968
movq -0x98(%rbp), %rax
movslq -0xb4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xd8(%rbp)
cmpq $0x0, %rax
je 0x292a
movq -0xd8(%rbp), %rdi
callq 0x1110
movq -0x90(%rbp), %rax
movslq -0xb4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xe0(%rbp)
cmpq $0x0, %rax
je 0x2955
movq -0xe0(%rbp), %rdi
callq 0x1110
jmp 0x2957
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x28f4
movq -0x98(%rbp), %rax
movq %rax, -0xe8(%rbp)
cmpq $0x0, %rax
je 0x2988
movq -0xe8(%rbp), %rdi
callq 0x1110
movq -0x90(%rbp), %rax
movq %rax, -0xf0(%rbp)
cmpq $0x0, %rax
je 0x29a8
movq -0xf0(%rbp), %rdi
callq 0x1110
movq -0x60(%rbp), %rax
movq %rax, -0xf8(%rbp)
cmpq $0x0, %rax
je 0x29c5
movq -0xf8(%rbp), %rdi
callq 0x1110
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nop