// File: /workspace/github_c_makefile_star2_O3/guszejnovdavid[P]MISFIT/fft.c
// Function: cooley_tukey(complex*, int, int, int)
void cooley_tukey(complex x[], int n, int flag, int n2)
{
   complex c;
   int i, j, k, m, p, n1;
   int Ls, ks, ms, jm, dk;
   real wr, wi, tr, ti;

   n1 = n/n2;                               /* do bit reversal permutation */
   for(k = 0; k < n1; ++k) {        /* This is algorithms 1.5.1 and 1.5.2. */
      j = 0; 
      m = k;
      p = 1;                               /* p = 2^q,  q used in the book */
      while(p < n1) {
         j = 2*j + (m&1);
         m >>= 1;
         p <<= 1;
      }
      assert(p == n1);                   /* make sure n1 is a power of two */
      if(j > k) {
         for(i = 0; i < n2; ++i) {                     /* swap k <-> j row */
            c = x[k*n2+i];                              /* for all columns */
            x[k*n2+i] = x[j*n2+i];
            x[j*n2+i] = c;
         }
      }
   }
                                              /* This is (3.1.7), page 124 */
   p = 1;
   while(p < n1) {
      Ls = p;
      p <<= 1;
      jm = 0;                                                /* jm is j*n2 */
      dk = p*n2;
      for(j = 0; j < Ls; ++j) {
         wr = cos(M_PI*j/Ls);                   /* real and imaginary part */
         wi = -flag * sin(M_PI*j/Ls);                      /* of the omega */
         for(k = jm; k < n; k += dk) {                      /* "butterfly" */
            ks = k + Ls*n2;
            for(i = 0; i < n2; ++i) {                      /* for each row */
               m = k + i;
               ms = ks + i;
               tr =  wr*x[ms].Re - wi*x[ms].Im;
               ti =  wr*x[ms].Im + wi*x[ms].Re;
               x[ms].Re = x[m].Re - tr;
               x[ms].Im = x[m].Im - ti;
               x[m].Re += tr;
               x[m].Im += ti;
            }
         }
         jm += n2;
      } 
   }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %edx, %ebx
movl %esi, %eax
movq %rdi, 0x18(%rsp)
movl %esi, 0x8(%rsp)
cltd
idivl %ecx
testl %eax, %eax
jle 0x8718
movslq %ecx, %rdx
movl %eax, %r15d
movl %ecx, %r13d
movq %rdx, 0x38(%rsp)
shlq $0x4, %rdx
movq %rdx, 0x28(%rsp)
movq %r13, %rdx
shlq $0x4, %rdx
xorl %esi, %esi
movq 0x18(%rsp), %r14
movq %r14, %rdi
movl %ecx, 0xc(%rsp)
movl 0xc(%rsp), %ecx
movl $0x1, %r9d
movl $0x0, %r8d
cmpl $0x1, %eax
je 0x853e
xorl %r8d, %r8d
movl %esi, %r10d
movl %r10d, %r11d
andl $0x1, %r11d
leal (%r11,%r8,2), %r8d
shrl %r10d
addl %r9d, %r9d
cmpl %eax, %r9d
jl 0x8528
cmpl %eax, %r9d
jne 0x872a
testl %ecx, %ecx
setle %r9b
movslq %r8d, %r10
cmpq %r10, %rsi
setge %r10b
orb %r9b, %r10b
jne 0x8596
imull %ecx, %r8d
movslq %r8d, %r8
shlq $0x4, %r8
addq %r14, %r8
xorl %r9d, %r9d
movups (%rdi,%r9), %xmm0
movaps %xmm0, 0x70(%rsp)
movups (%r8,%r9), %xmm0
movups %xmm0, (%rdi,%r9)
movapd 0x70(%rsp), %xmm0
movupd %xmm0, (%r8,%r9)
addq $0x10, %r9
cmpq %r9, %rdx
jne 0x856d
incq %rsi
addq 0x28(%rsp), %rdi
cmpq %r15, %rsi
jne 0x8511
cmpl $0x1, %eax
je 0x8718
negl %ebx
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
movsd %xmm0, 0x30(%rsp)
movslq 0x8(%rsp), %rbp
shlq $0x4, %r13
movl $0x1, %edx
movl %eax, 0x10(%rsp)
leal (%rdx,%rdx), %eax
movl %eax, 0x4(%rsp)
movq %rdx, 0x20(%rsp)
testl %edx, %edx
jle 0x8708
movl 0x4(%rsp), %eax
movq 0x20(%rsp), %rdx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
movsd %xmm0, 0x40(%rsp)
imull %ecx, %eax
imull %ecx, %edx
movslq %eax, %r14
movslq %edx, %r15
movq %r14, %r12
shlq $0x4, %r12
shlq $0x4, %r15
xorl %ebx, %ebx
xorpd %xmm0, %xmm0
movq 0x18(%rsp), %r8
xorl %eax, %eax
movl %eax, 0x14(%rsp)
movq %r8, 0x50(%rsp)
movsd %xmm0, 0x58(%rsp)
mulsd 0x30da(%rip), %xmm0     # 0xb710
divsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
callq 0x23e0
movapd %xmm0, 0x60(%rsp)
movsd 0x48(%rsp), %xmm0
callq 0x2080
movapd 0x60(%rsp), %xmm4
movq 0x50(%rsp), %r8
movl 0xc(%rsp), %ecx
cmpl 0x8(%rsp), %ebx
jge 0x86e0
mulsd 0x30(%rsp), %xmm0
movapd %xmm0, %xmm1
xorpd 0x2e61(%rip), %xmm1     # 0xb4e0
unpcklpd %xmm4, %xmm4            # xmm4 = xmm4[0,0]
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
movq %r8, %rax
movq %rbx, %rdi
testl %ecx, %ecx
jle 0x86d5
leaq (%rax,%r15), %rdx
xorl %esi, %esi
movupd (%rdx,%rsi), %xmm1
movapd %xmm1, %xmm2
mulpd %xmm0, %xmm2
shufpd $0x1, %xmm2, %xmm2      # xmm2 = xmm2[1,0]
mulpd %xmm4, %xmm1
addpd %xmm2, %xmm1
movupd (%rax,%rsi), %xmm2
movapd %xmm2, %xmm3
subpd %xmm1, %xmm3
movupd %xmm3, (%rdx,%rsi)
addpd %xmm2, %xmm1
movupd %xmm1, (%rax,%rsi)
addq $0x10, %rsi
cmpq %rsi, %r13
jne 0x8697
addq %r14, %rdi
addq %r12, %rax
cmpq %rbp, %rdi
jl 0x868d
addq 0x38(%rsp), %rbx
movsd 0x58(%rsp), %xmm0
addsd 0x295d(%rip), %xmm0     # 0xb050
movl 0x14(%rsp), %eax
incl %eax
addq 0x28(%rsp), %r8
cmpl 0x20(%rsp), %eax
jne 0x861f
movl 0x10(%rsp), %eax
movl 0x4(%rsp), %edx
cmpl %eax, %edx
jl 0x85d1
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x303d(%rip), %rdi      # 0xb76e
leaq 0x2feb(%rip), %rsi      # 0xb723
leaq 0x3037(%rip), %rcx      # 0xb776
movl $0x8c, %edx
callq 0x2100