// File: 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
movq %rsp, %rbp
subq $0x4330, %rsp           # imm = 0x4330
movl %r8d, -0x432c(%rbp)
movq %rcx, %rax
movl -0x432c(%rbp), %ecx
movq %rax, -0x4328(%rbp)
movq %rdx, %rax
movq -0x4328(%rbp), %rdx
movq %rax, -0x4320(%rbp)
movq %rsi, %rax
movq -0x4320(%rbp), %rsi
movq %rax, -0x4318(%rbp)
movq %rdi, %r8
movq -0x4318(%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 -0x20c0(%rbp), %rdi
movl $0x10, %esi
callq 0x3aab0
movq %rax, -0x42c8(%rbp)
leaq -0x4140(%rbp), %rdi
movl $0x10, %esi
callq 0x3aab0
movq %rax, -0x42d0(%rbp)
leaq -0x42c0(%rbp), %rdi
movl $0x10, %esi
callq 0x3aab0
movq %rax, -0x42d8(%rbp)
leaq -0x2907(%rip), %rax     # 0x4cee0
movq %rax, -0x42e8(%rbp)
leaq -0x1825(%rip), %rax     # 0x4dfd0
movq %rax, -0x42f0(%rbp)
cmpq $0x20, -0x10(%rbp)
jg 0x4f80a
cmpq $0x20, -0x18(%rbp)
jle 0x4f813
movb $0x0, -0x1(%rbp)
jmp 0x4fb60
movq -0x42f0(%rbp), %rax
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq 0x10(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x42c8(%rbp), %r9
callq *%rax
movq -0x42f0(%rbp), %rax
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq 0x18(%rbp), %rdx
movq 0x20(%rbp), %r8
movq -0x42d0(%rbp), %r9
xorl %ecx, %ecx
callq *%rax
testb $0x1, -0x2a(%rbp)
je 0x4f8aa
movq $0x0, -0x40(%rbp)
movq -0x42c8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x18(%rbp), %rax
jge 0x4f8a8
movq -0x38(%rbp), %rax
movsd 0x5780(%rip), %xmm0     # 0x55008
movsd %xmm0, (%rax)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
addq $0x108, %rax            # imm = 0x108
movq %rax, -0x38(%rbp)
jmp 0x4f872
jmp 0x4f8aa
cmpq $0x0, 0x10(%rbp)
jne 0x4f8be
movb -0x29(%rbp), %al
andb $0x1, %al
movb %al, -0x42d9(%rbp)
jmp 0x4f8cb
movb -0x29(%rbp), %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, -0x42d9(%rbp)
testb $0x1, -0x42d9(%rbp)
je 0x4f9f0
movq $0x0, -0x40(%rbp)
movq -0x42c8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x18(%rbp), %rax
jge 0x4f9cb
movq -0x38(%rbp), %rax
movsd 0x5703(%rip), %xmm0     # 0x55008
divsd (%rax), %xmm0
movsd %xmm0, -0x42f8(%rbp)
movsd -0x42f8(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x4300(%rbp)
movq -0x40(%rbp), %rdi
movq -0x42c8(%rbp), %rsi
movq -0x40(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
movq -0x42d8(%rbp), %rcx
movl $0x20, %edx
movl $0x1, %r8d
callq 0x4dc60
movq -0x42e8(%rbp), %rax
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x42d0(%rbp), %rdx
movq -0x42d8(%rbp), %rcx
movq -0x42d0(%rbp), %r8
movq -0x40(%rbp), %r9
shlq $0x3, %r9
addq %r9, %r8
movsd -0x4300(%rbp), %xmm0
movsd -0x42f8(%rbp), %xmm1
movl $0x20, %r9d
callq *%rax
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
addq $0x108, %rax            # imm = 0x108
movq %rax, -0x38(%rbp)
jmp 0x4f8eb
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x42d0(%rbp), %rdx
movq 0x18(%rbp), %r8
movq 0x20(%rbp), %r9
xorl %eax, %eax
movl %eax, %ecx
callq 0x4e1f0
jmp 0x4fb5c
movq -0x18(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x42c8(%rbp), %rax
movq -0x18(%rbp), %rcx
subq $0x1, %rcx
shlq $0x5, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq -0x18(%rbp), %rcx
subq $0x1, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x40(%rbp)
jl 0x4fb3c
movq -0x38(%rbp), %rax
movsd 0x55c8(%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 -0x18(%rbp), %rdi
subq $0x1, %rdi
subq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x100, %rsi            # imm = 0x100
movq -0x42d8(%rbp), %rcx
movq -0x40(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rcx
addq $0x8, %rcx
movl $0x20, %edx
movl $0x1, %r8d
callq 0x4dc60
movq -0x42e8(%rbp), %rax
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
subq $0x1, %rsi
subq -0x40(%rbp), %rsi
movq -0x42d0(%rbp), %rdx
movq -0x40(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rdx
addq $0x8, %rdx
movq -0x42d8(%rbp), %rcx
movq -0x40(%rbp), %r8
shlq $0x3, %r8
addq %r8, %rcx
addq $0x8, %rcx
movq -0x42d0(%rbp), %r8
movq -0x40(%rbp), %r9
shlq $0x3, %r9
addq %r9, %r8
movsd -0x4310(%rbp), %xmm0
movsd -0x4308(%rbp), %xmm1
movl $0x20, %r9d
callq *%rax
movq -0x40(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
addq $-0x108, %rax           # imm = 0xFEF8
movq %rax, -0x38(%rbp)
jmp 0x4fa29
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x42d0(%rbp), %rdx
movq 0x18(%rbp), %r8
movq 0x20(%rbp), %r9
xorl %eax, %eax
movl %eax, %ecx
callq 0x4e1f0
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x4330, %rsp           # imm = 0x4330
popq %rbp
retq
nop