// File: /workspace/github_cpp_makefile_star2_O2/mouda[P]LTE_random_access-simulate/alglibinternal.cpp
// Function: alglib_impl::ftbase_ffttwcalc(alglib_impl::ae_vector*, long, long, long, alglib_impl::ae_state*)
static void ftbase_ffttwcalc(/* Real    */ ae_vector* a,
     ae_int_t aoffset,
     ae_int_t n1,
     ae_int_t n2,
     ae_state *_state)
{
    ae_int_t i;
    ae_int_t j;
    ae_int_t n;
    ae_int_t idx;
    ae_int_t offs;
    double x;
    double y;
    double twxm1;
    double twy;
    double twbasexm1;
    double twbasey;
    double twrowxm1;
    double twrowy;
    double tmpx;
    double tmpy;
    double v;


    n = n1*n2;
    v = -2*ae_pi/n;
    twbasexm1 = -2*ae_sqr(ae_sin(0.5*v, _state), _state);
    twbasey = ae_sin(v, _state);
    twrowxm1 = 0;
    twrowy = 0;
    for(i=0; i<=n2-1; i++)
    {
        twxm1 = 0;
        twy = 0;
        for(j=0; j<=n1-1; j++)
        {
            idx = i*n1+j;
            offs = aoffset+2*idx;
            x = a->ptr.p_double[offs+0];
            y = a->ptr.p_double[offs+1];
            tmpx = x*twxm1-y*twy;
            tmpy = x*twy+y*twxm1;
            a->ptr.p_double[offs+0] = x+tmpx;
            a->ptr.p_double[offs+1] = y+tmpy;
            
            /*
             * update Tw: Tw(new) = Tw(old)*TwRow
             */
            if( j<n1-1 )
            {
                if( j%ftbase_ftbaseupdatetw==0 )
                {
                    v = -2*ae_pi*i*(j+1)/n;
                    twxm1 = -2*ae_sqr(ae_sin(0.5*v, _state), _state);
                    twy = ae_sin(v, _state);
                }
                else
                {
                    tmpx = twrowxm1+twxm1*twrowxm1-twy*twrowy;
                    tmpy = twrowy+twxm1*twrowy+twy*twrowxm1;
                    twxm1 = twxm1+tmpx;
                    twy = twy+tmpy;
                }
            }
        }
        
        /*
         * update TwRow: TwRow(new) = TwRow(old)*TwBase
         */
        if( i<n2-1 )
        {
            if( j%ftbase_ftbaseupdatetw==0 )
            {
                v = -2*ae_pi*(i+1)/n;
                twrowxm1 = -2*ae_sqr(ae_sin(0.5*v, _state), _state);
                twrowy = ae_sin(v, _state);
            }
            else
            {
                tmpx = twbasexm1+twrowxm1*twbasexm1-twrowy*twbasey;
                tmpy = twbasey+twrowxm1*twbasey+twrowy*twbasexm1;
                twrowxm1 = twrowxm1+tmpx;
                twrowy = twrowy+tmpy;
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %r8, %rbx
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, 0x8(%rsp)
movq %rdi, %r13
movq %rcx, %rax
imulq %rdx, %rax
cvtsi2sd %rax, %xmm0
movsd 0x10373(%rip), %xmm1    # 0x32af0
movsd %xmm0, 0x28(%rsp)
divsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movsd 0xdcf4(%rip), %xmm0     # 0x30488
mulsd %xmm1, %xmm0
movq %r8, %rdi
callq 0x2452d
movq %rbx, %rdi
callq 0x2441f
mulsd 0xdc50(%rip), %xmm0     # 0x30400
movapd %xmm0, 0x30(%rsp)
movsd (%rsp), %xmm0
movq %rbx, %rdi
callq 0x2452d
leaq -0x1(%r14), %rax
movq %rax, 0x58(%rsp)
leaq -0x1(%r12), %rbp
xorl %eax, %eax
testq %r12, %r12
movl $0x0, %r15d
cmovgq %r12, %r15
testq %r14, %r14
cmovleq %rax, %r14
movq %r14, 0x68(%rsp)
movq 0x8(%rsp), %r14
movapd %xmm0, %xmm1
movapd 0x30(%rsp), %xmm2
unpcklpd %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0]
movapd %xmm1, 0x80(%rsp)
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
movapd %xmm2, 0x30(%rsp)
shlq $0x3, %r14
shlq $0x4, %r12
movq %r12, 0x60(%rsp)
xorl %r12d, %r12d
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
cmpq 0x68(%rsp), %r12
je 0x22a44
movq %r12, 0x70(%rsp)
cvtsi2sd %r12, %xmm0
mulsd 0x102a7(%rip), %xmm0    # 0x32af0
movsd %xmm0, 0x78(%rsp)
movapd 0x10(%rsp), %xmm0
shufpd $0x1, %xmm0, %xmm0      # xmm0 = xmm0[1,0]
movapd %xmm0, 0x90(%rsp)
xorpd %xmm0, %xmm0
movq %r14, 0x8(%rsp)
movq %r14, %r12
xorl %r14d, %r14d
cmpq %r14, %r15
je 0x22974
movq 0x28(%r13), %rax
movsd (%rax,%r12), %xmm2
movsd 0x8(%rax,%r12), %xmm3
movapd %xmm0, %xmm4
mulsd %xmm3, %xmm4
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
movapd %xmm2, %xmm5
mulsd %xmm1, %xmm5
subsd %xmm4, %xmm5
movapd %xmm1, %xmm4
mulsd %xmm3, %xmm4
addsd %xmm2, %xmm5
mulsd %xmm0, %xmm2
addsd %xmm4, %xmm2
movsd %xmm5, (%rax,%r12)
addsd %xmm3, %xmm2
movq 0x28(%r13), %rax
movsd %xmm2, 0x8(%rax,%r12)
cmpq %rbp, %r14
jge 0x22968
testb $0x3, %r14b
je 0x22915
movapd %xmm0, %xmm2
xorpd 0xd8c4(%rip), %xmm2     # 0x301b0
movapd 0x10(%rsp), %xmm3
mulpd %xmm3, %xmm1
addpd %xmm3, %xmm1
movapd %xmm0, %xmm3
unpcklpd %xmm2, %xmm3            # xmm3 = xmm3[0],xmm2[0]
mulpd 0x90(%rsp), %xmm3
addpd %xmm1, %xmm3
addpd %xmm3, %xmm0
jmp 0x22968
leaq 0x1(%r14), %rax
cvtsi2sd %rax, %xmm0
mulsd 0x78(%rsp), %xmm0
divsd 0x28(%rsp), %xmm0
movsd %xmm0, (%rsp)
mulsd 0xdb51(%rip), %xmm0     # 0x30488
movq %rbx, %rdi
callq 0x2452d
movq %rbx, %rdi
callq 0x2441f
mulsd 0xdab1(%rip), %xmm0     # 0x30400
movapd %xmm0, 0x40(%rsp)
movsd (%rsp), %xmm0
movq %rbx, %rdi
callq 0x2452d
unpcklpd 0x40(%rsp), %xmm0       # xmm0 = xmm0[0],mem[0]
incq %r14
addq $0x10, %r12
jmp 0x22872
movq 0x70(%rsp), %r12
cmpq 0x58(%rsp), %r12
jge 0x229d4
testb $0x3, %r15b
movq 0x8(%rsp), %r14
je 0x229db
movapd 0x10(%rsp), %xmm3
movapd %xmm3, %xmm0
unpckhpd %xmm3, %xmm0            # xmm0 = xmm0[1],xmm3[1]
movapd 0x80(%rsp), %xmm1
mulpd %xmm1, %xmm0
addpd %xmm1, %xmm0
movapd %xmm3, %xmm1
xorpd 0xd7fa(%rip), %xmm1     # 0x301b0
movapd %xmm3, %xmm2
unpcklpd %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0]
mulpd 0x30(%rsp), %xmm2
addpd %xmm0, %xmm2
addpd %xmm2, %xmm3
movapd %xmm3, 0x10(%rsp)
jmp 0x22a37
movq 0x8(%rsp), %r14
jmp 0x22a37
leaq 0x1(%r12), %rax
cvtsi2sd %rax, %xmm0
mulsd 0x10103(%rip), %xmm0    # 0x32af0
divsd 0x28(%rsp), %xmm0
movsd %xmm0, (%rsp)
mulsd 0xda88(%rip), %xmm0     # 0x30488
movq %rbx, %rdi
callq 0x2452d
movq %rbx, %rdi
callq 0x2441f
mulsd 0xd9e8(%rip), %xmm0     # 0x30400
movapd %xmm0, 0x40(%rsp)
movsd (%rsp), %xmm0
movq %rbx, %rdi
callq 0x2452d
unpcklpd 0x40(%rsp), %xmm0       # xmm0 = xmm0[0],mem[0]
movapd %xmm0, 0x10(%rsp)
incq %r12
addq 0x60(%rsp), %r14
jmp 0x2282c
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq