// File: 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
movq %rsp, %rbp
subq $0x4340, %rsp           # imm = 0x4340
movl %r8d, -0x433c(%rbp)
movq %rcx, %rax
movl -0x433c(%rbp), %ecx
movq %rax, -0x4338(%rbp)
movq %rdx, %rax
movq -0x4338(%rbp), %rdx
movq %rax, -0x4330(%rbp)
movq %rsi, %rax
movq -0x4330(%rbp), %rsi
movq %rax, -0x4328(%rbp)
movq %rdi, %r8
movq -0x4328(%rbp), %rdi
movb %r9b, %al
movq 0x20(%rbp), %r9
movq 0x18(%rbp), %r9
movq 0x10(%rbp), %r9
movq %r8, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
andb $0x1, %cl
movb %cl, -0x29(%rbp)
andb $0x1, %al
movb %al, -0x2a(%rbp)
leaq -0x20d0(%rbp), %rdi
movl $0x10, %esi
callq 0x3aab0
movq %rax, -0x42d8(%rbp)
leaq -0x4150(%rbp), %rdi
movl $0x10, %esi
callq 0x3aab0
movq %rax, -0x42e0(%rbp)
leaq -0x42d0(%rbp), %rdi
movl $0x10, %esi
callq 0x3aab0
movq %rax, -0x42e8(%rbp)
leaq -0x3367(%rip), %rax     # 0x4cee0
movq %rax, -0x42f8(%rbp)
leaq -0x2285(%rip), %rax     # 0x4dfd0
movq %rax, -0x4300(%rbp)
cmpq $0x20, -0x10(%rbp)
jg 0x5026a
cmpq $0x20, -0x18(%rbp)
jle 0x50273
movb $0x0, -0x1(%rbp)
jmp 0x505c9
movq -0x4300(%rbp), %rax
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq 0x10(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x42d8(%rbp), %r9
callq *%rax
movq -0x4300(%rbp), %rax
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq 0x18(%rbp), %rdx
movq 0x20(%rbp), %r8
movq -0x42e0(%rbp), %r9
movl $0x1, %ecx
callq *%rax
testb $0x1, -0x2a(%rbp)
je 0x5030d
movq $0x0, -0x48(%rbp)
movq -0x42d8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x10(%rbp), %rax
jge 0x5030b
movq -0x38(%rbp), %rax
movsd 0x4d1d(%rip), %xmm0     # 0x55008
movsd %xmm0, (%rax)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
addq $0x108, %rax            # imm = 0x108
movq %rax, -0x38(%rbp)
jmp 0x502d5
jmp 0x5030d
cmpq $0x0, 0x10(%rbp)
jne 0x50321
movb -0x29(%rbp), %al
andb $0x1, %al
movb %al, -0x42e9(%rbp)
jmp 0x5032e
movb -0x29(%rbp), %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, -0x42e9(%rbp)
testb $0x1, -0x42e9(%rbp)
je 0x504a8
movq -0x10(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x42d8(%rbp), %rax
movq -0x10(%rbp), %rcx
subq $0x1, %rcx
shlq $0x5, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
subq $0x1, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x48(%rbp)
jl 0x50482
movq -0x38(%rbp), %rax
movsd 0x4c7d(%rip), %xmm0     # 0x55008
divsd (%rax), %xmm0
movsd %xmm0, -0x4308(%rbp)
movsd -0x4308(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x4310(%rbp)
movq -0x10(%rbp), %rdi
subq $0x1, %rdi
subq -0x48(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x8, %rsi
movq -0x42e8(%rbp), %rcx
movq -0x48(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rcx
addq $0x8, %rcx
movl $0x1, %r8d
movq %r8, %rdx
callq 0x4dc60
movq -0x42f8(%rbp), %rax
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
subq $0x1, %rsi
subq -0x48(%rbp), %rsi
movq -0x42e0(%rbp), %rdx
movq -0x48(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rdx
addq $0x8, %rdx
movq -0x42e8(%rbp), %rcx
movq -0x48(%rbp), %r8
shlq $0x3, %r8
addq %r8, %rcx
addq $0x8, %rcx
movq -0x42e0(%rbp), %r8
movq -0x48(%rbp), %r9
shlq $0x3, %r9
addq %r9, %r8
movsd -0x4310(%rbp), %xmm0
movsd -0x4308(%rbp), %xmm1
movl $0x20, %r9d
callq *%rax
movq -0x48(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
addq $-0x108, %rax           # imm = 0xFEF8
movq %rax, -0x38(%rbp)
jmp 0x50374
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x42e0(%rbp), %rdx
movq 0x18(%rbp), %r8
movq 0x20(%rbp), %r9
movl $0x1, %ecx
callq 0x4e1f0
jmp 0x505c5
movq $0x0, -0x48(%rbp)
movq -0x42d8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x42d8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x10(%rbp), %rax
jge 0x505a4
movq -0x38(%rbp), %rax
movsd 0x4b28(%rip), %xmm0     # 0x55008
divsd (%rax), %xmm0
movsd %xmm0, -0x4318(%rbp)
movsd -0x4318(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x4320(%rbp)
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x42e8(%rbp), %rcx
movl $0x1, %r8d
movq %r8, %rdx
callq 0x4dc60
movq -0x42f8(%rbp), %rax
movq -0x18(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x42e0(%rbp), %rdx
movq -0x42e8(%rbp), %rcx
movq -0x42e0(%rbp), %r8
movq -0x48(%rbp), %r9
shlq $0x3, %r9
addq %r9, %r8
movsd -0x4320(%rbp), %xmm0
movsd -0x4318(%rbp), %xmm1
movl $0x20, %r9d
callq *%rax
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
addq $0x108, %rax            # imm = 0x108
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
addq $0x100, %rax            # imm = 0x100
movq %rax, -0x40(%rbp)
jmp 0x504c6
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x42e0(%rbp), %rdx
movq 0x18(%rbp), %r8
movq 0x20(%rbp), %r9
movl $0x1, %ecx
callq 0x4e1f0
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x4340, %rsp           # imm = 0x4340
popq %rbp
retq
nopw (%rax,%rax)