// File: /workspace/github_cpp_makefile_star2_O3/mouda[P]LTE_random_access-simulate/alglibinternal.cpp
// Function: alglib_impl::rmatrixscaledtrsafesolve(alglib_impl::ae_matrix*, double, long, alglib_impl::ae_vector*, bool, long, bool, double, alglib_impl::ae_state*)
ae_bool rmatrixscaledtrsafesolve(/* Real    */ ae_matrix* a,
     double sa,
     ae_int_t n,
     /* Real    */ ae_vector* x,
     ae_bool isupper,
     ae_int_t trans,
     ae_bool isunit,
     double maxgrowth,
     ae_state *_state)
{
    ae_frame _frame_block;
    double lnmax;
    double nrmb;
    double nrmx;
    ae_int_t i;
    ae_complex alpha;
    ae_complex beta;
    double vr;
    ae_complex cx;
    ae_vector tmp;
    ae_bool result;

    ae_frame_make(_state, &_frame_block);
    ae_vector_init(&tmp, 0, DT_REAL, _state, ae_true);

    ae_assert(n>0, "RMatrixTRSafeSolve: incorrect N!", _state);
    ae_assert(trans==0||trans==1, "RMatrixTRSafeSolve: incorrect Trans!", _state);
    result = ae_true;
    lnmax = ae_log(ae_maxrealnumber, _state);
    
    /*
     * Quick return if possible
     */
    if( n<=0 )
    {
        ae_frame_leave(_state);
        return result;
    }
    
    /*
     * Load norms: right part and X
     */
    nrmb = 0;
    for(i=0; i<=n-1; i++)
    {
        nrmb = ae_maxreal(nrmb, ae_fabs(x->ptr.p_double[i], _state), _state);
    }
    nrmx = 0;
    
    /*
     * Solve
     */
    ae_vector_set_length(&tmp, n, _state);
    result = ae_true;
    if( isupper&&trans==0 )
    {
        
        /*
         * U*x = b
         */
        for(i=n-1; i>=0; i--)
        {
            
            /*
             * Task is reduced to alpha*x[i] = beta
             */
            if( isunit )
            {
                alpha = ae_complex_from_d(sa);
            }
            else
            {
                alpha = ae_complex_from_d(a->ptr.pp_double[i][i]*sa);
            }
            if( i<n-1 )
            {
                ae_v_moved(&tmp.ptr.p_double[i+1], 1, &a->ptr.pp_double[i][i+1], 1, ae_v_len(i+1,n-1), sa);
                vr = ae_v_dotproduct(&tmp.ptr.p_double[i+1], 1, &x->ptr.p_double[i+1], 1, ae_v_len(i+1,n-1));
                beta = ae_complex_from_d(x->ptr.p_double[i]-vr);
            }
            else
            {
                beta = ae_complex_from_d(x->ptr.p_double[i]);
            }
            
            /*
             * solve alpha*x[i] = beta
             */
            result = safesolve_cbasicsolveandupdate(alpha, beta, lnmax, nrmb, maxgrowth, &nrmx, &cx, _state);
            if( !result )
            {
                ae_frame_leave(_state);
                return result;
            }
            x->ptr.p_double[i] = cx.x;
        }
        ae_frame_leave(_state);
        return result;
    }
    if( !isupper&&trans==0 )
    {
        
        /*
         * L*x = b
         */
        for(i=0; i<=n-1; i++)
        {
            
            /*
             * Task is reduced to alpha*x[i] = beta
             */
            if( isunit )
            {
                alpha = ae_complex_from_d(sa);
            }
            else
            {
                alpha = ae_complex_from_d(a->ptr.pp_double[i][i]*sa);
            }
            if( i>0 )
            {
                ae_v_moved(&tmp.ptr.p_double[0], 1, &a->ptr.pp_double[i][0], 1, ae_v_len(0,i-1), sa);
                vr = ae_v_dotproduct(&tmp.ptr.p_double[0], 1, &x->ptr.p_double[0], 1, ae_v_len(0,i-1));
                beta = ae_complex_from_d(x->ptr.p_double[i]-vr);
            }
            else
            {
                beta = ae_complex_from_d(x->ptr.p_double[i]);
            }
            
            /*
             * solve alpha*x[i] = beta
             */
            result = safesolve_cbasicsolveandupdate(alpha, beta, lnmax, nrmb, maxgrowth, &nrmx, &cx, _state);
            if( !result )
            {
                ae_frame_leave(_state);
                return result;
            }
            x->ptr.p_double[i] = cx.x;
        }
        ae_frame_leave(_state);
        return result;
    }
    if( isupper&&trans==1 )
    {
        
        /*
         * U^T*x = b
         */
        for(i=0; i<=n-1; i++)
        {
            
            /*
             * Task is reduced to alpha*x[i] = beta
             */
            if( isunit )
            {
                alpha = ae_complex_from_d(sa);
            }
            else
            {
                alpha = ae_complex_from_d(a->ptr.pp_double[i][i]*sa);
            }
            beta = ae_complex_from_d(x->ptr.p_double[i]);
            
            /*
             * solve alpha*x[i] = beta
             */
            result = safesolve_cbasicsolveandupdate(alpha, beta, lnmax, nrmb, maxgrowth, &nrmx, &cx, _state);
            if( !result )
            {
                ae_frame_leave(_state);
                return result;
            }
            x->ptr.p_double[i] = cx.x;
            
            /*
             * update the rest of right part
             */
            if( i<n-1 )
            {
                vr = cx.x;
                ae_v_moved(&tmp.ptr.p_double[i+1], 1, &a->ptr.pp_double[i][i+1], 1, ae_v_len(i+1,n-1), sa);
                ae_v_subd(&x->ptr.p_double[i+1], 1, &tmp.ptr.p_double[i+1], 1, ae_v_len(i+1,n-1), vr);
            }
        }
        ae_frame_leave(_state);
        return result;
    }
    if( !isupper&&trans==1 )
    {
        
        /*
         * L^T*x = b
         */
        for(i=n-1; i>=0; i--)
        {
            
            /*
             * Task is reduced to alpha*x[i] = beta
             */
            if( isunit )
            {
                alpha = ae_complex_from_d(sa);
            }
            else
            {
                alpha = ae_complex_from_d(a->ptr.pp_double[i][i]*sa);
            }
            beta = ae_complex_from_d(x->ptr.p_double[i]);
            
            /*
             * solve alpha*x[i] = beta
             */
            result = safesolve_cbasicsolveandupdate(alpha, beta, lnmax, nrmb, maxgrowth, &nrmx, &cx, _state);
            if( !result )
            {
                ae_frame_leave(_state);
                return result;
            }
            x->ptr.p_double[i] = cx.x;
            
            /*
             * update the rest of right part
             */
            if( i>0 )
            {
                vr = cx.x;
                ae_v_moved(&tmp.ptr.p_double[0], 1, &a->ptr.pp_double[i][0], 1, ae_v_len(0,i-1), sa);
                ae_v_subd(&x->ptr.p_double[0], 1, &tmp.ptr.p_double[0], 1, ae_v_len(0,i-1), vr);
            }
        }
        ae_frame_leave(_state);
        return result;
    }
    result = ae_false;
    ae_frame_leave(_state);
    return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movsd %xmm1, 0x58(%rsp)
movl %r9d, 0x24(%rsp)
movq %r8, %r12
movl %ecx, %ebp
movq %rdx, %r14
movq %rsi, %r15
movsd %xmm0, 0x8(%rsp)
movq %rdi, 0x28(%rsp)
movq 0xf0(%rsp), %r13
leaq 0xa0(%rsp), %rsi
movq %r13, %rdi
callq 0x25055
leaq 0x70(%rsp), %rdi
movl $0x3, %edx
xorl %esi, %esi
movq %r13, %rcx
movl $0x1, %r8d
callq 0x251ec
xorl %edi, %edi
testq %r15, %r15
setg %dil
leaq 0x17c21(%rip), %rsi     # 0x36072
movq %r13, %rdx
callq 0x2510e
xorl %edi, %edi
cmpq $0x2, %r12
setb %dil
leaq 0x17c29(%rip), %rsi     # 0x36093
movq %r13, %rdx
callq 0x2510e
movsd 0x151e6(%rip), %xmm0    # 0x33660
movq %r13, %rdi
callq 0x25f91
movsd %xmm0, 0x50(%rsp)
testq %r15, %r15
jle 0x1e65f
xorps %xmm0, %xmm0
xorl %ebx, %ebx
movsd %xmm0, 0x38(%rsp)
movq 0x28(%r14), %rax
movsd (%rax,%rbx,8), %xmm0
movq %r13, %rdi
callq 0x25e30
movapd %xmm0, %xmm1
movsd 0x38(%rsp), %xmm0
movq %r13, %rdi
callq 0x25edc
incq %rbx
cmpq %rbx, %r15
jne 0x1e496
movsd %xmm0, 0x38(%rsp)
testq %r12, %r12
setne %bl
leaq -0x1(%r15), %rax
movq %rax, 0x40(%rsp)
movq $0x0, 0x48(%rsp)
leaq 0x70(%rsp), %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x25326
movl %ebp, %eax
xorb $0x1, %al
orb %al, %bl
movq %r14, 0x30(%rsp)
jne 0x1e67e
leaq (,%r15,8), %rbx
movsd 0x8(%rsp), %xmm0
cmpb $0x0, 0x24(%rsp)
jne 0x1e535
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rax
movq -0x8(%rax,%rbx), %rax
movsd -0x8(%rax,%rbx), %xmm0
mulsd 0x8(%rsp), %xmm0
leaq -0x1(%r15), %r12
callq 0x276c0
movsd %xmm0, 0x18(%rsp)
movsd %xmm1, 0x10(%rsp)
movq 0x40(%rsp), %r14
cmpq %r14, %r12
jge 0x1e5ee
movq 0x98(%rsp), %rbp
addq %rbx, %rbp
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rax
movq -0x8(%rax,%rbx), %r12
addq %rbx, %r12
movq %r15, %rdi
movq %r14, %rsi
callq 0x2897c
movl $0x1, %esi
movl $0x1, %ecx
movq %rbp, %rdi
movq %r12, %rdx
movq %rax, %r8
movsd 0x8(%rsp), %xmm0
callq 0x2870e
movq 0x98(%rsp), %r12
addq %rbx, %r12
movq 0x30(%rsp), %rax
movq 0x28(%rax), %rbp
addq %rbx, %rbp
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %r14
callq 0x2897c
movl $0x1, %esi
movl $0x1, %ecx
movq %r12, %rdi
movq %rbp, %rdx
movq %rax, %r8
callq 0x28519
movapd %xmm0, %xmm1
movq 0x28(%r14), %rax
movsd -0x8(%rax,%rbx), %xmm0
subsd %xmm1, %xmm0
jmp 0x1e5fd
movq 0x30(%rsp), %r14
movq 0x28(%r14), %rax
movsd -0x8(%rax,%rbx), %xmm0
callq 0x276c0
movapd %xmm0, %xmm2
movapd %xmm1, %xmm3
movsd 0x18(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x50(%rsp), %xmm4
movsd 0x38(%rsp), %xmm5
movsd 0x58(%rsp), %xmm6
leaq 0x48(%rsp), %rdi
leaq 0x60(%rsp), %rsi
movq %r13, %rdx
callq 0x1eac1
movl %eax, %ebp
testb %al, %al
je 0x1e662
movsd 0x60(%rsp), %xmm0
movq 0x28(%r14), %rax
movsd %xmm0, -0x8(%rax,%rbx)
addq $-0x8, %rbx
decq %r15
jg 0x1e50e
jmp 0x1e662
movb $0x1, %bpl
movq %r13, %rdi
callq 0x24ff2
movl %ebp, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r12, %r12
setne %cl
orb %bpl, %cl
jne 0x1e7df
negq %r15
movq $-0x1, %r12
leaq 0x48(%rsp), %rbx
movsd 0x8(%rsp), %xmm0
cmpb $0x0, 0x24(%rsp)
jne 0x1e6c4
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax,%r12,8), %rax
movsd 0x8(%rax,%r12,8), %xmm0
mulsd 0x8(%rsp), %xmm0
callq 0x276c0
movsd %xmm0, 0x18(%rsp)
movsd %xmm1, 0x10(%rsp)
cmpq $-0x1, %r12
je 0x1e768
movq 0x98(%rsp), %rbp
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax,%r12,8), %r13
xorl %edi, %edi
movq %r12, %rsi
callq 0x2897c
movl $0x1, %esi
movl $0x1, %ecx
movq %rbp, %rdi
movq %r13, %rdx
movq %rax, %r8
movsd 0x8(%rsp), %xmm0
callq 0x2870e
movq 0x98(%rsp), %r13
movq 0x28(%r14), %rbp
xorl %edi, %edi
movq %r12, %rsi
callq 0x2897c
movl $0x1, %esi
movl $0x1, %ecx
movq %r13, %rdi
movq 0xf0(%rsp), %r13
movq %rbp, %rdx
movq %rax, %r8
callq 0x28519
movapd %xmm0, %xmm1
movq 0x28(%r14), %rax
movsd 0x8(%rax,%r12,8), %xmm0
subsd %xmm1, %xmm0
jmp 0x1e770
movq 0x28(%r14), %rax
movsd (%rax), %xmm0
callq 0x276c0
movapd %xmm0, %xmm2
movapd %xmm1, %xmm3
movsd 0x18(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x50(%rsp), %xmm4
movsd 0x38(%rsp), %xmm5
movsd 0x58(%rsp), %xmm6
movq %rbx, %rdi
leaq 0x60(%rsp), %rsi
movq %r13, %rdx
callq 0x1eac1
movl %eax, %ebp
testb %al, %al
je 0x1e662
movsd 0x60(%rsp), %xmm0
movq 0x28(%r14), %rax
movsd %xmm0, 0x8(%rax,%r12,8)
leaq (%r15,%r12), %rax
incq %rax
incq %r12
cmpq $-0x1, %rax
jne 0x1e69c
jmp 0x1e662
cmpq $0x1, %r12
setne %cl
orb %al, %cl
jne 0x1e95a
xorl %ebx, %ebx
leaq 0x48(%rsp), %r12
movsd 0x8(%rsp), %xmm0
cmpb $0x0, 0x24(%rsp)
jne 0x1e81a
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rax
movq (%rax,%rbx,8), %rax
movsd (%rax,%rbx,8), %xmm0
mulsd 0x8(%rsp), %xmm0
callq 0x276c0
movsd %xmm0, 0x10(%rsp)
movsd %xmm1, 0x18(%rsp)
movq 0x28(%r14), %rax
movsd (%rax,%rbx,8), %xmm0
callq 0x276c0
movapd %xmm0, %xmm2
movapd %xmm1, %xmm3
movsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
movsd 0x50(%rsp), %xmm4
movsd 0x38(%rsp), %xmm5
movsd 0x58(%rsp), %xmm6
movq %r12, %rdi
leaq 0x60(%rsp), %rsi
movq %r13, %rdx
callq 0x1eac1
movl %eax, %ebp
testb %al, %al
je 0x1e662
movsd 0x60(%rsp), %xmm0
movq 0x28(%r14), %rax
movsd %xmm0, (%rax,%rbx,8)
movq 0x40(%rsp), %r14
cmpq %r14, %rbx
jge 0x1e944
leaq 0x1(%rbx), %rdi
movq %rdi, 0x18(%rsp)
leaq 0x8(,%rbx,8), %r12
movq 0x98(%rsp), %r13
addq %r12, %r13
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rax
movq (%rax,%rbx,8), %rbx
addq %r12, %rbx
movq %r14, %rsi
movsd %xmm0, 0x10(%rsp)
callq 0x2897c
movl $0x1, %esi
movl $0x1, %ecx
movq %r13, %rdi
movq 0xf0(%rsp), %r13
movq %rbx, %rdx
movq %rax, %r8
movsd 0x8(%rsp), %xmm0
callq 0x2870e
movq 0x30(%rsp), %rax
movq 0x28(%rax), %rbx
addq %r12, %rbx
addq 0x98(%rsp), %r12
movq 0x18(%rsp), %r14
movq %r14, %rdi
movq 0x40(%rsp), %rsi
callq 0x2897c
movl $0x1, %esi
movl $0x1, %ecx
movq %rbx, %rdi
movq %r12, %rdx
leaq 0x48(%rsp), %r12
movq %rax, %r8
movsd 0x10(%rsp), %xmm0
callq 0x2892d
movq %r14, %rbx
jmp 0x1e947
incq %rbx
cmpq %r15, %rbx
movq 0x30(%rsp), %r14
jne 0x1e7f5
jmp 0x1e662
cmpq $0x1, %r12
setne %cl
xorb $0x1, %al
orb %cl, %al
jne 0x1eaba
movsd 0x8(%rsp), %xmm0
cmpb $0x0, 0x24(%rsp)
jne 0x1e993
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rax
movq -0x8(%rax,%r15,8), %rax
movsd -0x8(%rax,%r15,8), %xmm0
mulsd 0x8(%rsp), %xmm0
callq 0x276c0
movsd %xmm0, 0x10(%rsp)
movsd %xmm1, 0x18(%rsp)
movq 0x28(%r14), %rax
movsd -0x8(%rax,%r15,8), %xmm0
callq 0x276c0
movapd %xmm0, %xmm2
movapd %xmm1, %xmm3
movsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
movsd 0x50(%rsp), %xmm4
movsd 0x38(%rsp), %xmm5
movsd 0x58(%rsp), %xmm6
leaq 0x48(%rsp), %rdi
leaq 0x60(%rsp), %rsi
movq %r13, %rdx
callq 0x1eac1
movl %eax, %ebp
testb %al, %al
je 0x1e662
movsd 0x60(%rsp), %xmm0
movq 0x28(%r14), %rax
movsd %xmm0, -0x8(%rax,%r15,8)
cmpq $0x1, %r15
je 0x1e662
movq 0x98(%rsp), %rbx
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rax
movq -0x8(%rax,%r15,8), %r13
movq 0x40(%rsp), %r14
leaq -0x1(%r14), %r12
xorl %edi, %edi
movq %r12, %rsi
movsd %xmm0, 0x10(%rsp)
callq 0x2897c
movl $0x1, %esi
movl $0x1, %ecx
movq %rbx, %rdi
movq %r13, %rdx
movq %rax, %r8
movsd 0x8(%rsp), %xmm0
callq 0x2870e
movq 0x30(%rsp), %rax
movq 0x28(%rax), %rbx
movq 0x98(%rsp), %r13
xorl %edi, %edi
movq %r12, %rsi
callq 0x2897c
movl $0x1, %esi
movl $0x1, %ecx
movq %rbx, %rdi
movq %r13, %rdx
movq 0xf0(%rsp), %r13
movq %rax, %r8
movsd 0x10(%rsp), %xmm0
callq 0x2892d
decq %r15
testq %r14, %r14
movq 0x30(%rsp), %r14
movq %r12, 0x40(%rsp)
jg 0x1e96b
jmp 0x1e662
xorl %ebp, %ebp
jmp 0x1e662