// File: /workspace/github_cpp_makefile_star2_O3/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, 0x68(%rsp)
movq %rdi, 0x10(%rsp)
movl 0x8(%rsi), %eax
cmpl 0xc(%rsi), %eax
jne 0x4ca4
movq %rsi, %r14
leaq 0x48(%rsp), %rdi
callq 0x3d86
movl 0x8(%r14), %ebx
leaq 0x78(%rsp), %rdi
movl %ebx, %esi
callq 0x8ded
leaq 0x28(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x3d0b
movq %rbx, 0x20(%rsp)
cmpl $0x2, %ebx
jl 0x4a7e
leaq 0x28(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x70(%rsp)
leaq 0x48(%rsp), %r13
movq (%r13), %rbx
movq 0x20(%rsp), %rax
leaq 0x1(%rax), %r12
movl $0x1, %r14d
movl $0x2, %r15d
leaq 0x1(%r14), %rax
movq %rax, 0x58(%rsp)
movq %r15, 0x60(%rsp)
movq %r13, %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0x2f5c
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r13, %rdi
movl %r14d, %esi
movl %r14d, %edx
callq 0x2f5c
movsd 0x8(%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 0x2f5c
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r13, %rdi
movl %r14d, %esi
movl %ebp, %edx
callq 0x2f5c
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
leaq 0x28(%rsp), %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0x2f5c
movsd 0x18(%rsp), %xmm1
mulsd (%rax), %xmm1
movsd 0x8(%rsp), %xmm0
subsd %xmm1, %xmm0
movq -0x8(%rbx,%r15,8), %rax
movsd %xmm0, -0x8(%rax,%rbp,8)
incq %rbp
cmpq %rbp, %r12
jne 0x49f7
incq %r15
cmpq %r12, %r15
jne 0x49b3
movq 0x60(%rsp), %r15
incq %r15
cmpq %r12, %r15
movq 0x58(%rsp), %r14
jne 0x49a5
leaq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rbx
movl %ebx, %esi
callq 0x81e8
xorl %r14d, %r14d
testl %ebx, %ebx
movl $0x0, %eax
cmovgl %ebx, %eax
movl %eax, %ebx
leaq 0x38(%rsp), %r12
leaq 0x28(%rsp), %r13
xorl %ebp, %ebp
cmpl %ebx, %ebp
je 0x4b72
incl %ebp
movq 0x68(%rsp), %rdi
movl %ebp, %esi
callq 0x8abc
movsd (%rax), %xmm0
movq %r12, %rdi
movl %ebp, %esi
callq 0x8e60
movl $0x1, %r15d
leal (%r14,%r15), %eax
cmpl $0x1, %eax
je 0x4b36
movq %r12, %rdi
movl %ebp, %esi
callq 0x8abc
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r13, %rdi
movl %ebp, %esi
movl %r15d, %edx
callq 0x2f5c
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %r12, %rdi
movl %r15d, %esi
callq 0x8abc
movsd 0x18(%rsp), %xmm1
mulsd (%rax), %xmm1
movsd 0x8(%rsp), %xmm0
subsd %xmm1, %xmm0
incl %r15d
movq %r12, %rdi
movl %ebp, %esi
callq 0x8e60
jmp 0x4ad4
movq %r12, %rdi
movl %ebp, %esi
callq 0x8abc
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r13, %rdi
movl %ebp, %esi
movl %ebp, %edx
callq 0x2f5c
movsd 0x8(%rsp), %xmm0
divsd (%rax), %xmm0
decl %r14d
movq %r12, %rdi
movl %ebp, %esi
callq 0x8e60
jmp 0x4aaa
movq 0x10(%rsp), %rdi
movq 0x20(%rsp), %r14
movl %r14d, %esi
callq 0x81e8
leaq 0x38(%rsp), %r15
leaq 0x48(%rsp), %r12
movl %r14d, %r13d
testl %r13d, %r13d
jle 0x4c65
movq %r15, %rdi
movl %r13d, %esi
callq 0x8abc
movsd (%rax), %xmm0
movq 0x10(%rsp), %rdi
movl %r13d, %esi
callq 0x8e60
leal -0x1(%r13), %ebx
movl %r13d, %ebp
cmpl %r14d, %ebp
jge 0x4c21
movq 0x10(%rsp), %rdi
movl %r13d, %esi
callq 0x8abc
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
incl %ebp
movq %r12, %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0x2f5c
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x10(%rsp), %rdi
movl %ebp, %esi
callq 0x8abc
movsd 0x18(%rsp), %xmm1
mulsd (%rax), %xmm1
movsd 0x8(%rsp), %xmm0
subsd %xmm1, %xmm0
movq 0x10(%rsp), %rdi
movl %r13d, %esi
callq 0x8e60
jmp 0x4bbd
movq 0x10(%rsp), %rdi
movl %r13d, %esi
callq 0x8abc
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r12, %rdi
movl %r13d, %esi
movl %r13d, %edx
callq 0x2f5c
movsd 0x8(%rsp), %xmm0
divsd (%rax), %xmm0
movq 0x10(%rsp), %rdi
movl %r13d, %esi
callq 0x8e60
movl %ebx, %r13d
jmp 0x4b91
leaq 0x38(%rsp), %rdi
callq 0x827e
leaq 0x28(%rsp), %rdi
callq 0x2f1c
leaq 0x78(%rsp), %rdi
callq 0x827e
leaq 0x48(%rsp), %rdi
callq 0x2f1c
movq 0x10(%rsp), %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x466f(%rip), %rdi      # 0x931a
leaq 0x449f(%rip), %rsi      # 0x9151
leaq 0x468e(%rip), %rcx      # 0x9347
movl $0x1bf, %edx            # imm = 0x1BF
callq 0x20b0
jmp 0x4ce6
jmp 0x4cf5
movq %rax, %r14
jmp 0x4d02
movq %rax, %r14
jmp 0x4d0c
jmp 0x4cd7
jmp 0x4ce6
jmp 0x4cf5
movq %rax, %r14
movq 0x10(%rsp), %rdi
callq 0x827e
jmp 0x4ce9
movq %rax, %r14
leaq 0x38(%rsp), %rdi
callq 0x827e
jmp 0x4cf8
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x2f1c
leaq 0x78(%rsp), %rdi
callq 0x827e
leaq 0x48(%rsp), %rdi
callq 0x2f1c
movq %r14, %rdi
callq 0x21f0