// File: /workspace/github_cpp_makefile_star2_O3/mouda[P]LTE_random_access-simulate/ap.cpp
// Function: alglib_impl::_ialglib_rmatrixrighttrsm(long, long, double*, long, bool, bool, long, double*, long)
ae_bool _ialglib_rmatrixrighttrsm(ae_int_t m,
     ae_int_t n,
     double *_a,
     ae_int_t _a_stride,
     ae_bool isupper,
     ae_bool isunit,
     ae_int_t optype,
     double *_x,
     ae_int_t _x_stride)
{
    /*
     * local buffers
     */
    double *pdiag;
    ae_int_t i;
    double _loc_abuf[alglib_r_block*alglib_r_block+alglib_simd_alignment];
    double _loc_xbuf[alglib_r_block*alglib_r_block+alglib_simd_alignment];
    double _loc_tmpbuf[alglib_r_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 (*rmv)(ae_int_t, ae_int_t, const double *, const double *, double *, ae_int_t, double, double) = &_ialglib_rmv;
    void (*mcopyblock)(ae_int_t, ae_int_t, const double *, ae_int_t, ae_int_t, double *) = &_ialglib_mcopyblock;
    
    if( m>alglib_r_block || n>alglib_r_block )
        return ae_false;

    /*
     * Check for SSE2 support
     */
#ifdef AE_HAS_SSE2_INTRINSICS
    if( ae_cpuid() & CPU_SSE2 )
    {
        rmv = &_ialglib_rmv_sse2;
        mcopyblock = &_ialglib_mcopyblock_sse2;
    }    
#endif
    
    /*
     * Prepare
     */
    mcopyblock(n, n, _a, optype, _a_stride, abuf);
    mcopyblock(m, n, _x, 0, _x_stride, xbuf);
    if( isunit )
        for(i=0,pdiag=abuf; i<n; i++,pdiag+=alglib_r_block+1)
            *pdiag = 1.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+=alglib_r_block+1)
        {
            double beta  = 1.0/(*pdiag);
            double alpha = -beta;
            _ialglib_vcopy(i, abuf+i, alglib_r_block, tmpbuf, 1);
            rmv(m, i, xbuf, tmpbuf, xbuf+i, alglib_r_block, alpha, beta);
        }
        _ialglib_mcopyunblock(m, n, xbuf, 0, _x, _x_stride);
    }
    else
    {
        for(i=n-1,pdiag=abuf+(n-1)*alglib_r_block+(n-1); i>=0; i--,pdiag-=alglib_r_block+1)
        {
            double beta = 1.0/(*pdiag);
            double alpha = -beta;
            _ialglib_vcopy(n-1-i, pdiag+alglib_r_block, alglib_r_block, tmpbuf+i+1, 1);
            rmv(m, n-1-i, xbuf+i+1, tmpbuf+i+1, xbuf+i, alglib_r_block, alpha, beta);
        }
        _ialglib_mcopyunblock(m, n, xbuf, 0, _x, _x_stride);
    }
    return ae_true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x42b8, %rsp           # imm = 0x42B8
movl %r9d, %ebp
movq %rcx, %r9
cmpq $0x21, %rdi
setl %cl
cmpq $0x21, %rsi
setl %al
andb %cl, %al
cmpb $0x1, %al
jne 0x304e4
movq %rsi, %rbx
movq %rdi, %r14
movl %r8d, 0x10(%rsp)
movb %al, 0xf(%rsp)
movq 0x4300(%rsp), %r12
movq 0x42f8(%rsp), %r13
movq 0x42f0(%rsp), %rcx
leaq 0x2230(%rsp), %r15
movq %rsi, %rdi
movq %r9, %r8
movq %r15, %r9
callq 0x2f1b2
movq %rbx, %r10
shrq $0x3f, %r10
addq %rbx, %r10
sarq %r10
testq %r14, %r14
jle 0x301b7
leaq 0x1b0(%rsp), %rax
xorl %ecx, %ecx
movq %r13, %rdx
movq %rdx, %rdi
movq %rax, %rsi
cmpq $0x2, %rbx
jl 0x30198
movq %r10, %r8
movq %rax, %rsi
movq %rdx, %rdi
movdqu (%rdi), %xmm0
movdqu %xmm0, (%rsi)
addq $0x10, %rsi
addq $0x10, %rdi
decq %r8
jne 0x30183
testb $0x1, %bl
je 0x301a5
movq (%rdi), %xmm0
movq %xmm0, (%rsi)
incq %rcx
leaq (%rdx,%r12,8), %rdx
addq $0x100, %rax            # imm = 0x100
cmpq %r14, %rcx
jne 0x3016e
testq %rbx, %rbx
setle %al
xorb $0x1, %bpl
orb %al, %bpl
movl 0x10(%rsp), %r8d
jne 0x30276
leaq 0x1(%rbx), %rax
andq $-0x2, %rax
leaq -0x1(%rbx), %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
leaq 0x2230(%rsp), %rcx
xorl %edx, %edx
movdqa 0x6059(%rip), %xmm1     # 0x36250
movdqa 0x6061(%rip), %xmm2     # 0x36260
pxor %xmm2, %xmm0
movabsq $0x3ff0000000000000, %rsi # imm = 0x3FF0000000000000
pcmpeqd %xmm3, %xmm3
movq %rdx, %xmm4
pshufd $0x44, %xmm4, %xmm4     # xmm4 = xmm4[0,1,0,1]
por %xmm1, %xmm4
pxor %xmm2, %xmm4
movdqa %xmm4, %xmm5
pcmpgtd %xmm0, %xmm5
pcmpeqd %xmm0, %xmm4
pshufd $0xf5, %xmm4, %xmm6     # xmm6 = xmm4[1,1,3,3]
pand %xmm5, %xmm6
pshufd $0xf5, %xmm5, %xmm4     # xmm4 = xmm5[1,1,3,3]
por %xmm6, %xmm4
movd %xmm4, %edi
notl %edi
testb $0x1, %dil
je 0x30250
movq %rsi, (%rcx)
pxor %xmm3, %xmm4
pextrw $0x4, %xmm4, %edi
testb $0x1, %dil
je 0x30266
movq %rsi, 0x108(%rcx)
addq $0x2, %rdx
addq $0x210, %rcx            # imm = 0x210
cmpq %rdx, %rax
jne 0x30211
movq %r10, 0x20(%rsp)
cmpq $0x0, 0x42f0(%rsp)
setne %al
cmpb %r8b, %al
je 0x3038d
testq %rbx, %rbx
jle 0x30319
xorl %r12d, %r12d
leaq 0x30(%rsp), %rbp
testq %r12, %r12
je 0x302ca
leaq (%rsp,%r12,8), %rax
addq $0x2230, %rax           # imm = 0x2230
xorl %ecx, %ecx
movq (%rax), %xmm0
movq %xmm0, 0x30(%rsp,%rcx,8)
incq %rcx
addq $0x100, %rax            # imm = 0x100
cmpq %rcx, %r12
jne 0x302b2
movsd 0x2f0e(%rip), %xmm1     # 0x331e0
divsd (%r15), %xmm1
movapd %xmm1, %xmm0
xorpd 0x2ecd(%rip), %xmm0     # 0x331b0
leaq (%rsp,%r12,8), %r8
addq $0x1b0, %r8             # imm = 0x1B0
movl $0x20, %r9d
movq %r14, %rdi
movq %r12, %rsi
leaq 0x1b0(%rsp), %rdx
movq %rbp, %rcx
callq 0x2ea57
incq %r12
addq $0x108, %r15            # imm = 0x108
cmpq %rbx, %r12
jne 0x302a1
testq %r14, %r14
movb 0xf(%rsp), %al
movq 0x4300(%rsp), %r9
movq 0x20(%rsp), %r10
jle 0x304e4
leaq 0x1b0(%rsp), %r8
xorl %ecx, %ecx
movq %r8, %rsi
movq %r13, %rdx
cmpq $0x2, %rbx
jl 0x30367
movq %r10, %rdi
movq %r13, %rdx
movq %r8, %rsi
movdqu (%rsi), %xmm0
movdqu %xmm0, (%rdx)
addq $0x10, %rdx
addq $0x10, %rsi
decq %rdi
jne 0x30352
testb $0x1, %bl
je 0x30374
movq (%rsi), %xmm0
movq %xmm0, (%rdx)
incq %rcx
addq $0x100, %r8             # imm = 0x100
leaq (%r13,%r9,8), %r13
cmpq %r14, %rcx
jne 0x3033d
jmp 0x304e4
movq %r14, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
testq %rbx, %rbx
jle 0x3046e
movq 0x18(%rsp), %rcx
leaq -0x1(%rcx), %rbx
movq %rbx, %rax
shlq $0x8, %rax
addq %rsp, %rax
addq $0x2230, %rax           # imm = 0x2230
leaq (%rax,%rbx,8), %rbp
movq %rcx, %rax
shlq $0x8, %rax
leaq (%rax,%rcx,8), %rax
leaq (%rsp,%rax), %r12
addq $0x2228, %r12           # imm = 0x2228
leaq (%rsp,%rcx,8), %r15
addq $0x30, %r15
xorl %r14d, %r14d
movq %rbx, 0x28(%rsp)
movq 0x28(%rsp), %rsi
subq %rbx, %rsi
je 0x30409
movq %r14, %rax
movq %r12, %rcx
movq (%rcx), %xmm0
movq %xmm0, (%r15,%rax,8)
addq $0x100, %rcx            # imm = 0x100
incq %rax
jne 0x303f3
movsd 0x2dcf(%rip), %xmm1     # 0x331e0
divsd (%rbp), %xmm1
movapd %xmm1, %xmm0
xorpd 0x2d8e(%rip), %xmm0     # 0x331b0
leaq 0x38(%rsp), %rax
leaq (%rax,%rbx,8), %rcx
leaq 0x1b0(%rsp,%rbx,8), %r8
leaq (%rsp,%rbx,8), %rdx
addq $0x1b8, %rdx            # imm = 0x1B8
movl $0x20, %r9d
movq 0x10(%rsp), %rdi
callq 0x2ea57
leaq -0x1(%rbx), %rax
movq $-0x108, %rcx           # imm = 0xFEF8
addq %rcx, %rbp
addq %rcx, %r12
decq %r14
testq %rbx, %rbx
movq %rax, %rbx
jg 0x303e3
movq 0x10(%rsp), %r9
testq %r9, %r9
movq 0x18(%rsp), %r8
movb 0xf(%rsp), %al
movq 0x4300(%rsp), %r11
movq 0x20(%rsp), %rbx
jle 0x304e4
leaq 0x1b0(%rsp), %r10
xorl %ecx, %ecx
movq %r10, %rsi
movq %r13, %rdx
cmpq $0x2, %r8
jl 0x304c2
movq %rbx, %rdi
movq %r13, %rdx
movq %r10, %rsi
movdqu (%rsi), %xmm0
movdqu %xmm0, (%rdx)
addq $0x10, %rdx
addq $0x10, %rsi
decq %rdi
jne 0x304ad
testb $0x1, %r8b
je 0x304d0
movq (%rsi), %xmm0
movq %xmm0, (%rdx)
incq %rcx
addq $0x100, %r10            # imm = 0x100
leaq (%r13,%r11,8), %r13
cmpq %r9, %rcx
jne 0x30498
addq $0x42b8, %rsp           # imm = 0x42B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq