// File: /workspace/github_c_makefile_star2_O1/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, %ebp
movl %esi, %eax
movl %esi, 0xc(%rsp)
cltd
idivl %ecx
movslq %ecx, %rdx
movq %rdx, 0x10(%rsp)
movl %ecx, 0x4(%rsp)
movl %ecx, %r13d
testl %eax, %eax
jle 0x8626
movl %eax, %r14d
movq 0x10(%rsp), %rdx
shlq $0x4, %rdx
movq %r13, %rsi
shlq $0x4, %rsi
xorl %ecx, %ecx
movq %rdi, %r8
movl $0x1, %r10d
movl $0x0, %r9d
cmpl $0x1, %eax
je 0x85ba
xorl %r9d, %r9d
movl %ecx, %r11d
movl %r11d, %ebx
andl $0x1, %ebx
leal (%rbx,%r9,2), %r9d
shrl %r11d
addl %r10d, %r10d
cmpl %eax, %r10d
jl 0x85a5
cmpl %eax, %r10d
jne 0x87c5
cmpl $0x0, 0x4(%rsp)
setle %r10b
movslq %r9d, %r11
cmpq %r11, %rcx
setge %r11b
orb %r10b, %r11b
jne 0x8617
imull 0x4(%rsp), %r9d
movslq %r9d, %r9
shlq $0x4, %r9
addq %rdi, %r9
xorl %r10d, %r10d
movups (%r8,%r10), %xmm0
movaps %xmm0, 0x70(%rsp)
movups (%r9,%r10), %xmm0
movups %xmm0, (%r8,%r10)
movapd 0x70(%rsp), %xmm0
movupd %xmm0, (%r9,%r10)
addq $0x10, %r10
cmpq %r10, %rsi
jne 0x85ee
incq %rcx
addq %rdx, %r8
cmpq %r14, %rcx
jne 0x858e
movq %rdi, 0x28(%rsp)
cmpl $0x2, %eax
movl 0x4(%rsp), %edi
jl 0x87b3
negl %ebp
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x30(%rsp)
movslq 0xc(%rsp), %r14
movq 0x10(%rsp), %rcx
shlq $0x4, %rcx
movq %rcx, 0x38(%rsp)
shlq $0x4, %r13
movl $0x1, %ecx
movl %eax, 0x18(%rsp)
leal (%rcx,%rcx), %eax
movl %eax, 0x8(%rsp)
movq %rcx, 0x20(%rsp)
testl %ecx, %ecx
jle 0x87a3
movl 0x8(%rsp), %eax
movq 0x20(%rsp), %rcx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd %xmm0, 0x40(%rsp)
imull %edi, %eax
imull %edi, %ecx
movslq %eax, %rbp
movslq %ecx, %r12
movq %rbp, %r15
shlq $0x4, %r15
shlq $0x4, %r12
xorl %ebx, %ebx
xorpd %xmm0, %xmm0
movq 0x28(%rsp), %r8
xorl %eax, %eax
movl %eax, 0x1c(%rsp)
movq %r8, 0x50(%rsp)
movsd %xmm0, 0x58(%rsp)
mulsd 0x3044(%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 0x4(%rsp), %edi
cmpl 0xc(%rsp), %ebx
jge 0x877b
mulsd 0x30(%rsp), %xmm0
movapd %xmm0, %xmm1
xorpd 0x2dcb(%rip), %xmm1     # 0xb4e0
unpcklpd %xmm4, %xmm4            # xmm4 = xmm4[0,0]
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
movq %r8, %rax
movq %rbx, %rcx
testl %edi, %edi
jle 0x8770
leaq (%rax,%r12), %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
movlpd (%rax,%rsi), %xmm3      # xmm3 = mem[0],xmm3[1]
subpd %xmm1, %xmm3
movupd %xmm3, (%rdx,%rsi)
addpd %xmm2, %xmm1
movupd %xmm1, (%rax,%rsi)
addq $0x10, %rsi
cmpq %rsi, %r13
jne 0x872d
addq %rbp, %rcx
addq %r15, %rax
cmpq %r14, %rcx
jl 0x8723
addq 0x10(%rsp), %rbx
movsd 0x58(%rsp), %xmm0
addsd 0x28c2(%rip), %xmm0     # 0xb050
movl 0x1c(%rsp), %eax
incl %eax
addq 0x38(%rsp), %r8
cmpl 0x20(%rsp), %eax
jne 0x86b5
movl 0x18(%rsp), %eax
movl 0x8(%rsp), %ecx
cmpl %eax, %ecx
jl 0x8667
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2fa2(%rip), %rdi      # 0xb76e
leaq 0x2f50(%rip), %rsi      # 0xb723
leaq 0x2f9c(%rip), %rcx      # 0xb776
movl $0x8c, %edx
callq 0x2100