// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4b78, %rsp           # imm = 0x4B78
movl %r8d, %r14d
movq %rcx, %r8
cmpq $0x19, %rdi
setl %cl
cmpq $0x19, %rsi
setl %al
andb %cl, %al
cmpb $0x1, %al
jne 0x2d0d8
movl %r9d, %ebp
movq %rsi, %r12
movq %rdi, %r15
movb %al, 0x17(%rsp)
movq 0x4bb8(%rsp), %r13
movq 0x4bb0(%rsp), %rcx
leaq 0x26f0(%rsp), %rbx
movq %rsi, %rdi
movq %rbx, %r9
callq 0x2c669
leaq 0x270(%rsp), %r9
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
movq 0x4bc0(%rsp), %r8
callq 0x2c669
testb %bpl, %bpl
je 0x2cedb
xorl %eax, %eax
testq %r12, %r12
cmovgq %r12, %rax
leaq 0x26f0(%rsp), %rcx
movsd 0x332f(%rip), %xmm0     # 0x301f8
subq $0x1, %rax
jb 0x2cedb
movups %xmm0, (%rcx)
addq $0x190, %rcx            # imm = 0x190
jmp 0x2cec9
movq %r15, 0x18(%rsp)
cmpq $0x0, 0x4bb0(%rsp)
setne %al
cmpb %r14b, %al
movq %r12, 0x68(%rsp)
je 0x2cfca
xorl %r13d, %r13d
testq %r12, %r12
movl $0x0, %r15d
cmovgq %r12, %r15
leaq 0x70(%rsp), %r12
leaq 0x270(%rsp), %r14
movq %rbx, %rbp
cmpq %r13, %r15
je 0x2d0ab
movsd (%rbx), %xmm1
movsd 0x8(%rbx), %xmm2
movsd 0x32c4(%rip), %xmm0     # 0x301f8
callq 0x25afb
movaps %xmm0, 0x50(%rsp)
movaps %xmm1, 0x40(%rsp)
movaps %xmm0, %xmm2
movaps 0x3263(%rip), %xmm0     # 0x301b0
xorps %xmm0, %xmm2
movaps %xmm2, 0x30(%rsp)
xorps %xmm0, %xmm1
movaps %xmm1, 0x20(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
pushq $0x18
popq %rdx
movq %r12, %rcx
pushq $0x1
popq %r8
leaq 0x6cce(%rip), %r9       # 0x33c42
callq 0x2c42d
movq $0x18, (%rsp)
movq 0x18(%rsp), %rdi
movq %r13, %rsi
leaq 0x270(%rsp), %rdx
movq %r12, %rcx
xorl %r8d, %r8d
movq %r14, %r9
movaps 0x30(%rsp), %xmm0
movaps 0x20(%rsp), %xmm1
movaps 0x50(%rsp), %xmm2
movaps 0x40(%rsp), %xmm3
callq 0x2c1a9
incq %r13
addq $0x190, %rbx            # imm = 0x190
addq $0x10, %rbp
addq $0x10, %r14
jmp 0x2cf1a
leaq -0x1(%r12), %rbp
imulq $0x190, %rbp, %rax      # imm = 0x190
leaq (%rsp,%rax), %r15
addq $0x26f0, %r15           # imm = 0x26F0
shlq $0x4, %r12
leaq (%rsp,%r12), %rbx
addq $0x270, %rbx            # imm = 0x270
xorl %r12d, %r12d
leaq 0x70(%rsp), %r14
testq %rbp, %rbp
js 0x2d0ab
movsd (%r15), %xmm1
movsd 0x8(%r15), %xmm2
movsd 0x31e4(%rip), %xmm0     # 0x301f8
callq 0x25afb
movaps %xmm0, 0x50(%rsp)
movaps %xmm1, 0x40(%rsp)
movaps %xmm0, %xmm2
movaps 0x3183(%rip), %xmm0     # 0x301b0
xorps %xmm0, %xmm2
movaps %xmm2, 0x30(%rsp)
xorps %xmm0, %xmm1
movaps %xmm1, 0x20(%rsp)
leaq 0x180(%r15), %rsi
movq %r12, %rdi
pushq $0x18
popq %rdx
movq %r14, %rcx
pushq $0x1
popq %r8
leaq 0x6bea(%rip), %r9       # 0x33c42
callq 0x2c42d
leaq -0x10(%rbx), %r13
movq $0x18, (%rsp)
movq 0x18(%rsp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq %r14, %rcx
xorl %r8d, %r8d
movq %r13, %r9
movaps 0x30(%rsp), %xmm0
movaps 0x20(%rsp), %xmm1
movaps 0x50(%rsp), %xmm2
movaps 0x40(%rsp), %xmm3
callq 0x2c1a9
decq %rbp
incq %r12
addq $-0x190, %r15           # imm = 0xFE70
movq %r13, %rbx
jmp 0x2cff8
leaq 0x270(%rsp), %rdx
movq 0x18(%rsp), %rdi
movq 0x68(%rsp), %rsi
xorl %ecx, %ecx
movq 0x4bb8(%rsp), %r8
movq 0x4bc0(%rsp), %r9
callq 0x2c82d
movb 0x17(%rsp), %al
addq $0x4b78, %rsp           # imm = 0x4B78
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq