// File: /workspace/github_cpp_makefile_star2_O3/mouda[P]LTE_random_access-simulate/ap.cpp
// Function: alglib_impl::_ialglib_cmatrixrighttrsm(long, long, alglib_impl::ae_complex*, long, bool, bool, long, alglib_impl::ae_complex*, long)
ae_bool _ialglib_cmatrixrighttrsm(ae_int_t m,
     ae_int_t n,
     ae_complex *_a,
     ae_int_t _a_stride,
     ae_bool isupper,
     ae_bool isunit,
     ae_int_t optype,
     ae_complex *_x,
     ae_int_t _x_stride)
{
    /*
     * local buffers
     */
    double *pdiag;
    ae_int_t i;
    double _loc_abuf[2*alglib_c_block*alglib_c_block+alglib_simd_alignment];
    double _loc_xbuf[2*alglib_c_block*alglib_c_block+alglib_simd_alignment];
    double _loc_tmpbuf[2*alglib_c_block+alglib_simd_alignment];
    double * const abuf   = (double * const) ae_align(_loc_abuf,  alglib_simd_alignment);
    double * const xbuf   = (double * const) ae_align(_loc_xbuf,  alglib_simd_alignment);
    double * const tmpbuf = (double * const) ae_align(_loc_tmpbuf,alglib_simd_alignment);
    ae_bool uppera;
    void (*cmv)(ae_int_t, ae_int_t, const double *, const double *, ae_complex *, double *, ae_int_t, ae_complex, ae_complex) = &_ialglib_cmv;
    
    if( m>alglib_c_block || n>alglib_c_block )
        return ae_false;

    /*
     * Check for SSE2 support
     */
#ifdef AE_HAS_SSE2_INTRINSICS
    if( ae_cpuid() & CPU_SSE2 )
    {
        cmv = &_ialglib_cmv_sse2;
    }    
#endif
    
    /*
     * Prepare
     */
    _ialglib_mcopyblock_complex(n, n, _a, optype, _a_stride, abuf);
    _ialglib_mcopyblock_complex(m, n, _x, 0, _x_stride, xbuf);
    if( isunit )
        for(i=0,pdiag=abuf; i<n; i++,pdiag+=2*(alglib_c_block+1))
        {
            pdiag[0] = 1.0;
            pdiag[1] = 0.0;
        }
    if( optype==0 )
        uppera = isupper;
    else
        uppera = !isupper;

    /*
     * Solve Y*A^-1=X where A is upper or lower triangular
     */
    if( uppera )
    {
        for(i=0,pdiag=abuf; i<n; i++,pdiag+=2*(alglib_c_block+1))
        {
            ae_complex tmp_c;
            ae_complex beta;
            ae_complex alpha;
            tmp_c.x = pdiag[0];
            tmp_c.y = pdiag[1];
            beta = ae_c_d_div(1.0, tmp_c);
            alpha.x = -beta.x;
            alpha.y = -beta.y;
            _ialglib_vcopy_dcomplex(i, abuf+2*i, alglib_c_block, tmpbuf, 1, "No conj");
            cmv(m, i, xbuf, tmpbuf, NULL, xbuf+2*i, alglib_c_block, alpha, beta);
        }
        _ialglib_mcopyunblock_complex(m, n, xbuf, 0, _x, _x_stride);
    }
    else
    {
        for(i=n-1,pdiag=abuf+2*((n-1)*alglib_c_block+(n-1)); i>=0; i--,pdiag-=2*(alglib_c_block+1))
        {
            ae_complex tmp_c;
            ae_complex beta;
            ae_complex alpha;
            tmp_c.x = pdiag[0];
            tmp_c.y = pdiag[1];
            beta = ae_c_d_div(1.0, tmp_c);
            alpha.x = -beta.x;
            alpha.y = -beta.y;
            _ialglib_vcopy_dcomplex(n-1-i, pdiag+2*alglib_c_block, alglib_c_block, tmpbuf, 1, "No conj");
            cmv(m, n-1-i, xbuf+2*(i+1), tmpbuf, NULL, xbuf+2*i, alglib_c_block, alpha, beta);
        }
        _ialglib_mcopyunblock_complex(m, n, xbuf, 0, _x, _x_stride);
    }
    return ae_true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4b68, %rsp           # imm = 0x4B68
movl %r8d, %ebp
movq %rcx, %r8
cmpq $0x19, %rdi
setl %cl
cmpq $0x19, %rsi
setl %al
andb %cl, %al
cmpb $0x1, %al
jne 0x300d1
movl %r9d, %r13d
movq %rsi, %rbx
movq %rdi, %r9
movb %al, 0xf(%rsp)
movq 0x4ba8(%rsp), %r14
movq 0x4ba0(%rsp), %r15
leaq 0x26e0(%rsp), %r12
movq %rsi, %rdi
movq %r15, %rcx
movq %r9, 0x10(%rsp)
movq %r12, %r9
callq 0x2f376
movq 0x10(%rsp), %r9
testq %r9, %r9
jle 0x2fd30
movq 0x4bb0(%rsp), %rax
shlq $0x4, %rax
leaq 0x260(%rsp), %rcx
xorl %edx, %edx
movq %r14, %rsi
testq %rbx, %rbx
jle 0x2fd1e
movq %rbx, %rdi
xorl %r8d, %r8d
movups (%rsi,%r8), %xmm0
movups %xmm0, (%rcx,%r8)
addq $0x10, %r8
decq %rdi
jne 0x2fd0b
incq %rdx
addq $0x180, %rcx            # imm = 0x180
addq %rax, %rsi
cmpq %r9, %rdx
jne 0x2fd00
testq %rbx, %rbx
setle %al
xorb $0x1, %r13b
orb %al, %r13b
jne 0x2fd60
leaq 0x26e0(%rsp), %rax
movsd 0x3491(%rip), %xmm0     # 0x331e0
movq %rbx, %rcx
movups %xmm0, (%rax)
addq $0x190, %rax            # imm = 0x190
decq %rcx
jne 0x2fd52
testq %r15, %r15
setne %al
cmpb %bpl, %al
je 0x2ff16
testq %rbx, %rbx
jle 0x2feba
leaq 0x260(%rsp), %rbp
xorl %r13d, %r13d
movq %r12, %r15
movq %rbx, 0x18(%rsp)
movdqu (%r12), %xmm0
movdqa %xmm0, %xmm1
pand 0x6483(%rip), %xmm1     # 0x36220
pshufd $0xee, %xmm1, %xmm2     # xmm2 = xmm1[2,3,2,3]
ucomisd %xmm2, %xmm1
jbe 0x2fdde
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
movapd %xmm1, %xmm2
divsd %xmm0, %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
xorpd 0x33e8(%rip), %xmm2     # 0x331b0
movapd 0x4f40(%rip), %xmm3     # 0x34d10
unpcklpd %xmm2, %xmm3            # xmm3 = xmm3[0],xmm2[0]
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
divpd %xmm1, %xmm3
jmp 0x2fe07
movdqa %xmm0, %xmm1
punpckhqdq %xmm0, %xmm1    # xmm1 = xmm1[1],xmm0[1]
movdqa %xmm0, %xmm3
divsd %xmm1, %xmm3
mulsd %xmm3, %xmm0
addsd %xmm1, %xmm0
shufpd $0x2, 0x6441(%rip), %xmm3 # xmm3 = xmm3[0],mem[1]
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
divpd %xmm0, %xmm3
movapd %xmm3, 0x20(%rsp)
movapd %xmm3, %xmm1
movapd 0x3397(%rip), %xmm0     # 0x331b0
xorpd %xmm0, %xmm1
movapd %xmm1, 0x50(%rsp)
movapd %xmm3, %xmm1
unpckhpd %xmm3, %xmm1            # xmm1 = xmm1[1],xmm3[1]
movapd %xmm1, 0x40(%rsp)
xorpd %xmm0, %xmm1
movapd %xmm1, 0x30(%rsp)
movl $0x18, %edx
movl $0x1, %r8d
movq %r13, %rdi
movq %r15, %rsi
leaq 0x60(%rsp), %rbx
movq %rbx, %rcx
leaq 0x6e53(%rip), %r9       # 0x36cae
callq 0x2f136
movq $0x18, (%rsp)
movq 0x10(%rsp), %rdi
movq %r13, %rsi
leaq 0x260(%rsp), %rdx
movq %rbx, %rcx
xorl %r8d, %r8d
movq %rbp, %r9
movaps 0x50(%rsp), %xmm0
movaps 0x30(%rsp), %xmm1
movaps 0x20(%rsp), %xmm2
movaps 0x40(%rsp), %xmm3
callq 0x2eebd
incq %r13
addq $0x190, %r12            # imm = 0x190
addq $0x10, %r15
addq $0x10, %rbp
movq 0x18(%rsp), %rbx
cmpq %r13, %rbx
jne 0x2fd8b
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
movb 0xf(%rsp), %al
movq 0x4bb0(%rsp), %r9
jle 0x300d1
shlq $0x4, %r9
leaq 0x260(%rsp), %r8
xorl %ecx, %ecx
testq %rbx, %rbx
jle 0x2feff
movq %rbx, %rdx
xorl %esi, %esi
movups (%r8,%rsi), %xmm0
movups %xmm0, (%r14,%rsi)
addq $0x10, %rsi
decq %rdx
jne 0x2feec
incq %rcx
addq $0x180, %r8             # imm = 0x180
addq %r9, %r14
cmpq %rdi, %rcx
jne 0x2fee2
jmp 0x300d1
movq %rbx, 0x18(%rsp)
testq %rbx, %rbx
jle 0x30079
movq 0x18(%rsp), %rbx
leaq -0x1(%rbx), %rax
imulq $0x190, %rax, %rax      # imm = 0x190
leaq (%rsp,%rax), %r13
addq $0x26e0, %r13           # imm = 0x26E0
movq %rbx, %rax
shlq $0x4, %rax
leaq (%rsp,%rax), %rbp
addq $0x260, %rbp            # imm = 0x260
xorl %r15d, %r15d
movdqu (%r13), %xmm0
movdqa %xmm0, %xmm1
pand 0x62ba(%rip), %xmm1     # 0x36220
pshufd $0xee, %xmm1, %xmm2     # xmm2 = xmm1[2,3,2,3]
ucomisd %xmm2, %xmm1
jbe 0x2ffa7
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
movapd %xmm1, %xmm2
divsd %xmm0, %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
xorpd 0x321f(%rip), %xmm2     # 0x331b0
movapd 0x4d77(%rip), %xmm3     # 0x34d10
unpcklpd %xmm2, %xmm3            # xmm3 = xmm3[0],xmm2[0]
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
divpd %xmm1, %xmm3
jmp 0x2ffd0
movdqa %xmm0, %xmm1
punpckhqdq %xmm0, %xmm1    # xmm1 = xmm1[1],xmm0[1]
movdqa %xmm0, %xmm3
divsd %xmm1, %xmm3
mulsd %xmm3, %xmm0
addsd %xmm1, %xmm0
shufpd $0x2, 0x6278(%rip), %xmm3 # xmm3 = xmm3[0],mem[1]
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
divpd %xmm0, %xmm3
movapd %xmm3, 0x20(%rsp)
movapd %xmm3, %xmm1
movapd 0x31ce(%rip), %xmm0     # 0x331b0
xorpd %xmm0, %xmm1
movapd %xmm1, 0x50(%rsp)
movapd %xmm3, %xmm1
unpckhpd %xmm3, %xmm1            # xmm1 = xmm1[1],xmm3[1]
movapd %xmm1, 0x40(%rsp)
xorpd %xmm0, %xmm1
movapd %xmm1, 0x30(%rsp)
leaq 0x180(%r13), %rsi
movl $0x18, %edx
movl $0x1, %r8d
movq %r15, %rdi
leaq 0x60(%rsp), %r12
movq %r12, %rcx
leaq 0x6c86(%rip), %r9       # 0x36cae
callq 0x2f136
movq %rbp, %rdx
addq $-0x10, %rbp
movq $0x18, (%rsp)
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rcx
xorl %r8d, %r8d
movq %rbp, %r9
movaps 0x50(%rsp), %xmm0
movaps 0x30(%rsp), %xmm1
movaps 0x20(%rsp), %xmm2
movaps 0x40(%rsp), %xmm3
callq 0x2eebd
incq %r15
addq $-0x190, %r13           # imm = 0xFE70
decq %rbx
jg 0x2ff54
movq 0x10(%rsp), %r8
testq %r8, %r8
movq 0x18(%rsp), %rdi
movb 0xf(%rsp), %al
movq 0x4bb0(%rsp), %r10
jle 0x300d1
shlq $0x4, %r10
leaq 0x260(%rsp), %r9
xorl %ecx, %ecx
testq %rdi, %rdi
jle 0x300bf
movq %rdi, %rdx
xorl %esi, %esi
movups (%r9,%rsi), %xmm0
movups %xmm0, (%r14,%rsi)
addq $0x10, %rsi
decq %rdx
jne 0x300ac
incq %rcx
addq $0x180, %r9             # imm = 0x180
addq %r10, %r14
cmpq %r8, %rcx
jne 0x300a2
addq $0x4b68, %rsp           # imm = 0x4B68
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq