// File: /workspace/github_cpp_makefile_star2_O2/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 %rdi, 0x8(%rsp)
movl 0x8(%rsi), %eax
cmpl 0xc(%rsi), %eax
jne 0x4adb
movq %rdx, %rbx
movq %rsi, %r14
leaq 0x50(%rsp), %rdi
callq 0x3b80
movl 0x8(%r14), %r14d
leaq 0x78(%rsp), %rdi
movl %r14d, %esi
callq 0x8995
movq %rbx, 0x60(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x3b09
movslq %r14d, %rax
movq %rax, 0x68(%rsp)
leaq 0x30(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x18(%rsp)
leaq 0x50(%rsp), %r13
movq (%r13), %rbx
movq %r14, 0x20(%rsp)
leal 0x1(%r14), %r12d
pushq $0x1
popq %r14
pushq $0x2
popq %rax
movq %rax, 0x28(%rsp)
cmpq 0x68(%rsp), %r14
jge 0x48b6
leaq 0x1(%r14), %rax
movq %rax, 0x70(%rsp)
movq 0x28(%rsp), %r15
cmpl %r15d, 0x20(%rsp)
jl 0x48a7
movq %r13, %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0x2e20
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
movq %r13, %rdi
movl %r14d, %esi
movl %r14d, %edx
callq 0x2e20
movsd (%rsp), %xmm0
divsd (%rax), %xmm0
movq 0x18(%rsp), %rax
movq -0x8(%rax,%r15,8), %rax
movsd %xmm0, -0x8(%rax,%r14,8)
movq %r14, %rbp
cmpq %rbp, %r12
je 0x489f
movq %r13, %rdi
movl %r15d, %esi
movl %ebp, %edx
callq 0x2e20
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
movq %r13, %rdi
movl %r14d, %esi
movl %ebp, %edx
callq 0x2e20
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x30(%rsp), %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0x2e20
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
jmp 0x483a
incq %r15
jmp 0x47ed
incq 0x28(%rsp)
movq 0x70(%rsp), %r14
jmp 0x47d4
leaq 0x40(%rsp), %rdi
movq 0x20(%rsp), %rbx
movl %ebx, %esi
callq 0x8068
xorl %r14d, %r14d
testl %ebx, %ebx
movl $0x0, %eax
cmovgl %ebx, %eax
movl %eax, 0x18(%rsp)
leaq 0x40(%rsp), %r12
leaq 0x30(%rsp), %r13
xorl %ebp, %ebp
movq 0x60(%rsp), %rbx
cmpl 0x18(%rsp), %ebp
je 0x49ad
incl %ebp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x86de
movsd (%rax), %xmm0
movq %r12, %rdi
movl %ebp, %esi
callq 0x89d4
pushq $0x1
popq %rax
movl %eax, %r15d
leal (%r14,%r15), %eax
cmpl $0x1, %eax
je 0x4973
movq %r12, %rdi
movl %ebp, %esi
callq 0x86de
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
movq %r13, %rdi
movl %ebp, %esi
movl %r15d, %edx
callq 0x2e20
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r12, %rdi
movl %r15d, %esi
callq 0x86de
movsd 0x10(%rsp), %xmm1
mulsd (%rax), %xmm1
movsd (%rsp), %xmm0
subsd %xmm1, %xmm0
incl %r15d
movq %r12, %rdi
movl %ebp, %esi
callq 0x89d4
jmp 0x4913
movq %r12, %rdi
movl %ebp, %esi
callq 0x86de
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
movq %r13, %rdi
movl %ebp, %esi
movl %ebp, %edx
callq 0x2e20
movsd (%rsp), %xmm0
divsd (%rax), %xmm0
decl %r14d
movq %r12, %rdi
movl %ebp, %esi
callq 0x89d4
jmp 0x48e9
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %r14
movl %r14d, %esi
callq 0x8068
leaq 0x40(%rsp), %r15
leaq 0x50(%rsp), %r12
movl %r14d, %r13d
testl %r13d, %r13d
jle 0x4a9c
movq %r15, %rdi
movl %r13d, %esi
callq 0x86de
movsd (%rax), %xmm0
movq 0x8(%rsp), %rdi
movl %r13d, %esi
callq 0x89d4
leal -0x1(%r13), %ebx
movl %r13d, %ebp
cmpl %r14d, %ebp
jge 0x4a5a
movq 0x8(%rsp), %rdi
movl %r13d, %esi
callq 0x86de
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
incl %ebp
movq %r12, %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0x2e20
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x8(%rsp), %rdi
movl %ebp, %esi
callq 0x86de
movsd 0x10(%rsp), %xmm1
mulsd (%rax), %xmm1
movsd (%rsp), %xmm0
subsd %xmm1, %xmm0
movq 0x8(%rsp), %rdi
movl %r13d, %esi
callq 0x89d4
jmp 0x49f8
movq 0x8(%rsp), %rdi
movl %r13d, %esi
callq 0x86de
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
movq %r12, %rdi
movl %r13d, %esi
movl %r13d, %edx
callq 0x2e20
movsd (%rsp), %xmm0
divsd (%rax), %xmm0
movq 0x8(%rsp), %rdi
movl %r13d, %esi
callq 0x89d4
movl %ebx, %r13d
jmp 0x49cc
leaq 0x40(%rsp), %rdi
callq 0x8104
leaq 0x30(%rsp), %rdi
callq 0x2dea
leaq 0x78(%rsp), %rdi
callq 0x8104
leaq 0x50(%rsp), %rdi
callq 0x2dea
movq 0x8(%rsp), %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4838(%rip), %rdi      # 0x931a
leaq 0x4668(%rip), %rsi      # 0x9151
leaq 0x4857(%rip), %rcx      # 0x9347
movl $0x1bf, %edx            # imm = 0x1BF
callq 0x20b0
jmp 0x4b1d
jmp 0x4b2c
movq %rax, %r14
jmp 0x4b39
movq %rax, %r14
jmp 0x4b43
jmp 0x4b0e
jmp 0x4b1d
jmp 0x4b2c
movq %rax, %r14
movq 0x8(%rsp), %rdi
callq 0x8104
jmp 0x4b20
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0x8104
jmp 0x4b2f
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x2dea
leaq 0x78(%rsp), %rdi
callq 0x8104
leaq 0x50(%rsp), %rdi
callq 0x2dea
movq %r14, %rdi
callq 0x21d0