// File: Sleepwalking[P]world-octave/stonemask.cpp
// Function: (anonymous namespace)::GetSpectra(double*, int, int, int*, double*, double*, int, ForwardRealFFT*, double (*) [2], double (*) [2])
void GetSpectra(double *x, int x_length, int fft_size, int *index_raw,
    double *main_window, double *diff_window, int base_time_length,
    ForwardRealFFT *forward_real_fft, fft_complex *main_spectrum,
    fft_complex *diff_spectrum) {
  int *index = new int[base_time_length];

  for (int i = 0; i < base_time_length; ++i)
    index[i] = MyMax(0, MyMin(x_length - 1, index_raw[i] - 1));
  for (int i = 0; i < base_time_length; ++i)
    forward_real_fft->waveform[i] = x[index[i]] * main_window[i];
  for (int i = base_time_length; i < fft_size; ++i)
    forward_real_fft->waveform[i] = 0.0;

  fft_execute(forward_real_fft->forward_fft);
  for (int i = 0; i <= fft_size / 2; ++i) {
    main_spectrum[i][0] = forward_real_fft->spectrum[i][0];
    main_spectrum[i][1] = -forward_real_fft->spectrum[i][1];
  }

  for (int i = 0; i < base_time_length; ++i)
    forward_real_fft->waveform[i] = x[index[i]] * diff_window[i];
  for (int i = base_time_length; i < fft_size; ++i)
    forward_real_fft->waveform[i] = 0.0;
  fft_execute(forward_real_fft->forward_fft);
  for (int i = 0; i <= fft_size / 2; ++i) {
    diff_spectrum[i][0] = forward_real_fft->spectrum[i][0];
    diff_spectrum[i][1] = -forward_real_fft->spectrum[i][1];
  }

  delete[] index;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movslq 0x10(%rbp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x1030
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl 0x10(%rbp), %eax
jge 0x9dd2
movl -0xc(%rbp), %edi
subl $0x1, %edi
movq -0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %esi
subl $0x1, %esi
callq 0x4fb0
movl %eax, %esi
xorl %edi, %edi
callq 0x4f80
movl %eax, %edx
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x9d90
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl 0x10(%rbp), %eax
jge 0x9e1f
movq -0x8(%rbp), %rax
movq -0x30(%rbp), %rcx
movslq -0x38(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x20(%rbp), %rax
movslq -0x38(%rbp), %rcx
mulsd (%rax,%rcx,8), %xmm0
movq 0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x38(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x9dd9
movl 0x10(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x9e4c
movq 0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x3c(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x9e25
movq 0x18(%rbp), %rsi
addq $0x18, %rsi
leaq -0x88(%rbp), %rdi
movl $0x48, %edx
callq 0x10b0
movq -0x48(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x40(%rax)
movups -0x88(%rbp), %xmm0
movups -0x78(%rbp), %xmm1
movups -0x68(%rbp), %xmm2
movups -0x58(%rbp), %xmm3
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0xd500
movl $0x0, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, -0xe8(%rbp)
movl -0x10(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0xe8(%rbp), %eax
cmpl %ecx, %eax
jg 0x9f55
movq 0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x8c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movq 0x20(%rbp), %rax
movslq -0x8c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, (%rax)
movq 0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x8c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq 0x20(%rbp), %rax
movslq -0x8c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x9ea1
movl $0x0, -0x90(%rbp)
movl -0x90(%rbp), %eax
cmpl 0x10(%rbp), %eax
jge 0x9fb7
movq -0x8(%rbp), %rax
movq -0x30(%rbp), %rcx
movslq -0x90(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x28(%rbp), %rax
movslq -0x90(%rbp), %rcx
mulsd (%rax,%rcx,8), %xmm0
movq 0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x90(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x9f5f
movl 0x10(%rbp), %eax
movl %eax, -0x94(%rbp)
movl -0x94(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x9ff3
movq 0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x94(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x9fc0
movq 0x18(%rbp), %rsi
addq $0x18, %rsi
leaq -0xe0(%rbp), %rdi
movl $0x48, %edx
callq 0x10b0
movq -0xa0(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x40(%rax)
movups -0xe0(%rbp), %xmm0
movups -0xd0(%rbp), %xmm1
movups -0xc0(%rbp), %xmm2
movups -0xb0(%rbp), %xmm3
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0xd500
movl $0x0, -0xe4(%rbp)
movl -0xe4(%rbp), %eax
movl %eax, -0xec(%rbp)
movl -0x10(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0xec(%rbp), %eax
cmpl %ecx, %eax
jg 0xa108
movq 0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xe4(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movq 0x28(%rbp), %rax
movslq -0xe4(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, (%rax)
movq 0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xe4(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq 0x28(%rbp), %rax
movslq -0xe4(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movl -0xe4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe4(%rbp)
jmp 0xa054
movq -0x30(%rbp), %rax
movq %rax, -0xf8(%rbp)
cmpq $0x0, %rax
je 0xa125
movq -0xf8(%rbp), %rdi
callq 0x1110
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nop