// File: /workspace/github_cpp_makefile_star2_O1/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 $0x38, %rsp
movl %esi, %r12d
movq %rdi, %r15
cmpl %esi, 0x34fec6(%rip)    # 0x457034
je 0x107242
movl %r12d, 0x34feb9(%rip)   # 0x457034
testl %r12d, %r12d
je 0x107441
movl $0x1, %r14d
movl %r12d, %ecx
shll %cl, %r14d
movl %r14d, 0x69ab1(%rip)    # 0x170c48
movl %r14d, %ebx
shrl $0x1f, %ebx
addl %r14d, %ebx
sarl %ebx
cvtsi2sd %ebx, %xmm1
movsd 0x466a(%rip), %xmm0     # 0x10b818
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x9710
movsd %xmm0, -0x38(%rbp)
movsd -0x30(%rbp), %xmm0
callq 0x9080
movsd -0x38(%rbp), %xmm7
cmpl $0x4, %r14d
jl 0x107242
movaps 0x1fc3(%rip), %xmm1     # 0x1091a0
xorps %xmm0, %xmm1
leaq 0x238bc1(%rip), %rax    # 0x33fda8
movq (%rax), %rax
cmpl $0x3, %ebx
movl $0x2, %ecx
cmovgel %ebx, %ecx
decq %rcx
xorl %edx, %edx
movaps %xmm1, %xmm2
movaps %xmm7, %xmm4
movaps %xmm7, %xmm3
xorps %xmm5, %xmm5
cvtsd2ss %xmm4, %xmm5
xorps %xmm6, %xmm6
cvtsd2ss %xmm2, %xmm6
movss %xmm5, (%rax,%rdx,8)
movss %xmm6, 0x4(%rax,%rdx,8)
movaps %xmm0, %xmm5
mulsd %xmm2, %xmm5
mulsd %xmm7, %xmm3
addsd %xmm5, %xmm3
mulsd %xmm7, %xmm2
mulsd %xmm1, %xmm4
addsd %xmm4, %xmm2
incq %rdx
movapd %xmm3, %xmm4
cmpl %edx, %ecx
jne 0x107203
movq %r15, -0x48(%rbp)
movl 0x699fc(%rip), %eax     # 0x170c48
testl %r12d, %r12d
jle 0x1073f4
movslq %eax, %rcx
leaq 0x238b49(%rip), %rdx    # 0x33fda8
movq (%rdx), %rdx
addq $-0x8, %rdx
movq %rdx, -0x58(%rbp)
movq -0x48(%rbp), %rdx
leaq 0x4(%rdx), %rsi
addq $0xc, %rdx
movq %rdx, -0x50(%rbp)
xorl %edi, %edi
movl $0x1, -0x30(%rbp)
movl %eax, %edx
movl %r12d, -0x3c(%rbp)
movq %rdi, -0x38(%rbp)
movl %edx, %r10d
shrl $0x1f, %r10d
addl %edx, %r10d
sarl %r10d
testl %eax, %eax
jle 0x107301
movslq %r10d, %r8
leal (%r8,%r8), %edi
movslq %edi, %rdi
leaq (%rsi,%r8,8), %r8
xorl %r9d, %r9d
movss -0x4(%rsi,%r9,8), %xmm0
movss (%rsi,%r9,8), %xmm1
movss -0x4(%r8,%r9,8), %xmm2
movss (%r8,%r9,8), %xmm3
movaps %xmm0, %xmm4
addss %xmm2, %xmm4
movaps %xmm1, %xmm5
addss %xmm3, %xmm5
subss %xmm2, %xmm0
movss %xmm0, -0x4(%r8,%r9,8)
subss %xmm3, %xmm1
movss %xmm1, (%r8,%r9,8)
movss %xmm4, -0x4(%rsi,%r9,8)
movss %xmm5, (%rsi,%r9,8)
addq %rdi, %r9
cmpq %rcx, %r9
jl 0x1072af
cmpl $0x4, %edx
jl 0x1073d6
movl -0x30(%rbp), %r11d
movl %r10d, %r15d
leal (%r10,%r10), %r12d
cmpl $0x3, %r10d
movl $0x2, %r13d
cmovgel %r10d, %r13d
leaq (,%r12,8), %rdi
movl $0x1, %edx
movq -0x50(%rbp), %r8
movq -0x58(%rbp), %rbx
cmpl %edx, %eax
jle 0x1073c2
movss (%rbx,%r11,8), %xmm0
movss 0x4(%rbx,%r11,8), %xmm1
movl %edx, %r9d
movq %r8, %r14
movss -0x4(%r14), %xmm2
movss (%r14), %xmm3
movss -0x4(%r14,%r15,8), %xmm4
movss (%r14,%r15,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, -0x4(%r14,%r15,8)
mulss %xmm0, %xmm3
mulss %xmm1, %xmm2
addss %xmm3, %xmm2
movss %xmm2, (%r14,%r15,8)
movss %xmm6, -0x4(%r14)
movss %xmm7, (%r14)
addq %rdi, %r14
addl %r12d, %r9d
cmpl %r9d, %eax
jg 0x107353
leaq (%rbx,%r11,8), %rbx
incq %rdx
addq $0x8, %r8
cmpq %r13, %rdx
jne 0x107338
movl -0x30(%rbp), %edx
addl %edx, %edx
movl %edx, -0x30(%rbp)
movq -0x38(%rbp), %rdi
incl %edi
movl %r10d, %edx
movl -0x3c(%rbp), %r12d
cmpl %r12d, %edi
jne 0x107289
cmpl $0x3, %eax
movq -0x48(%rbp), %r10
jl 0x107441
leal -0x1(%rax), %ecx
xorl %esi, %esi
movl $0x1, %edx
movl %esi, %edi
movl %eax, %esi
movl %edi, %r8d
movl %esi, %r9d
shrl $0x1f, %r9d
addl %r9d, %esi
sarl %esi
subl %esi, %edi
jge 0x10740b
addl %r8d, %esi
movslq %esi, %rdi
cmpq %rdi, %rdx
jge 0x107439
movq (%r10,%rdi,8), %r8
movq (%r10,%rdx,8), %r9
movq %r9, (%r10,%rdi,8)
movq %r8, (%r10,%rdx,8)
incq %rdx
cmpq %rcx, %rdx
jne 0x107407
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq