// File: /workspace/github_cpp_makefile_star2_O2/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 $0x42c8, %rsp           # imm = 0x42C8
movl %r8d, %ebx
movq %rcx, %r8
cmpq $0x21, %rdi
setl %cl
cmpq $0x21, %rsi
setl %al
andb %cl, %al
cmpb $0x1, %al
jne 0x2d34a
movl %r9d, %ebp
movq %rsi, %r14
movq %rdi, %r12
movb %al, 0x7(%rsp)
movq 0x4308(%rsp), %r13
movq 0x4300(%rsp), %rcx
leaq 0x2240(%rsp), %r15
movq %rsi, %rdi
movq %r15, %r9
callq 0x2c4ad
leaq 0x1c0(%rsp), %r9
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
movq 0x4310(%rsp), %r8
callq 0x2c4ad
testb %bpl, %bpl
je 0x2d19b
xorl %eax, %eax
testq %r14, %r14
cmovgq %r14, %rax
leaq 0x2240(%rsp), %rcx
movabsq $0x3ff0000000000000, %rdx # imm = 0x3FF0000000000000
subq $0x1, %rax
jb 0x2d19b
movq %rdx, (%rcx)
addq $0x108, %rcx            # imm = 0x108
jmp 0x2d189
movq %r12, 0x8(%rsp)
cmpq $0x0, 0x4300(%rsp)
setne %al
cmpb %bl, %al
movq %r14, 0x30(%rsp)
je 0x2d261
xorl %r13d, %r13d
testq %r14, %r14
movl $0x0, %eax
cmovgq %r14, %rax
movq %rax, 0x38(%rsp)
leaq 0x1c0(%rsp), %r12
movq %r15, %rbp
pushq $0x20
popq %r14
cmpq %r13, 0x38(%rsp)
je 0x2d31d
movsd 0x3009(%rip), %xmm0     # 0x301f8
divsd (%r15), %xmm0
movapd %xmm0, 0x20(%rsp)
xorpd 0x2fae(%rip), %xmm0     # 0x301b0
movapd %xmm0, 0x10(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
movq %r14, %rdx
leaq 0x40(%rsp), %rbx
movq %rbx, %rcx
pushq $0x1
popq %r8
callq 0x2c32e
movq 0x8(%rsp), %rdi
movq %r13, %rsi
leaq 0x1c0(%rsp), %rdx
movq %rbx, %rcx
movq %r12, %r8
movq %r14, %r9
movaps 0x10(%rsp), %xmm0
movaps 0x20(%rsp), %xmm1
callq 0x2bded
incq %r13
addq $0x108, %r15            # imm = 0x108
addq $0x8, %rbp
addq $0x8, %r12
jmp 0x2d1dc
leaq -0x1(%r14), %rcx
movq %rcx, %rax
shlq $0x8, %rax
addq %rsp, %rax
addq $0x2240, %rax           # imm = 0x2240
leaq (%rax,%r14,8), %rbp
addq $-0x8, %rbp
leaq (%rsp,%r14,8), %r12
addq $0x40, %r12
leaq (%rsp,%r14,8), %r14
addq $0x1c0, %r14            # imm = 0x1C0
xorl %r13d, %r13d
testq %rcx, %rcx
js 0x2d31d
movsd 0x2f54(%rip), %xmm0     # 0x301f8
divsd (%rbp), %xmm0
movapd %xmm0, 0x20(%rsp)
xorpd 0x2ef9(%rip), %xmm0     # 0x301b0
movapd %xmm0, 0x10(%rsp)
leaq 0x100(%rbp), %rsi
movq %r13, %rdi
pushq $0x20
popq %rdx
movq %rcx, %rbx
movq %r12, %rcx
pushq $0x1
popq %r8
callq 0x2c32e
leaq -0x8(%r14), %r15
movq 0x8(%rsp), %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %r12, %rcx
movq %r15, %r8
pushq $0x20
popq %r9
movaps 0x10(%rsp), %xmm0
movaps 0x20(%rsp), %xmm1
callq 0x2bded
movq %rbx, %rcx
decq %rcx
addq $-0x8, %r12
incq %r13
addq $-0x108, %rbp           # imm = 0xFEF8
movq %r15, %r14
jmp 0x2d293
leaq 0x1c0(%rsp), %rdx
movq 0x8(%rsp), %rdi
movq 0x30(%rsp), %rsi
xorl %ecx, %ecx
movq 0x4308(%rsp), %r8
movq 0x4310(%rsp), %r9
callq 0x2c58b
movb 0x7(%rsp), %al
addq $0x42c8, %rsp           # imm = 0x42C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq