// File: /workspace/github_cpp_makefile_star2_O1/IlanPrice[P]Linear-Algebra-Library-in-Cplusplus/Matrix.cpp
// Function: LU(Matrix const&)
boost::tuple< Matrix, Matrix, Matrix> LU(const Matrix& A)
	{
		Vector dim = size(A);
		int m = dim(1);
		int n = dim(2);
		Matrix U(A);
		Matrix pivot(m,m);
		Matrix P = eye(m);
		Matrix L = eye(m);

		for (int k=1;k<m;k++)
		{
			// partial pivoting
			double max = U(k,k);
			int index = k;
			pivot = eye(m);
			for (int i = k; i<=m; i++)
			{
				if (std::abs(U(i,k)) > std::abs(max))
				{
					index = i;
					max = U(i,k);
				}
			}
			if (index != k)
			{

				Vector temp = U.getElements(k,k,1,n,"vector");
				U.setElements(k,k,1,n,U.getElements(index,index,1,n,"Vector"));
				U.setElements(index,index,1,n,temp);
				Vector temp2 = L.getElements(k,k,1,m,"vector");

				L.setElements(k,k,1,m,L.getElements(index,index,1,m,"Vector"));
				L.setElements(index,index,1,m,temp2);
				pivot(index,index)=0; pivot(k,k) = 0;
				pivot(index,k) = 1; pivot(k,index) = 1;
				P = pivot*P;
			}
			// variant of Gaussian elimination
			Matrix Lk = eye(m);
			for (int i = k+1; i<=m;i++)
			{
				Lk(i,k) = U(i,k)/U(k,k);
				for (int j=k+1;j<=n;j++)
				{
					U(i,j) = U(i,j) - Lk(i,k)*U(k,j);
				}
				U(i,k) = 0;
			}
			L = L*pivot*Lk;
		}
		boost::tuple<Matrix,Matrix,Matrix> LUP = boost::make_tuple(L, U, P);
		return LUP;
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movq %rsi, %rbx
movq %rdi, 0x70(%rsp)
leaq 0xe8(%rsp), %r14
movq %r14, %rdi
callq 0x6c8e
movq %r14, %rdi
movl $0x1, %esi
callq 0x3354
cvttsd2si (%rax), %eax
movl %eax, 0x28(%rsp)
leaq 0xe8(%rsp), %rdi
movl $0x2, %esi
callq 0x3354
cvttsd2si (%rax), %ebp
leaq 0xc8(%rsp), %rdi
movq %rbx, %rsi
callq 0x3f5e
movq 0x70(%rsp), %r14
leaq 0xa8(%rsp), %rdi
movl 0x28(%rsp), %ebx
movl %ebx, %esi
movl %ebx, %edx
callq 0x3df8
leaq 0x98(%rsp), %rdi
movl %ebx, %esi
movl %ebx, %edx
callq 0x3df8
movl %ebx, %r13d
movabsq $0x3ff0000000000000, %rsi # imm = 0x3FF0000000000000
testl %ebx, %ebx
jle 0x5729
movq 0x98(%rsp), %rax
xorl %ecx, %ecx
movq (%rax,%rcx,8), %rdx
movq %rsi, (%rdx,%rcx,8)
incq %rcx
cmpq %rcx, %r13
jne 0x5719
leaq 0x38(%rsp), %rdi
movl 0x28(%rsp), %ebx
movl %ebx, %esi
movl %ebx, %edx
callq 0x3df8
movl %ebp, 0x2c(%rsp)
testl %ebx, %ebx
movabsq $0x3ff0000000000000, %rsi # imm = 0x3FF0000000000000
jle 0x5764
movq 0x38(%rsp), %rax
xorl %ecx, %ecx
movq (%rax,%rcx,8), %rdx
movq %rsi, (%rdx,%rcx,8)
incq %rcx
cmpq %rcx, %r13
jne 0x5754
cmpl $0x2, 0x28(%rsp)
jl 0x5d4e
movl 0x28(%rsp), %eax
negl %eax
movq %rax, 0xd8(%rsp)
movl 0x2c(%rsp), %eax
movl %eax, %ebp
negl %ebp
movl $0x1, %ebx
leaq 0xc8(%rsp), %r15
leaq 0x88(%rsp), %r12
movq %r13, 0x68(%rsp)
movq %r15, %rdi
movl %ebx, %esi
movl %ebx, %edx
callq 0x51ec
movsd (%rax), %xmm0
movapd %xmm0, 0x50(%rsp)
movq %r12, %rdi
movl 0x28(%rsp), %r14d
movl %r14d, %esi
movl %r14d, %edx
callq 0x3df8
testl %r14d, %r14d
movabsq $0x3ff0000000000000, %rsi # imm = 0x3FF0000000000000
jle 0x57f1
movq 0x88(%rsp), %rax
xorl %ecx, %ecx
movq (%rax,%rcx,8), %rdx
movq %rsi, (%rdx,%rcx,8)
incq %rcx
cmpq %rcx, %r13
jne 0x57e1
leaq 0xa8(%rsp), %rdi
movq %r12, %rsi
callq 0x67e4
movq %r12, %rdi
callq 0x4016
movl %ebx, %r14d
movl %ebx, %r13d
movq %r15, %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x51ec
movsd (%rax), %xmm0
movapd 0x6828(%rip), %xmm2     # 0xc050
andpd %xmm2, %xmm0
movapd 0x50(%rsp), %xmm1
andpd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x5856
movq %r15, %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x51ec
movsd (%rax), %xmm0
movapd %xmm0, 0x50(%rsp)
movl %r14d, %r13d
movq 0xd8(%rsp), %rax
addl %r14d, %eax
incl %eax
movl %r14d, %ecx
incl %ecx
movl %ecx, %r14d
cmpl $0x1, %eax
jne 0x580f
cmpl %ebx, %r13d
movl 0x28(%rsp), %r14d
je 0x5b88
leaq 0x168(%rsp), %rax
movq %rax, 0x158(%rsp)
leaq 0x158(%rsp), %rdi
leaq 0x6aec(%rip), %rsi      # 0xc389
leaq 0x6aeb(%rip), %rdx      # 0xc38f
callq 0x3c6e
movq %r12, %rdi
movq %r15, %rsi
movl %ebx, %edx
movl %ebx, %ecx
movl $0x1, %r8d
movl 0x2c(%rsp), %r9d
callq 0x43be
movq 0x158(%rsp), %rdi
leaq 0x168(%rsp), %rax
cmpq %rax, %rdi
je 0x58dd
callq 0x2110
leaq 0x148(%rsp), %rax
movq %rax, 0x138(%rsp)
leaq 0x138(%rsp), %rdi
leaq 0x6cea(%rip), %rsi      # 0xc5e6
leaq 0x6ce9(%rip), %rdx      # 0xc5ec
callq 0x3c6e
leaq 0x198(%rsp), %rdi
movq %r15, %rsi
movl %r13d, %edx
movl %r13d, %ecx
movl $0x1, %r8d
movl 0x2c(%rsp), %r14d
movl %r14d, %r9d
callq 0x43be
movq %r15, %rdi
movl %ebx, %esi
movl %ebx, %edx
movl $0x1, %ecx
movl %r14d, %r8d
leaq 0x198(%rsp), %r14
movq %r14, %r9
callq 0x49d8
movq %r14, %rdi
callq 0x2970
movq 0x138(%rsp), %rdi
leaq 0x148(%rsp), %rax
cmpq %rax, %rdi
je 0x596d
callq 0x2110
leaq 0x1a8(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x2918
movq %r15, %rdi
movl %r13d, %esi
movl %r13d, %edx
movl $0x1, %ecx
movl 0x2c(%rsp), %r8d
movq %r14, %r9
callq 0x49d8
movq %r14, %rdi
callq 0x2970
leaq 0x128(%rsp), %rax
movq %rax, 0x118(%rsp)
leaq 0x118(%rsp), %rdi
leaq 0x69c7(%rip), %rsi      # 0xc389
leaq 0x69c6(%rip), %rdx      # 0xc38f
callq 0x3c6e
leaq 0x78(%rsp), %rdi
leaq 0x38(%rsp), %rsi
movl %ebx, %edx
movl %ebx, %ecx
movl $0x1, %r8d
movl 0x28(%rsp), %r9d
callq 0x43be
leaq 0x188(%rsp), %r14
movq 0x118(%rsp), %rdi
leaq 0x128(%rsp), %rax
cmpq %rax, %rdi
je 0x5a0e
callq 0x2110
leaq 0x108(%rsp), %rax
movq %rax, 0xf8(%rsp)
leaq 0xf8(%rsp), %rdi
leaq 0x6bb9(%rip), %rsi      # 0xc5e6
leaq 0x6bb8(%rip), %rdx      # 0xc5ec
callq 0x3c6e
movq %r14, %rdi
leaq 0x38(%rsp), %rsi
movl %r13d, %edx
movl %r13d, %ecx
movl $0x1, %r8d
movl 0x28(%rsp), %r14d
movl %r14d, %r9d
callq 0x43be
leaq 0x38(%rsp), %rdi
movl %ebx, %esi
movl %ebx, %edx
movl $0x1, %ecx
movl %r14d, %r8d
leaq 0x188(%rsp), %r14
movq %r14, %r9
callq 0x49d8
movq %r14, %rdi
callq 0x2970
movq 0xf8(%rsp), %rdi
leaq 0x108(%rsp), %rax
cmpq %rax, %rdi
je 0x5a9d
callq 0x2110
leaq 0x178(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x2918
leaq 0x38(%rsp), %rdi
movl %r13d, %esi
movl %r13d, %edx
movl $0x1, %ecx
movl 0x28(%rsp), %r8d
leaq 0x178(%rsp), %r14
movq %r14, %r9
callq 0x49d8
movq %r14, %rdi
callq 0x2970
leaq 0xa8(%rsp), %r14
movq %r14, %rdi
movl %r13d, %esi
movl %r13d, %edx
callq 0x51ec
movq $0x0, (%rax)
movq %r14, %rdi
movl %ebx, %esi
movl %ebx, %edx
callq 0x51ec
movq $0x0, (%rax)
movq %r14, %rdi
movl %r13d, %esi
movl %ebx, %edx
callq 0x51ec
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, (%rax)
movq %r14, %rdi
movl %ebx, %esi
movl %r13d, %edx
callq 0x51ec
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, (%rax)
leaq 0xb8(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
leaq 0x98(%rsp), %r14
movq %r14, %rdx
callq 0x4eee
movq %r14, %rdi
movq %r13, %rsi
callq 0x67e4
movq %r13, %rdi
callq 0x4016
leaq 0x78(%rsp), %rdi
callq 0x2970
movq %r12, %rdi
callq 0x2970
movl 0x28(%rsp), %r14d
movq %r12, %rdi
movl %r14d, %esi
movl %r14d, %edx
callq 0x3df8
testl %r14d, %r14d
movq 0x68(%rsp), %rsi
movabsq $0x3ff0000000000000, %rdi # imm = 0x3FF0000000000000
jle 0x5bc4
movq 0x88(%rsp), %rax
xorl %ecx, %ecx
movq (%rax,%rcx,8), %rdx
movq %rdi, (%rdx,%rcx,8)
incq %rcx
cmpq %rcx, %rsi
jne 0x5bb4
leal 0x1(%rbx), %eax
movl %eax, 0x34(%rsp)
movl %eax, %r13d
movq %r15, %rdi
movl %r13d, %esi
movl %ebx, %edx
callq 0x51ec
movsd (%rax), %xmm0
movsd %xmm0, 0x50(%rsp)
movq %r15, %rdi
movl %ebx, %esi
movl %ebx, %edx
callq 0x51ec
movsd (%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movq %r12, %rdi
movl %r13d, %esi
movl %ebx, %edx
callq 0x51ec
movsd 0x50(%rsp), %xmm0
divsd 0x48(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x34(%rsp), %eax
movl %eax, %r14d
cmpl 0x2c(%rsp), %ebx
jge 0x5cb4
movq %r15, %rdi
movl %r13d, %esi
movl %r14d, %edx
callq 0x51ec
movsd (%rax), %xmm0
movsd %xmm0, 0x50(%rsp)
movq %r12, %rdi
movl %r13d, %esi
movl %ebx, %edx
callq 0x51ec
movsd (%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movq %r15, %rdi
movl %ebx, %esi
movl %r14d, %edx
callq 0x51ec
movsd (%rax), %xmm0
movsd %xmm0, 0xe0(%rsp)
movq %r15, %rdi
movl %r13d, %esi
movl %r14d, %edx
callq 0x51ec
movsd 0x48(%rsp), %xmm1
mulsd 0xe0(%rsp), %xmm1
movsd 0x50(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax)
leal (%r14,%rbp), %eax
incl %eax
movl %r14d, %ecx
incl %ecx
movl %ecx, %r14d
cmpl $0x1, %eax
jne 0x5c29
movq %r15, %rdi
movl %r13d, %esi
movl %ebx, %edx
callq 0x51ec
movq 0x70(%rsp), %r14
movq $0x0, (%rax)
leal 0x1(%r13), %eax
cmpl 0x28(%rsp), %r13d
movl %eax, %r13d
jne 0x5bce
leaq 0xb8(%rsp), %r13
movq %r13, %rdi
leaq 0x38(%rsp), %rsi
leaq 0xa8(%rsp), %rdx
callq 0x4eee
leaq 0x78(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x4eee
movq 0x68(%rsp), %r13
leaq 0x38(%rsp), %rdi
movq %rbx, %rsi
callq 0x67e4
movq %rbx, %rdi
callq 0x4016
leaq 0xb8(%rsp), %rdi
callq 0x4016
movq %r12, %rdi
callq 0x4016
movl 0x34(%rsp), %eax
movl %eax, %ebx
cmpl 0x28(%rsp), %eax
jne 0x579f
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x31(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x32(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x33(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0xb8(%rsp), %rax
movq %rax, (%rsp)
leaq 0x38(%rsp), %rsi
leaq 0xc8(%rsp), %rdx
leaq 0x98(%rsp), %rcx
leaq 0x88(%rsp), %r8
leaq 0x78(%rsp), %r9
movq %r14, %rdi
callq 0xb196
leaq 0x38(%rsp), %rdi
callq 0x4016
leaq 0x98(%rsp), %rdi
callq 0x4016
leaq 0xa8(%rsp), %rdi
callq 0x4016
leaq 0xc8(%rsp), %rdi
callq 0x4016
leaq 0xe8(%rsp), %rdi
callq 0x2970
movq %r14, %rax
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5f38
movq %rax, %rbx
jmp 0x5f59
movq %rax, %rbx
jmp 0x5f66
movq %rax, %rbx
jmp 0x5f73
jmp 0x5e20
jmp 0x5e20
movq %rax, %rbx
jmp 0x5f80
jmp 0x5e3b
jmp 0x5e3b
jmp 0x5f38
jmp 0x5f1c
jmp 0x5f1c
movq %rax, %rbx
jmp 0x5f29
movq %rax, %rbx
leaq 0x188(%rsp), %rdi
callq 0x2970
jmp 0x5eb5
movq %rax, %rbx
leaq 0x198(%rsp), %rdi
callq 0x2970
jmp 0x5ed4
movq %rax, %rbx
leaq 0x1a8(%rsp), %rdi
jmp 0x5f24
movq %rax, %rbx
movq 0x118(%rsp), %rdi
leaq 0x128(%rsp), %rax
jmp 0x5ee4
movq %rax, %rbx
movq 0x158(%rsp), %rdi
leaq 0x168(%rsp), %rax
cmpq %rax, %rdi
je 0x5f4f
callq 0x2110
jmp 0x5f4f
movq %rax, %rbx
movq 0xf8(%rsp), %rdi
leaq 0x108(%rsp), %rax
cmpq %rax, %rdi
je 0x5f1f
callq 0x2110
jmp 0x5f1f
movq %rax, %rbx
movq 0x138(%rsp), %rdi
leaq 0x148(%rsp), %rax
cmpq %rax, %rdi
je 0x5f29
callq 0x2110
jmp 0x5f29
movq %rax, %rbx
leaq 0x178(%rsp), %rdi
callq 0x2970
jmp 0x5f1f
jmp 0x5f3f
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x4016
jmp 0x5f42
jmp 0x5f38
jmp 0x5f38
jmp 0x5f38
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x2970
leaq 0x88(%rsp), %rdi
callq 0x2970
jmp 0x5f4f
movq %rax, %rbx
jmp 0x5f4f
jmp 0x5f3f
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x4016
leaq 0x38(%rsp), %rdi
callq 0x4016
leaq 0x98(%rsp), %rdi
callq 0x4016
leaq 0xa8(%rsp), %rdi
callq 0x4016
leaq 0xc8(%rsp), %rdi
callq 0x4016
leaq 0xe8(%rsp), %rdi
callq 0x2970
movq %rbx, %rdi
callq 0x21c0