// File: /workspace/github_cpp_makefile_star2_O2/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 $0x3c8, %rsp            # imm = 0x3C8
movq %rdx, %rbx
movq %rsi, 0xc8(%rsp)
movq %rdi, 0x90(%rsp)
leaq 0x1c8(%rsp), %r14
movq %r14, %rdi
callq 0x1140
leaq 0x341c(%rip), %rsi      # 0x95c5
pushq $0x10
popq %rdx
movq %r14, %rdi
callq 0x1040
movq %rbx, %rdi
callq 0x2141
movl %eax, %r12d
leaq 0x158(%rsp), %rdi
movl %eax, %esi
callq 0x186c
leaq 0x108(%rsp), %rdi
leaq 0x158(%rsp), %rdx
movq 0xc8(%rsp), %rsi
callq 0x38bd
leaq 0xf8(%rsp), %rdi
leaq 0x108(%rsp), %rdx
movq %rbx, %rsi
callq 0x1a3c
leaq 0xf8(%rsp), %rdi
pushq $0x2
popq %rsi
callq 0x20c8
movsd %xmm0, 0x88(%rsp)
leaq 0x1c8(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
movq $0xf, 0x1d0(%rsp,%rax)
callq 0x1130
leaq 0x3087(%rip), %rsi      # 0x92ca
movq %rax, %rdi
callq 0x10e0
leaq 0x88(%rsp), %rdx
movsd (%rdx), %xmm0
movsd %xmm0, 0x50(%rsp)
leaq 0xe8(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x1c60
leaq 0xe8(%rsp), %rdi
callq 0x2141
leaq 0x98(%rsp), %rdi
movl %eax, %esi
movl %r12d, %edx
callq 0x285c
movl %r12d, %ebx
incl %ebx
leaq 0x78(%rsp), %rdi
movl %ebx, %esi
movl %r12d, %edx
callq 0x285c
leaq 0xb8(%rsp), %rdi
movl %ebx, %esi
callq 0x186c
leaq 0xb8(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x2030
movsd 0x50(%rsp), %xmm0
movsd %xmm0, (%rax)
leaq 0xa8(%rsp), %rdi
movl %ebx, %esi
callq 0x50c7
leaq 0x148(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x18bc
leaq 0x98(%rsp), %rdi
pushq $0x1
popq %rcx
leaq 0x148(%rsp), %r9
movl %ecx, %esi
movl %r12d, %edx
movl %ecx, %r8d
callq 0x32d6
leaq 0x148(%rsp), %rdi
callq 0x1908
leaq 0x60(%rsp), %rax
andq $0x0, (%rax)
xorl %r13d, %r13d
pushq $0x1
popq %r14
movl %r12d, 0x24(%rsp)
movsd 0x88(%rsp), %xmm0
ucomisd 0x2f93(%rip), %xmm0     # 0x92d8
jbe 0x675f
leaq 0x1a8(%rsp), %rdi
leaq 0x3264(%rip), %rsi      # 0x95be
leaq 0x10(%rsp), %rdx
callq 0x1060
leal 0x1(%r13), %r15d
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
leaq 0x98(%rsp), %rsi
movl %r14d, %edx
movl %r12d, %ecx
movl %r15d, %r8d
movl %r15d, %r9d
callq 0x2d9e
leaq 0x1a8(%rsp), %rdi
callq 0x1070
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movq 0xc8(%rsp), %rsi
movq %rbx, %rdx
callq 0x38bd
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1b63
movsd %xmm0, 0xd0(%rsp)
leaq 0x78(%rsp), %rdi
movl %r15d, %esi
movl %r15d, %edx
movsd %xmm0, 0x50(%rsp)
callq 0x3a1a
movsd 0x50(%rsp), %xmm0
movsd %xmm0, (%rax)
testl %r13d, %r13d
je 0x64ff
movsd 0x60(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
leaq 0x78(%rsp), %rdi
movl %r13d, %esi
movl %r15d, %edx
callq 0x3a1a
movsd 0x50(%rsp), %xmm0
movsd %xmm0, (%rax)
leaq 0x138(%rsp), %rbx
movq %rbx, %rdi
leaq 0xd0(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x1c1c
leaq 0x68(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq %rbx, %rdx
callq 0x1a3c
movl 0x24(%rsp), %r12d
leaq 0x188(%rsp), %rdi
leaq 0x316a(%rip), %rsi      # 0x95be
leaq 0x3f(%rsp), %rdx
callq 0x1060
leaq 0x168(%rsp), %rbx
movq %rbx, %rdi
leaq 0x98(%rsp), %rsi
pushq $0x1
popq %rdx
movl %r12d, %ecx
movl %r13d, %r8d
movl %r13d, %r9d
callq 0x2d9e
leaq 0xd8(%rsp), %r14
movq %r14, %rdi
leaq 0x60(%rsp), %rsi
movq %rbx, %rdx
callq 0x1c1c
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
leaq 0x68(%rsp), %rsi
movq %r14, %rdx
callq 0x1a3c
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x1da0
movq %rbx, %rdi
callq 0x1908
leaq 0xd8(%rsp), %rdi
callq 0x1908
leaq 0x168(%rsp), %rdi
callq 0x1908
leaq 0x188(%rsp), %rdi
callq 0x1070
leaq 0x68(%rsp), %rdi
callq 0x1908
leaq 0x138(%rsp), %rdi
jmp 0x6549
leaq 0x68(%rsp), %r12
movq %r12, %rdi
leaq 0xd0(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x1c1c
leaq 0x40(%rsp), %r14
movq %r14, %rdi
leaq 0x10(%rsp), %rbx
movq %rbx, %rsi
movq %r12, %rdx
callq 0x1a3c
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1da0
movq %r14, %rdi
callq 0x1908
leaq 0x68(%rsp), %rdi
callq 0x1908
leaq 0x10(%rsp), %rdi
pushq $0x2
popq %rsi
callq 0x20c8
movsd %xmm0, 0x60(%rsp)
leal 0x2(%r13), %r12d
leaq 0x78(%rsp), %rdi
movl %r12d, %esi
movl %r15d, %edx
movsd %xmm0, 0x50(%rsp)
callq 0x3a1a
movsd 0x50(%rsp), %xmm0
movsd %xmm0, (%rax)
movsd 0x2d5b(%rip), %xmm0     # 0x92e8
ucomisd 0x60(%rsp), %xmm0
ja 0x6764
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
leaq 0x60(%rsp), %rdx
callq 0x1c60
leaq 0x178(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x18bc
leaq 0x98(%rsp), %rdi
pushq $0x1
popq %rbx
movl %ebx, %esi
movl 0x24(%rsp), %edx
movl %r12d, %ecx
movl %r12d, %r8d
movq %r14, %r9
callq 0x32d6
movq %r14, %rdi
callq 0x1908
leaq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rsi
movl %ebx, %edx
movl %r12d, %ecx
movl %ebx, %r8d
movl %r15d, %r9d
callq 0x2b96
leaq 0xd8(%rsp), %r14
movq %r14, %rdi
leaq 0xa8(%rsp), %rsi
movl %ebx, %edx
movl %r12d, %ecx
movl %ebx, %r8d
movl %r12d, %r9d
callq 0x2b96
leaq 0x138(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
leaq 0x68(%rsp), %rbx
movq %rbx, %rdx
callq 0x376b
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x4c1c
movq %rbp, %rdi
callq 0x2a78
movq %r14, %rdi
callq 0x2a78
movq %rbx, %rdi
movl %r15d, %esi
movl %r15d, %edx
callq 0x3a1a
movsd (%rax), %xmm0
movsd %xmm0, 0x50(%rsp)
movq %rbx, %rdi
movl %r12d, %esi
movl %r15d, %edx
callq 0x3a1a
movsd (%rax), %xmm3
movapd %xmm3, %xmm2
mulsd %xmm3, %xmm2
movsd 0x50(%rsp), %xmm0
movapd %xmm0, %xmm1
mulsd %xmm0, %xmm1
addsd %xmm2, %xmm1
sqrtsd %xmm1, %xmm1
divsd %xmm1, %xmm0
xorpd 0x298f(%rip), %xmm3     # 0x9040
divsd %xmm1, %xmm3
movapd %xmm3, 0x50(%rsp)
leaq 0xa8(%rsp), %rdi
movl %r15d, %esi
movl %r12d, %edx
movapd %xmm3, %xmm1
callq 0x610e
movapd 0x50(%rsp), %xmm0
mulsd 0x88(%rsp), %xmm0
andpd 0x2967(%rip), %xmm0     # 0x9050
movlpd %xmm0, 0x88(%rsp)
movq 0x1c8(%rsp), %rax
movq -0x18(%rax), %rax
movq $0xf, 0x1d0(%rsp,%rax)
leaq 0x1c8(%rsp), %rdi
callq 0x1130
movq %rax, %rdi
leaq 0x2ba9(%rip), %rsi      # 0x92ca
callq 0x10e0
leaq 0x68(%rsp), %rdi
callq 0x2a78
leaq 0x40(%rsp), %rdi
callq 0x1908
leaq 0x10(%rsp), %rdi
callq 0x1908
leaq 0x28(%rsp), %rdi
callq 0x1908
incl %r13d
movl 0x24(%rsp), %r12d
pushq $0x1
popq %r14
jmp 0x6334
movl %r13d, %r15d
jmp 0x677d
leaq 0x10(%rsp), %rdi
callq 0x1908
leaq 0x28(%rsp), %rdi
callq 0x1908
movl 0x24(%rsp), %r12d
leal 0x1(%r15), %ebx
leaq 0x28(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
pushq $0x1
popq %rdx
movl %ebx, %ecx
movl %edx, %r8d
movl %ebx, %r9d
callq 0x2b96
leaq 0x10(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
pushq $0x1
popq %rdx
movl %ebx, %ecx
callq 0x2446
leaq 0x128(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x38bd
leaq 0xb8(%rsp), %rdi
pushq $0x1
popq %rsi
leaq 0x128(%rsp), %rcx
movl %ebx, %edx
callq 0x2488
leaq 0x128(%rsp), %rdi
callq 0x1908
leaq 0x10(%rsp), %rdi
callq 0x1908
leaq 0x28(%rsp), %rdi
callq 0x2a78
leaq 0x28(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
pushq $0x1
popq %rdx
movl %ebx, %ecx
movl %edx, %r8d
movl %ebx, %r9d
callq 0x2b96
leaq 0x10(%rsp), %rdi
leaq 0x78(%rsp), %rsi
pushq $0x1
popq %rdx
movl %ebx, %ecx
movl %edx, %r8d
movl %r15d, %r9d
callq 0x2b96
leaq 0x118(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x376b
leaq 0x78(%rsp), %rdi
pushq $0x1
popq %rcx
leaq 0x118(%rsp), %r9
movl %ecx, %esi
movl %ebx, %edx
movl %r15d, %r8d
callq 0x30c2
leaq 0x118(%rsp), %rdi
callq 0x2a78
leaq 0x10(%rsp), %rdi
callq 0x2a78
leaq 0x28(%rsp), %rdi
callq 0x2a78
leaq 0x10(%rsp), %rdi
leaq 0x78(%rsp), %rsi
pushq $0x1
popq %rdx
movl %r15d, %ecx
movl %edx, %r8d
movl %r15d, %r9d
callq 0x2b96
leaq 0x40(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
pushq $0x1
popq %rdx
movl %r15d, %ecx
callq 0x2446
leaq 0x28(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rdx
pushq $0x3
popq %rcx
callq 0x46e5
leaq 0x40(%rsp), %rdi
callq 0x1908
leaq 0x10(%rsp), %rdi
callq 0x2a78
leaq 0x40(%rsp), %rdi
leaq 0x98(%rsp), %rsi
pushq $0x1
popq %rdx
movl %r12d, %ecx
movl %edx, %r8d
movl %r15d, %r9d
callq 0x2b96
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x38bd
leaq 0x108(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movq 0x90(%rsp), %rdi
callq 0x1915
leaq 0x10(%rsp), %rdi
callq 0x1908
leaq 0x40(%rsp), %rdi
callq 0x2a78
leaq 0x1c8(%rsp), %rdi
callq 0x1100
leaq 0x28(%rsp), %rdi
callq 0x1908
leaq 0xa8(%rsp), %rdi
callq 0x2a78
leaq 0xb8(%rsp), %rdi
callq 0x1908
leaq 0x78(%rsp), %rdi
callq 0x2a78
leaq 0x98(%rsp), %rdi
callq 0x2a78
leaq 0xe8(%rsp), %rdi
callq 0x1908
leaq 0xf8(%rsp), %rdi
callq 0x1908
leaq 0x108(%rsp), %rdi
callq 0x1908
leaq 0x158(%rsp), %rdi
callq 0x1908
leaq 0x1c8(%rsp), %rdi
callq 0x1110
movq 0x90(%rsp), %rax
addq $0x3c8, %rsp            # imm = 0x3C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq 0x90(%rsp), %rdi
jmp 0x6bf9
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x1908
jmp 0x6a15
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0x2a78
jmp 0x6bfe
jmp 0x6bd1
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0x1908
jmp 0x6a3b
movq %rax, %r14
leaq 0x10(%rsp), %rdi
jmp 0x6a98
jmp 0x6bba
movq %rax, %r14
leaq 0x118(%rsp), %rdi
callq 0x2a78
jmp 0x6a5c
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x2a78
jmp 0x6a93
jmp 0x6a90
jmp 0x6bba
movq %rax, %r14
leaq 0x128(%rsp), %rdi
callq 0x1908
jmp 0x6a84
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x1908
jmp 0x6a93
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x2a78
jmp 0x6c08
jmp 0x6bba
movq %rax, %r14
leaq 0x148(%rsp), %rdi
jmp 0x6c03
jmp 0x6bba
jmp 0x6abe
movq %rax, %r14
jmp 0x6c15
movq %rax, %r14
jmp 0x6c22
movq %rax, %r14
jmp 0x6c2c
jmp 0x6afc
movq %rax, %r14
jmp 0x6c53
movq %rax, %r14
jmp 0x6c60
jmp 0x6aec
jmp 0x6aec
movq %rax, %r14
jmp 0x6c6d
movq %rax, %r14
jmp 0x6c39
movq %rax, %r14
jmp 0x6c46
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0x1908
jmp 0x6b16
movq %rax, %r14
leaq 0x68(%rsp), %rdi
jmp 0x6bea
jmp 0x6bf1
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0x1908
jmp 0x6b4b
movq %rax, %r14
jmp 0x6b72
movq %rax, %r14
jmp 0x6b65
movq %rax, %r14
jmp 0x6b58
jmp 0x6bf1
movq %rax, %r14
leaq 0xd8(%rsp), %rdi
callq 0x1908
leaq 0x168(%rsp), %rdi
callq 0x1908
leaq 0x188(%rsp), %rdi
callq 0x1070
leaq 0x68(%rsp), %rdi
callq 0x1908
leaq 0x138(%rsp), %rdi
jmp 0x6bea
movq %rax, %r14
jmp 0x6b7c
movq %rax, %r14
leaq 0xd8(%rsp), %rdi
callq 0x2a78
jmp 0x6bdb
jmp 0x6bd8
jmp 0x6bf1
jmp 0x6ba3
movq %rax, %r14
jmp 0x6be5
movq %rax, %r14
leaq 0x178(%rsp), %rdi
callq 0x1908
jmp 0x6be5
movq %rax, %r14
jmp 0x6c08
movq %rax, %r14
leaq 0x1a8(%rsp), %rdi
callq 0x1070
jmp 0x6c08
movq %rax, %r14
jmp 0x6bfe
jmp 0x6bd8
movq %rax, %r14
leaq 0x68(%rsp), %rdi
callq 0x2a78
leaq 0x40(%rsp), %rdi
callq 0x1908
jmp 0x6bf4
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x1908
leaq 0x28(%rsp), %rdi
callq 0x1908
leaq 0xa8(%rsp), %rdi
callq 0x2a78
leaq 0xb8(%rsp), %rdi
callq 0x1908
leaq 0x78(%rsp), %rdi
callq 0x2a78
leaq 0x98(%rsp), %rdi
callq 0x2a78
leaq 0xe8(%rsp), %rdi
callq 0x1908
leaq 0xf8(%rsp), %rdi
callq 0x1908
leaq 0x108(%rsp), %rdi
callq 0x1908
leaq 0x158(%rsp), %rdi
callq 0x1908
leaq 0x1c8(%rsp), %rdi
callq 0x1110
movq %r14, %rdi
callq 0x1180