// File: /workspace/github_cpp_makefile_star2_O3/IlanPrice[P]Linear-Algebra-Library-in-Cplusplus/Matrix.cpp
// Function: GMRES(Matrix const&, Vector const&)
Vector GMRES(const Matrix& A, const Vector& b)
{
	std::ofstream GMRESres;
	GMRESres.open("GMRESres.txt");
	int n = length(b);
	Vector x(n);
	Vector temp1 = A*x;
	Vector r = b - temp1;
	double norm_r = norm(r);
	GMRESres << 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-14;
	int k=0;
	while (norm_r > Tol)
		{
			k = k+1;
			Vector v_k = V.getElements(1,n,k,k,"Vector");
			Vector w = A*v_k;
			for (int j = 1; j<=k; j++)
			{
				Vector v_j = V.getElements(1,n,j,j,"Vector");
				double h = v_j*w;
				H(j,k) = h;
				w = w - h*v_j;
			}
			double hplus = norm(w);
			H(k+1,k) = hplus;
			if (hplus<1e-13)
			{break;}
			else
			{
				Vector v_kplus1 = w/hplus;
				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);
				GMRESres << 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));
		Vector xfinal = temp1 + V.getElements(1,n,1,k)*y;
		GMRESres.close();
		return xfinal;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3b8, %rsp            # imm = 0x3B8
movq %rdx, %rbx
movq %rsi, 0xb8(%rsp)
movq %rdi, 0x80(%rsp)
leaq 0x1b8(%rsp), %r14
movq %r14, %rdi
callq 0x2170
leaq 0x523c(%rip), %rsi      # 0xc5d9
movq %r14, %rdi
movl $0x10, %edx
callq 0x2040
movq %rbx, %rdi
callq 0x3461
leaq 0x138(%rsp), %rdi
movq %rax, 0x30(%rsp)
movl %eax, %esi
callq 0x28b8
leaq 0xf8(%rsp), %rdi
leaq 0x138(%rsp), %rdx
movq 0xb8(%rsp), %rsi
callq 0x5071
leaq 0xe8(%rsp), %rdi
leaq 0xf8(%rsp), %rdx
movq %rbx, %rsi
callq 0x2af8
leaq 0xe8(%rsp), %rdi
movl $0x2, %esi
callq 0x33e7
movsd %xmm0, 0x48(%rsp)
leaq 0x1b8(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
movq $0xf, 0x1c0(%rsp,%rax)
callq 0x2160
leaq 0x4eba(%rip), %rsi      # 0xc2f4
movl $0x1, %edx
movq %rax, %rdi
callq 0x2110
leaq 0x48(%rsp), %rdx
movsd (%rdx), %xmm0
movsd %xmm0, 0x38(%rsp)
leaq 0xd8(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x2e28
leaq 0xd8(%rsp), %rdi
callq 0x3461
movq 0x30(%rsp), %r14
leaq 0x98(%rsp), %rdi
movl %eax, %esi
movl %r14d, %edx
callq 0x3dd4
leal 0x1(%r14), %ebx
leaq 0x70(%rsp), %rdi
movl %ebx, %esi
movl %r14d, %edx
callq 0x3dd4
leaq 0xa8(%rsp), %rdi
movl %ebx, %esi
callq 0x28b8
leaq 0xa8(%rsp), %rdi
movl $0x1, %esi
callq 0x3330
movsd 0x38(%rsp), %xmm0
movsd %xmm0, (%rax)
leaq 0x60(%rsp), %rdi
movl %ebx, %esi
movl %ebx, %edx
callq 0x3dd4
cmpl $0x0, 0x30(%rsp)
js 0x7505
movq 0x60(%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 0x74f5
leaq 0x128(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x28fa
leaq 0x98(%rsp), %rdi
leaq 0x128(%rsp), %r9
movl $0x1, %esi
movq 0x30(%rsp), %rdx
movl $0x1, %ecx
movl $0x1, %r8d
callq 0x49d8
leaq 0x128(%rsp), %rdi
callq 0x294e
movsd 0x48(%rsp), %xmm0
xorl %r12d, %r12d
ucomisd 0x4da6(%rip), %xmm0     # 0xc308
jbe 0x79b7
leaq 0x198(%rsp), %r14
movq $0x0, 0x90(%rsp)
leaq 0x10(%rsp), %rbx
leaq 0x50(%rsp), %r13
leaq 0x1a8(%rsp), %r15
leaq 0x178(%rsp), %rbp
movq $0x0, 0x40(%rsp)
movq %r14, 0x188(%rsp)
leaq 0x188(%rsp), %rdi
leaq 0x5030(%rip), %rsi      # 0xc5e6
leaq 0x502f(%rip), %rdx      # 0xc5ec
callq 0x3c44
movq 0x40(%rsp), %rax
leaq 0x1(%rax), %r8
leaq 0x20(%rsp), %rdi
leaq 0x98(%rsp), %rsi
movl $0x1, %edx
movq 0x30(%rsp), %rcx
movq %r8, %r12
movl %r8d, %r9d
callq 0x4398
movq 0x188(%rsp), %rdi
cmpq %r14, %rdi
je 0x75ff
callq 0x2100
movq %rbx, %rdi
movq 0xb8(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x5071
movl $0x1, %r14d
leaq 0x158(%rsp), %rax
movq %rax, 0x148(%rsp)
leaq 0x148(%rsp), %rdi
leaq 0x4fad(%rip), %rsi      # 0xc5e6
leaq 0x4fac(%rip), %rdx      # 0xc5ec
callq 0x3c44
movq %r13, %rdi
leaq 0x98(%rsp), %rsi
movl $0x1, %edx
movq 0x30(%rsp), %rcx
movl %r14d, %r8d
movl %r14d, %r9d
callq 0x4398
movq 0x148(%rsp), %rdi
leaq 0x158(%rsp), %rax
cmpq %rax, %rdi
je 0x767f
callq 0x2100
movq %r13, %rdi
movq %rbx, %rsi
callq 0x2c95
movsd %xmm0, 0xc8(%rsp)
leaq 0x70(%rsp), %rdi
movl %r14d, %esi
movl %r12d, %edx
movsd %xmm0, 0x38(%rsp)
callq 0x5202
movsd 0x38(%rsp), %xmm0
movsd %xmm0, (%rax)
movq %r15, %rdi
leaq 0xc8(%rsp), %rsi
movq %r13, %rdx
callq 0x2da1
movq %rbp, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2af8
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x300a
movq %rbp, %rdi
callq 0x294e
movq %r15, %rdi
callq 0x294e
movq %r13, %rdi
callq 0x294e
movq 0x90(%rsp), %rax
addl %r14d, %eax
incl %eax
movl %r14d, %ecx
incl %ecx
movl %ecx, %r14d
cmpl $0x2, %eax
jne 0x761a
movq %rbx, %rdi
movl $0x2, %esi
callq 0x33e7
movsd %xmm0, 0xc0(%rsp)
movq 0x40(%rsp), %rax
leal 0x2(%rax), %esi
leaq 0x70(%rsp), %rdi
movl %esi, 0x38(%rsp)
movl %r12d, %edx
movsd %xmm0, 0x88(%rsp)
callq 0x5202
movsd 0x88(%rsp), %xmm0
movsd %xmm0, (%rax)
movsd 0x4bae(%rip), %xmm0     # 0xc310
ucomisd 0xc0(%rsp), %xmm0
leaq 0x168(%rsp), %r14
ja 0x79a3
movq %r13, %rdi
movq %rbx, %rsi
leaq 0xc0(%rsp), %rdx
callq 0x2e28
movq %r14, %rdi
movq %r13, %rsi
callq 0x28fa
movq %r14, %r9
movq 0x40(%rsp), %rax
leaq 0x2(%rax), %r14
leaq 0x98(%rsp), %rdi
movl $0x1, %esi
movq 0x30(%rsp), %rdx
movl %r14d, %ecx
movl %r14d, %r8d
callq 0x49d8
leaq 0x168(%rsp), %rdi
callq 0x294e
movq %rbp, %rdi
leaq 0x70(%rsp), %rsi
movl $0x1, %edx
movl 0x38(%rsp), %ecx
movl $0x1, %r8d
movl %r12d, %r9d
callq 0x412c
leaq 0xc8(%rsp), %rdi
leaq 0x60(%rsp), %rsi
movl $0x1, %edx
movl %r14d, %ecx
movl $0x1, %r8d
movl %r14d, %r9d
callq 0x412c
movq %r15, %rdi
leaq 0xc8(%rsp), %r14
movq %r14, %rsi
movq %rbp, %rdx
callq 0x4ef7
movq %rbp, %rdi
movq %r15, %rsi
callq 0x681a
movq %r15, %rdi
callq 0x3fe2
movq %r14, %rdi
callq 0x3fe2
movq %rbp, %rdi
movq %r12, %r14
movl %r14d, %esi
movl %r14d, %edx
callq 0x5202
movsd (%rax), %xmm0
movsd %xmm0, 0x88(%rsp)
movq %rbp, %rdi
movl 0x38(%rsp), %esi
movl %r14d, %edx
callq 0x5202
movsd (%rax), %xmm0
movapd %xmm0, %xmm1
mulsd %xmm0, %xmm1
movsd 0x88(%rsp), %xmm5
movapd %xmm5, %xmm2
mulsd %xmm5, %xmm2
addsd %xmm1, %xmm2
xorps %xmm1, %xmm1
sqrtsd %xmm2, %xmm1
xorpd 0x47a3(%rip), %xmm0     # 0xc040
divsd %xmm1, %xmm0
movl 0x6c(%rsp), %eax
testl %eax, %eax
jle 0x78ff
divsd %xmm1, %xmm5
movq 0x60(%rsp), %rdx
movq -0x8(%rdx,%r12,8), %rcx
movq 0x40(%rsp), %rsi
movq 0x8(%rdx,%rsi,8), %rdx
xorl %esi, %esi
movsd (%rcx,%rsi,8), %xmm1
movsd (%rdx,%rsi,8), %xmm2
movapd %xmm0, %xmm3
mulsd %xmm2, %xmm3
movapd %xmm5, %xmm4
mulsd %xmm1, %xmm4
subsd %xmm3, %xmm4
mulsd %xmm5, %xmm2
mulsd %xmm0, %xmm1
addsd %xmm2, %xmm1
movsd %xmm4, (%rcx,%rsi,8)
movsd %xmm1, (%rdx,%rsi,8)
incq %rsi
cmpq %rsi, %rax
jne 0x78c3
mulsd 0x48(%rsp), %xmm0
andpd 0x4743(%rip), %xmm0     # 0xc050
movlpd %xmm0, 0x48(%rsp)
movq 0x1b8(%rsp), %rax
movq -0x18(%rax), %rax
movq $0xf, 0x1c0(%rsp,%rax)
leaq 0x1b8(%rsp), %rdi
callq 0x2160
leaq 0x198(%rsp), %r14
movl $0x1, %edx
movq %rax, %rdi
leaq 0x49a5(%rip), %rsi      # 0xc2f4
callq 0x2110
movq %rbp, %rdi
callq 0x3fe2
movq %r13, %rdi
callq 0x294e
movq %rbx, %rdi
callq 0x294e
leaq 0x20(%rsp), %rdi
callq 0x294e
movsd 0x48(%rsp), %xmm0
movq 0x90(%rsp), %rax
decl %eax
movq %rax, 0x90(%rsp)
ucomisd 0x4972(%rip), %xmm0     # 0xc308
movq %r12, 0x40(%rsp)
ja 0x759f
jmp 0x79b7
leaq 0x10(%rsp), %rdi
callq 0x294e
leaq 0x20(%rsp), %rdi
callq 0x294e
leal 0x1(%r12), %ebx
leaq 0x20(%rsp), %rdi
leaq 0x60(%rsp), %rsi
movl $0x1, %edx
movl %ebx, %ecx
movl $0x1, %r8d
movl %ebx, %r9d
callq 0x412c
leaq 0x10(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
movl $0x1, %edx
movl %ebx, %ecx
callq 0x3802
leaq 0x118(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x5071
leaq 0xa8(%rsp), %rdi
leaq 0x118(%rsp), %rcx
movl $0x1, %esi
movl %ebx, %edx
callq 0x3882
leaq 0x118(%rsp), %rdi
callq 0x294e
leaq 0x10(%rsp), %rdi
callq 0x294e
leaq 0x20(%rsp), %rdi
callq 0x3fe2
leaq 0x20(%rsp), %rdi
leaq 0x60(%rsp), %rsi
movl $0x1, %edx
movl %ebx, %ecx
movl $0x1, %r8d
movl %ebx, %r9d
callq 0x412c
leaq 0x10(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl $0x1, %edx
movl %ebx, %ecx
movl $0x1, %r8d
movl %r12d, %r9d
callq 0x412c
leaq 0x108(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x4ef7
leaq 0x70(%rsp), %rdi
leaq 0x108(%rsp), %r9
movl $0x1, %esi
movl %ebx, %edx
movl $0x1, %ecx
movl %r12d, %r8d
callq 0x475c
leaq 0x108(%rsp), %rdi
callq 0x3fe2
leaq 0x10(%rsp), %rdi
callq 0x3fe2
leaq 0x20(%rsp), %rdi
callq 0x3fe2
leaq 0x10(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl $0x1, %edx
movl %r12d, %ecx
movl $0x1, %r8d
movl %r12d, %r9d
callq 0x412c
leaq 0x50(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
movl $0x1, %edx
movl %r12d, %ecx
callq 0x3802
leaq 0x20(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x50(%rsp), %rdx
xorl %ecx, %ecx
callq 0x620e
leaq 0x50(%rsp), %rdi
callq 0x294e
leaq 0x10(%rsp), %rdi
callq 0x3fe2
leaq 0x50(%rsp), %rdi
leaq 0x98(%rsp), %rsi
movl $0x1, %edx
movq 0x30(%rsp), %rcx
movl $0x1, %r8d
movl %r12d, %r9d
callq 0x412c
leaq 0x10(%rsp), %rdi
leaq 0x50(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x5071
leaq 0xf8(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movq 0x80(%rsp), %rdi
callq 0x295b
leaq 0x10(%rsp), %rdi
callq 0x294e
leaq 0x50(%rsp), %rdi
callq 0x3fe2
leaq 0x1b8(%rsp), %rdi
callq 0x2130
leaq 0x1c0(%rsp), %rbx
leaq 0x20(%rsp), %rdi
callq 0x294e
leaq 0x60(%rsp), %rdi
callq 0x3fe2
leaq 0xa8(%rsp), %rdi
callq 0x294e
leaq 0x70(%rsp), %rdi
callq 0x3fe2
leaq 0x98(%rsp), %rdi
callq 0x3fe2
leaq 0xd8(%rsp), %rdi
callq 0x294e
leaq 0xe8(%rsp), %rdi
callq 0x294e
leaq 0xf8(%rsp), %rdi
callq 0x294e
leaq 0x138(%rsp), %rdi
callq 0x294e
movq 0x8396(%rip), %rax      # 0xffc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
movq %rcx, -0x8(%rbx)
movq -0x18(%rcx), %rcx
movq %rax, 0x1b8(%rsp,%rcx)
movq %rbx, %rdi
callq 0x20e0
leaq 0x2b0(%rsp), %rdi
callq 0x2060
movq 0x80(%rsp), %rax
addq $0x3b8, %rsp            # imm = 0x3B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq 0x80(%rsp), %rdi
jmp 0x7e59
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x294e
jmp 0x7c9a
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0x3fe2
jmp 0x7e5e
jmp 0x7dda
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0x294e
jmp 0x7cc0
movq %rax, %r14
leaq 0x10(%rsp), %rdi
jmp 0x7d1d
jmp 0x7ddf
movq %rax, %r14
leaq 0x108(%rsp), %rdi
callq 0x3fe2
jmp 0x7ce1
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x3fe2
jmp 0x7d18
jmp 0x7d15
jmp 0x7ddf
movq %rax, %r14
leaq 0x118(%rsp), %rdi
callq 0x294e
jmp 0x7d09
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x294e
jmp 0x7d18
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x3fe2
jmp 0x7e68
jmp 0x7ddf
movq %rax, %r14
leaq 0x128(%rsp), %rdi
jmp 0x7e63
jmp 0x7ddf
jmp 0x7d43
movq %rax, %r14
jmp 0x7e72
movq %rax, %r14
jmp 0x7e7f
movq %rax, %r14
jmp 0x7e89
jmp 0x7d81
movq %rax, %r14
jmp 0x7eb0
movq %rax, %r14
jmp 0x7ebd
jmp 0x7d71
jmp 0x7d71
movq %rax, %r14
jmp 0x7eca
movq %rax, %r14
jmp 0x7e96
movq %rax, %r14
jmp 0x7ea3
jmp 0x7dfd
jmp 0x7e47
movq %rax, %r14
leaq 0x168(%rsp), %rdi
jmp 0x7e40
jmp 0x7e47
jmp 0x7de9
movq %rax, %r14
leaq 0xc8(%rsp), %rdi
callq 0x3fe2
jmp 0x7dec
movq %r14, %rcx
movq %rax, %r14
movq 0x188(%rsp), %rdi
cmpq %rcx, %rdi
je 0x7e68
callq 0x2100
jmp 0x7e68
movq %rax, %r14
jmp 0x7e5e
movq %rax, %r14
jmp 0x7e68
jmp 0x7de9
movq %rax, %r14
leaq 0x178(%rsp), %rdi
callq 0x3fe2
jmp 0x7e4a
jmp 0x7dfd
movq %rax, %r14
jmp 0x7e54
movq %rax, %r14
movq 0x148(%rsp), %rdi
leaq 0x158(%rsp), %rax
cmpq %rax, %rdi
je 0x7e54
callq 0x2100
jmp 0x7e54
movq %rax, %r14
leaq 0x178(%rsp), %rdi
callq 0x294e
jmp 0x7e38
jmp 0x7e47
movq %rax, %r14
leaq 0x1a8(%rsp), %rdi
callq 0x294e
jmp 0x7e4a
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0x294e
leaq 0x10(%rsp), %rdi
callq 0x294e
leaq 0x20(%rsp), %rdi
callq 0x294e
leaq 0x60(%rsp), %rdi
callq 0x3fe2
leaq 0xa8(%rsp), %rdi
callq 0x294e
leaq 0x70(%rsp), %rdi
callq 0x3fe2
leaq 0x98(%rsp), %rdi
callq 0x3fe2
leaq 0xd8(%rsp), %rdi
callq 0x294e
leaq 0xe8(%rsp), %rdi
callq 0x294e
leaq 0xf8(%rsp), %rdi
callq 0x294e
leaq 0x138(%rsp), %rdi
callq 0x294e
leaq 0x1b8(%rsp), %rdi
callq 0x2140
movq %r14, %rdi
callq 0x21b0