// File: mouda[P]LTE_random_access-simulate/ap.cpp
// Function: alglib_impl::_ialglib_cmatrixrighttrsm(long, long, alglib_impl::ae_complex*, long, bool, bool, long, alglib_impl::ae_complex*, long)
ae_bool _ialglib_cmatrixrighttrsm(ae_int_t m,
     ae_int_t n,
     ae_complex *_a,
     ae_int_t _a_stride,
     ae_bool isupper,
     ae_bool isunit,
     ae_int_t optype,
     ae_complex *_x,
     ae_int_t _x_stride)
{
    /*
     * local buffers
     */
    double *pdiag;
    ae_int_t i;
    double _loc_abuf[2*alglib_c_block*alglib_c_block+alglib_simd_alignment];
    double _loc_xbuf[2*alglib_c_block*alglib_c_block+alglib_simd_alignment];
    double _loc_tmpbuf[2*alglib_c_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 (*cmv)(ae_int_t, ae_int_t, const double *, const double *, ae_complex *, double *, ae_int_t, ae_complex, ae_complex) = &_ialglib_cmv;
    
    if( m>alglib_c_block || n>alglib_c_block )
        return ae_false;

    /*
     * Check for SSE2 support
     */
#ifdef AE_HAS_SSE2_INTRINSICS
    if( ae_cpuid() & CPU_SSE2 )
    {
        cmv = &_ialglib_cmv_sse2;
    }    
#endif
    
    /*
     * Prepare
     */
    _ialglib_mcopyblock_complex(n, n, _a, optype, _a_stride, abuf);
    _ialglib_mcopyblock_complex(m, n, _x, 0, _x_stride, xbuf);
    if( isunit )
        for(i=0,pdiag=abuf; i<n; i++,pdiag+=2*(alglib_c_block+1))
        {
            pdiag[0] = 1.0;
            pdiag[1] = 0.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+=2*(alglib_c_block+1))
        {
            ae_complex tmp_c;
            ae_complex beta;
            ae_complex alpha;
            tmp_c.x = pdiag[0];
            tmp_c.y = pdiag[1];
            beta = ae_c_d_div(1.0, tmp_c);
            alpha.x = -beta.x;
            alpha.y = -beta.y;
            _ialglib_vcopy_dcomplex(i, abuf+2*i, alglib_c_block, tmpbuf, 1, "No conj");
            cmv(m, i, xbuf, tmpbuf, NULL, xbuf+2*i, alglib_c_block, alpha, beta);
        }
        _ialglib_mcopyunblock_complex(m, n, xbuf, 0, _x, _x_stride);
    }
    else
    {
        for(i=n-1,pdiag=abuf+2*((n-1)*alglib_c_block+(n-1)); i>=0; i--,pdiag-=2*(alglib_c_block+1))
        {
            ae_complex tmp_c;
            ae_complex beta;
            ae_complex alpha;
            tmp_c.x = pdiag[0];
            tmp_c.y = pdiag[1];
            beta = ae_c_d_div(1.0, tmp_c);
            alpha.x = -beta.x;
            alpha.y = -beta.y;
            _ialglib_vcopy_dcomplex(n-1-i, pdiag+2*alglib_c_block, alglib_c_block, tmpbuf, 1, "No conj");
            cmv(m, n-1-i, xbuf+2*(i+1), tmpbuf, NULL, xbuf+2*i, alglib_c_block, alpha, beta);
        }
        _ialglib_mcopyunblock_complex(m, n, xbuf, 0, _x, _x_stride);
    }
    return ae_true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4c70, %rsp           # imm = 0x4C70
movl %r8d, -0x4c64(%rbp)
movq %rcx, %rax
movl -0x4c64(%rbp), %ecx
movq %rax, -0x4c60(%rbp)
movq %rdx, %rax
movq -0x4c60(%rbp), %rdx
movq %rax, -0x4c58(%rbp)
movq %rsi, %rax
movq -0x4c58(%rbp), %rsi
movq %rax, -0x4c50(%rbp)
movq %rdi, %r8
movq -0x4c50(%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 -0x24c0(%rbp), %rdi
movl $0x10, %esi
callq 0x3aab0
movq %rax, -0x4b48(%rbp)
leaq -0x4940(%rbp), %rdi
movl $0x10, %esi
callq 0x3aab0
movq %rax, -0x4b50(%rbp)
leaq -0x4b40(%rbp), %rdi
movl $0x10, %esi
callq 0x3aab0
movq %rax, -0x4b58(%rbp)
leaq -0x1a57(%rip), %rax     # 0x4d780
movq %rax, -0x4b68(%rbp)
cmpq $0x18, -0x10(%rbp)
jg 0x4f1ec
cmpq $0x18, -0x18(%rbp)
jle 0x4f1f5
movb $0x0, -0x1(%rbp)
jmp 0x4f707
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq 0x10(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x4b48(%rbp), %r9
callq 0x4e410
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq 0x18(%rbp), %rdx
movq 0x20(%rbp), %r8
movq -0x4b50(%rbp), %r9
xorl %eax, %eax
movl %eax, %ecx
callq 0x4e410
testb $0x1, -0x2a(%rbp)
je 0x4f292
movq $0x0, -0x40(%rbp)
movq -0x4b48(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x18(%rbp), %rax
jge 0x4f290
movq -0x38(%rbp), %rax
movsd 0x5da4(%rip), %xmm0     # 0x55008
movsd %xmm0, (%rax)
movq -0x38(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x8(%rax)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
addq $0x190, %rax            # imm = 0x190
movq %rax, -0x38(%rbp)
jmp 0x4f24e
jmp 0x4f292
cmpq $0x0, 0x10(%rbp)
jne 0x4f2a6
movb -0x29(%rbp), %al
andb $0x1, %al
movb %al, -0x4b59(%rbp)
jmp 0x4f2b3
movb -0x29(%rbp), %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, -0x4b59(%rbp)
testb $0x1, -0x4b59(%rbp)
je 0x4f4c7
movq $0x0, -0x40(%rbp)
movq -0x4b48(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x18(%rbp), %rax
jge 0x4f4a2
movq -0x38(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x4b78(%rbp)
movq -0x38(%rbp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x4b70(%rbp)
movq -0x4b78(%rbp), %rax
movq %rax, -0x4bb8(%rbp)
movq -0x4b70(%rbp), %rax
movq %rax, -0x4bb0(%rbp)
movsd -0x4bb8(%rbp), %xmm1
movsd -0x4bb0(%rbp), %xmm2
movsd 0x5cd2(%rip), %xmm0     # 0x55008
callq 0x3f980
movsd %xmm0, -0x4ba8(%rbp)
movsd %xmm1, -0x4ba0(%rbp)
movq -0x4ba8(%rbp), %rax
movq %rax, -0x4b88(%rbp)
movq -0x4ba0(%rbp), %rax
movq %rax, -0x4b80(%rbp)
movsd -0x4b88(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x4b98(%rbp)
movsd -0x4b80(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x4b90(%rbp)
movq -0x40(%rbp), %rdi
movq -0x4b48(%rbp), %rsi
movq -0x40(%rbp), %rax
shlq %rax
shlq $0x3, %rax
addq %rax, %rsi
movq -0x4b58(%rbp), %rcx
movl $0x18, %edx
movl $0x1, %r8d
leaq 0x916f(%rip), %r9       # 0x58556
callq 0x4dea0
movq -0x4b68(%rbp), %rax
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x4b50(%rbp), %rdx
movq -0x4b58(%rbp), %rcx
movq -0x4b50(%rbp), %r9
movq -0x40(%rbp), %r8
shlq %r8
shlq $0x3, %r8
addq %r8, %r9
movq -0x4b98(%rbp), %r8
movq %r8, -0x4bc8(%rbp)
movq -0x4b90(%rbp), %r8
movq %r8, -0x4bc0(%rbp)
movq -0x4b88(%rbp), %r8
movq %r8, -0x4bd8(%rbp)
movq -0x4b80(%rbp), %r8
movq %r8, -0x4bd0(%rbp)
movsd -0x4bc8(%rbp), %xmm0
movsd -0x4bc0(%rbp), %xmm1
movsd -0x4bd8(%rbp), %xmm2
movsd -0x4bd0(%rbp), %xmm3
xorl %r8d, %r8d
movq $0x18, (%rsp)
callq *%rax
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
addq $0x190, %rax            # imm = 0x190
movq %rax, -0x38(%rbp)
jmp 0x4f2d3
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x4b50(%rbp), %rdx
movq 0x18(%rbp), %r8
movq 0x20(%rbp), %r9
xorl %eax, %eax
movl %eax, %ecx
callq 0x4e780
jmp 0x4f703
movq -0x18(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x4b48(%rbp), %rax
movq -0x18(%rbp), %rcx
subq $0x1, %rcx
imulq $0x18, %rcx, %rcx
movq -0x18(%rbp), %rdx
subq $0x1, %rdx
addq %rdx, %rcx
shlq %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x40(%rbp)
jl 0x4f6e3
movq -0x38(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x4be8(%rbp)
movq -0x38(%rbp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x4be0(%rbp)
movq -0x4be8(%rbp), %rax
movq %rax, -0x4c28(%rbp)
movq -0x4be0(%rbp), %rax
movq %rax, -0x4c20(%rbp)
movsd -0x4c28(%rbp), %xmm1
movsd -0x4c20(%rbp), %xmm2
movsd 0x5aa9(%rip), %xmm0     # 0x55008
callq 0x3f980
movsd %xmm0, -0x4c18(%rbp)
movsd %xmm1, -0x4c10(%rbp)
movq -0x4c18(%rbp), %rax
movq %rax, -0x4bf8(%rbp)
movq -0x4c10(%rbp), %rax
movq %rax, -0x4bf0(%rbp)
movsd -0x4bf8(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x4c08(%rbp)
movsd -0x4bf0(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x4c00(%rbp)
movq -0x18(%rbp), %rdi
subq $0x1, %rdi
subq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x180, %rsi            # imm = 0x180
movq -0x4b58(%rbp), %rcx
movl $0x18, %edx
movl $0x1, %r8d
leaq 0x8f48(%rip), %r9       # 0x58556
callq 0x4dea0
movq -0x4b68(%rbp), %rax
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
subq $0x1, %rsi
subq -0x40(%rbp), %rsi
movq -0x4b50(%rbp), %rdx
movq -0x40(%rbp), %rcx
addq $0x1, %rcx
shlq %rcx
shlq $0x3, %rcx
addq %rcx, %rdx
movq -0x4b58(%rbp), %rcx
movq -0x4b50(%rbp), %r9
movq -0x40(%rbp), %r8
shlq %r8
shlq $0x3, %r8
addq %r8, %r9
movq -0x4c08(%rbp), %r8
movq %r8, -0x4c38(%rbp)
movq -0x4c00(%rbp), %r8
movq %r8, -0x4c30(%rbp)
movq -0x4bf8(%rbp), %r8
movq %r8, -0x4c48(%rbp)
movq -0x4bf0(%rbp), %r8
movq %r8, -0x4c40(%rbp)
movsd -0x4c38(%rbp), %xmm0
movsd -0x4c30(%rbp), %xmm1
movsd -0x4c48(%rbp), %xmm2
movsd -0x4c40(%rbp), %xmm3
xorl %r8d, %r8d
movq $0x18, (%rsp)
callq *%rax
movq -0x40(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
addq $-0x190, %rax           # imm = 0xFE70
movq %rax, -0x38(%rbp)
jmp 0x4f4ff
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x4b50(%rbp), %rdx
movq 0x18(%rbp), %r8
movq 0x20(%rbp), %r9
xorl %eax, %eax
movl %eax, %ecx
callq 0x4e780
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x4c70, %rsp           # imm = 0x4C70
popq %rbp
retq
nopw %cs:(%rax,%rax)