// File: /workspace/github_cpp_makefile_star2_O1/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
cmpq $0x21, %rdi
setl %al
cmpq $0x21, %rsi
setl %bpl
andb %al, %bpl
cmpb $0x1, %bpl
jne 0x31192
movl %r9d, %r12d
movq %rcx, %r9
movq %rsi, %rbx
movq %rdi, %r14
movl %r8d, 0x10(%rsp)
movq 0x42f8(%rsp), %r13
movq 0x42f0(%rsp), %rcx
leaq 0x2230(%rsp), %r15
movq %rsi, %rdi
movq %r9, %r8
movq %r15, %r9
callq 0x2fe5e
movq 0x4300(%rsp), %r9
movq %rbx, %r10
shrq $0x3f, %r10
addq %rbx, %r10
sarq %r10
testq %r14, %r14
jle 0x30ee3
leaq 0x1b0(%rsp), %rax
xorl %ecx, %ecx
movq %r13, %rdx
movq %rdx, %rdi
movq %rax, %rsi
cmpq $0x2, %rbx
jl 0x30ec4
movq %r10, %r8
movq %rax, %rsi
movq %rdx, %rdi
movsd (%rdi), %xmm0
movsd %xmm0, (%rsi)
movsd 0x8(%rdi), %xmm0
movsd %xmm0, 0x8(%rsi)
addq $0x10, %rsi
addq $0x10, %rdi
decq %r8
jne 0x30ea5
testb $0x1, %bl
je 0x30ed1
movsd (%rdi), %xmm0
movsd %xmm0, (%rsi)
incq %rcx
leaq (%rdx,%r9,8), %rdx
addq $0x100, %rax            # imm = 0x100
cmpq %r14, %rcx
jne 0x30e90
testq %rbx, %rbx
setle %al
xorb $0x1, %r12b
orb %al, %r12b
jne 0x30f15
leaq 0x2230(%rsp), %rax
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rbx, %rdx
movq %rcx, (%rax)
addq $0x108, %rax            # imm = 0x108
decq %rdx
jne 0x30f07
movq %r10, 0x20(%rsp)
cmpq $0x0, 0x42f0(%rsp)
setne %al
cmpb 0x10(%rsp), %al
je 0x3102b
testq %rbx, %rbx
jle 0x30fb2
xorl %r12d, %r12d
testq %r12, %r12
je 0x30f61
leaq (%rsp,%r12,8), %rax
addq $0x2230, %rax           # imm = 0x2230
xorl %ecx, %ecx
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp,%rcx,8)
incq %rcx
addq $0x100, %rax            # imm = 0x100
cmpq %rcx, %r12
jne 0x30f49
movsd 0x3237(%rip), %xmm1     # 0x341a0
divsd (%r15), %xmm1
movapd %xmm1, %xmm0
xorpd 0x3266(%rip), %xmm0     # 0x341e0
leaq (%rsp,%r12,8), %r8
addq $0x1b0, %r8             # imm = 0x1B0
movl $0x20, %r9d
movq %r14, %rdi
movq %r12, %rsi
leaq 0x1b0(%rsp), %rdx
leaq 0x30(%rsp), %rcx
callq 0x2f6c5
incq %r12
addq $0x108, %r15            # imm = 0x108
cmpq %rbx, %r12
jne 0x30f38
testq %r14, %r14
movq 0x4300(%rsp), %r8
movq 0x20(%rsp), %r9
jle 0x31192
leaq 0x1b0(%rsp), %rax
xorl %ecx, %ecx
movq %rax, %rsi
movq %r13, %rdx
cmpq $0x2, %rbx
jl 0x31006
movq %r9, %rdi
movq %r13, %rdx
movq %rax, %rsi
movsd (%rsi), %xmm0
movsd %xmm0, (%rdx)
movsd 0x8(%rsi), %xmm0
movsd %xmm0, 0x8(%rdx)
addq $0x10, %rdx
addq $0x10, %rsi
decq %rdi
jne 0x30fe7
testb $0x1, %bl
je 0x31013
movsd (%rsi), %xmm0
movsd %xmm0, (%rdx)
incq %rcx
addq $0x100, %rax            # imm = 0x100
leaq (%r13,%r8,8), %r13
cmpq %r14, %rcx
jne 0x30fd2
jmp 0x31192
movb %bpl, 0xf(%rsp)
movq %r14, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
testq %rbx, %rbx
jle 0x31112
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), %r12
movq %rcx, %rax
shlq $0x8, %rax
leaq (%rax,%rcx,8), %rax
leaq (%rsp,%rax), %rbp
addq $0x2228, %rbp           # 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 0x310ac
movq %r14, %rax
movq %rbp, %rcx
movsd (%rcx), %xmm0
movsd %xmm0, (%r15,%rax,8)
addq $0x100, %rcx            # imm = 0x100
incq %rax
jne 0x31096
movsd 0x30ec(%rip), %xmm1     # 0x341a0
divsd (%r12), %xmm1
movapd %xmm1, %xmm0
xorpd 0x311a(%rip), %xmm0     # 0x341e0
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 0x2f6c5
leaq -0x1(%rbx), %rax
movq $-0x108, %rcx           # imm = 0xFEF8
addq %rcx, %r12
addq %rcx, %rbp
decq %r14
testq %rbx, %rbx
movq %rax, %rbx
jg 0x31086
movq 0x10(%rsp), %r9
testq %r9, %r9
movq 0x18(%rsp), %r8
movb 0xf(%rsp), %bpl
movq 0x4300(%rsp), %r10
movq 0x20(%rsp), %r11
jle 0x31192
leaq 0x1b0(%rsp), %rax
xorl %ecx, %ecx
movq %rax, %rsi
movq %r13, %rdx
cmpq $0x2, %r8
jl 0x31171
movq %r11, %rdi
movq %r13, %rdx
movq %rax, %rsi
movsd (%rsi), %xmm0
movsd %xmm0, (%rdx)
movsd 0x8(%rsi), %xmm0
movsd %xmm0, 0x8(%rdx)
addq $0x10, %rdx
addq $0x10, %rsi
decq %rdi
jne 0x31152
testb $0x1, %r8b
je 0x3117f
movsd (%rsi), %xmm0
movsd %xmm0, (%rdx)
incq %rcx
addq $0x100, %rax            # imm = 0x100
leaq (%r13,%r10,8), %r13
cmpq %r9, %rcx
jne 0x3113d
movl %ebp, %eax
addq $0x42b8, %rsp           # imm = 0x42B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq