// File: /workspace/github_cpp_makefile_star2_O3/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, %r15
movq %rsi, %r12
movq %rdi, %r13
movq %rcx, %rax
imulq %rdx, %rax
cvtsi2sd %rax, %xmm0
movsd 0x11c1c(%rip), %xmm1    # 0x35b00
movsd %xmm0, 0x28(%rsp)
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0xf58c(%rip), %xmm0     # 0x33488
mulsd %xmm1, %xmm0
movq %r8, %rdi
callq 0x25f5f
movq %rbx, %rdi
callq 0x25e43
movapd %xmm0, 0x30(%rsp)
movsd 0x8(%rsp), %xmm0
movq %rbx, %rdi
callq 0x25f5f
movq %r14, 0x18(%rsp)
testq %r14, %r14
jle 0x241a4
movq 0x18(%rsp), %rax
decq %rax
movq %rax, 0x10(%rsp)
movapd 0x30(%rsp), %xmm1
mulsd 0xf4c3(%rip), %xmm1     # 0x33410
leaq -0x1(%r15), %rbp
movapd %xmm0, %xmm2
unpcklpd %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0]
movapd %xmm2, 0x70(%rsp)
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
movapd %xmm1, 0x30(%rsp)
shlq $0x3, %r12
movq %r15, %rax
shlq $0x4, %rax
movq %rax, 0x58(%rsp)
xorpd %xmm6, %xmm6
xorl %r14d, %r14d
testq %r15, %r15
jle 0x24125
movq %r14, 0x60(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r14, %xmm0
mulsd 0x11b62(%rip), %xmm0    # 0x35b00
movsd %xmm0, 0x68(%rsp)
movapd %xmm6, %xmm0
shufpd $0x1, %xmm6, %xmm0      # xmm0 = xmm0[1],xmm6[0]
movapd %xmm0, 0x90(%rsp)
xorpd %xmm0, %xmm0
movq %r12, 0x20(%rsp)
xorl %r14d, %r14d
movapd %xmm6, 0x80(%rsp)
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 0x240c0
testb $0x3, %r14b
je 0x2405f
movapd %xmm0, %xmm2
xorpd 0xf174(%rip), %xmm2     # 0x331b0
mulpd %xmm6, %xmm1
addpd %xmm6, %xmm1
movapd %xmm0, %xmm3
unpcklpd %xmm2, %xmm3            # xmm3 = xmm3[0],xmm2[0]
mulpd 0x90(%rsp), %xmm3
addpd %xmm1, %xmm3
addpd %xmm3, %xmm0
jmp 0x240c0
leaq 0x1(%r14), %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd 0x68(%rsp), %xmm0
divsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
mulsd 0xf403(%rip), %xmm0     # 0x33488
movq %rbx, %rdi
callq 0x25f5f
movq %rbx, %rdi
callq 0x25e43
mulsd 0xf373(%rip), %xmm0     # 0x33410
movapd %xmm0, 0x40(%rsp)
movsd 0x8(%rsp), %xmm0
movq %rbx, %rdi
callq 0x25f5f
movapd 0x80(%rsp), %xmm6
unpcklpd 0x40(%rsp), %xmm0       # xmm0 = xmm0[0],mem[0]
incq %r14
addq $0x10, %r12
cmpq %r14, %r15
jne 0x23fcb
movq 0x60(%rsp), %r14
cmpq 0x10(%rsp), %r14
jge 0x2418c
testb $0x3, %r15b
movq 0x20(%rsp), %r12
je 0x2412c
movapd %xmm6, %xmm0
unpckhpd %xmm6, %xmm0            # xmm0 = xmm0[1],xmm6[1]
movapd 0x70(%rsp), %xmm1
mulpd %xmm1, %xmm0
addpd %xmm1, %xmm0
movapd %xmm6, %xmm1
xorpd 0xf0a3(%rip), %xmm1     # 0x331b0
movapd %xmm6, %xmm2
unpcklpd %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0]
mulpd 0x30(%rsp), %xmm2
addpd %xmm0, %xmm2
addpd %xmm2, %xmm6
jmp 0x24191
cmpq 0x10(%rsp), %r14
jge 0x24191
leaq 0x1(%r14), %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd 0x119c0(%rip), %xmm0    # 0x35b00
divsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
mulsd 0xf334(%rip), %xmm0     # 0x33488
movq %rbx, %rdi
callq 0x25f5f
movq %rbx, %rdi
callq 0x25e43
mulsd 0xf2a4(%rip), %xmm0     # 0x33410
movapd %xmm0, 0x40(%rsp)
movsd 0x8(%rsp), %xmm0
movq %rbx, %rdi
callq 0x25f5f
movapd %xmm0, %xmm6
unpcklpd 0x40(%rsp), %xmm6       # xmm6 = xmm6[0],mem[0]
jmp 0x24191
movq 0x20(%rsp), %r12
incq %r14
addq 0x58(%rsp), %r12
cmpq 0x18(%rsp), %r14
jne 0x23f80
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq