// File: /workspace/github_c_makefile_star2_O2/diaxen[P]fft-garden/sr_dit_bi_L_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 = 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++)
              {
                complex double w1 = get_twiddle(k << t, log2_N);
                complex double w3 = get_twiddle_sr(k << t, log2_N);
                sr_dit_bf4(os, o + k, w1, w3);
                sr_dit_bf4(os, o + os - k, conj(w1 * I), -conj(w3 * I));
              }
          }

      }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
bsrl %edi, %r13d
xorl $0x1f, %r13d
leaq 0x37d8(%rip), %rax      # 0x5098
movq (%rax), %rax
leaq 0x37de(%rip), %rcx      # 0x50a8
movq (%rcx), %r12
movl %edi, %ecx
shrl %edi
movq %rsi, 0x8(%rsp)
addq $0x10, %rsi
xorl %r8d, %r8d
movq %rdi, %r9
shlq $0x4, %r9
xorl %r10d, %r10d
cmpq %rcx, %r8
jae 0x1956
movl (%rax,%r8,2), %r11d
movl %r10d, %ebx
movl (%r12,%rbx,4), %ebx
addl %ebx, %ebx
cmpq %rbx, %r8
jae 0x1920
movq %r11, %rbx
shlq $0x4, %rbx
movups (%rdx,%rbx), %xmm0
movups %xmm0, -0x10(%rsi)
addl %edi, %r11d
shlq $0x4, %r11
movupd (%rdx,%r11), %xmm0
movupd %xmm0, (%rsi)
jmp 0x194c
shlq $0x4, %r11
leaq (%rdx,%r11), %rbx
movupd (%rdx,%r11), %xmm0
movupd (%r9,%rbx), %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 0x18e7
movl %r13d, %ebp
xorl $0x1f, %ebp
cmpl $0x1, %ebp
jbe 0x1c5f
leaq 0x3734(%rip), %rax      # 0x50a0
movq (%rax), %rbx
movl 0x4(%rbx), %r14d
xorl %r15d, %r15d
cmpq %r15, %r14
je 0x1998
movl (%r12,%r15,4), %esi
shll $0x2, %esi
shlq $0x4, %rsi
addq 0x8(%rsp), %rsi
pushq $0x1
popq %rdi
callq 0x1c71
incq %r15
jmp 0x1976
cmpl $0x1d, %r13d
je 0x1c5f
movl %r13d, (%rsp)
movl 0x8(%rbx), %r13d
xorl %r15d, %r15d
pushq $0x2
popq %rbx
cmpq %r15, %r13
je 0x19e7
movl (%r12,%r15,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 0x1ce2
movl %ebx, %edi
movq %r14, %rsi
callq 0x1c71
incq %r15
jmp 0x19b0
cmpl $0x4, %ebp
movl (%rsp), %ecx
jb 0x1c5f
pushq $0x1e
popq %rax
subl %ecx, %eax
movl %eax, 0x10(%rsp)
movl %ebp, %eax
movq %rax, 0x38(%rsp)
movq 0x8(%rsp), %rax
leaq 0x10(%rax), %rcx
movq %rcx, 0x40(%rsp)
addq $-0x10, %rax
movq %rax, 0x30(%rsp)
pushq $0x3
popq %rcx
cmpq 0x38(%rsp), %rcx
je 0x1c5f
leaq 0x3671(%rip), %rax      # 0x50a0
movq (%rax), %rax
movl (%rax,%rcx,4), %eax
movq %rax, 0x58(%rsp)
leaq 0x1(%rcx), %rax
movq %rax, 0x18(%rsp)
movl %ecx, %eax
notl %eax
addl %ebp, %eax
movl %eax, 0x14(%rsp)
decb %cl
pushq $0x1
popq %rax
movl %eax, %r14d
shll %cl, %r14d
movl %r14d, %eax
shrl %eax
movq %r14, %rcx
shlq $0x4, %rcx
addq 0x30(%rsp), %rcx
movq %rcx, 0x50(%rsp)
movq %rax, 0x68(%rsp)
shlq $0x4, %rax
movq %rax, 0x48(%rsp)
xorl %ecx, %ecx
cmpq 0x58(%rsp), %rcx
je 0x1c55
leaq 0x3618(%rip), %rax      # 0x50a8
movq (%rax), %rax
movq %rcx, 0x60(%rsp)
movl (%rax,%rcx,4), %ebx
movq 0x18(%rsp), %rcx
shll %cl, %ebx
shlq $0x4, %rbx
movq 0x8(%rsp), %rax
leaq (%rax,%rbx), %r12
movl %r14d, %edi
movq %r12, %rsi
callq 0x1c71
addq 0x48(%rsp), %r12
movl %r14d, %edi
movq %r12, %rsi
callq 0x1ce2
movq 0x40(%rsp), %rax
leaq (%rax,%rbx), %r12
addq 0x50(%rsp), %rbx
pushq $0x1
popq %r13
cmpq 0x68(%rsp), %r13
jae 0x1c48
movl %r13d, %r15d
movl 0x14(%rsp), %ecx
shll %cl, %r15d
movl %r15d, %edi
movl %ebp, %esi
callq 0x1dd4
movsd %xmm0, (%rsp)
movsd %xmm1, 0x20(%rsp)
leal (%r15,%r15,2), %r15d
movl %r15d, %edi
movl %ebp, %esi
callq 0x1dd4
movapd %xmm0, %xmm2
movapd %xmm1, %xmm3
movl 0x10(%rsp), %ecx
shrl %cl, %r15d
testl %r15d, %r15d
je 0x1b38
movapd 0x1500(%rip), %xmm0     # 0x3030
xorpd %xmm0, %xmm2
xorpd %xmm0, %xmm3
movl %r14d, %edi
movq %r12, %rsi
movsd (%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movapd %xmm2, 0x70(%rsp)
movapd %xmm3, 0x80(%rsp)
callq 0x1e29
movsd 0x20(%rsp), %xmm1
movsd (%rsp), %xmm0
movapd %xmm0, %xmm5
xorpd %xmm2, %xmm2
mulsd %xmm2, %xmm5
movapd %xmm1, %xmm6
mulsd %xmm2, %xmm6
subsd %xmm1, %xmm5
addsd %xmm0, %xmm6
ucomisd %xmm5, %xmm5
jp 0x1bee
movapd 0x70(%rsp), %xmm0
movapd %xmm0, %xmm2
xorpd %xmm4, %xmm4
mulsd %xmm4, %xmm2
movapd 0x80(%rsp), %xmm1
movapd %xmm1, %xmm3
mulsd %xmm4, %xmm3
subsd %xmm1, %xmm2
addsd %xmm0, %xmm3
ucomisd %xmm2, %xmm2
jp 0x1c0e
movapd 0x146d(%rip), %xmm0     # 0x3030
xorpd %xmm0, %xmm6
xorpd %xmm0, %xmm2
movl %r14d, %edi
movq %rbx, %rsi
movapd %xmm5, %xmm0
movapd %xmm6, %xmm1
callq 0x1e29
incq %r13
addq $0x10, %r12
addq $-0x10, %rbx
jmp 0x1adc
ucomisd %xmm6, %xmm6
jnp 0x1b8a
movsd 0x1624(%rip), %xmm3     # 0x3220
callq 0x2860
movapd %xmm0, %xmm5
movapd %xmm1, %xmm6
jmp 0x1b8a
ucomisd %xmm3, %xmm3
jnp 0x1bbb
xorpd %xmm2, %xmm2
movsd 0x1600(%rip), %xmm3     # 0x3220
movsd %xmm5, (%rsp)
movapd %xmm6, 0x20(%rsp)
callq 0x2860
movapd 0x20(%rsp), %xmm6
movsd (%rsp), %xmm5
movapd %xmm0, %xmm2
movapd %xmm1, %xmm3
jmp 0x1bbb
movq 0x60(%rsp), %rcx
incq %rcx
jmp 0x1a7e
movq 0x18(%rsp), %rcx
jmp 0x1a1d
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq