// File: /workspace/github_cpp_makefile_star2_O2/mouda[P]LTE_random_access-simulate/ap.cpp
// Function: alglib_impl::_ialglib_cmatrixlefttrsm(long, long, alglib_impl::ae_complex*, long, bool, bool, long, alglib_impl::ae_complex*, long)
ae_bool _ialglib_cmatrixlefttrsm(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, *arow;
    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
     * Transpose X (so we may use mv, which calculates A*x, but not x*A)
     */
    _ialglib_mcopyblock_complex(m, m, _a, optype, _a_stride, abuf);
    _ialglib_mcopyblock_complex(m, n, _x, 1, _x_stride, xbuf);
    if( isunit )
        for(i=0,pdiag=abuf; i<m; i++,pdiag+=2*(alglib_c_block+1))
        {
            pdiag[0] = 1.0;
            pdiag[1] = 0.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+2*((m-1)*alglib_c_block+(m-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(m-1-i, pdiag+2, 1, tmpbuf, 1, "No conj");
            cmv(n, m-1-i, xbuf+2*(i+1), tmpbuf, NULL, xbuf+2*i, alglib_c_block, alpha, beta);
        }
        _ialglib_mcopyunblock_complex(m, n, xbuf, 1, _x, _x_stride);
    }
    else
    {   for(i=0,pdiag=abuf,arow=abuf; i<m; i++,pdiag+=2*(alglib_c_block+1),arow+=2*alglib_c_block)
        {
            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, arow, 1, tmpbuf, 1, "No conj");
            cmv(n, i, xbuf, tmpbuf, NULL, xbuf+2*i, alglib_c_block, alpha, beta);
        }
        _ialglib_mcopyunblock_complex(m, n, xbuf, 1, _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, %ebx
movq %rcx, %r8
cmpq $0x19, %rdi
setl %cl
cmpq $0x19, %rsi
setl %al
andb %cl, %al
cmpb $0x1, %al
jne 0x2d609
movl %r9d, %ebp
movq %rsi, %r15
movq %rdi, %r12
movb %al, 0x17(%rsp)
movq 0x4bb8(%rsp), %r13
movq 0x4bb0(%rsp), %rcx
leaq 0x26f0(%rsp), %r14
movq %rdi, %rsi
movq %r14, %r9
callq 0x2c669
pushq $0x1
popq %rcx
leaq 0x270(%rsp), %r9
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq 0x4bc0(%rsp), %r8
callq 0x2c669
testb %bpl, %bpl
je 0x2d40c
xorl %eax, %eax
testq %r12, %r12
cmovgq %r12, %rax
leaq 0x26f0(%rsp), %rcx
movsd 0x2dfe(%rip), %xmm0     # 0x301f8
subq $0x1, %rax
jb 0x2d40c
movups %xmm0, (%rcx)
addq $0x190, %rcx            # imm = 0x190
jmp 0x2d3fa
movq %r15, 0x18(%rsp)
cmpq $0x0, 0x4bb0(%rsp)
setne %al
xorb %bl, %al
movq %r12, 0x68(%rsp)
je 0x2d507
leaq -0x1(%r12), %rbx
imulq $0x190, %rbx, %rax      # imm = 0x190
leaq (%rsp,%rax), %r15
addq $0x26f0, %r15           # imm = 0x26F0
shlq $0x4, %r12
leaq (%rsp,%r12), %r14
addq $0x270, %r14            # imm = 0x270
xorl %r12d, %r12d
testq %rbx, %rbx
js 0x2d5db
movsd (%r15), %xmm1
movsd 0x8(%r15), %xmm2
movsd 0x2d89(%rip), %xmm0     # 0x301f8
callq 0x25afb
movaps %xmm0, 0x50(%rsp)
movaps %xmm1, 0x40(%rsp)
movaps %xmm0, %xmm2
movaps 0x2d28(%rip), %xmm0     # 0x301b0
xorps %xmm0, %xmm2
movaps %xmm2, 0x30(%rsp)
xorps %xmm0, %xmm1
movaps %xmm1, 0x20(%rsp)
leaq 0x10(%r15), %rsi
movq %r12, %rdi
pushq $0x1
popq %rdx
leaq 0x70(%rsp), %r13
movq %r13, %rcx
movq %rdx, %r8
leaq 0x678e(%rip), %r9       # 0x33c42
callq 0x2c42d
leaq -0x10(%r14), %rbp
movq $0x18, (%rsp)
movq 0x18(%rsp), %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %r13, %rcx
xorl %r8d, %r8d
movq %rbp, %r9
movaps 0x30(%rsp), %xmm0
movaps 0x20(%rsp), %xmm1
movaps 0x50(%rsp), %xmm2
movaps 0x40(%rsp), %xmm3
callq 0x2c1a9
decq %rbx
incq %r12
addq $-0x190, %r15           # imm = 0xFE70
movq %rbp, %r14
jmp 0x2d453
xorl %r13d, %r13d
testq %r12, %r12
movl $0x0, %r15d
cmovgq %r12, %r15
leaq 0x270(%rsp), %rbx
movq %r14, %rbp
cmpq %r13, %r15
je 0x2d5db
movsd (%r14), %xmm1
movsd 0x8(%r14), %xmm2
movsd 0x2cba(%rip), %xmm0     # 0x301f8
callq 0x25afb
movaps %xmm0, 0x50(%rsp)
movaps %xmm1, 0x40(%rsp)
movaps %xmm0, %xmm2
movaps 0x2c59(%rip), %xmm0     # 0x301b0
xorps %xmm0, %xmm2
movaps %xmm2, 0x30(%rsp)
xorps %xmm0, %xmm1
movaps %xmm1, 0x20(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
pushq $0x1
popq %rdx
leaq 0x70(%rsp), %r12
movq %r12, %rcx
movq %rdx, %r8
leaq 0x66c0(%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 %rbx, %r9
movaps 0x30(%rsp), %xmm0
movaps 0x20(%rsp), %xmm1
movaps 0x50(%rsp), %xmm2
movaps 0x40(%rsp), %xmm3
callq 0x2c1a9
incq %r13
addq $0x190, %r14            # imm = 0x190
addq $0x180, %rbp            # imm = 0x180
addq $0x10, %rbx
jmp 0x2d522
leaq 0x270(%rsp), %rdx
pushq $0x1
popq %rcx
movq 0x68(%rsp), %rdi
movq 0x18(%rsp), %rsi
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