// File: /workspace/github_cpp_makefile_star2_O1/yukimasano[P]cpp_matrix/Matrix.cpp
// Function: LUsolve(Matrix&, Vector&)
Vector LUsolve(Matrix& A, Vector& v){
	assert(nrows(A) == ncols(A));
	// we want a square system

	// INITIALISATION
	Matrix U=A;
	int m =nrows(A);
	Vector temp=ones(m);
	Matrix L = diag(temp);
	//LU FACTORISATION
	for (int k=1; k<=m-1; k++){
		for(int j = k+1; j<=m; j++){
			L.set_val(j,k,   (U(j,k)/U(k,k)));
			for (int l=k; l<=m; l++){
				U.set_val(j,l, (U(j,l) - U(k,l)*L(j,k)));
			}
		}
	}
	//std::cout<<L<<std::endl;
	Vector y(m);
	// FORWARD SOLVE
	for (int k=0; k<m; k++){
		y.set_val(k+1, v(k+1));
		for(int j = 0; j<k; j++){
			y.set_val(k+1, y(k+1)-(L(k+1,j+1))*y(j+1));
		}
		y.set_val(k+1, y(k+1)/L(k+1,k+1));
		}
	//std::cout<<y<<std::endl;
	Vector x(m);
	// BACKSUBSTITUTION
	for (int k=m-1; k>=0; k--){
		x.set_val(k+1, y(k+1));
		for (int j = k+1; j<m; j++){
			x.set_val(k+1, x(k+1)- U(k+1,j+1)*x(j+1));
		}
		x.set_val(k+1, x(k+1)/U(k+1,k+1));
	}
	//std::cout<<U<<std::endl;
	return x;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdx, 0x60(%rsp)
movq %rdi, 0x8(%rsp)
movl 0x8(%rsi), %eax
cmpl 0xc(%rsi), %eax
jne 0x4cd7
movq %rsi, %r14
leaq 0x40(%rsp), %rdi
callq 0x3db2
movl 0x8(%r14), %ebx
leaq 0x78(%rsp), %rdi
movl %ebx, %esi
callq 0x8e81
leaq 0x20(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x3d37
movq %rbx, 0x18(%rsp)
cmpl $0x2, %ebx
jl 0x4ab9
leaq 0x20(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x70(%rsp)
leaq 0x40(%rsp), %r13
movq (%r13), %rbx
movq 0x18(%rsp), %rax
leaq 0x1(%rax), %r12
movl %r12d, %eax
movq %rax, 0x68(%rsp)
movl $0x1, %r14d
movl $0x2, %r15d
leaq 0x1(%r14), %rax
movq %rax, 0x50(%rsp)
movq %r15, 0x58(%rsp)
movq %r13, %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0x2f92
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
movq %r13, %rdi
movl %r14d, %esi
movl %r14d, %edx
callq 0x2f92
movsd (%rsp), %xmm0
divsd (%rax), %xmm0
movq 0x70(%rsp), %rax
movq -0x8(%rax,%r15,8), %rax
movsd %xmm0, -0x8(%rax,%r14,8)
movq %r14, %rbp
movq %r13, %rdi
movl %r15d, %esi
movl %ebp, %edx
callq 0x2f92
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
movq %r13, %rdi
movl %r14d, %esi
movl %ebp, %edx
callq 0x2f92
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x20(%rsp), %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0x2f92
movsd 0x10(%rsp), %xmm1
mulsd (%rax), %xmm1
movsd (%rsp), %xmm0
subsd %xmm1, %xmm0
movq -0x8(%rbx,%r15,8), %rax
movsd %xmm0, -0x8(%rax,%rbp,8)
incq %rbp
cmpq %rbp, %r12
jne 0x4a32
incq %r15
cmpq 0x68(%rsp), %r15
jne 0x49f0
movq 0x58(%rsp), %r15
incq %r15
cmpq %r12, %r15
movq 0x50(%rsp), %r14
jne 0x49e2
leaq 0x30(%rsp), %rdi
movq 0x18(%rsp), %rbx
movl %ebx, %esi
callq 0x8268
xorl %r14d, %r14d
testl %ebx, %ebx
movl $0x0, %eax
cmovgl %ebx, %eax
movl %eax, %ebx
leaq 0x30(%rsp), %r12
leaq 0x20(%rsp), %r13
xorl %ebp, %ebp
cmpl %ebx, %ebp
je 0x4ba9
incl %ebp
movq 0x60(%rsp), %rdi
movl %ebp, %esi
callq 0x8b5a
movsd (%rax), %xmm0
movq %r12, %rdi
movl %ebp, %esi
callq 0x8ef8
movl $0x1, %r15d
leal (%r14,%r15), %eax
cmpl $0x1, %eax
je 0x4b6f
movq %r12, %rdi
movl %ebp, %esi
callq 0x8b5a
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
movq %r13, %rdi
movl %ebp, %esi
movl %r15d, %edx
callq 0x2f92
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r12, %rdi
movl %r15d, %esi
callq 0x8b5a
movsd 0x10(%rsp), %xmm1
mulsd (%rax), %xmm1
movsd (%rsp), %xmm0
subsd %xmm1, %xmm0
incl %r15d
movq %r12, %rdi
movl %ebp, %esi
callq 0x8ef8
jmp 0x4b0f
movq %r12, %rdi
movl %ebp, %esi
callq 0x8b5a
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
movq %r13, %rdi
movl %ebp, %esi
movl %ebp, %edx
callq 0x2f92
movsd (%rsp), %xmm0
divsd (%rax), %xmm0
decl %r14d
movq %r12, %rdi
movl %ebp, %esi
callq 0x8ef8
jmp 0x4ae5
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %r14
movl %r14d, %esi
callq 0x8268
leaq 0x30(%rsp), %r15
leaq 0x40(%rsp), %r12
movl %r14d, %r13d
testl %r13d, %r13d
jle 0x4c98
movq %r15, %rdi
movl %r13d, %esi
callq 0x8b5a
movsd (%rax), %xmm0
movq 0x8(%rsp), %rdi
movl %r13d, %esi
callq 0x8ef8
leal -0x1(%r13), %ebx
movl %r13d, %ebp
cmpl %r14d, %ebp
jge 0x4c56
movq 0x8(%rsp), %rdi
movl %r13d, %esi
callq 0x8b5a
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
incl %ebp
movq %r12, %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0x2f92
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x8(%rsp), %rdi
movl %ebp, %esi
callq 0x8b5a
movsd 0x10(%rsp), %xmm1
mulsd (%rax), %xmm1
movsd (%rsp), %xmm0
subsd %xmm1, %xmm0
movq 0x8(%rsp), %rdi
movl %r13d, %esi
callq 0x8ef8
jmp 0x4bf4
movq 0x8(%rsp), %rdi
movl %r13d, %esi
callq 0x8b5a
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
movq %r12, %rdi
movl %r13d, %esi
movl %r13d, %edx
callq 0x2f92
movsd (%rsp), %xmm0
divsd (%rax), %xmm0
movq 0x8(%rsp), %rdi
movl %r13d, %esi
callq 0x8ef8
movl %ebx, %r13d
jmp 0x4bc8
leaq 0x30(%rsp), %rdi
callq 0x8310
leaq 0x20(%rsp), %rdi
callq 0x2f4c
leaq 0x78(%rsp), %rdi
callq 0x8310
leaq 0x40(%rsp), %rdi
callq 0x2f4c
movq 0x8(%rsp), %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x563c(%rip), %rdi      # 0xa31a
leaq 0x546c(%rip), %rsi      # 0xa151
leaq 0x565b(%rip), %rcx      # 0xa347
movl $0x1bf, %edx            # imm = 0x1BF
callq 0x20b0
jmp 0x4d19
jmp 0x4d28
movq %rax, %r14
jmp 0x4d35
movq %rax, %r14
jmp 0x4d3f
jmp 0x4d0a
jmp 0x4d19
jmp 0x4d28
movq %rax, %r14
movq 0x8(%rsp), %rdi
callq 0x8310
jmp 0x4d1c
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x8310
jmp 0x4d2b
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x2f4c
leaq 0x78(%rsp), %rdi
callq 0x8310
leaq 0x40(%rsp), %rdi
callq 0x2f4c
movq %r14, %rdi
callq 0x21f0