// File: /workspace/github_c_makefile_star2_O2/diaxen[P]fft-garden/cp_dit_bi_S_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;

            unsigned m = os / 2;
            cp_dit_bf_0(os, out + o);
            cp_dit_bf_pi4(os, out + o + m);
            for (k = 1; k < m; k++)
              {
                complex double w = get_twiddle(k << t, log2_N);
                cp_dit_bf(os, out + o + k, w);
                cp_dit_bf(os, out + o + os - k, -I * conj(w));
              }
          }
      }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
bsrl %edi, %ebp
xorl $0x1f, %ebp
leaq 0x36d1(%rip), %rax      # 0x5090
movq (%rax), %rax
leaq 0x36df(%rip), %rcx      # 0x50a8
movq (%rcx), %rbx
movl %edi, %ecx
shrl %edi
movq %rsi, 0x10(%rsp)
addq $0x10, %rsi
xorl %r8d, %r8d
xorl %r9d, %r9d
cmpq %rcx, %r8
jae 0x1a4b
movl (%rax,%r8,2), %r10d
movl %r10d, %r11d
xorl %edi, %r11d
movl %r9d, %r14d
movl (%rbx,%r14,4), %r14d
addl %r14d, %r14d
shlq $0x4, %r10
movupd (%rdx,%r10), %xmm0
movl %r11d, %r10d
cmpq %r14, %r8
jae 0x1a1f
movupd %xmm0, -0x10(%rsi)
shlq $0x4, %r10
movupd (%rdx,%r10), %xmm0
movupd %xmm0, (%rsi)
jmp 0x1a41
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 0x19df
movl %ebp, %eax
xorl $0x1f, %eax
movl %eax, 0xc(%rsp)
cmpl $0x1, %eax
jbe 0x1c90
leaq 0x363c(%rip), %rax      # 0x50a0
movq (%rax), %r14
movl 0x4(%r14), %r15d
xorl %r12d, %r12d
cmpq %r12, %r15
je 0x1a90
movl (%rbx,%r12,4), %esi
shll $0x2, %esi
shlq $0x4, %rsi
addq 0x10(%rsp), %rsi
pushq $0x1
popq %rdi
callq 0x1c9f
incq %r12
jmp 0x1a6e
cmpl $0x1d, %ebp
je 0x1c90
movl 0x8(%r14), %r15d
xorl %r12d, %r12d
pushq $0x2
popq %rbp
cmpq %r12, %r15
je 0x1ada
movl (%rbx,%r12,4), %eax
shll $0x3, %eax
shlq $0x4, %rax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax), %r14
leaq (%rcx,%rax), %rsi
addq $0x10, %rsi
movl %ebp, %edi
callq 0x1d10
movl %ebp, %edi
movq %r14, %rsi
callq 0x1c9f
incq %r12
jmp 0x1aa3
cmpl $0x4, 0xc(%rsp)
jb 0x1c90
movl 0xc(%rsp), %eax
movq %rax, 0x28(%rsp)
movq 0x10(%rsp), %rax
leaq 0x10(%rax), %rcx
movq %rcx, 0x30(%rsp)
addq $-0x10, %rax
movq %rax, 0x20(%rsp)
pushq $0x3
popq %rcx
cmpq 0x28(%rsp), %rcx
je 0x1c90
leaq 0x3586(%rip), %rax      # 0x50a0
movq (%rax), %rax
movl (%rax,%rcx,4), %eax
movq %rax, 0x48(%rsp)
leaq 0x1(%rcx), %rax
movq %rax, 0x18(%rsp)
movl %ecx, %r15d
notl %r15d
addl 0xc(%rsp), %r15d
decb %cl
pushq $0x1
popq %rax
movl %eax, %r12d
shll %cl, %r12d
movl %r12d, %r14d
shrl %r14d
movq %r12, %rax
shlq $0x4, %rax
addq 0x20(%rsp), %rax
movq %rax, 0x40(%rsp)
movq %r14, %rax
shlq $0x4, %rax
movq %rax, 0x38(%rsp)
xorl %ecx, %ecx
cmpq 0x48(%rsp), %rcx
je 0x1c86
leaq 0x352d(%rip), %rax      # 0x50a8
movq (%rax), %rax
movq %rcx, 0x50(%rsp)
movl (%rax,%rcx,4), %r13d
movq 0x18(%rsp), %rcx
shll %cl, %r13d
shlq $0x4, %r13
movq 0x10(%rsp), %rax
leaq (%rax,%r13), %rbp
movl %r12d, %edi
movq %rbp, %rsi
callq 0x1c9f
addq 0x38(%rsp), %rbp
movl %r12d, %edi
movq %rbp, %rsi
callq 0x1d10
movq 0x30(%rsp), %rax
leaq (%rax,%r13), %rbp
addq 0x40(%rsp), %r13
pushq $0x1
popq %rbx
cmpq %r14, %rbx
jae 0x1c79
movl %ebx, %eax
movl %r15d, %ecx
shll %cl, %eax
leaq 0x34a1(%rip), %rcx      # 0x5080
movq (%rcx), %rcx
shlq $0x4, %rax
movsd (%rcx,%rax), %xmm0
movsd %xmm0, 0x58(%rsp)
movsd 0x8(%rcx,%rax), %xmm1
movaps %xmm1, 0x60(%rsp)
movl %r12d, %edi
movq %rbp, %rsi
callq 0x1dc0
movapd 0x60(%rsp), %xmm3
movsd 0x58(%rsp), %xmm2
movapd %xmm2, %xmm0
mulsd 0x1451(%rip), %xmm0     # 0x3070
movapd %xmm3, %xmm1
mulsd 0x13ed(%rip), %xmm1     # 0x3018
subsd %xmm3, %xmm0
subsd %xmm2, %xmm1
ucomisd %xmm0, %xmm0
jp 0x1c54
movl %r12d, %edi
movq %r13, %rsi
callq 0x1dc0
incq %rbx
addq $0x10, %rbp
addq $-0x10, %r13
jmp 0x1bc8
ucomisd %xmm1, %xmm1
jnp 0x1c39
xorpd 0x13ce(%rip), %xmm3     # 0x3030
movsd 0x1406(%rip), %xmm0     # 0x3070
movsd 0x15ee(%rip), %xmm1     # 0x3260
callq 0x27a0
jmp 0x1c39
movq 0x50(%rsp), %rcx
incq %rcx
jmp 0x1b69
movq 0x18(%rsp), %rcx
jmp 0x1b08
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq