// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movq %rdi, %r15
movl 0x8(%rsi), %ebx
movl 0xc(%rsi), %r14d
cmpl %ebx, %r14d
movl %ebx, %eax
cmovll %r14d, %eax
movl %eax, 0x44(%rsp)
leaq 0x28(%rsp), %rdi
callq 0x29b2
leaq 0x78(%rsp), %rdi
movl %ebx, 0x14(%rsp)
movl %ebx, %esi
callq 0x50c7
leaq 0x1514(%rip), %rsi      # 0x95be
leaq 0x198(%rsp), %rdi
leaq 0x98(%rsp), %rdx
callq 0x1060
leaq 0xa8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
pushq $0x1
popq %rdx
movl 0x14(%rsp), %ecx
movl %edx, %r8d
movl %edx, %r9d
callq 0x2d9e
leaq 0x198(%rsp), %rdi
callq 0x1070
leaq 0xa8(%rsp), %rdi
callq 0x2141
leaq 0x98(%rsp), %rdi
movl %eax, %esi
callq 0x186c
leaq 0xa8(%rsp), %rdi
pushq $0x2
popq %rsi
callq 0x20c8
movsd %xmm0, 0x38(%rsp)
leaq 0x98(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x2030
movsd 0x38(%rsp), %xmm0
movsd %xmm0, (%rax)
leaq 0x68(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
leaq 0x98(%rsp), %rdx
callq 0x1a3c
leaq 0x58(%rsp), %rdi
movl 0x14(%rsp), %esi
callq 0x50c7
leaq 0x68(%rsp), %rdi
pushq $0x2
popq %rsi
callq 0x20c8
ucomisd 0x1164(%rip), %xmm0     # 0x92d8
jbe 0x8249
leaq 0xf8(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x18bc
leaq 0xe8(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x18bc
leaq 0x18(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
leaq 0xe8(%rsp), %rdx
callq 0x4d38
leaq 0xe8(%rsp), %rdi
callq 0x1908
leaq 0xf8(%rsp), %rdi
callq 0x1908
leaq 0x68(%rsp), %rdi
movq %rdi, %rsi
callq 0x1b63
movsd 0x1109(%rip), %xmm1     # 0x92f0
divsd %xmm0, %xmm1
leaq 0x88(%rsp), %rdi
leaq 0x18(%rsp), %rsi
movapd %xmm1, %xmm0
callq 0x36ec
leaq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rsi
leaq 0x88(%rsp), %rdx
callq 0x3642
leaq 0x58(%rsp), %rdi
leaq 0x48(%rsp), %rbx
movq %rbx, %rsi
callq 0x4c1c
movq %rbx, %rdi
callq 0x2a78
leaq 0x88(%rsp), %rdi
callq 0x2a78
leaq 0x18(%rsp), %rdi
callq 0x2a78
leaq 0x18(%rsp), %rdi
leaq 0x58(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x376b
movq %r15, 0xb8(%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x18(%rsp), %rbx
movq %rbx, %rsi
callq 0x4c1c
movq %rbx, %rdi
callq 0x2a78
leaq 0x18(%rsp), %rdi
leaq 0x78(%rsp), %rsi
leaq 0x58(%rsp), %rdx
callq 0x376b
leaq 0x78(%rsp), %rdi
leaq 0x18(%rsp), %rbx
movq %rbx, %rsi
callq 0x4c1c
movq %rbx, %rdi
callq 0x2a78
leaq 0x28(%rsp), %rsi
leaq 0x88(%rsp), %rbx
leaq 0x158(%rsp), %r12
pushq $0x2
popq %rdx
cmpl 0x44(%rsp), %edx
jge 0x8550
leaq 0x18(%rsp), %rdi
movl 0x14(%rsp), %ecx
movl %edx, 0x38(%rsp)
movl %edx, %r8d
movl %r14d, %r9d
callq 0x2b96
movl 0x20(%rsp), %r13d
leaq 0x178(%rsp), %rdi
leaq 0x12c3(%rip), %rsi      # 0x95be
movq %rbx, %rdx
callq 0x1060
leaq 0x48(%rsp), %r15
movq %r15, %rdi
leaq 0x18(%rsp), %rsi
pushq $0x1
popq %rdx
movl %r13d, %ecx
movl %edx, %r8d
movl %edx, %r9d
callq 0x2d9e
leaq 0x178(%rsp), %rdi
callq 0x1070
movq %r15, %rdi
callq 0x2141
movq %rbx, %rdi
movl %eax, %esi
callq 0x186c
leaq 0x48(%rsp), %rdi
pushq $0x2
popq %rsi
callq 0x20c8
movsd %xmm0, 0xc0(%rsp)
movq %rbx, %r15
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0x2030
movsd 0xc0(%rsp), %xmm0
movsd %xmm0, (%rax)
leaq 0x118(%rsp), %rdi
leaq 0x48(%rsp), %rsi
movq %r15, %rdx
callq 0x1a3c
leaq 0xd8(%rsp), %rdi
movl %r13d, %esi
callq 0x50c7
leaq 0x108(%rsp), %rdi
leaq 0x118(%rsp), %r15
movq %r15, %rsi
callq 0x18bc
leaq 0x168(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
callq 0x18bc
leaq 0xc8(%rsp), %rdi
leaq 0x108(%rsp), %r13
movq %r13, %rsi
movq %rbp, %rdx
callq 0x4d38
movq %rbp, %rdi
callq 0x1908
movq %r13, %rdi
callq 0x1908
movq %r12, %r13
movq %r12, %rdi
movl 0x14(%rsp), %esi
callq 0x50c7
movq %r15, %rdi
pushq $0x2
popq %rsi
callq 0x20c8
leaq 0x138(%rsp), %r12
leaq 0x148(%rsp), %rbp
ucomisd 0xeba(%rip), %xmm0      # 0x92d8
jbe 0x84a5
movq %r15, %rdi
movq %r15, %rsi
callq 0x1b63
movsd 0xeb9(%rip), %xmm1      # 0x92f0
divsd %xmm0, %xmm1
movq %r12, %rdi
movapd %xmm1, %xmm0
leaq 0xc8(%rsp), %rsi
callq 0x36ec
movq %rbp, %rdi
leaq 0xd8(%rsp), %rsi
movq %r12, %rdx
callq 0x3642
movq %r12, %rdi
callq 0x2a78
leaq 0x128(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rsi
callq 0x29b2
movq %r13, %rdi
movl 0x38(%rsp), %ecx
movl %ecx, %esi
movl 0x14(%rsp), %edx
movl %edx, %r8d
movq %r12, %r9
callq 0x30c2
movq %r12, %rdi
callq 0x2a78
movq %rbp, %rdi
callq 0x2a78
movq %rbp, %rdi
movq %r13, %rsi
movq %rbp, %r12
movq %r13, %rbp
leaq 0x28(%rsp), %r13
movq %r13, %rdx
callq 0x376b
movq %r13, %rdi
movq %r12, %rsi
callq 0x4c1c
movq %r12, %rdi
callq 0x2a78
movq %r12, %rdi
leaq 0x78(%rsp), %r13
movq %r13, %rsi
movq %rbp, %rdx
callq 0x376b
movq %r13, %rdi
movq %r12, %rsi
callq 0x4c1c
movq %r12, %rdi
callq 0x2a78
movq %rbp, %rdi
callq 0x2a78
leaq 0xc8(%rsp), %rdi
callq 0x2a78
leaq 0xd8(%rsp), %rdi
callq 0x2a78
movq %r15, %rdi
callq 0x1908
movq %rbx, %rdi
callq 0x1908
leaq 0x48(%rsp), %rdi
callq 0x1908
leaq 0x18(%rsp), %rdi
callq 0x2a78
movl 0x38(%rsp), %edx
incl %edx
leaq 0x28(%rsp), %rsi
movq %rbp, %r12
jmp 0x82c5
xorl %r12d, %r12d
testl %r14d, %r14d
cmovlel %r12d, %r14d
movl 0x14(%rsp), %eax
testl %eax, %eax
cmovgl %eax, %r12d
incl %r12d
negl %r14d
leaq 0x28(%rsp), %rbx
pushq $0x1
popq %rbp
cmpl %r12d, %ebp
je 0x85c7
pushq $0x1
popq %rax
movl %eax, %r15d
leal (%r14,%r15), %eax
cmpl $0x1, %eax
je 0x85c3
movq %rbx, %rdi
movl %ebp, %esi
movl %r15d, %edx
callq 0x3a1a
movsd (%rax), %xmm0
andpd 0xab1(%rip), %xmm0      # 0x9050
movsd 0xd39(%rip), %xmm1      # 0x92e0
ucomisd %xmm0, %xmm1
jbe 0x85be
movq %rbx, %rdi
movl %ebp, %esi
movl %r15d, %edx
callq 0x3a1a
andq $0x0, (%rax)
incl %r15d
jmp 0x857d
incl %ebp
jmp 0x8572
leaq 0x78(%rsp), %rsi
leaq 0x28(%rsp), %rdx
movq 0xb8(%rsp), %rbx
movq %rbx, %rdi
callq 0x8c32
leaq 0x58(%rsp), %rdi
callq 0x2a78
leaq 0x68(%rsp), %rdi
callq 0x1908
leaq 0x98(%rsp), %rdi
callq 0x1908
leaq 0xa8(%rsp), %rdi
callq 0x1908
leaq 0x78(%rsp), %rdi
callq 0x2a78
leaq 0x28(%rsp), %rdi
callq 0x2a78
movq %rbx, %rax
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x2a78
jmp 0x87ac
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0x1908
jmp 0x8662
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x1908
jmp 0x87bb
jmp 0x87b8
jmp 0x87b8
jmp 0x8708
jmp 0x87b8
movq %rax, %rbx
jmp 0x87c5
jmp 0x86bc
movq %rax, %rbx
leaq 0x198(%rsp), %rdi
callq 0x1070
jmp 0x87e9
movq %rax, %rbx
jmp 0x87e9
movq %rax, %rbx
jmp 0x87f3
jmp 0x87b8
movq %rax, %rbx
jmp 0x87cf
movq %rax, %rbx
jmp 0x87dc
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x2a78
jmp 0x86e1
movq %rax, %rbx
leaq 0x148(%rsp), %rdi
jmp 0x86f6
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
callq 0x2a78
jmp 0x8713
jmp 0x8710
jmp 0x8710
jmp 0x8710
movq %rax, %rbx
jmp 0x8744
movq %rax, %rbx
jmp 0x87ac
movq %rax, %rbx
leaq 0x158(%rsp), %rdi
callq 0x2a78
leaq 0xc8(%rsp), %rdi
callq 0x2a78
jmp 0x8756
movq %rax, %rbx
jmp 0x8720
movq %rax, %rbx
leaq 0x168(%rsp), %rdi
callq 0x1908
leaq 0x108(%rsp), %rdi
callq 0x1908
jmp 0x8756
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x2a78
leaq 0x118(%rsp), %rdi
callq 0x1908
jmp 0x8795
movq %rax, %rbx
jmp 0x8763
jmp 0x8792
jmp 0x87b8
movq %rax, %rbx
leaq 0x178(%rsp), %rdi
callq 0x1070
jmp 0x87ac
movq %rax, %rbx
jmp 0x87a2
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x1908
leaq 0x48(%rsp), %rdi
callq 0x1908
leaq 0x18(%rsp), %rdi
callq 0x2a78
jmp 0x87bb
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x2a78
leaq 0x68(%rsp), %rdi
callq 0x1908
leaq 0x98(%rsp), %rdi
callq 0x1908
leaq 0xa8(%rsp), %rdi
callq 0x1908
leaq 0x78(%rsp), %rdi
callq 0x2a78
leaq 0x28(%rsp), %rdi
callq 0x2a78
movq %rbx, %rdi
callq 0x1180