// File: IlanPrice[P]Linear-Algebra-Library-in-Cplusplus/Matrix.cpp
// Function: QR(Matrix const&)
std::pair <Matrix,Matrix> QR(const Matrix& A)
{
	int Rrows = A.mRows;
	int Rcolumns = A.mColumns;
	int t = std::min(Rrows,Rcolumns);
	Matrix R = A;
	Matrix Q = eye(Rrows);
	Vector u = R.getElements(1,Rrows,1,1,"Vector");
	Vector v(length(u));
	v(1) = norm(u,2);
	Vector w = u-v;
	Matrix H = eye(Rrows);
	if (norm(w,2)>1e-15)
		{
			Matrix temp = outer(w,w);
			H = H - (2/(w*w))*temp;
		}
	R = H*R;
	Q = Q*H;
	for (int i=2;i<t;i++)
	{
		Matrix B = R.getElements(i,Rrows,i, Rcolumns);
		Vector u2 = B.getElements(1,B.mRows,1,1,"Vector");
		Vector v2(length(u2));
		v2(1) = norm(u2,2);;
		Vector w2 = u2-v2;
		Matrix I2 = eye(B.mRows);
		Matrix temp2 = outer(w2,w2);
		Matrix H2 = eye(Rrows);
		if (norm(w2,2)>1e-15)
		{
		Matrix Hhat = I2 - (2/(w2*w2))*temp2;
		H2.setElements(i,Rrows,i,Rrows,Hhat);
		}
		R = H2*R;
		Q = Q*H2;
	}
	for (int i=1;i<=Rrows;i++)
	{
		for(int j=1;j<=Rcolumns;j++)
		{
			if (std::abs(R(i,j)) < 1e-14)
				{R(i,j) = 0;}
		}
	}
	std::pair<Matrix,Matrix> qr = std::make_pair(Q,R);
	return qr;

}

// Assembly:
subq $0x2f8, %rsp            # imm = 0x2F8
movq %rdi, 0xa0(%rsp)
movq %rdi, %rax
movq %rax, 0xa8(%rsp)
movq %rdi, 0x2f0(%rsp)
movq %rsi, 0x2e8(%rsp)
movq 0x2e8(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x2e4(%rsp)
movq 0x2e8(%rsp), %rax
movl 0xc(%rax), %eax
movl %eax, 0x2e0(%rsp)
leaq 0x2e4(%rsp), %rdi
leaq 0x2e0(%rsp), %rsi
callq 0x10e90
movl (%rax), %eax
movl %eax, 0x2dc(%rsp)
movq 0x2e8(%rsp), %rsi
leaq 0x2c8(%rsp), %rdi
callq 0x50f0
movl 0x2e4(%rsp), %esi
leaq 0x2b8(%rsp), %rdi
callq 0xa210
jmp 0xfa67
movl 0x2e4(%rsp), %eax
movl %eax, 0x94(%rsp)
leaq 0x277(%rsp), %rdi
movq %rdi, 0x98(%rsp)
callq 0x21c0
movq 0x98(%rsp), %rdx
leaq 0x2b15(%rip), %rsi      # 0x125ae
leaq 0x278(%rsp), %rdi
callq 0x2110
jmp 0xfaa8
movl 0x94(%rsp), %ecx
movq %rsp, %rax
leaq 0x278(%rsp), %rdx
movq %rdx, (%rax)
leaq 0x298(%rsp), %rdi
leaq 0x2c8(%rsp), %rsi
movl $0x1, %r9d
movl %r9d, %edx
movl %r9d, %r8d
callq 0x5870
jmp 0xfae0
leaq 0x278(%rsp), %rdi
callq 0x2080
leaq 0x277(%rsp), %rdi
callq 0x20f0
leaq 0x298(%rsp), %rdi
callq 0x4090
movl %eax, 0x90(%rsp)
jmp 0xfb10
movl 0x90(%rsp), %esi
leaq 0x260(%rsp), %rdi
callq 0x2d70
jmp 0xfb26
leaq 0x298(%rsp), %rdi
movl $0x2, %esi
callq 0x3fe0
movsd %xmm0, 0x88(%rsp)
jmp 0xfb43
leaq 0x260(%rsp), %rdi
movl $0x1, %esi
callq 0x3ee0
movq %rax, 0x80(%rsp)
jmp 0xfb5f
movq 0x80(%rsp), %rax
movsd 0x88(%rsp), %xmm0
movsd %xmm0, (%rax)
leaq 0x250(%rsp), %rdi
leaq 0x298(%rsp), %rsi
leaq 0x260(%rsp), %rdx
callq 0x31a0
jmp 0xfb93
movl 0x2e4(%rsp), %esi
leaq 0x240(%rsp), %rdi
callq 0xa210
jmp 0xfba9
leaq 0x250(%rsp), %rdi
movl $0x2, %esi
callq 0x3fe0
movsd %xmm0, 0x78(%rsp)
jmp 0xfbc3
movsd 0x78(%rsp), %xmm0
movsd 0x26df(%rip), %xmm1     # 0x122b0
ucomisd %xmm1, %xmm0
jbe 0xfe3b
leaq 0x220(%rsp), %rdi
leaq 0x250(%rsp), %rsi
callq 0x2e00
jmp 0xfbf2
leaq 0x210(%rsp), %rdi
leaq 0x250(%rsp), %rsi
callq 0x2e00
jmp 0xfc09
leaq 0x230(%rsp), %rdi
leaq 0x220(%rsp), %rsi
leaq 0x210(%rsp), %rdx
callq 0x9b50
jmp 0xfc28
leaq 0x210(%rsp), %rdi
callq 0x2ea0
leaq 0x220(%rsp), %rdi
callq 0x2ea0
leaq 0x250(%rsp), %rsi
movq %rsi, %rdi
callq 0x3470
movsd %xmm0, 0x70(%rsp)
jmp 0xfc5a
movsd 0x70(%rsp), %xmm1
movsd 0x2660(%rip), %xmm0     # 0x122c8
divsd %xmm1, %xmm0
leaq 0x1f0(%rsp), %rdi
leaq 0x230(%rsp), %rsi
callq 0x6ba0
jmp 0xfc83
leaq 0x200(%rsp), %rdi
leaq 0x240(%rsp), %rsi
leaq 0x1f0(%rsp), %rdx
callq 0x6a60
jmp 0xfca2
leaq 0x240(%rsp), %rdi
leaq 0x200(%rsp), %rsi
callq 0x9930
leaq 0x200(%rsp), %rdi
callq 0x5230
leaq 0x1f0(%rsp), %rdi
callq 0x5230
leaq 0x230(%rsp), %rdi
callq 0x5230
jmp 0xfe3b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x10684
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0xfd33
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
leaq 0x278(%rsp), %rdi
callq 0x2080
leaq 0x277(%rsp), %rdi
callq 0x20f0
jmp 0x10677
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x1066a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x1065d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x10650
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x10643
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0xfde0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
leaq 0x210(%rsp), %rdi
callq 0x2ea0
leaq 0x220(%rsp), %rdi
callq 0x2ea0
jmp 0x10643
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0xfe29
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
leaq 0x1f0(%rsp), %rdi
callq 0x5230
leaq 0x230(%rsp), %rdi
callq 0x5230
jmp 0x10643
leaq 0x1e0(%rsp), %rdi
leaq 0x240(%rsp), %rsi
leaq 0x2c8(%rsp), %rdx
callq 0x6cc0
jmp 0xfe5a
leaq 0x2c8(%rsp), %rdi
leaq 0x1e0(%rsp), %rsi
movq %rsi, 0x68(%rsp)
callq 0x9930
movq 0x68(%rsp), %rdi
callq 0x5230
leaq 0x1d0(%rsp), %rdi
leaq 0x2b8(%rsp), %rsi
leaq 0x240(%rsp), %rdx
callq 0x6cc0
jmp 0xfe9d
leaq 0x2b8(%rsp), %rdi
leaq 0x1d0(%rsp), %rsi
callq 0x9930
leaq 0x1d0(%rsp), %rdi
callq 0x5230
movl $0x2, 0x1cc(%rsp)
movl 0x1cc(%rsp), %eax
cmpl 0x2dc(%rsp), %eax
jge 0x104b7
movl 0x1cc(%rsp), %r8d
movl 0x2e4(%rsp), %ecx
movl 0x2e0(%rsp), %r9d
leaq 0x1b8(%rsp), %rdi
leaq 0x2c8(%rsp), %rsi
movl %r8d, %edx
callq 0x5440
jmp 0xff0f
movl 0x1c0(%rsp), %eax
movl %eax, 0x5c(%rsp)
leaq 0x187(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x21c0
movq 0x60(%rsp), %rdx
leaq 0x2676(%rip), %rsi      # 0x125ae
leaq 0x188(%rsp), %rdi
callq 0x2110
jmp 0xff47
movl 0x5c(%rsp), %ecx
movq %rsp, %rax
leaq 0x188(%rsp), %rdx
movq %rdx, (%rax)
leaq 0x1a8(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
movl $0x1, %r9d
movl %r9d, %edx
movl %r9d, %r8d
callq 0x5870
jmp 0xff7c
leaq 0x188(%rsp), %rdi
callq 0x2080
leaq 0x187(%rsp), %rdi
callq 0x20f0
leaq 0x1a8(%rsp), %rdi
callq 0x4090
movl %eax, 0x58(%rsp)
jmp 0xffa9
movl 0x58(%rsp), %esi
leaq 0x170(%rsp), %rdi
callq 0x2d70
jmp 0xffbc
leaq 0x1a8(%rsp), %rdi
movl $0x2, %esi
callq 0x3fe0
movsd %xmm0, 0x50(%rsp)
jmp 0xffd6
leaq 0x170(%rsp), %rdi
movl $0x1, %esi
callq 0x3ee0
movq %rax, 0x48(%rsp)
jmp 0xffef
movq 0x48(%rsp), %rax
movsd 0x50(%rsp), %xmm0
movsd %xmm0, (%rax)
leaq 0x160(%rsp), %rdi
leaq 0x1a8(%rsp), %rsi
leaq 0x170(%rsp), %rdx
callq 0x31a0
jmp 0x1001d
movl 0x1c0(%rsp), %esi
leaq 0x150(%rsp), %rdi
callq 0xa210
jmp 0x10033
leaq 0x130(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0x2e00
jmp 0x1004a
leaq 0x120(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0x2e00
jmp 0x10061
leaq 0x140(%rsp), %rdi
leaq 0x130(%rsp), %rsi
leaq 0x120(%rsp), %rdx
callq 0x9b50
jmp 0x10080
leaq 0x120(%rsp), %rdi
callq 0x2ea0
leaq 0x130(%rsp), %rdi
callq 0x2ea0
movl 0x2e4(%rsp), %esi
leaq 0x110(%rsp), %rdi
callq 0xa210
jmp 0x100b0
leaq 0x160(%rsp), %rdi
movl $0x2, %esi
callq 0x3fe0
movsd %xmm0, 0x40(%rsp)
jmp 0x100ca
movsd 0x40(%rsp), %xmm0
movsd 0x21d8(%rip), %xmm1     # 0x122b0
ucomisd %xmm1, %xmm0
jbe 0x10362
leaq 0x160(%rsp), %rsi
movq %rsi, %rdi
callq 0x3470
movsd %xmm0, 0x38(%rsp)
jmp 0x100fa
movsd 0x38(%rsp), %xmm1
movsd 0x21c0(%rip), %xmm0     # 0x122c8
divsd %xmm1, %xmm0
leaq 0xf0(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x6ba0
jmp 0x10123
leaq 0x100(%rsp), %rdi
leaq 0x150(%rsp), %rsi
leaq 0xf0(%rsp), %rdx
callq 0x6a60
jmp 0x10142
leaq 0xf0(%rsp), %rdi
callq 0x5230
movl 0x1cc(%rsp), %eax
movl %eax, 0x28(%rsp)
movl %eax, 0x2c(%rsp)
movl 0x2e4(%rsp), %eax
movl %eax, 0x30(%rsp)
movl %eax, 0x34(%rsp)
leaq 0xe0(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x50f0
jmp 0x10184
movl 0x30(%rsp), %r8d
movl 0x28(%rsp), %ecx
movl 0x34(%rsp), %edx
movl 0x2c(%rsp), %esi
leaq 0x110(%rsp), %rdi
leaq 0xe0(%rsp), %r9
callq 0x5f20
jmp 0x101ac
leaq 0xe0(%rsp), %rdi
callq 0x5230
leaq 0x100(%rsp), %rdi
callq 0x5230
jmp 0x10362
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x10202
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
leaq 0x188(%rsp), %rdi
callq 0x2080
leaq 0x187(%rsp), %rdi
callq 0x20f0
jmp 0x104a5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x10498
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x1048b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x1047e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x10471
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x102af
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
leaq 0x120(%rsp), %rdi
callq 0x2ea0
leaq 0x130(%rsp), %rdi
callq 0x2ea0
jmp 0x10471
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x10464
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x10457
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0x5230
jmp 0x10457
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x10350
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x5230
leaq 0x100(%rsp), %rdi
callq 0x5230
jmp 0x10457
leaq 0xd0(%rsp), %rdi
leaq 0x110(%rsp), %rsi
leaq 0x2c8(%rsp), %rdx
callq 0x6cc0
jmp 0x10381
leaq 0x2c8(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
movq %rsi, 0x20(%rsp)
callq 0x9930
movq 0x20(%rsp), %rdi
callq 0x5230
leaq 0xc0(%rsp), %rdi
leaq 0x2b8(%rsp), %rsi
leaq 0x110(%rsp), %rdx
callq 0x6cc0
jmp 0x103c4
leaq 0x2b8(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x9930
leaq 0xc0(%rsp), %rdi
callq 0x5230
leaq 0x110(%rsp), %rdi
callq 0x5230
leaq 0x140(%rsp), %rdi
callq 0x5230
leaq 0x150(%rsp), %rdi
callq 0x5230
leaq 0x160(%rsp), %rdi
callq 0x2ea0
leaq 0x170(%rsp), %rdi
callq 0x2ea0
leaq 0x1a8(%rsp), %rdi
callq 0x2ea0
leaq 0x1b8(%rsp), %rdi
callq 0x5230
movl 0x1cc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1cc(%rsp)
jmp 0xfeca
leaq 0x110(%rsp), %rdi
callq 0x5230
leaq 0x140(%rsp), %rdi
callq 0x5230
leaq 0x150(%rsp), %rdi
callq 0x5230
leaq 0x160(%rsp), %rdi
callq 0x2ea0
leaq 0x170(%rsp), %rdi
callq 0x2ea0
leaq 0x1a8(%rsp), %rdi
callq 0x2ea0
leaq 0x1b8(%rsp), %rdi
callq 0x5230
jmp 0x10643
movl $0x1, 0xbc(%rsp)
movl 0xbc(%rsp), %eax
cmpl 0x2e4(%rsp), %eax
jg 0x1059f
movl $0x1, 0xb8(%rsp)
movl 0xb8(%rsp), %eax
cmpl 0x2e0(%rsp), %eax
jg 0x10587
movl 0xbc(%rsp), %esi
movl 0xb8(%rsp), %edx
leaq 0x2c8(%rsp), %rdi
callq 0x96e0
movq %rax, 0x18(%rsp)
jmp 0x10517
movq 0x18(%rsp), %rax
movsd (%rax), %xmm0
callq 0x10e30
movsd %xmm0, 0x10(%rsp)
jmp 0x1052d
movsd 0x10(%rsp), %xmm1
movsd 0x1d7d(%rip), %xmm0     # 0x122b8
ucomisd %xmm1, %xmm0
jbe 0x1056f
movl 0xbc(%rsp), %esi
movl 0xb8(%rsp), %edx
leaq 0x2c8(%rsp), %rdi
callq 0x96e0
movq %rax, 0x8(%rsp)
jmp 0x10563
movq 0x8(%rsp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
jmp 0x10571
movl 0xb8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb8(%rsp)
jmp 0x104e1
jmp 0x10589
movl 0xbc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xbc(%rsp)
jmp 0x104c2
movq 0xa0(%rsp), %rdi
movb $0x0, 0xb7(%rsp)
leaq 0x2b8(%rsp), %rsi
leaq 0x2c8(%rsp), %rdx
callq 0x10ed0
jmp 0x105c6
movb $0x1, 0xb7(%rsp)
testb $0x1, 0xb7(%rsp)
jne 0x105e5
movq 0xa0(%rsp), %rdi
callq 0x10f10
leaq 0x240(%rsp), %rdi
callq 0x5230
leaq 0x250(%rsp), %rdi
callq 0x2ea0
leaq 0x260(%rsp), %rdi
callq 0x2ea0
leaq 0x298(%rsp), %rdi
callq 0x2ea0
leaq 0x2b8(%rsp), %rdi
callq 0x5230
leaq 0x2c8(%rsp), %rdi
callq 0x5230
movq 0xa8(%rsp), %rax
addq $0x2f8, %rsp            # imm = 0x2F8
retq
leaq 0x240(%rsp), %rdi
callq 0x5230
leaq 0x250(%rsp), %rdi
callq 0x2ea0
leaq 0x260(%rsp), %rdi
callq 0x2ea0
leaq 0x298(%rsp), %rdi
callq 0x2ea0
leaq 0x2b8(%rsp), %rdi
callq 0x5230
leaq 0x2c8(%rsp), %rdi
callq 0x5230
movq 0x2b0(%rsp), %rdi
callq 0x21b0
nop