// File: /workspace/github_cpp_makefile_star2_O1/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 $0x78, %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 0x12306(%rip), %xmm1    # 0x36960
movsd %xmm0, 0x38(%rsp)
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0xfdf6(%rip), %xmm0     # 0x34468
mulsd %xmm1, %xmm0
movq %r8, %rdi
callq 0x266a4
movq %rbx, %rdi
callq 0x26588
movsd %xmm0, 0x28(%rsp)
movsd 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0x266a4
movsd %xmm0, 0x40(%rsp)
movq %r14, 0x30(%rsp)
testq %r14, %r14
jle 0x2492a
movsd 0x28(%rsp), %xmm0
mulsd 0xfd34(%rip), %xmm0     # 0x343f0
movsd %xmm0, 0x28(%rsp)
movq 0x30(%rsp), %rax
decq %rax
movq %rax, 0x50(%rsp)
leaq -0x1(%r15), %rbp
testb $0x3, %r15b
sete 0xf(%rsp)
shlq $0x3, %r12
movq %r15, %rax
shlq $0x4, %rax
movq %rax, 0x48(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
xorl %r14d, %r14d
movsd %xmm0, 0x20(%rsp)
testq %r15, %r15
jle 0x2484e
movq %r14, 0x58(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r14, %xmm0
mulsd 0x12243(%rip), %xmm0    # 0x36960
movsd %xmm0, 0x68(%rsp)
xorpd %xmm0, %xmm0
movq %r12, 0x60(%rsp)
xorl %r14d, %r14d
xorpd %xmm5, %xmm5
movq 0x28(%r13), %rax
movsd (%rax,%r12), %xmm1
movsd 0x8(%rax,%r12), %xmm2
movapd %xmm0, %xmm3
mulsd %xmm2, %xmm3
movapd %xmm1, %xmm4
mulsd %xmm5, %xmm4
subsd %xmm3, %xmm4
movapd %xmm5, %xmm3
mulsd %xmm2, %xmm3
addsd %xmm1, %xmm4
mulsd %xmm0, %xmm1
addsd %xmm3, %xmm1
movsd %xmm4, (%rax,%r12)
addsd %xmm2, %xmm1
movq 0x28(%r13), %rax
movsd %xmm1, 0x8(%rax,%r12)
cmpq %rbp, %r14
jge 0x2482e
testb $0x3, %r14b
je 0x247d6
movapd %xmm5, %xmm1
movsd 0x20(%rsp), %xmm4
mulsd %xmm4, %xmm1
addsd %xmm4, %xmm1
movapd %xmm0, %xmm2
movsd 0x18(%rsp), %xmm3
mulsd %xmm3, %xmm2
subsd %xmm2, %xmm1
movapd %xmm5, %xmm2
mulsd %xmm3, %xmm2
addsd %xmm3, %xmm2
movapd %xmm0, %xmm3
mulsd %xmm4, %xmm3
addsd %xmm2, %xmm3
addsd %xmm1, %xmm5
addsd %xmm3, %xmm0
jmp 0x2482e
leaq 0x1(%r14), %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd 0x68(%rsp), %xmm0
divsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
mulsd 0xfc6c(%rip), %xmm0     # 0x34468
movq %rbx, %rdi
callq 0x266a4
movq %rbx, %rdi
callq 0x26588
mulsd 0xfbdc(%rip), %xmm0     # 0x343f0
movsd %xmm0, 0x70(%rsp)
movsd 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0x266a4
movsd 0x70(%rsp), %xmm5
incq %r14
addq $0x10, %r12
cmpq %r14, %r15
jne 0x24733
movb 0xf(%rsp), %al
movq 0x60(%rsp), %r12
movq 0x58(%rsp), %r14
jmp 0x24850
movb $0x1, %al
cmpq 0x50(%rsp), %r14
jge 0x24917
testb %al, %al
je 0x248bb
leaq 0x1(%r14), %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd 0x120ed(%rip), %xmm0    # 0x36960
divsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
mulsd 0xfbe1(%rip), %xmm0     # 0x34468
movq %rbx, %rdi
callq 0x266a4
movq %rbx, %rdi
callq 0x26588
mulsd 0xfb51(%rip), %xmm0     # 0x343f0
movsd %xmm0, 0x20(%rsp)
movsd 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0x266a4
movsd %xmm0, 0x18(%rsp)
jmp 0x24917
movsd 0x20(%rsp), %xmm4
movapd %xmm4, %xmm0
movsd 0x28(%rsp), %xmm3
mulsd %xmm3, %xmm0
addsd %xmm3, %xmm0
movsd 0x18(%rsp), %xmm5
movapd %xmm5, %xmm1
movsd 0x40(%rsp), %xmm2
mulsd %xmm2, %xmm1
subsd %xmm1, %xmm0
movapd %xmm4, %xmm1
mulsd %xmm2, %xmm1
addsd %xmm2, %xmm1
movapd %xmm5, %xmm2
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
addsd %xmm0, %xmm4
movsd %xmm4, 0x20(%rsp)
addsd %xmm2, %xmm5
movsd %xmm5, 0x18(%rsp)
incq %r14
addq 0x48(%rsp), %r12
cmpq 0x30(%rsp), %r14
jne 0x246ff
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq