// File: /workspace/github_c_makefile_star2_O2/guszejnovdavid[P]MISFIT/fft.c
// Function: stockham(complex*, int, int, int, complex*)
void stockham(complex x[], int n, int flag, int n2, complex y[])
{
   complex  *y_orig, *tmp;
   int  i, j, k, k2, Ls, r, jrs;
   int  half, m, m2=0;
   real  wr, wi, tr, ti;
   
   y_orig = y;
   r = half = n >> 1;
   Ls = 1;                                         /* Ls=L/2 is the L star */
  
   while(r >= n2) {                              /* loops log2(n/n2) times */
      tmp = x;                           /* swap pointers, y is always old */
      x = y;                                   /* x is always for new data */
      y = tmp;
      m = 0;                        /* m runs over first half of the array */
      m2 = half;                             /* m2 for second half, n2=n/2 */
      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 */
         jrs = j*(r+r);
         for(k = jrs; k < jrs+r; ++k) {           /* "butterfly" operation */
            k2 = k + r;
            tr =  wr*y[k2].Re - wi*y[k2].Im;      /* complex multiply, w*y */
            ti =  wr*y[k2].Im + wi*y[k2].Re;
            x[m].Re = y[k].Re + tr;
            x[m].Im = y[k].Im + ti;
            x[m2].Re = y[k].Re - tr;
            x[m2].Im = y[k].Im - ti;
            ++m;
            ++m2;
         }
      } 
      r  >>= 1;
      Ls <<= 1;
   };

   if (y != y_orig) {                     /* copy back to permanent memory */
      for(i = 0; i < n; ++i) {               /* if it is not already there */
         y[i] = x[i];               /* performed only if log2(n/n2) is odd */
      }
   }
   
   assert(Ls == n/n2);                        /* ensure n is a power of 2  */
   assert(1 == n || m2 == n);           /* check array index within bound  */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %ecx, 0x4(%rsp)
movq %rdi, 0x8(%rsp)
movl %esi, 0x1c(%rsp)
movl %esi, %eax
sarl %eax
negl %edx
cvtsi2sd %edx, %xmm0
movsd %xmm0, 0x48(%rsp)
xorl %r13d, %r13d
pushq $0x1
popq %rsi
movl %eax, 0x20(%rsp)
movl %eax, %edx
movq %r8, 0x38(%rsp)
movq %r8, %rax
movq %rax, 0x10(%rsp)
cmpl 0x4(%rsp), %edx
jl 0x7dd6
cvtsi2sd %esi, %xmm0
movsd %xmm0, 0x58(%rsp)
leal (%rdx,%rdx), %eax
movq %rdx, 0x40(%rsp)
movslq %edx, %rcx
movq %rcx, 0x30(%rsp)
xorl %ebp, %ebp
testl %esi, %esi
movl $0x0, %ecx
movl %esi, 0x24(%rsp)
cmovgl %esi, %ecx
movq %rcx, 0x60(%rsp)
movl %eax, 0x28(%rsp)
cltq
movq %rax, 0x50(%rsp)
xorl %ecx, %ecx
xorl %r15d, %r15d
movl 0x20(%rsp), %eax
movl %eax, %r13d
cmpq 0x60(%rsp), %rbp
je 0x7db5
movl %ecx, 0x2c(%rsp)
movslq %ecx, %r14
movq 0x30(%rsp), %rax
leaq (%rax,%r14), %r12
shlq $0x4, %r12
movq 0x8(%rsp), %rax
addq %rax, %r12
movq %r14, %rbx
shlq $0x4, %rbx
addq %rax, %rbx
cvtsi2sd %ebp, %xmm0
mulsd 0x39c4(%rip), %xmm0     # 0xb6b0
divsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
callq 0x23a0
movapd %xmm0, 0x70(%rsp)
movsd 0x68(%rsp), %xmm0
callq 0x2080
movapd 0x70(%rsp), %xmm3
mulsd 0x48(%rsp), %xmm0
movq %rbp, %rax
imulq 0x50(%rsp), %rax
addq 0x30(%rsp), %rax
movapd %xmm0, %xmm1
xorpd 0x375c(%rip), %xmm1     # 0xb490
movslq %r15d, %r15
movslq %r13d, %rcx
unpcklpd %xmm3, %xmm3            # xmm3 = xmm3[0,0]
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
shlq $0x4, %rcx
movq 0x10(%rsp), %rsi
addq %rsi, %rcx
movq %r15, %rdx
shlq $0x4, %rdx
addq %rsi, %rdx
xorl %esi, %esi
cmpq %rax, %r14
jge 0x7da5
movupd (%r12,%rsi), %xmm1
movapd %xmm1, %xmm2
mulpd %xmm0, %xmm2
shufpd $0x1, %xmm2, %xmm2      # xmm2 = xmm2[1,0]
mulpd %xmm3, %xmm1
addpd %xmm2, %xmm1
movupd (%rbx,%rsi), %xmm2
addpd %xmm1, %xmm2
movupd %xmm2, (%rdx,%rsi)
movupd (%rbx,%rsi), %xmm2
subpd %xmm1, %xmm2
movupd %xmm2, (%rcx,%rsi)
incq %r15
incq %r14
incl %r13d
addq $0x10, %rsi
jmp 0x7d5a
incq %rbp
movl 0x2c(%rsp), %ecx
addl 0x28(%rsp), %ecx
jmp 0x7caf
movq 0x40(%rsp), %rdx
sarl %edx
movl 0x24(%rsp), %esi
addl %esi, %esi
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, 0x8(%rsp)
jmp 0x7c5a
movq 0x38(%rsp), %rax
cmpq %rax, 0x10(%rsp)
movl 0x1c(%rsp), %eax
je 0x7e15
xorl %edx, %edx
testl %eax, %eax
movl $0x0, %ecx
cmovgl %eax, %ecx
shlq $0x4, %rcx
cmpq %rdx, %rcx
je 0x7e15
movq 0x8(%rsp), %rdi
movupd (%rdi,%rdx), %xmm0
movq 0x10(%rsp), %rdi
movupd %xmm0, (%rdi,%rdx)
addq $0x10, %rdx
jmp 0x7df6
movl %eax, %ecx
cltd
idivl 0x4(%rsp)
cmpl %eax, %esi
jne 0x7e42
cmpl $0x1, %ecx
sete %al
cmpl %ecx, %r13d
sete %cl
orb %al, %cl
je 0x7e5b
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x386f(%rip), %rdi      # 0xb6b8
leaq 0x3873(%rip), %rsi      # 0xb6c3
leaq 0x3872(%rip), %rcx      # 0xb6c9
pushq $0x72
jmp 0x7e72
leaq 0x389a(%rip), %rdi      # 0xb6fc
leaq 0x385a(%rip), %rsi      # 0xb6c3
leaq 0x3859(%rip), %rcx      # 0xb6c9
pushq $0x73
popq %rdx
callq 0x20e0