// File: /workspace/github_cpp_makefile_star2_O1/IlanPrice[P]Linear-Algebra-Library-in-Cplusplus/Matrix.cpp
// Function: MINRES(Matrix const&, Vector const&)
Vector MINRES(const Matrix& A, const Vector& b)
{
	std::ofstream MINRESres;
	MINRESres.open("MINRESres.txt");
	int n = length(b);
	Vector x(n);
	Vector temp1 = A*x;
	Vector r = b - temp1;
	double norm_r = norm(r);
	MINRESres << std::setprecision(15) << norm_r << "\n";
	double norm_r0 = norm_r;
	Vector v = r/norm_r;
	Matrix V(length(v),n);
	Matrix H(n+1,n);
	Vector r_e1(n+1);
	r_e1(1) = norm_r0;
	Matrix G = eye(n+1);
	V.setElements(1,n,1,1,v);
	double Tol = 1e-15;
	int k=0;
	double gamma = 0;
	while (norm_r > Tol)
		{
			k = k+1;
			Vector v_k = V.getElements(1,n,k,k,"Vector");
			Vector w = A*v_k;
			double delta = v_k*w;
			H(k,k) = delta;
			if (k>1)
			{
				H(k-1,k) = gamma;
				w = w - delta*v_k - gamma*V.getElements(1,n,k-1,k-1,"Vector");
			}
			else
			{
					w = w - delta*v_k;
			}
			gamma = norm(w);
			H(k+1,k) = gamma;
			if (gamma<1e-13)
			{ break;}
			else
			{
				Vector v_kplus1 = w/gamma;
				V.setElements(1,n,k+1,k+1,v_kplus1);
				Matrix Hhat = H.getElements(1,(k+1),1,k);
				Hhat = G.getElements(1,k+1,1,k+1)*Hhat;
				std::pair<double,double> g = givens(Hhat(k,k),Hhat(k+1,k));
				double gcos = g.first; double gsin = g.second;
				G.applygivens(k,k+1,gcos,gsin);
				norm_r = std::abs(norm_r*gsin);
				MINRESres << std::setprecision(15) << norm_r << "\n";
			}

		}

		r_e1.setValues(1,k+1,G.getElements(1,k+1,1,k+1)*r_e1.getValues(1,k+1));
		H.setElements(1,k+1,1,k, G.getElements(1,k+1,1,k+1)*H.getElements(1,(k+1),1,k));
		Vector y = backsubst(H.getElements(1,k,1,k),r_e1.getValues(1,k), 3);
		Vector xfinal = temp1 + V.getElements(1,n,1,k)*y;
		MINRESres.close();
		return xfinal;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3d8, %rsp            # imm = 0x3D8
movq %rdx, %rbx
movq %rsi, 0xb0(%rsp)
movq %rdi, %r15
leaq 0x1d8(%rsp), %r14
movq %r14, %rdi
callq 0x2180
leaq 0x4612(%rip), %rsi      # 0xc5ed
movq %r14, %rdi
movl $0x10, %edx
callq 0x2040
movq %rbx, %rdi
callq 0x3485
movl %eax, %r14d
leaq 0x150(%rsp), %rdi
movl %eax, %esi
callq 0x28c8
leaq 0xf0(%rsp), %rdi
leaq 0x150(%rsp), %rdx
movq 0xb0(%rsp), %rsi
callq 0x505f
leaq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rdx
movq %rbx, %rsi
callq 0x2b28
leaq 0xe0(%rsp), %rdi
movl $0x2, %esi
callq 0x340b
movsd %xmm0, 0x78(%rsp)
leaq 0x1d8(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
movq $0xf, 0x1e0(%rsp,%rax)
callq 0x2170
leaq 0x427e(%rip), %rsi      # 0xc2f4
movl $0x1, %edx
movq %rax, %rdi
callq 0x2120
leaq 0x78(%rsp), %rdx
movsd (%rdx), %xmm0
movsd %xmm0, 0x48(%rsp)
leaq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x2e64
leaq 0xd0(%rsp), %rdi
callq 0x3485
leaq 0x90(%rsp), %rdi
movl %eax, %esi
movl %r14d, %edx
callq 0x3df8
leal 0x1(%r14), %ebx
leaq 0x68(%rsp), %rdi
movl %ebx, %esi
movl %r14d, %edx
callq 0x3df8
leaq 0xa0(%rsp), %rdi
movl %ebx, %esi
callq 0x28c8
leaq 0xa0(%rsp), %rdi
movl $0x1, %esi
callq 0x3354
movsd 0x48(%rsp), %xmm0
movsd %xmm0, (%rax)
leaq 0x80(%rsp), %rdi
movl %ebx, %esi
movl %ebx, %edx
callq 0x3df8
testl %r14d, %r14d
js 0x8140
movq 0x80(%rsp), %rax
movl %ebx, %ecx
xorl %edx, %edx
movabsq $0x3ff0000000000000, %rsi # imm = 0x3FF0000000000000
movq (%rax,%rdx,8), %rdi
movq %rsi, (%rdi,%rdx,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x8130
leaq 0x140(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x2918
movq %r15, 0x100(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x140(%rsp), %r9
movl $0x1, %esi
movq %r14, 0x48(%rsp)
movl %r14d, %edx
movl $0x1, %ecx
movl $0x1, %r8d
callq 0x49d8
leaq 0x140(%rsp), %rdi
callq 0x2970
leaq 0x50(%rsp), %rax
movq $0x0, (%rax)
leaq 0x190(%rsp), %r14
xorl %r13d, %r13d
leaq 0x20(%rsp), %rbx
movsd 0x78(%rsp), %xmm0
ucomisd 0x413f(%rip), %xmm0     # 0xc300
jbe 0x8694
movq %r14, 0x180(%rsp)
leaq 0x180(%rsp), %rdi
leaq 0x4408(%rip), %rsi      # 0xc5e6
leaq 0x4407(%rip), %rdx      # 0xc5ec
callq 0x3c6e
leaq 0x1(%r13), %r12
movq %rbx, %rdi
leaq 0x90(%rsp), %rsi
movl $0x1, %edx
movq 0x48(%rsp), %rcx
movl %r12d, %r8d
movl %r12d, %r9d
callq 0x43be
movq 0x180(%rsp), %rdi
cmpq %r14, %rdi
je 0x8220
callq 0x2110
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq 0xb0(%rsp), %rsi
movq %rbx, %rdx
callq 0x505f
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2cd3
movsd %xmm0, 0xb8(%rsp)
leaq 0x68(%rsp), %rdi
movl %r12d, %esi
movl %r12d, %edx
movsd %xmm0, 0x30(%rsp)
callq 0x51ec
movsd 0x30(%rsp), %xmm0
movsd %xmm0, (%rax)
testq %r13, %r13
je 0x83a3
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
leaq 0x68(%rsp), %rdi
movl %r13d, %esi
movl %r12d, %edx
callq 0x51ec
movsd 0x30(%rsp), %xmm0
movsd %xmm0, (%rax)
leaq 0x130(%rsp), %rbx
movq %rbx, %rdi
leaq 0xb8(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x2dde
leaq 0x58(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x2b28
leaq 0x170(%rsp), %rax
movq %rax, 0x160(%rsp)
leaq 0x160(%rsp), %rdi
leaq 0x42ff(%rip), %rsi      # 0xc5e6
leaq 0x42fe(%rip), %rdx      # 0xc5ec
callq 0x3c6e
leaq 0x1a0(%rsp), %r15
movq %r15, %rdi
leaq 0x90(%rsp), %rsi
movl $0x1, %edx
movq 0x48(%rsp), %rcx
movl %r13d, %r8d
movl %r13d, %r9d
callq 0x43be
leaq 0xc0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x50(%rsp), %rsi
movq %r15, %rdx
callq 0x2dde
leaq 0x38(%rsp), %r15
movq %r15, %rdi
leaq 0x58(%rsp), %rsi
movq %rbx, %rdx
callq 0x2b28
movq %r14, %rdi
movq %r15, %rsi
callq 0x303c
movq %r15, %rdi
callq 0x2970
leaq 0xc0(%rsp), %rdi
callq 0x2970
leaq 0x1a0(%rsp), %rdi
callq 0x2970
movq 0x160(%rsp), %rdi
leaq 0x170(%rsp), %rax
cmpq %rax, %rdi
je 0x838f
callq 0x2110
leaq 0x58(%rsp), %rdi
callq 0x2970
leaq 0x130(%rsp), %rdi
jmp 0x83e8
leaq 0x58(%rsp), %r15
movq %r15, %rdi
leaq 0xb8(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x2dde
leaq 0x38(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x2b28
movq %r14, %rdi
movq %rbx, %rsi
callq 0x303c
movq %rbx, %rdi
callq 0x2970
leaq 0x58(%rsp), %rdi
callq 0x2970
movq %r14, %rdi
movl $0x2, %esi
callq 0x340b
movsd %xmm0, 0x50(%rsp)
leal 0x2(%r13), %r15d
leaq 0x68(%rsp), %rdi
movl %r15d, %esi
movl %r12d, %edx
movsd %xmm0, 0x30(%rsp)
callq 0x51ec
movsd 0x30(%rsp), %xmm0
movsd %xmm0, (%rax)
movsd 0x50(%rsp), %xmm1
movsd 0x3ede(%rip), %xmm0     # 0xc310
movsd %xmm1, 0x108(%rsp)
ucomisd %xmm1, %xmm0
ja 0x8699
leaq 0x38(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x50(%rsp), %rdx
callq 0x2e64
leaq 0x1c8(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x2918
leaq 0x2(%r13), %r14
leaq 0x90(%rsp), %rdi
movl $0x1, %esi
movq 0x48(%rsp), %rdx
movl %r14d, %ecx
movl %r14d, %r8d
movq %rbp, %r9
callq 0x49d8
movq %rbp, %rdi
callq 0x2970
leaq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rsi
movl $0x1, %edx
movl %r15d, %ecx
movl $0x1, %r8d
movl %r12d, %r9d
callq 0x415c
leaq 0xc0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x80(%rsp), %rsi
movl $0x1, %edx
movl %r14d, %ecx
movl $0x1, %r8d
movl %r14d, %r9d
callq 0x415c
leaq 0x130(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
leaq 0x58(%rsp), %r14
movq %r14, %rdx
callq 0x4eee
movq %r14, %rdi
movq %rbp, %rsi
callq 0x67e4
movq %rbp, %rdi
callq 0x4016
movq %rbx, %rdi
callq 0x4016
movq %r14, %rdi
movl %r12d, %esi
movl %r12d, %edx
callq 0x51ec
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %r14, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x51ec
movsd (%rax), %xmm5
movapd %xmm5, %xmm1
mulsd %xmm5, %xmm1
movsd 0x30(%rsp), %xmm4
movapd %xmm4, %xmm0
mulsd %xmm4, %xmm0
addsd %xmm1, %xmm0
ucomisd 0x3d94(%rip), %xmm0     # 0xc2f8
jb 0x856c
sqrtsd %xmm0, %xmm0
jmp 0x8589
movapd %xmm5, 0x1b0(%rsp)
callq 0x20d0
movapd 0x1b0(%rsp), %xmm5
movsd 0x30(%rsp), %xmm4
leaq 0x190(%rsp), %r14
leaq 0x20(%rsp), %rbx
xorpd 0x3aa2(%rip), %xmm5     # 0xc040
divsd %xmm0, %xmm5
movl 0x8c(%rsp), %eax
testl %eax, %eax
jle 0x8601
divsd %xmm0, %xmm4
movq 0x80(%rsp), %rdx
movq -0x8(%rdx,%r12,8), %rcx
movq 0x8(%rdx,%r13,8), %rdx
xorl %esi, %esi
movsd (%rcx,%rsi,8), %xmm0
movsd (%rdx,%rsi,8), %xmm1
movapd %xmm5, %xmm2
mulsd %xmm1, %xmm2
movapd %xmm4, %xmm3
mulsd %xmm0, %xmm3
subsd %xmm2, %xmm3
mulsd %xmm4, %xmm1
mulsd %xmm5, %xmm0
addsd %xmm1, %xmm0
movsd %xmm3, (%rcx,%rsi,8)
movsd %xmm0, (%rdx,%rsi,8)
incq %rsi
cmpq %rsi, %rax
jne 0x85c5
mulsd 0x78(%rsp), %xmm5
andpd 0x3a41(%rip), %xmm5     # 0xc050
movlpd %xmm5, 0x78(%rsp)
movq 0x1d8(%rsp), %rax
movq -0x18(%rax), %rax
movq $0xf, 0x1e0(%rsp,%rax)
leaq 0x1d8(%rsp), %rdi
movapd %xmm5, %xmm0
callq 0x2170
movl $0x1, %edx
movq %rax, %rdi
leaq 0x3ca7(%rip), %rsi      # 0xc2f4
callq 0x2120
leaq 0x58(%rsp), %rdi
callq 0x4016
leaq 0x38(%rsp), %rdi
callq 0x2970
leaq 0x10(%rsp), %rdi
callq 0x2970
movq %rbx, %rdi
callq 0x2970
movsd 0x3c90(%rip), %xmm0     # 0xc310
ucomisd 0x108(%rsp), %xmm0
movq %r12, %r13
jbe 0x81b3
jmp 0x86ad
movl %r13d, %r12d
jmp 0x86ad
leaq 0x10(%rsp), %rdi
callq 0x2970
leaq 0x20(%rsp), %rdi
callq 0x2970
leal 0x1(%r12), %ebx
leaq 0x20(%rsp), %rdi
leaq 0x80(%rsp), %rsi
movl $0x1, %edx
movl %ebx, %ecx
movl $0x1, %r8d
movl %ebx, %r9d
callq 0x415c
leaq 0x10(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
movl $0x1, %edx
movl %ebx, %ecx
callq 0x3834
leaq 0x120(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x505f
leaq 0xa0(%rsp), %rdi
leaq 0x120(%rsp), %rcx
movl $0x1, %esi
movl %ebx, %edx
callq 0x38c0
leaq 0x120(%rsp), %rdi
callq 0x2970
leaq 0x10(%rsp), %rdi
callq 0x2970
leaq 0x20(%rsp), %rdi
callq 0x4016
leaq 0x20(%rsp), %rdi
leaq 0x80(%rsp), %rsi
movl $0x1, %edx
movl %ebx, %ecx
movl $0x1, %r8d
movl %ebx, %r9d
callq 0x415c
leaq 0x10(%rsp), %rdi
leaq 0x68(%rsp), %rsi
movl $0x1, %edx
movl %ebx, %ecx
movl $0x1, %r8d
movl %r12d, %r9d
callq 0x415c
leaq 0x110(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x4eee
leaq 0x68(%rsp), %rdi
leaq 0x110(%rsp), %r9
movl $0x1, %esi
movl %ebx, %edx
movl $0x1, %ecx
movl %r12d, %r8d
callq 0x4768
leaq 0x110(%rsp), %rdi
callq 0x4016
leaq 0x10(%rsp), %rdi
callq 0x4016
leaq 0x20(%rsp), %rdi
callq 0x4016
leaq 0x10(%rsp), %rdi
leaq 0x68(%rsp), %rsi
movl $0x1, %edx
movl %r12d, %ecx
movl $0x1, %r8d
movl %r12d, %r9d
callq 0x415c
leaq 0x38(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
movl $0x1, %edx
movl %r12d, %ecx
callq 0x3834
leaq 0x20(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x38(%rsp), %rdx
movl $0x3, %ecx
callq 0x61eb
leaq 0x38(%rsp), %rdi
callq 0x2970
leaq 0x10(%rsp), %rdi
callq 0x4016
leaq 0x38(%rsp), %rdi
leaq 0x90(%rsp), %rsi
movl $0x1, %edx
movq 0x48(%rsp), %rcx
movl $0x1, %r8d
movl %r12d, %r9d
callq 0x415c
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x505f
movq 0x100(%rsp), %r14
leaq 0xf0(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movq %r14, %rdi
callq 0x297d
leaq 0x10(%rsp), %rdi
callq 0x2970
leaq 0x38(%rsp), %rdi
callq 0x4016
leaq 0x1d8(%rsp), %rdi
callq 0x2140
leaq 0x20(%rsp), %rdi
callq 0x2970
leaq 0x80(%rsp), %rdi
callq 0x4016
leaq 0xa0(%rsp), %rdi
callq 0x2970
leaq 0x68(%rsp), %rdi
callq 0x4016
leaq 0x90(%rsp), %rdi
callq 0x4016
leaq 0xd0(%rsp), %rdi
callq 0x2970
leaq 0xe0(%rsp), %rdi
callq 0x2970
leaq 0xf0(%rsp), %rdi
callq 0x2970
leaq 0x150(%rsp), %rdi
callq 0x2970
movq 0x7699(%rip), %rax      # 0xffc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x1e0(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x1d8(%rsp,%rcx)
callq 0x20f0
leaq 0x2d0(%rsp), %rdi
callq 0x2060
movq %r14, %rax
addq $0x3d8, %rsp            # imm = 0x3D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq %r14, %rdi
jmp 0x8b88
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x2970
jmp 0x8992
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x4016
jmp 0x8b8d
jmp 0x8b5b
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x2970
jmp 0x89b8
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
jmp 0x8a15
jmp 0x8b60
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0x4016
jmp 0x89d9
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x4016
jmp 0x8a10
jmp 0x8a0d
jmp 0x8b60
movq %rax, %rbx
leaq 0x120(%rsp), %rdi
callq 0x2970
jmp 0x8a01
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x2970
jmp 0x8a10
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x4016
jmp 0x8b97
jmp 0x8b60
movq %rax, %rbx
leaq 0x140(%rsp), %rdi
jmp 0x8b92
jmp 0x8b60
jmp 0x8a3b
movq %rax, %rbx
jmp 0x8ba4
movq %rax, %rbx
jmp 0x8bb1
movq %rax, %rbx
jmp 0x8bbb
jmp 0x8a79
movq %rax, %rbx
jmp 0x8be2
movq %rax, %rbx
jmp 0x8bef
jmp 0x8a69
jmp 0x8a69
movq %rax, %rbx
jmp 0x8bfc
movq %rax, %rbx
jmp 0x8bc8
movq %rax, %rbx
jmp 0x8bd5
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x2970
jmp 0x8a93
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
jmp 0x8b79
jmp 0x8b80
movq %rax, %rbx
jmp 0x8b01
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x2970
jmp 0x8abe
movq %rax, %rbx
jmp 0x8b0b
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x2970
jmp 0x8ad5
jmp 0x8b80
movq %rax, %rbx
leaq 0x1a0(%rsp), %rdi
callq 0x2970
jmp 0x8ae7
movq %rax, %rbx
movq 0x160(%rsp), %rdi
leaq 0x170(%rsp), %rax
cmpq %rax, %rdi
je 0x8b01
callq 0x2110
leaq 0x58(%rsp), %rdi
callq 0x2970
leaq 0x130(%rsp), %rdi
jmp 0x8b79
jmp 0x8b80
jmp 0x8b2b
movq %rax, %rbx
leaq 0x1c8(%rsp), %rdi
callq 0x2970
jmp 0x8b74
movq %rax, %rbx
jmp 0x8b74
jmp 0x8b67
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x4016
jmp 0x8b6a
movq %rax, %rbx
movq 0x180(%rsp), %rdi
cmpq %r14, %rdi
je 0x8b97
callq 0x2110
jmp 0x8b97
movq %rax, %rbx
jmp 0x8b8d
movq %rax, %rbx
jmp 0x8b97
jmp 0x8b67
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x4016
leaq 0x38(%rsp), %rdi
callq 0x2970
jmp 0x8b83
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x2970
leaq 0x20(%rsp), %rdi
callq 0x2970
leaq 0x80(%rsp), %rdi
callq 0x4016
leaq 0xa0(%rsp), %rdi
callq 0x2970
leaq 0x68(%rsp), %rdi
callq 0x4016
leaq 0x90(%rsp), %rdi
callq 0x4016
leaq 0xd0(%rsp), %rdi
callq 0x2970
leaq 0xe0(%rsp), %rdi
callq 0x2970
leaq 0xf0(%rsp), %rdi
callq 0x2970
leaq 0x150(%rsp), %rdi
callq 0x2970
leaq 0x1d8(%rsp), %rdi
callq 0x2150
movq %rbx, %rdi
callq 0x21c0