// File: mouda[P]LTE_random_access-simulate/alglibinternal.cpp
// Function: alglib_impl::rmatrixtrsafesolve(alglib_impl::ae_matrix*, long, alglib_impl::ae_vector*, double*, bool, bool, bool, alglib_impl::ae_state*)
void rmatrixtrsafesolve(/* Real    */ ae_matrix* a,
     ae_int_t n,
     /* Real    */ ae_vector* x,
     double* s,
     ae_bool isupper,
     ae_bool istrans,
     ae_bool isunit,
     ae_state *_state)
{
    ae_frame _frame_block;
    ae_bool normin;
    ae_vector cnorm;
    ae_matrix a1;
    ae_vector x1;
    ae_int_t i;

    ae_frame_make(_state, &_frame_block);
    *s = 0;
    ae_vector_init(&cnorm, 0, DT_REAL, _state, ae_true);
    ae_matrix_init(&a1, 0, 0, DT_REAL, _state, ae_true);
    ae_vector_init(&x1, 0, DT_REAL, _state, ae_true);

    
    /*
     * From 0-based to 1-based
     */
    normin = ae_false;
    ae_matrix_set_length(&a1, n+1, n+1, _state);
    ae_vector_set_length(&x1, n+1, _state);
    for(i=1; i<=n; i++)
    {
        ae_v_move(&a1.ptr.pp_double[i][1], 1, &a->ptr.pp_double[i-1][0], 1, ae_v_len(1,n));
    }
    ae_v_move(&x1.ptr.p_double[1], 1, &x->ptr.p_double[0], 1, ae_v_len(1,n));
    
    /*
     * Solve 1-based
     */
    safesolvetriangular(&a1, n, &x1, s, isupper, istrans, isunit, normin, &cnorm, _state);
    
    /*
     * From 1-based to 0-based
     */
    ae_v_move(&x->ptr.p_double[0], 1, &x1.ptr.p_double[1], 1, ae_v_len(0,n-1));
    ae_frame_leave(_state);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movl %r9d, -0x10c(%rbp)
movl %r8d, %eax
movq %rcx, %r8
movl -0x10c(%rbp), %ecx
movq %r8, -0x108(%rbp)
movq %rdx, -0x100(%rbp)
movq %rsi, %r8
movq -0x108(%rbp), %rsi
movq %rdi, %r9
movq -0x100(%rbp), %rdi
movb %al, %dl
movq 0x18(%rbp), %rax
movb 0x10(%rbp), %al
movq %r9, -0x10(%rbp)
movq %r8, -0x18(%rbp)
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
andb $0x1, %dl
movb %dl, -0x29(%rbp)
andb $0x1, %cl
movb %cl, -0x2a(%rbp)
andb $0x1, %al
movb %al, -0x2b(%rbp)
movq 0x18(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x3b0f0
movq -0x28(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq 0x18(%rbp), %rcx
leaq -0x80(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x3, %edx
movl $0x1, %r8d
callq 0x3b400
movq 0x18(%rbp), %r8
leaq -0xc0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
movl $0x3, %ecx
movl $0x1, %r9d
movq %rdx, %rsi
callq 0x3b7d0
movq 0x18(%rbp), %rcx
leaq -0xf0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x3, %edx
movl $0x1, %r8d
callq 0x3b400
movb $0x0, -0x49(%rbp)
movq -0x18(%rbp), %rsi
addq $0x1, %rsi
movq -0x18(%rbp), %rdx
addq $0x1, %rdx
movq 0x18(%rbp), %rcx
leaq -0xc0(%rbp), %rdi
callq 0x3bc30
movq -0x18(%rbp), %rsi
addq $0x1, %rsi
movq 0x18(%rbp), %rdx
leaq -0xf0(%rbp), %rdi
callq 0x3b620
movq $0x1, -0xf8(%rbp)
movq -0xf8(%rbp), %rax
cmpq -0x18(%rbp), %rax
jg 0x2c252
movq -0x88(%rbp), %rax
movq -0xf8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq $0x8, %rax
movq %rax, -0x120(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq -0xf8(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x118(%rbp)
movq -0x18(%rbp), %rsi
movl $0x1, %edi
callq 0x42370
movq -0x120(%rbp), %rdi
movq -0x118(%rbp), %rdx
movq %rax, %r8
movl $0x1, %ecx
movq %rcx, %rsi
callq 0x41b10
movq -0xf8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xf8(%rbp)
jmp 0x2c1c7
movq -0xc8(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x140(%rbp)
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x138(%rbp)
movq -0x18(%rbp), %rsi
movl $0x1, %edi
callq 0x42370
movq -0x140(%rbp), %rdi
movq -0x138(%rbp), %rdx
movq %rax, %r8
movl $0x1, %ecx
movq %rcx, %rsi
callq 0x41b10
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rcx
movb -0x29(%rbp), %r8b
movb -0x2a(%rbp), %r9b
movb -0x2b(%rbp), %bl
movb -0x49(%rbp), %r11b
movq 0x18(%rbp), %rax
leaq -0xc0(%rbp), %rdi
leaq -0xf0(%rbp), %rdx
leaq -0x80(%rbp), %r10
andb $0x1, %r8b
andb $0x1, %r9b
andb $0x1, %bl
andb $0x1, %r11b
movzbl %r8b, %r8d
movzbl %r9b, %r9d
movzbl %bl, %ebx
movl %ebx, (%rsp)
movzbl %r11b, %r11d
movl %r11d, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x2c370
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x130(%rbp)
movq -0xc8(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x128(%rbp)
movq -0x18(%rbp), %rsi
subq $0x1, %rsi
xorl %eax, %eax
movl %eax, %edi
callq 0x42370
movq -0x130(%rbp), %rdi
movq -0x128(%rbp), %rdx
movq %rax, %r8
movl $0x1, %ecx
movq %rcx, %rsi
callq 0x41b10
movq 0x18(%rbp), %rdi
callq 0x3b030
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)