// File: /workspace/github_c_makefile_star2_O2/diaxen[P]fft-garden/cp_dit_bi_P.c
// Function: fft
void
fft(unsigned N, complex double * restrict out,
    const complex double * restrict in)
{
  unsigned log2_N = 31 - clz32(N);

  /* stage 0 */
  for (unsigned j = 0, i = 0; i < N; i += 2)
    {
      unsigned i0 = cp_input_lut[i / 2];
      unsigned i1 = i0 ^ (N >> 1);

      if (sr_sched_off[j] * 2 > i)
        {
          out[i    ] = in[i0];
          out[i + 1] = in[i1];
        }
      else
        {
          complex double a = in[i0];
          complex double b = in[i1];
          out[i    ] = a + b;
          out[i + 1] = a - b;
          j++;
        }
    }

  /* stage 1 */
  if (log2_N > 1)
    {
      unsigned c = sr_sched_cnt[1];
      for (unsigned i = 0; i < c; i++)
        {
          unsigned o = sr_sched_off[i] << 2;
          cp_dit_bf_0(1, out + o);
        }
    }

  /* stage 2 */
  if (log2_N > 2)
    {
      unsigned c = sr_sched_cnt[2];
      for (unsigned i = 0; i < c; i++)
        {
          unsigned o = sr_sched_off[i] << 3;

          cp_dit_bf_pi4(2, out + o + 1);
          cp_dit_bf_0(2, out + o);
        }
    }

  /* stage >= 3 */
  if (log2_N > 3)
    for (unsigned s = 3; s < log2_N; s++)
      {
        unsigned c = sr_sched_cnt[s];
        for (unsigned i = 0; i < c; i++)
          {
            unsigned o = sr_sched_off[i] << (s + 1);
            unsigned t = log2_N - s - 1;
            unsigned os = 1 << (s - 1);
            unsigned k;

            cp_dit_bf_0(os, out + o);
            for (k = 1; k < os / 2; k++)
              cp_dit_bf(os, out + o + k, get_twiddle(k << t, log2_N));
            cp_dit_bf_pi4(os, out + o + k);
            for (k += 1; k < os; k++)
              cp_dit_bf(os, out + o + k, get_twiddle(k << t, log2_N));
          }
      }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
bsrl %edi, %ebx
xorl $0x1f, %ebx
leaq 0x37d5(%rip), %rax      # 0x5090
movq (%rax), %rax
leaq 0x37e3(%rip), %rcx      # 0x50a8
movq (%rcx), %r15
movl %edi, %ecx
shrl %edi
movq %rsi, 0x8(%rsp)
addq $0x10, %rsi
xorl %r8d, %r8d
xorl %r9d, %r9d
cmpq %rcx, %r8
jae 0x1947
movl (%rax,%r8,2), %r10d
movl %r10d, %r11d
xorl %edi, %r11d
movl %r9d, %r14d
movl (%r15,%r14,4), %r14d
addl %r14d, %r14d
shlq $0x4, %r10
movupd (%rdx,%r10), %xmm0
movl %r11d, %r10d
cmpq %r14, %r8
jae 0x191b
movupd %xmm0, -0x10(%rsi)
shlq $0x4, %r10
movupd (%rdx,%r10), %xmm0
movupd %xmm0, (%rsi)
jmp 0x193d
shlq $0x4, %r10
movupd (%rdx,%r10), %xmm1
movapd %xmm0, %xmm2
addpd %xmm1, %xmm2
movupd %xmm2, -0x10(%rsi)
subpd %xmm1, %xmm0
movupd %xmm0, (%rsi)
incl %r9d
addq $0x2, %r8
addq $0x20, %rsi
jmp 0x18db
movl %ebx, %eax
xorl $0x1f, %eax
movl %eax, 0x4(%rsp)
cmpl $0x1, %eax
jbe 0x1b1a
leaq 0x3740(%rip), %rax      # 0x50a0
movq (%rax), %r14
movl 0x4(%r14), %r12d
xorl %r13d, %r13d
cmpq %r13, %r12
je 0x198c
movl (%r15,%r13,4), %esi
shll $0x2, %esi
shlq $0x4, %rsi
addq 0x8(%rsp), %rsi
pushq $0x1
popq %rdi
callq 0x1b29
incq %r13
jmp 0x196a
cmpl $0x1d, %ebx
je 0x1b1a
movl 0x8(%r14), %r12d
xorl %r13d, %r13d
pushq $0x2
popq %rbx
cmpq %r13, %r12
je 0x19d6
movl (%r15,%r13,4), %eax
shll $0x3, %eax
shlq $0x4, %rax
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax), %r14
leaq (%rcx,%rax), %rsi
addq $0x10, %rsi
movl %ebx, %edi
callq 0x1b9a
movl %ebx, %edi
movq %r14, %rsi
callq 0x1b29
incq %r13
jmp 0x199f
cmpl $0x4, 0x4(%rsp)
jb 0x1b1a
movl 0x4(%rsp), %eax
movq %rax, 0x18(%rsp)
movq 0x8(%rsp), %rax
leaq 0x10(%rax), %rcx
movq %rcx, 0x28(%rsp)
addq $0x20, %rax
movq %rax, 0x20(%rsp)
pushq $0x3
popq %rcx
cmpq 0x18(%rsp), %rcx
je 0x1b1a
leaq 0x368a(%rip), %rax      # 0x50a0
movq (%rax), %rax
movl (%rax,%rcx,4), %eax
movq %rax, 0x30(%rsp)
leaq 0x1(%rcx), %rax
movq %rax, 0x10(%rsp)
movl %ecx, %r12d
notl %r12d
decb %cl
pushq $0x1
popq %rax
movl %eax, %r13d
shll %cl, %r13d
addl 0x4(%rsp), %r12d
movl %r13d, %eax
shrl %eax
movq %rax, 0x40(%rsp)
xorl %ecx, %ecx
cmpq 0x30(%rsp), %rcx
je 0x1b10
leaq 0x364a(%rip), %rax      # 0x50a8
movq (%rax), %rax
movq %rcx, 0x38(%rsp)
movl (%rax,%rcx,4), %r14d
movq 0x10(%rsp), %rcx
shll %cl, %r14d
shlq $0x4, %r14
movq 0x8(%rsp), %rax
leaq (%rax,%r14), %rsi
movl %r13d, %edi
callq 0x1b29
movq 0x28(%rsp), %rax
leaq (%rax,%r14), %rbx
addq 0x20(%rsp), %r14
pushq $0x2
popq %r15
pushq $0x1
popq %rbp
cmpq 0x40(%rsp), %rbp
jae 0x1ace
movl %ebp, %edi
movl %r12d, %ecx
shll %cl, %edi
movl 0x4(%rsp), %esi
callq 0x25ec
movl %r13d, %edi
movq %rbx, %rsi
callq 0x1c4a
incq %rbp
addq $0x10, %rbx
incq %r15
addq $0x10, %r14
jmp 0x1a9c
movl %r13d, %edi
movq %rbx, %rsi
callq 0x1b9a
cmpq %r13, %r15
jae 0x1b03
movl %r15d, %edi
movl %r12d, %ecx
shll %cl, %edi
movl 0x4(%rsp), %esi
callq 0x25ec
movl %r13d, %edi
movq %r14, %rsi
callq 0x1c4a
incq %r15
addq $0x10, %r14
jmp 0x1ad9
movq 0x38(%rsp), %rcx
incq %rcx
jmp 0x1a4c
movq 0x10(%rsp), %rcx
jmp 0x1a04
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq