// File: /workspace/github_cpp_makefile_star2_O2/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, 0x48(%rsp)
movl %r9d, 0x24(%rsp)
movq %r8, %r13
movl %ecx, (%rsp)
movq %rdx, %r14
movq %rsi, %r12
movsd %xmm0, 0x8(%rsp)
movq %rdi, 0x28(%rsp)
movq 0xf0(%rsp), %rbp
leaq 0xa0(%rsp), %rsi
movq %rbp, %rdi
callq 0x23815
leaq 0x70(%rsp), %rdi
pushq $0x3
popq %rdx
pushq $0x1
popq %r8
xorl %esi, %esi
movq %rbp, %rcx
callq 0x239a5
xorl %edi, %edi
testq %r12, %r12
setg %dil
leaq 0x16242(%rip), %rsi     # 0x33062
movq %rbp, %rdx
callq 0x238ca
xorl %edi, %edi
cmpq $0x2, %r13
setb %dil
leaq 0x1624a(%rip), %rsi     # 0x33083
movq %rbp, %rdx
callq 0x238ca
movsd 0x13817(%rip), %xmm0    # 0x30660
movq %rbp, %rdi
callq 0x2455f
movsd %xmm0, 0x40(%rsp)
testq %r12, %r12
jle 0x1d04f
xorps %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
xorl %ebx, %ebx
cmpq %rbx, %r12
je 0x1ce9e
movq 0x28(%r14), %rax
movsd (%rax,%rbx,8), %xmm0
movq %rbp, %rdi
callq 0x2440c
movapd %xmm0, %xmm1
movsd 0x38(%rsp), %xmm0
movq %rbp, %rdi
callq 0x244b6
movsd %xmm0, 0x38(%rsp)
incq %rbx
jmp 0x1ce6b
testq %r13, %r13
setne %r15b
movq %r12, %rbx
leaq -0x1(%r12), %rax
movq %rax, 0x68(%rsp)
andq $0x0, 0x30(%rsp)
leaq 0x70(%rsp), %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x23add
movl (%rsp), %edx
movl %edx, %eax
xorb $0x1, %al
orb %al, %r15b
movq %r14, 0x10(%rsp)
jne 0x1d074
leaq (,%rbx,8), %rbp
leaq 0x30(%rsp), %r15
leaq -0x1(%rbx), %r13
movq %r13, %r14
shrq $0x3f, %r14
testq %r13, %r13
movq 0x68(%rsp), %r12
js 0x1d052
movsd 0x8(%rsp), %xmm0
cmpb $0x0, 0x24(%rsp)
jne 0x1cf2a
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rax
movq -0x8(%rax,%rbp), %rax
movsd -0x8(%rax,%rbp), %xmm0
mulsd 0x8(%rsp), %xmm0
callq 0x25861
movsd %xmm0, 0x18(%rsp)
movsd %xmm1, (%rsp)
cmpq %r12, %r13
jge 0x1cfdc
movq 0x98(%rsp), %r15
addq %rbp, %r15
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rax
movq %rbx, %rdi
movq %rbx, 0x60(%rsp)
movq -0x8(%rax,%rbp), %rbx
addq %rbp, %rbx
movq %r12, %rsi
callq 0x26b4d
movq %r15, %rdi
pushq $0x1
popq %rcx
movq %rcx, %rsi
movq %rbx, %rdx
movq %rax, %r8
movsd 0x8(%rsp), %xmm0
callq 0x26888
movq 0x98(%rsp), %rbx
addq %rbp, %rbx
movq %r12, %rsi
movq 0x10(%rsp), %r12
movq 0x28(%r12), %r15
addq %rbp, %r15
movq 0x60(%rsp), %rdi
callq 0x26b4d
movq %rbx, %rdi
pushq $0x1
popq %rcx
movq %rcx, %rsi
movq %r15, %rdx
leaq 0x30(%rsp), %r15
movq %rax, %r8
callq 0x2668d
movapd %xmm0, %xmm1
movq 0x28(%r12), %rax
movsd -0x8(%rax,%rbp), %xmm0
subsd %xmm1, %xmm0
jmp 0x1cfeb
movq 0x10(%rsp), %rax
movq 0x28(%rax), %rax
movsd -0x8(%rax,%rbp), %xmm0
callq 0x25861
movapd %xmm0, %xmm2
movapd %xmm1, %xmm3
movsd 0x18(%rsp), %xmm0
movsd (%rsp), %xmm1
movsd 0x40(%rsp), %xmm4
movsd 0x38(%rsp), %xmm5
movsd 0x48(%rsp), %xmm6
movq %r15, %rdi
leaq 0x50(%rsp), %rsi
movq 0xf0(%rsp), %rdx
callq 0x1d4c5
testb %al, %al
je 0x1d052
movsd 0x50(%rsp), %xmm0
movq 0x10(%rsp), %rax
movq 0x28(%rax), %rax
movsd %xmm0, -0x8(%rax,%rbp)
addq $-0x8, %rbp
movq %r13, %rbx
jmp 0x1ceea
movb $0x1, %r14b
movq 0xf0(%rsp), %rdi
callq 0x237b6
movl %r14d, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r13, %r13
setne %cl
orb %dl, %cl
jne 0x1d1e6
movq %r12, %rbx
negq %rbx
pushq $-0x1
popq %rbp
leaq 0x30(%rsp), %r15
leaq 0x50(%rsp), %r12
movq %rbx, 0x60(%rsp)
leaq (%rbx,%rbp), %rax
cmpq $-0x1, %rax
sete %r14b
je 0x1d052
movsd 0x8(%rsp), %xmm0
cmpb $0x0, 0x24(%rsp)
jne 0x1d0cf
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax,%rbp,8), %rax
movsd 0x8(%rax,%rbp,8), %xmm0
mulsd 0x8(%rsp), %xmm0
callq 0x25861
movsd %xmm0, 0x18(%rsp)
movsd %xmm1, (%rsp)
movq %rbp, %r13
incq %r13
jne 0x1d0f9
movq 0x10(%rsp), %rax
movq 0x28(%rax), %rax
movsd (%rax), %xmm0
jmp 0x1d184
movq 0x98(%rsp), %rbx
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rax
movq (%rax,%r13,8), %r15
xorl %edi, %edi
movq %rbp, %rsi
callq 0x26b4d
movq %rbx, %rdi
pushq $0x1
popq %rcx
movq %rcx, %rsi
movq %r15, %rdx
movq %rax, %r8
movsd 0x8(%rsp), %xmm0
callq 0x26888
movq 0x98(%rsp), %rbx
movq 0x10(%rsp), %r12
movq 0x28(%r12), %r15
xorl %edi, %edi
movq %rbp, %rsi
callq 0x26b4d
movq %rbx, %rdi
movq 0x60(%rsp), %rbx
pushq $0x1
popq %rcx
movq %rcx, %rsi
movq %r15, %rdx
leaq 0x30(%rsp), %r15
movq %rax, %r8
callq 0x2668d
movapd %xmm0, %xmm1
movq 0x28(%r12), %rax
leaq 0x50(%rsp), %r12
movsd (%rax,%r13,8), %xmm0
subsd %xmm1, %xmm0
callq 0x25861
movapd %xmm0, %xmm2
movapd %xmm1, %xmm3
movsd 0x18(%rsp), %xmm0
movsd (%rsp), %xmm1
movsd 0x40(%rsp), %xmm4
movsd 0x38(%rsp), %xmm5
movsd 0x48(%rsp), %xmm6
movq %r15, %rdi
movq %r12, %rsi
movq 0xf0(%rsp), %rdx
callq 0x1d4c5
testb %al, %al
je 0x1d052
movsd 0x50(%rsp), %xmm0
movq 0x10(%rsp), %rax
movq 0x28(%rax), %rax
movsd %xmm0, (%rax,%r13,8)
movq %r13, %rbp
jmp 0x1d09a
cmpq $0x1, %r13
setne %cl
orb %al, %cl
jne 0x1d367
movq %r12, %rbx
xorl %r13d, %r13d
leaq 0x30(%rsp), %r15
cmpq %rbx, %r13
sete %r14b
je 0x1d052
movsd 0x8(%rsp), %xmm0
cmpb $0x0, 0x24(%rsp)
jne 0x1d233
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rax
movq (%rax,%r13,8), %rax
movsd (%rax,%r13,8), %xmm0
mulsd 0x8(%rsp), %xmm0
callq 0x25861
movsd %xmm0, (%rsp)
movsd %xmm1, 0x18(%rsp)
movq 0x10(%rsp), %rax
movq 0x28(%rax), %rax
movsd (%rax,%r13,8), %xmm0
callq 0x25861
movapd %xmm0, %xmm2
movapd %xmm1, %xmm3
movsd (%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
movsd 0x40(%rsp), %xmm4
movsd 0x38(%rsp), %xmm5
movsd 0x48(%rsp), %xmm6
movq %r15, %rdi
leaq 0x50(%rsp), %rsi
movq %rbp, %rdx
callq 0x1d4c5
testb %al, %al
je 0x1d052
movsd 0x50(%rsp), %xmm0
movq 0x10(%rsp), %r14
movq 0x28(%r14), %rax
movsd %xmm0, (%rax,%r13,8)
movq 0x68(%rsp), %rbp
cmpq %rbp, %r13
jge 0x1d357
leaq 0x1(%r13), %rdi
movq %rdi, 0x18(%rsp)
leaq 0x8(,%r13,8), %r15
movq 0x98(%rsp), %rbx
addq %r15, %rbx
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rax
movq (%rax,%r13,8), %r13
addq %r15, %r13
movq %rbp, %rsi
movsd %xmm0, (%rsp)
callq 0x26b4d
movq %rbx, %rdi
pushq $0x1
popq %rcx
movq %rcx, %rsi
movq %r13, %rdx
movq %rax, %r8
movsd 0x8(%rsp), %xmm0
callq 0x26888
movq 0x28(%r14), %rbx
addq %r15, %rbx
addq 0x98(%rsp), %r15
movq 0x18(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
callq 0x26b4d
movq %rbx, %rdi
movq %r12, %rbx
pushq $0x1
popq %rcx
movq %rcx, %rsi
movq %r15, %rdx
leaq 0x30(%rsp), %r15
movq %rax, %r8
movsd (%rsp), %xmm0
callq 0x26afc
movq 0xf0(%rsp), %rbp
jmp 0x1d200
incq %r13
movq 0xf0(%rsp), %rbp
jmp 0x1d200
cmpq $0x1, %r13
setne %cl
xorb $0x1, %al
orb %cl, %al
jne 0x1d4bd
movq 0x68(%rsp), %r12
movq %r12, %r14
shrq $0x3f, %r14
testq %r12, %r12
js 0x1d052
movsd 0x8(%rsp), %xmm0
cmpb $0x0, 0x24(%rsp)
jne 0x1d3b3
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rax
movq (%rax,%r12,8), %rax
movsd (%rax,%r12,8), %xmm0
mulsd 0x8(%rsp), %xmm0
callq 0x25861
movsd %xmm0, (%rsp)
movsd %xmm1, 0x18(%rsp)
movq 0x10(%rsp), %rax
movq 0x28(%rax), %rax
movq %r12, %r15
movsd (%rax,%r12,8), %xmm0
callq 0x25861
movapd %xmm0, %xmm2
movapd %xmm1, %xmm3
movsd (%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
movsd 0x40(%rsp), %xmm4
movsd 0x38(%rsp), %xmm5
movsd 0x48(%rsp), %xmm6
leaq 0x30(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movq %rbp, %rdx
callq 0x1d4c5
testb %al, %al
je 0x1d052
movsd 0x50(%rsp), %xmm0
movq 0x10(%rsp), %r14
movq 0x28(%r14), %rax
movq %r15, %r12
movsd %xmm0, (%rax,%r15,8)
testq %r15, %r15
je 0x1d4ad
movq 0x98(%rsp), %rbx
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rax
movq (%rax,%r12,8), %r13
leaq -0x1(%r15), %r12
xorl %edi, %edi
movq %r12, %rsi
movsd %xmm0, (%rsp)
callq 0x26b4d
movq %rbx, %rdi
pushq $0x1
popq %rbp
movq %rbp, %rsi
movq %r13, %rdx
movq %rbp, %rcx
movq %rax, %r8
movsd 0x8(%rsp), %xmm0
callq 0x26888
movq 0x28(%r14), %rbx
movq 0x98(%rsp), %r13
xorl %edi, %edi
movq %r12, %rsi
movq %r15, %r12
callq 0x26b4d
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %rbp, %rcx
movq %rax, %r8
movsd (%rsp), %xmm0
callq 0x26afc
decq %r12
movq 0xf0(%rsp), %rbp
jmp 0x1d37d
xorl %r14d, %r14d
jmp 0x1d052