// File: 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:
subq $0x368, %rsp            # imm = 0x368
movq %rdi, 0x150(%rsp)
movq %rdi, %rax
movq %rax, 0x158(%rsp)
movq %rdi, 0x360(%rsp)
movq %rsi, 0x358(%rsp)
movq 0x358(%rsp), %rsi
leaq 0x348(%rsp), %rdi
movq %rdi, 0x160(%rsp)
callq 0xa130
movq 0x160(%rsp), %rdi
movl $0x1, %esi
callq 0x3ee0
movq %rax, 0x168(%rsp)
jmp 0x7b03
movq 0x168(%rsp), %rax
cvttsd2si (%rax), %eax
movl %eax, 0x344(%rsp)
leaq 0x348(%rsp), %rdi
movl $0x2, %esi
callq 0x3ee0
movq %rax, 0x148(%rsp)
jmp 0x7b32
movq 0x148(%rsp), %rax
cvttsd2si (%rax), %eax
movl %eax, 0x330(%rsp)
movq 0x358(%rsp), %rsi
leaq 0x320(%rsp), %rdi
callq 0x50f0
jmp 0x7b5c
movl 0x344(%rsp), %edx
leaq 0x310(%rsp), %rdi
movl %edx, %esi
callq 0x4e80
jmp 0x7b74
movl 0x344(%rsp), %esi
leaq 0x300(%rsp), %rdi
callq 0xa210
jmp 0x7b8a
movl 0x344(%rsp), %esi
leaq 0x2f0(%rsp), %rdi
callq 0xa210
jmp 0x7ba0
movl $0x1, 0x2ec(%rsp)
movl 0x2ec(%rsp), %eax
cmpl 0x344(%rsp), %eax
jge 0x8859
movl 0x2ec(%rsp), %edx
leaq 0x320(%rsp), %rdi
movl %edx, %esi
callq 0x96e0
movq %rax, 0x140(%rsp)
jmp 0x7bdf
movq 0x140(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x2e0(%rsp)
movl 0x2ec(%rsp), %eax
movl %eax, 0x2dc(%rsp)
movl 0x344(%rsp), %esi
leaq 0x2c8(%rsp), %rdi
callq 0xa210
jmp 0x7c18
leaq 0x310(%rsp), %rdi
leaq 0x2c8(%rsp), %rsi
callq 0x9930
leaq 0x2c8(%rsp), %rdi
callq 0x5230
movl 0x2ec(%rsp), %eax
movl %eax, 0x2c4(%rsp)
movl 0x2c4(%rsp), %eax
cmpl 0x344(%rsp), %eax
jg 0x7db1
movl 0x2c4(%rsp), %esi
movl 0x2ec(%rsp), %edx
leaq 0x320(%rsp), %rdi
callq 0x96e0
movq %rax, 0x138(%rsp)
jmp 0x7c81
movq 0x138(%rsp), %rax
movsd (%rax), %xmm0
callq 0x10e30
movsd %xmm0, 0x130(%rsp)
jmp 0x7c9d
movsd 0x2e0(%rsp), %xmm0
callq 0x10e30
movsd %xmm0, 0x128(%rsp)
jmp 0x7cb6
movsd 0x130(%rsp), %xmm0
movsd 0x128(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x7d99
movl 0x2c4(%rsp), %eax
movl %eax, 0x2dc(%rsp)
movl 0x2c4(%rsp), %esi
movl 0x2ec(%rsp), %edx
leaq 0x320(%rsp), %rdi
callq 0x96e0
movq %rax, 0x120(%rsp)
jmp 0x7d05
movq 0x120(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x2e0(%rsp)
jmp 0x7d99
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
jmp 0x892c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
jmp 0x891f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
jmp 0x8912
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
jmp 0x8905
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
jmp 0x88f8
jmp 0x7d9b
movl 0x2c4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c4(%rsp)
jmp 0x7c48
movl 0x2dc(%rsp), %eax
cmpl 0x2ec(%rsp), %eax
je 0x8553
movl 0x2ec(%rsp), %eax
movl %eax, 0x10c(%rsp)
movl %eax, 0x110(%rsp)
movl 0x330(%rsp), %eax
movl %eax, 0x114(%rsp)
leaq 0x28f(%rsp), %rdi
movq %rdi, 0x118(%rsp)
callq 0x21c0
movq 0x118(%rsp), %rdx
leaq 0xa545(%rip), %rsi      # 0x12351
leaq 0x290(%rsp), %rdi
callq 0x2110
jmp 0x7e1b
movl 0x114(%rsp), %r9d
movl 0x10c(%rsp), %ecx
movl 0x110(%rsp), %edx
movq %rsp, %rax
leaq 0x290(%rsp), %rsi
movq %rsi, (%rax)
leaq 0x2b0(%rsp), %rdi
leaq 0x320(%rsp), %rsi
movl $0x1, %r8d
callq 0x5870
jmp 0x7e5c
leaq 0x290(%rsp), %rdi
callq 0x2080
leaq 0x28f(%rsp), %rdi
callq 0x20f0
movl 0x2ec(%rsp), %eax
movl %eax, 0xe8(%rsp)
movl %eax, 0xec(%rsp)
movl 0x330(%rsp), %eax
movl %eax, 0xf0(%rsp)
movl %eax, 0xf4(%rsp)
movl 0x2dc(%rsp), %eax
movl %eax, 0xf8(%rsp)
movl %eax, 0xfc(%rsp)
leaq 0x257(%rsp), %rdi
movq %rdi, 0x100(%rsp)
callq 0x21c0
movq 0x100(%rsp), %rdx
leaq 0xa6d5(%rip), %rsi      # 0x125ae
leaq 0x258(%rsp), %rdi
callq 0x2110
jmp 0x7ee8
movl 0xf0(%rsp), %r9d
movl 0xf8(%rsp), %ecx
movl 0xfc(%rsp), %edx
movq %rsp, %rax
leaq 0x258(%rsp), %rsi
movq %rsi, (%rax)
leaq 0x278(%rsp), %rdi
leaq 0x320(%rsp), %rsi
movl $0x1, %r8d
callq 0x5870
jmp 0x7f29
movl 0xf4(%rsp), %r8d
movl 0xe8(%rsp), %edx
movl 0xec(%rsp), %esi
leaq 0x320(%rsp), %rdi
movl $0x1, %ecx
leaq 0x278(%rsp), %r9
callq 0x6340
jmp 0x7f5b
leaq 0x278(%rsp), %rdi
callq 0x2ea0
leaq 0x258(%rsp), %rdi
callq 0x2080
leaq 0x257(%rsp), %rdi
callq 0x20f0
movl 0x2dc(%rsp), %eax
movl %eax, 0xdc(%rsp)
movl %eax, 0xe0(%rsp)
movl 0x330(%rsp), %eax
movl %eax, 0xe4(%rsp)
leaq 0x240(%rsp), %rdi
leaq 0x2b0(%rsp), %rsi
callq 0x2e00
jmp 0x7fbc
movl 0xe4(%rsp), %r8d
movl 0xdc(%rsp), %edx
movl 0xe0(%rsp), %esi
leaq 0x320(%rsp), %rdi
movl $0x1, %ecx
leaq 0x240(%rsp), %r9
callq 0x6340
jmp 0x7fee
leaq 0x240(%rsp), %rdi
callq 0x2ea0
movl 0x2ec(%rsp), %eax
movl %eax, 0xc4(%rsp)
movl %eax, 0xc8(%rsp)
movl 0x344(%rsp), %eax
movl %eax, 0xcc(%rsp)
leaq 0x20f(%rsp), %rdi
movq %rdi, 0xd0(%rsp)
callq 0x21c0
movq 0xd0(%rsp), %rdx
leaq 0xa30f(%rip), %rsi      # 0x12351
leaq 0x210(%rsp), %rdi
callq 0x2110
jmp 0x8051
movl 0xcc(%rsp), %r9d
movl 0xc4(%rsp), %ecx
movl 0xc8(%rsp), %edx
movq %rsp, %rax
leaq 0x210(%rsp), %rsi
movq %rsi, (%rax)
leaq 0x230(%rsp), %rdi
leaq 0x2f0(%rsp), %rsi
movl $0x1, %r8d
callq 0x5870
jmp 0x8092
leaq 0x210(%rsp), %rdi
callq 0x2080
leaq 0x20f(%rsp), %rdi
callq 0x20f0
movl 0x2ec(%rsp), %eax
movl %eax, 0xa0(%rsp)
movl %eax, 0xa4(%rsp)
movl 0x344(%rsp), %eax
movl %eax, 0xa8(%rsp)
movl %eax, 0xac(%rsp)
movl 0x2dc(%rsp), %eax
movl %eax, 0xb0(%rsp)
movl %eax, 0xb4(%rsp)
leaq 0x1d7(%rsp), %rdi
movq %rdi, 0xb8(%rsp)
callq 0x21c0
movq 0xb8(%rsp), %rdx
leaq 0xa49f(%rip), %rsi      # 0x125ae
leaq 0x1d8(%rsp), %rdi
callq 0x2110
jmp 0x811e
movl 0xa8(%rsp), %r9d
movl 0xb0(%rsp), %ecx
movl 0xb4(%rsp), %edx
movq %rsp, %rax
leaq 0x1d8(%rsp), %rsi
movq %rsi, (%rax)
leaq 0x1f8(%rsp), %rdi
leaq 0x2f0(%rsp), %rsi
movl $0x1, %r8d
callq 0x5870
jmp 0x815f
movl 0xac(%rsp), %r8d
movl 0xa0(%rsp), %edx
movl 0xa4(%rsp), %esi
leaq 0x2f0(%rsp), %rdi
movl $0x1, %ecx
leaq 0x1f8(%rsp), %r9
callq 0x6340
jmp 0x8191
leaq 0x1f8(%rsp), %rdi
callq 0x2ea0
leaq 0x1d8(%rsp), %rdi
callq 0x2080
leaq 0x1d7(%rsp), %rdi
callq 0x20f0
movl 0x2dc(%rsp), %eax
movl %eax, 0x94(%rsp)
movl %eax, 0x98(%rsp)
movl 0x344(%rsp), %eax
movl %eax, 0x9c(%rsp)
leaq 0x1c0(%rsp), %rdi
leaq 0x230(%rsp), %rsi
callq 0x2e00
jmp 0x81f2
movl 0x9c(%rsp), %r8d
movl 0x94(%rsp), %edx
movl 0x98(%rsp), %esi
leaq 0x2f0(%rsp), %rdi
movl $0x1, %ecx
leaq 0x1c0(%rsp), %r9
callq 0x6340
jmp 0x8224
leaq 0x1c0(%rsp), %rdi
callq 0x2ea0
movl 0x2dc(%rsp), %edx
leaq 0x310(%rsp), %rdi
movl %edx, %esi
callq 0x96e0
movq %rax, 0x88(%rsp)
jmp 0x8251
movq 0x88(%rsp), %rax
movq $0x0, (%rax)
movl 0x2ec(%rsp), %edx
leaq 0x310(%rsp), %rdi
movl %edx, %esi
callq 0x96e0
movq %rax, 0x80(%rsp)
jmp 0x8280
movq 0x80(%rsp), %rax
movq $0x0, (%rax)
movl 0x2dc(%rsp), %esi
movl 0x2ec(%rsp), %edx
leaq 0x310(%rsp), %rdi
callq 0x96e0
movq %rax, 0x78(%rsp)
jmp 0x82b1
movq 0x78(%rsp), %rax
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, (%rax)
movl 0x2ec(%rsp), %esi
movl 0x2dc(%rsp), %edx
leaq 0x310(%rsp), %rdi
callq 0x96e0
movq %rax, 0x70(%rsp)
jmp 0x82e5
movq 0x70(%rsp), %rax
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, (%rax)
leaq 0x1b0(%rsp), %rdi
leaq 0x310(%rsp), %rsi
leaq 0x300(%rsp), %rdx
callq 0x6cc0
jmp 0x8316
leaq 0x300(%rsp), %rdi
leaq 0x1b0(%rsp), %rsi
callq 0x9930
leaq 0x1b0(%rsp), %rdi
callq 0x5230
leaq 0x230(%rsp), %rdi
callq 0x2ea0
leaq 0x2b0(%rsp), %rdi
callq 0x2ea0
jmp 0x8553
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
jmp 0x838e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
leaq 0x290(%rsp), %rdi
callq 0x2080
leaq 0x28f(%rsp), %rdi
callq 0x20f0
jmp 0x88f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
jmp 0x83fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
jmp 0x83ed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
leaq 0x278(%rsp), %rdi
callq 0x2ea0
leaq 0x258(%rsp), %rdi
callq 0x2080
leaq 0x257(%rsp), %rdi
callq 0x20f0
jmp 0x8541
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
jmp 0x8541
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
leaq 0x240(%rsp), %rdi
callq 0x2ea0
jmp 0x8541
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
jmp 0x8482
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
leaq 0x210(%rsp), %rdi
callq 0x2080
leaq 0x20f(%rsp), %rdi
callq 0x20f0
jmp 0x8541
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
jmp 0x84ee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
jmp 0x84e1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
leaq 0x1f8(%rsp), %rdi
callq 0x2ea0
leaq 0x1d8(%rsp), %rdi
callq 0x2080
leaq 0x1d7(%rsp), %rdi
callq 0x20f0
jmp 0x8534
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
jmp 0x8534
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0x2ea0
leaq 0x230(%rsp), %rdi
callq 0x2ea0
leaq 0x2b0(%rsp), %rdi
callq 0x2ea0
jmp 0x88f8
movl 0x344(%rsp), %esi
leaq 0x1a0(%rsp), %rdi
callq 0xa210
jmp 0x8569
movl 0x2ec(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x19c(%rsp)
movl 0x19c(%rsp), %eax
cmpl 0x344(%rsp), %eax
jg 0x8796
movl 0x19c(%rsp), %esi
movl 0x2ec(%rsp), %edx
leaq 0x320(%rsp), %rdi
callq 0x96e0
movq %rax, 0x68(%rsp)
jmp 0x85b0
movq 0x68(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x58(%rsp)
movl 0x2ec(%rsp), %edx
leaq 0x320(%rsp), %rdi
movl %edx, %esi
callq 0x96e0
movq %rax, 0x60(%rsp)
jmp 0x85dc
movsd 0x58(%rsp), %xmm0
movq 0x60(%rsp), %rax
movsd (%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
movl 0x19c(%rsp), %esi
movl 0x2ec(%rsp), %edx
leaq 0x1a0(%rsp), %rdi
callq 0x96e0
movq %rax, 0x50(%rsp)
jmp 0x8617
movq 0x50(%rsp), %rax
movsd 0x48(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x2ec(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x198(%rsp)
movl 0x198(%rsp), %eax
cmpl 0x330(%rsp), %eax
jg 0x8752
movl 0x19c(%rsp), %esi
movl 0x198(%rsp), %edx
leaq 0x320(%rsp), %rdi
callq 0x96e0
movq %rax, 0x40(%rsp)
jmp 0x866d
movq 0x40(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movl 0x19c(%rsp), %esi
movl 0x2ec(%rsp), %edx
leaq 0x1a0(%rsp), %rdi
callq 0x96e0
movq %rax, 0x38(%rsp)
jmp 0x869e
movq 0x38(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movl 0x2ec(%rsp), %esi
movl 0x198(%rsp), %edx
leaq 0x320(%rsp), %rdi
callq 0x96e0
movq %rax, 0x28(%rsp)
jmp 0x86cf
movsd 0x30(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movq 0x28(%rsp), %rax
movsd (%rax), %xmm2
mulsd %xmm2, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movl 0x19c(%rsp), %esi
movl 0x198(%rsp), %edx
leaq 0x320(%rsp), %rdi
callq 0x96e0
movq %rax, 0x18(%rsp)
jmp 0x8714
movq 0x18(%rsp), %rax
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x198(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x198(%rsp)
jmp 0x8637
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
jmp 0x8847
movl 0x19c(%rsp), %esi
movl 0x2ec(%rsp), %edx
leaq 0x320(%rsp), %rdi
callq 0x96e0
movq %rax, 0x8(%rsp)
jmp 0x8774
movq 0x8(%rsp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movl 0x19c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x19c(%rsp)
jmp 0x857a
leaq 0x178(%rsp), %rdi
leaq 0x2f0(%rsp), %rsi
leaq 0x310(%rsp), %rdx
callq 0x6cc0
jmp 0x87b5
leaq 0x188(%rsp), %rdi
leaq 0x178(%rsp), %rsi
leaq 0x1a0(%rsp), %rdx
callq 0x6cc0
jmp 0x87d4
leaq 0x2f0(%rsp), %rdi
leaq 0x188(%rsp), %rsi
callq 0x9930
leaq 0x188(%rsp), %rdi
callq 0x5230
leaq 0x178(%rsp), %rdi
callq 0x5230
leaq 0x1a0(%rsp), %rdi
callq 0x5230
movl 0x2ec(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2ec(%rsp)
jmp 0x7bab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
leaq 0x178(%rsp), %rdi
callq 0x5230
leaq 0x1a0(%rsp), %rdi
callq 0x5230
jmp 0x88f8
movq 0x150(%rsp), %rdi
movb $0x0, 0x177(%rsp)
leaq 0x2f0(%rsp), %rsi
leaq 0x320(%rsp), %rdx
leaq 0x300(%rsp), %rcx
callq 0x10e50
jmp 0x8888
movb $0x1, 0x177(%rsp)
testb $0x1, 0x177(%rsp)
jne 0x88a7
movq 0x150(%rsp), %rdi
callq 0x10e00
leaq 0x2f0(%rsp), %rdi
callq 0x5230
leaq 0x300(%rsp), %rdi
callq 0x5230
leaq 0x310(%rsp), %rdi
callq 0x5230
leaq 0x320(%rsp), %rdi
callq 0x5230
leaq 0x348(%rsp), %rdi
callq 0x2ea0
movq 0x158(%rsp), %rax
addq $0x368, %rsp            # imm = 0x368
retq
leaq 0x2f0(%rsp), %rdi
callq 0x5230
leaq 0x300(%rsp), %rdi
callq 0x5230
leaq 0x310(%rsp), %rdi
callq 0x5230
leaq 0x320(%rsp), %rdi
callq 0x5230
leaq 0x348(%rsp), %rdi
callq 0x2ea0
movq 0x338(%rsp), %rdi
callq 0x21b0
nopw %cs:(%rax,%rax)