// File: /workspace/github_cpp_makefile_star2_O1/mouda[P]LTE_random_access-simulate/ap.cpp
// Function: alglib_impl::_ialglib_rmatrixlefttrsm(long, long, double*, long, bool, bool, long, double*, long)
ae_bool _ialglib_rmatrixlefttrsm(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, *arow;
    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
     * Transpose X (so we may use mv, which calculates A*x, but not x*A)
     */
    mcopyblock(m, m, _a, optype, _a_stride, abuf);
    mcopyblock(m, n, _x, 1, _x_stride, xbuf);
    if( isunit )
        for(i=0,pdiag=abuf; i<m; i++,pdiag+=alglib_r_block+1)
            *pdiag = 1.0;
    if( optype==0 )
        uppera = isupper;
    else
        uppera = !isupper;

    /*
     * Solve A^-1*Y^T=X^T where A is upper or lower triangular
     */
    if( uppera )
    {
        for(i=m-1,pdiag=abuf+(m-1)*alglib_r_block+(m-1); i>=0; i--,pdiag-=alglib_r_block+1)
        {
            double beta = 1.0/(*pdiag);
            double alpha = -beta;
            _ialglib_vcopy(m-1-i, pdiag+1, 1, tmpbuf+i+1, 1);
            rmv(n, m-1-i, xbuf+i+1, tmpbuf+i+1, xbuf+i, alglib_r_block, alpha, beta);
        }
        _ialglib_mcopyunblock(m, n, xbuf, 1, _x, _x_stride);
    }
    else
    {   for(i=0,pdiag=abuf,arow=abuf; i<m; i++,pdiag+=alglib_r_block+1,arow+=alglib_r_block)
        {
            double beta = 1.0/(*pdiag);
            double alpha = -beta;
            _ialglib_vcopy(i, arow, 1, tmpbuf, 1);
            rmv(n, i, xbuf, tmpbuf, xbuf+i, alglib_r_block, alpha, beta);
        }
        _ialglib_mcopyunblock(m, n, xbuf, 1, _x, _x_stride);
    }
    return ae_true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x42a8, %rsp           # imm = 0x42A8
cmpq $0x21, %rdi
setl %al
cmpq $0x21, %rsi
setl %r15b
andb %al, %r15b
cmpb $0x1, %r15b
jne 0x31a00
movl %r9d, %r12d
movq %rcx, %r9
movq %rsi, %rbx
movq %rdi, %r14
movl %r8d, 0x10(%rsp)
movq 0x42e8(%rsp), %rbp
movq 0x42e0(%rsp), %rcx
leaq 0x2220(%rsp), %r13
movq %rdi, %rsi
movq %r9, %r8
movq %r13, %r9
callq 0x2fe5e
movq %rbx, %rax
shrq $0x3f, %rax
addq %rbx, %rax
sarq %rax
movq %rax, 0x18(%rsp)
testq %r14, %r14
jle 0x31727
leaq 0x1a0(%rsp), %rax
xorl %ecx, %ecx
movq %rbp, %rdx
movq %rdx, %rdi
movq %rax, %rsi
cmpq $0x2, %rbx
jl 0x31702
movq 0x18(%rsp), %r8
movq %rax, %rsi
movq %rdx, %rdi
movsd (%rdi), %xmm0
movsd %xmm0, (%rsi)
movsd 0x8(%rdi), %xmm0
movsd %xmm0, 0x100(%rsi)
addq $0x200, %rsi            # imm = 0x200
addq $0x10, %rdi
decq %r8
jne 0x316dd
testb $0x1, %bl
je 0x3170f
movsd (%rdi), %xmm0
movsd %xmm0, (%rsi)
incq %rcx
movq 0x42f0(%rsp), %rsi
leaq (%rdx,%rsi,8), %rdx
addq $0x8, %rax
cmpq %r14, %rcx
jne 0x316c6
testq %r14, %r14
setle %al
xorb $0x1, %r12b
orb %al, %r12b
movl 0x10(%rsp), %esi
jne 0x3175d
leaq 0x2220(%rsp), %rax
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %r14, %rdx
movq %rcx, (%rax)
addq $0x108, %rax            # imm = 0x108
decq %rdx
jne 0x3174f
movb %r15b, 0xf(%rsp)
cmpq $0x0, 0x42e0(%rsp)
setne %al
xorb %sil, %al
je 0x318c4
testq %r14, %r14
jle 0x31845
leaq -0x1(%r14), %r15
movq %r15, %rax
shlq $0x8, %rax
addq %rsp, %rax
addq $0x2220, %rax           # imm = 0x2220
leaq (%rax,%r15,8), %r12
movq %r15, %r13
movq %r15, %rsi
subq %r13, %rsi
leaq 0x8(%r12), %rax
leaq 0x28(%rsp), %rcx
leaq (%rcx,%r13,8), %rcx
cmpq $0x2, %rsi
jae 0x317ba
movq %rcx, %rdx
jmp 0x317e2
movq %rsi, %rdi
shrq %rdi
movq %rcx, %rdx
movsd (%rax), %xmm0
movsd %xmm0, (%rdx)
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%rdx)
addq $0x10, %rax
addq $0x10, %rdx
decq %rdi
jne 0x317c3
testb $0x1, %sil
je 0x317f0
movsd (%rax), %xmm0
movsd %xmm0, (%rdx)
movsd 0x29a8(%rip), %xmm1     # 0x341a0
divsd (%r12), %xmm1
movapd %xmm1, %xmm0
xorpd 0x29d6(%rip), %xmm0     # 0x341e0
leaq (%rsp,%r13,8), %r8
addq $0x1a0, %r8             # imm = 0x1A0
leaq (%rsp,%r13,8), %rdx
addq $0x1a8, %rdx            # imm = 0x1A8
movl $0x20, %r9d
movq %rbx, %rdi
callq 0x2f6c5
leaq -0x1(%r13), %rax
addq $-0x108, %r12           # imm = 0xFEF8
testq %r13, %r13
movq %rax, %r13
jg 0x3179b
testq %r14, %r14
movb 0xf(%rsp), %r15b
jle 0x31a00
leaq 0x1a0(%rsp), %rax
xorl %ecx, %ecx
movq %rax, %rsi
movq %rbp, %rdx
cmpq $0x2, %rbx
jl 0x31899
movq 0x18(%rsp), %rdi
movq %rbp, %rdx
movq %rax, %rsi
movsd (%rsi), %xmm0
movsd %xmm0, (%rdx)
movsd 0x100(%rsi), %xmm0
movsd %xmm0, 0x8(%rdx)
addq $0x10, %rdx
addq $0x200, %rsi            # imm = 0x200
decq %rdi
jne 0x31874
testb $0x1, %bl
je 0x318a6
movsd (%rsi), %xmm0
movsd %xmm0, (%rdx)
incq %rcx
addq $0x8, %rax
movq 0x42f0(%rsp), %rdx
leaq (%rbp,%rdx,8), %rbp
cmpq %r14, %rcx
jne 0x3185d
jmp 0x31a00
movq %rbx, 0x10(%rsp)
testq %r14, %r14
jle 0x31984
xorl %esi, %esi
leaq 0x20(%rsp), %rcx
movq %r13, %r15
movq %rcx, %rax
movq %r13, %rdi
cmpq $0x2, %rsi
jb 0x31913
movq %rsi, %rdx
shrq %rdx
movq %r13, %rdi
movq %rcx, %rax
movsd (%rdi), %xmm0
movsd %xmm0, (%rax)
movsd 0x8(%rdi), %xmm0
movsd %xmm0, 0x8(%rax)
addq $0x10, %rdi
addq $0x10, %rax
decq %rdx
jne 0x318f4
movq %r14, %rbx
testb $0x1, %sil
je 0x31924
movsd (%rdi), %xmm0
movsd %xmm0, (%rax)
movsd 0x2874(%rip), %xmm1     # 0x341a0
divsd (%r15), %xmm1
movapd %xmm1, %xmm0
xorpd 0x28a3(%rip), %xmm0     # 0x341e0
leaq 0x1(%rsi), %r12
leaq 0x1a0(%rsp,%rsi,8), %r8
movl $0x20, %r9d
movq 0x10(%rsp), %rdi
leaq 0x1a0(%rsp), %rdx
movq %rcx, %r14
callq 0x2f6c5
movq %r14, %rcx
addq $0x108, %r15            # imm = 0x108
addq $0x100, %r13            # imm = 0x100
movq %r12, %rsi
movq %rbx, %r14
cmpq %rbx, %r12
jne 0x318dc
testq %r14, %r14
movb 0xf(%rsp), %r15b
movq 0x10(%rsp), %r8
jle 0x31a00
leaq 0x1a0(%rsp), %rax
xorl %ecx, %ecx
movq %rax, %rsi
movq %rbp, %rdx
cmpq $0x2, %r8
jl 0x319d9
movq 0x18(%rsp), %rdi
movq %rbp, %rdx
movq %rax, %rsi
movsd (%rsi), %xmm0
movsd %xmm0, (%rdx)
movsd 0x100(%rsi), %xmm0
movsd %xmm0, 0x8(%rdx)
addq $0x10, %rdx
addq $0x200, %rsi            # imm = 0x200
decq %rdi
jne 0x319b4
testb $0x1, %r8b
je 0x319e7
movsd (%rsi), %xmm0
movsd %xmm0, (%rdx)
incq %rcx
addq $0x8, %rax
movq 0x42f0(%rsp), %rdx
leaq (%rbp,%rdx,8), %rbp
cmpq %r14, %rcx
jne 0x3199d
movl %r15d, %eax
addq $0x42a8, %rsp           # imm = 0x42A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq