// File: /workspace/github_c_makefile_star2_O2/diaxen[P]fft-garden/sr_dit_bi_L_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 = sr_input_lut[i / 2];

      if (sr_sched_off[j] * 2 > i)
        {
          out[i    ] = in[i0];
          out[i + 1] = in[i0 + N / 2];
        }
      else
        {
          ct_dit_bf2_0(1, N / 2, out + i, in + i0);
          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;
          sr_dit_bf4_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;

          sr_dit_bf4_pi4(2, out + o + 1);
          sr_dit_bf4_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++)
          {
            complex double *o = out + (sr_sched_off[i] << (s + 1));
            unsigned t = log2_N - s - 1;
            unsigned os = 1 << (s - 1);
            unsigned k;

            sr_dit_bf4_0(os, o);
            sr_dit_bf4_pi4(os, o + os / 2);

            for (k = 1; k < os / 2; k++)
              sr_dit_bf4(os, o + k,
                     get_twiddle(k << t, log2_N),
                     get_twiddle_sr(k << t, log2_N));

            for (k++; k < os; k++)
              sr_dit_bf4(os, o + k,
                     get_twiddle(k << t, log2_N),
                     get_twiddle_sr(k << t, log2_N));
          }

      }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
bsrl %edi, %ebp
xorl $0x1f, %ebp
leaq 0x36d9(%rip), %rax      # 0x5098
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
movq %rdi, %r9
shlq $0x4, %r9
xorl %r10d, %r10d
cmpq %rcx, %r8
jae 0x1a57
movl (%rax,%r8,2), %r11d
movl %r10d, %r14d
movl (%rbx,%r14,4), %r14d
addl %r14d, %r14d
cmpq %r14, %r8
jae 0x1a21
movq %r11, %r14
shlq $0x4, %r14
movups (%rdx,%r14), %xmm0
movups %xmm0, -0x10(%rsi)
addl %edi, %r11d
shlq $0x4, %r11
movupd (%rdx,%r11), %xmm0
movupd %xmm0, (%rsi)
jmp 0x1a4d
shlq $0x4, %r11
leaq (%rdx,%r11), %r14
movupd (%rdx,%r11), %xmm0
movupd (%r9,%r14), %xmm1
movapd %xmm0, %xmm2
addpd %xmm1, %xmm2
movupd %xmm2, -0x10(%rsi)
subpd %xmm1, %xmm0
movupd %xmm0, (%rsi)
incl %r10d
addq $0x2, %r8
addq $0x20, %rsi
jmp 0x19e6
movl %ebp, %eax
xorl $0x1f, %eax
movl %eax, 0xc(%rsp)
cmpl $0x1, %eax
jbe 0x1c87
leaq 0x3630(%rip), %rax      # 0x50a0
movq (%rax), %r14
movl 0x4(%r14), %r15d
xorl %r12d, %r12d
cmpq %r12, %r15
je 0x1a9c
movl (%rbx,%r12,4), %esi
shll $0x2, %esi
shlq $0x4, %rsi
addq 0x10(%rsp), %rsi
pushq $0x1
popq %rdi
callq 0x1c96
incq %r12
jmp 0x1a7a
cmpl $0x1d, %ebp
je 0x1c87
movl 0x8(%r14), %r15d
xorl %r12d, %r12d
pushq $0x2
popq %rbp
cmpq %r12, %r15
je 0x1ae6
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 0x1d07
movl %ebp, %edi
movq %r14, %rsi
callq 0x1c96
incq %r12
jmp 0x1aaf
cmpl $0x4, 0xc(%rsp)
jb 0x1c87
movl 0xc(%rsp), %eax
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %rax
leaq 0x10(%rax), %rcx
movq %rcx, 0x30(%rsp)
addq $0x20, %rax
movq %rax, 0x28(%rsp)
pushq $0x3
popq %rcx
cmpq 0x20(%rsp), %rcx
je 0x1c87
leaq 0x357a(%rip), %rax      # 0x50a0
movq (%rax), %rax
movl (%rax,%rcx,4), %eax
movq %rax, 0x40(%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, %eax
shrl %eax
movq %rax, 0x50(%rsp)
shlq $0x4, %rax
movq %rax, 0x38(%rsp)
xorl %ecx, %ecx
cmpq 0x40(%rsp), %rcx
je 0x1c7d
leaq 0x3531(%rip), %rax      # 0x50a8
movq (%rax), %rax
movq %rcx, 0x48(%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 0x1c96
addq 0x38(%rsp), %rbp
movl %r12d, %edi
movq %rbp, %rsi
callq 0x1d07
movq 0x30(%rsp), %rax
leaq (%rax,%r13), %rbp
addq 0x28(%rsp), %r13
pushq $0x2
popq %r14
pushq $0x1
popq %rbx
cmpq 0x50(%rsp), %rbx
jae 0x1c6b
movl %ebx, %eax
movl %r15d, %ecx
shll %cl, %eax
leaq 0x349f(%rip), %rcx      # 0x5080
movq (%rcx), %rcx
shlq $0x4, %rax
movsd (%rcx,%rax), %xmm0
movsd 0x8(%rcx,%rax), %xmm1
leaq 0x348e(%rip), %rcx      # 0x5088
movq (%rcx), %rcx
movsd (%rcx,%rax), %xmm2
movsd 0x8(%rcx,%rax), %xmm3
movl %r12d, %edi
movq %rbp, %rsi
callq 0x1df9
incq %rbx
addq $0x10, %rbp
incq %r14
addq $0x10, %r13
jmp 0x1bc8
movl %r14d, %eax
movl %r15d, %ecx
shll %cl, %eax
leaq 0x344e(%rip), %rcx      # 0x5080
movq (%rcx), %rcx
shlq $0x4, %rax
movsd (%rcx,%rax), %xmm0
movsd 0x8(%rcx,%rax), %xmm1
leaq 0x343d(%rip), %rcx      # 0x5088
movq (%rcx), %rcx
movsd (%rcx,%rax), %xmm2
movsd 0x8(%rcx,%rax), %xmm3
movl %r12d, %edi
movq %r13, %rsi
callq 0x1df9
incq %r14
addq $0x10, %r13
cmpq %r12, %r14
jb 0x1c23
movq 0x48(%rsp), %rcx
incq %rcx
jmp 0x1b65
movq 0x18(%rsp), %rcx
jmp 0x1b14
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq