// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathmsc.cpp
// Function: fft(COMPLEX*, int)
void fft(COMPLEX *x, int m)
{
static int mstore = 0;       /* stores m for future reference */
static int n = 1;            /* length of fft stored for future */

COMPLEX u,temp,tm;
COMPLEX *xi, *xip, *xj, *wptr;

int i,j,k,l,le,windex;

double arg,w_real,w_imag,wrecur_real,wrecur_imag,wtemp_real;

    if(m != mstore) {  // fft size changed,  redo w array
        /* free previously allocated storage and set new m */
        mstore = m;
        if(m == 0) return;       /* if m=0 then done */

        /* n = 2**m = fft length */
        n = 1 << m;
        le = n/2;

        /* calculate the w values recursively */
        arg = 4.0*atan(1.0)/le;         /* PI/le calculation */
        wrecur_real = w_real = cos(arg);
        wrecur_imag = w_imag = -sin(arg);
        xj = w;
        for(j=1; j<le; j++) {
            xj->real = (float) wrecur_real;
            xj->imag = (float) wrecur_imag;
            xj++;
            wtemp_real = wrecur_real*w_real - wrecur_imag*w_imag;
            wrecur_imag = wrecur_real*w_imag + wrecur_imag*w_real;
            wrecur_real = wtemp_real;
        }
    }

    /* start fft */
    le = n;
    windex = 1;
    for(l=0; l<m; l++) {
       le = le/2;

       /* first iteration with no multiplies */
       for(i=0; i<n; i=i+2*le) {
           xi = x + i;
           xip = xi + le;
           temp.real = xi->real + xip->real;
           temp.imag = xi->imag + xip->imag;
           xip->real = xi->real - xip->real;
           xip->imag = xi->imag - xip->imag;
           *xi = temp;
       }

       /* remaining iterations use stored w */
       wptr = w + windex - 1;
       for(j=1; j<le; j++) {
          u = *wptr;
          for(i=j; i<n; i=i+2*le) {
             xi = x + i;
             xip = xi + le;
             temp.real = xi->real + xip->real;
             temp.imag = xi->imag + xip->imag;
             tm.real = xi->real - xip->real;
             tm.imag = xi->imag - xip->imag;
             xip->real = tm.real*u.real - tm.imag*u.imag;
             xip->imag = tm.real*u.imag + tm.imag*u.real;
             *xi = temp;
          }
          wptr = wptr + windex;
       }
       windex = 2*windex;
    }

    /* rearrange data by bit reversing */
    j = 0;
    for(i=1; i<(n-1); i++) {
        k = n/2;
        while(k <= j) {
           j = j - k;
           k = k/2;
        }
        j = j + k;
        if(i < j) {
           xi = x + i;
           xj = x + j;
           temp = *xj;
           *xj = *xi;
           *xi = temp;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
pushq $0x1
popq %r13
pushq $0x2
popq %r12
cmpl %esi, 0x350135(%rip)    # 0x440f54
jne 0xf0fb1
movl 0x69e1d(%rip), %ecx     # 0x15ac48
leaq 0x238f76(%rip), %rax    # 0x329da8
movq (%rax), %rax
addq $-0x8, %rax
movq %rax, -0x38(%rbp)
xorl %r8d, %r8d
testl %esi, %esi
cmovlel %r8d, %esi
movslq %ecx, %r14
leaq 0x4(%rbx), %r9
movl %ecx, -0x30(%rbp)
movl %ecx, %eax
cmpl %esi, %r8d
je 0xf0f6e
cltd
idivl %r12d
movslq %eax, %rcx
leal (%rcx,%rcx), %edx
movslq %edx, %rdx
leaq (%r9,%rcx,8), %rdi
xorl %r10d, %r10d
cmpq %r14, %r10
jge 0xf0ec3
movss -0x4(%r9,%r10,8), %xmm0
movss (%r9,%r10,8), %xmm1
movss -0x4(%rdi,%r10,8), %xmm2
movss (%rdi,%r10,8), %xmm3
movaps %xmm0, %xmm4
addss %xmm2, %xmm4
movaps %xmm1, %xmm5
addss %xmm3, %xmm5
subss %xmm2, %xmm0
movss %xmm0, -0x4(%rdi,%r10,8)
subss %xmm3, %xmm1
movss %xmm1, (%rdi,%r10,8)
movss %xmm4, -0x4(%r9,%r10,8)
movss %xmm5, (%r9,%r10,8)
addq %rdx, %r10
jmp 0xf0e6f
movl %r13d, %r11d
leaq (%rbx,%rcx,8), %r15
pushq $0x1
popq %rcx
movq -0x38(%rbp), %rdi
cmpl %ecx, %eax
jle 0xf0f63
leaq (%rdi,%r11,8), %rdi
movss (%rdi), %xmm0
movss 0x4(%rdi), %xmm1
movq %rcx, %r10
cmpq %r14, %r10
jge 0xf0f5b
movss (%rbx,%r10,8), %xmm2
movss 0x4(%rbx,%r10,8), %xmm3
movss (%r15,%r10,8), %xmm4
movss 0x4(%r15,%r10,8), %xmm5
movaps %xmm2, %xmm6
addss %xmm4, %xmm6
movaps %xmm3, %xmm7
addss %xmm5, %xmm7
subss %xmm4, %xmm2
subss %xmm5, %xmm3
movaps %xmm1, %xmm4
mulss %xmm3, %xmm4
movaps %xmm2, %xmm5
mulss %xmm0, %xmm5
subss %xmm4, %xmm5
movss %xmm5, (%r15,%r10,8)
mulss %xmm0, %xmm3
mulss %xmm1, %xmm2
addss %xmm3, %xmm2
movss %xmm2, 0x4(%r15,%r10,8)
movss %xmm6, (%rbx,%r10,8)
movss %xmm7, 0x4(%rbx,%r10,8)
addq %rdx, %r10
jmp 0xf0ee9
incq %rcx
jmp 0xf0ed1
addl %r13d, %r13d
incl %r8d
jmp 0xf0e52
decq %r14
xorl %eax, %eax
pushq $0x1
popq %rdi
movl -0x30(%rbp), %esi
cmpq %r14, %rdi
jge 0xf1069
movl %eax, %ecx
movl %esi, %eax
movl %ecx, %r8d
cltd
idivl %r12d
subl %eax, %ecx
jge 0xf0f86
addl %r8d, %eax
movslq %eax, %rcx
cmpq %rcx, %rdi
jge 0xf0fac
movq (%rbx,%rcx,8), %rdx
movq (%rbx,%rdi,8), %r8
movq %r8, (%rbx,%rcx,8)
movq %rdx, (%rbx,%rdi,8)
incq %rdi
jmp 0xf0f79
movl %esi, 0x34ff9d(%rip)    # 0x440f54
testl %esi, %esi
je 0xf1069
movl %r13d, %eax
movl %esi, %ecx
shll %cl, %eax
movl %eax, 0x69c7c(%rip)     # 0x15ac48
cltd
idivl %r12d
movl %eax, %r15d
cvtsi2sd %eax, %xmm1
movsd 0x48c1(%rip), %xmm0     # 0xf58a0
divsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movl %esi, %r14d
callq 0x9710
movsd %xmm0, -0x30(%rbp)
movsd -0x38(%rbp), %xmm0
callq 0x9080
movsd -0x30(%rbp), %xmm6
movl %r14d, %esi
movaps 0x21a2(%rip), %xmm1     # 0xf31b0
xorps %xmm0, %xmm1
leaq 0x238d90(%rip), %rax    # 0x329da8
movq (%rax), %rax
xorl %ecx, %ecx
movaps %xmm6, %xmm3
movaps %xmm1, %xmm2
leal 0x1(%rcx), %edx
cmpl %r15d, %edx
jge 0xf0e25
cvtsd2ss %xmm3, %xmm4
cvtsd2ss %xmm2, %xmm5
movss %xmm4, (%rax,%rcx,8)
movss %xmm5, 0x4(%rax,%rcx,8)
movaps %xmm0, %xmm4
mulsd %xmm2, %xmm4
movaps %xmm3, %xmm5
mulsd %xmm6, %xmm5
addsd %xmm4, %xmm5
mulsd %xmm6, %xmm2
mulsd %xmm1, %xmm3
addsd %xmm3, %xmm2
incq %rcx
movapd %xmm5, %xmm3
jmp 0xf1023
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq