// File: /workspace/github_cpp_makefile_star2_O1/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 $0x4b68, %rsp           # imm = 0x4B68
movl %r8d, %ebp
movq %rcx, %r8
cmpq $0x19, %rdi
setl %cl
cmpq $0x19, %rsi
setl %al
andb %cl, %al
cmpb $0x1, %al
jne 0x30df3
movl %r9d, %r13d
movq %rsi, %rbx
movq %rdi, %r9
movb %al, 0xf(%rsp)
movq 0x4ba8(%rsp), %r14
movq 0x4ba0(%rsp), %r15
leaq 0x26e0(%rsp), %r12
movq %rsi, %rdi
movq %r15, %rcx
movq %r9, 0x10(%rsp)
movq %r12, %r9
callq 0x30022
movq 0x10(%rsp), %r9
testq %r9, %r9
jle 0x30a3c
movq 0x4bb0(%rsp), %rax
shlq $0x4, %rax
leaq 0x260(%rsp), %rcx
xorl %edx, %edx
movq %r14, %rsi
testq %rbx, %rbx
jle 0x30a2a
movq %rbx, %rdi
xorl %r8d, %r8d
movsd (%rsi,%r8), %xmm0
movsd %xmm0, (%rcx,%r8)
movsd 0x8(%rsi,%r8), %xmm0
movsd %xmm0, 0x8(%rcx,%r8)
addq $0x10, %r8
decq %rdi
jne 0x30a07
incq %rdx
addq $0x180, %rcx            # imm = 0x180
addq %rax, %rsi
cmpq %r9, %rdx
jne 0x309fc
testq %rbx, %rbx
setle %al
xorb $0x1, %r13b
orb %al, %r13b
jne 0x30a76
leaq 0x26e0(%rsp), %rax
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rbx, %rdx
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
addq $0x190, %rax            # imm = 0x190
decq %rdx
jne 0x30a60
testq %r15, %r15
setne %al
cmpb %bpl, %al
je 0x30c31
testq %rbx, %rbx
jle 0x30bc5
leaq 0x260(%rsp), %rbp
xorl %r13d, %r13d
movq %r12, %r15
movq %rbx, 0x18(%rsp)
movsd (%r12), %xmm1
movsd 0x8(%r12), %xmm0
movapd %xmm0, %xmm2
movapd 0x65e6(%rip), %xmm4     # 0x370a0
andpd %xmm4, %xmm2
movapd %xmm1, %xmm3
andpd %xmm4, %xmm3
ucomisd %xmm2, %xmm3
jbe 0x30af6
movapd %xmm0, %xmm3
divsd %xmm1, %xmm3
mulsd %xmm3, %xmm0
addsd %xmm1, %xmm0
movsd 0x36bc(%rip), %xmm2     # 0x341a0
divsd %xmm0, %xmm2
xorpd 0x36f0(%rip), %xmm3     # 0x341e0
divsd %xmm0, %xmm3
jmp 0x30b16
movapd %xmm1, %xmm2
divsd %xmm0, %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
divsd %xmm1, %xmm2
movsd 0x36be(%rip), %xmm3     # 0x341d0
divsd %xmm1, %xmm3
movapd %xmm2, 0x20(%rsp)
movapd %xmm3, 0x30(%rsp)
movapd %xmm2, %xmm1
movapd 0x36b2(%rip), %xmm0     # 0x341e0
xorpd %xmm0, %xmm1
movapd %xmm1, 0x50(%rsp)
movapd %xmm3, %xmm1
xorpd %xmm0, %xmm1
movapd %xmm1, 0x40(%rsp)
movl $0x18, %edx
movl $0x1, %r8d
movq %r13, %rdi
movq %r15, %rsi
leaq 0x60(%rsp), %rbx
movq %rbx, %rcx
leaq 0x6f6c(%rip), %r9       # 0x37ad2
callq 0x2fde2
movq $0x18, (%rsp)
movq 0x10(%rsp), %rdi
movq %r13, %rsi
leaq 0x260(%rsp), %rdx
movq %rbx, %rcx
xorl %r8d, %r8d
movq %rbp, %r9
movaps 0x50(%rsp), %xmm0
movaps 0x40(%rsp), %xmm1
movaps 0x20(%rsp), %xmm2
movaps 0x30(%rsp), %xmm3
callq 0x2fb27
incq %r13
addq $0x190, %r12            # imm = 0x190
addq $0x10, %r15
addq $0x10, %rbp
movq 0x18(%rsp), %rbx
cmpq %r13, %rbx
jne 0x30aa1
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
movb 0xf(%rsp), %al
movq 0x4bb0(%rsp), %r9
jle 0x30df3
shlq $0x4, %r9
leaq 0x260(%rsp), %r8
xorl %ecx, %ecx
testq %rbx, %rbx
jle 0x30c1a
movq %rbx, %rdx
xorl %esi, %esi
movsd (%r8,%rsi), %xmm0
movsd %xmm0, (%r14,%rsi)
movsd 0x8(%r8,%rsi), %xmm0
movsd %xmm0, 0x8(%r14,%rsi)
addq $0x10, %rsi
decq %rdx
jne 0x30bf7
incq %rcx
addq $0x180, %r8             # imm = 0x180
addq %r9, %r14
cmpq %rdi, %rcx
jne 0x30bed
jmp 0x30df3
movq %rbx, 0x18(%rsp)
testq %rbx, %rbx
jle 0x30d8b
movq 0x18(%rsp), %rbx
leaq -0x1(%rbx), %rax
imulq $0x190, %rax, %rax      # imm = 0x190
leaq (%rsp,%rax), %r13
addq $0x26e0, %r13           # imm = 0x26E0
movq %rbx, %rax
shlq $0x4, %rax
leaq (%rsp,%rax), %r12
addq $0x260, %r12            # imm = 0x260
xorl %r15d, %r15d
movsd (%r13), %xmm1
movsd 0x8(%r13), %xmm0
movapd %xmm0, %xmm2
movapd 0x6419(%rip), %xmm4     # 0x370a0
andpd %xmm4, %xmm2
movapd %xmm1, %xmm3
andpd %xmm4, %xmm3
ucomisd %xmm2, %xmm3
jbe 0x30cc3
movapd %xmm0, %xmm3
divsd %xmm1, %xmm3
mulsd %xmm3, %xmm0
addsd %xmm1, %xmm0
movsd 0x34ef(%rip), %xmm2     # 0x341a0
divsd %xmm0, %xmm2
xorpd 0x3523(%rip), %xmm3     # 0x341e0
divsd %xmm0, %xmm3
jmp 0x30ce3
movapd %xmm1, %xmm2
divsd %xmm0, %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
divsd %xmm1, %xmm2
movsd 0x34f1(%rip), %xmm3     # 0x341d0
divsd %xmm1, %xmm3
movapd %xmm2, 0x20(%rsp)
movapd %xmm3, 0x30(%rsp)
movapd %xmm2, %xmm1
movapd 0x34e5(%rip), %xmm0     # 0x341e0
xorpd %xmm0, %xmm1
movapd %xmm1, 0x50(%rsp)
movapd %xmm3, %xmm1
xorpd %xmm0, %xmm1
movapd %xmm1, 0x40(%rsp)
leaq 0x180(%r13), %rsi
movl $0x18, %edx
movl $0x1, %r8d
movq %r15, %rdi
leaq 0x60(%rsp), %rcx
leaq 0x6d9e(%rip), %r9       # 0x37ad2
callq 0x2fde2
leaq -0x10(%r12), %rbp
movq $0x18, (%rsp)
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
leaq 0x60(%rsp), %rcx
xorl %r8d, %r8d
movq %rbp, %r9
movaps 0x50(%rsp), %xmm0
movaps 0x40(%rsp), %xmm1
movaps 0x20(%rsp), %xmm2
movaps 0x30(%rsp), %xmm3
callq 0x2fb27
incq %r15
addq $-0x190, %r13           # imm = 0xFE70
movq %rbp, %r12
decq %rbx
jg 0x30c6f
movq 0x10(%rsp), %r8
testq %r8, %r8
movq 0x18(%rsp), %rdi
movb 0xf(%rsp), %al
movq 0x4bb0(%rsp), %r10
jle 0x30df3
shlq $0x4, %r10
leaq 0x260(%rsp), %r9
xorl %ecx, %ecx
testq %rdi, %rdi
jle 0x30de1
movq %rdi, %rdx
xorl %esi, %esi
movsd (%r9,%rsi), %xmm0
movsd %xmm0, (%r14,%rsi)
movsd 0x8(%r9,%rsi), %xmm0
movsd %xmm0, 0x8(%r14,%rsi)
addq $0x10, %rsi
decq %rdx
jne 0x30dbe
incq %rcx
addq $0x180, %r9             # imm = 0x180
addq %r10, %r14
cmpq %r8, %rcx
jne 0x30db4
addq $0x4b68, %rsp           # imm = 0x4B68
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq