// File: /workspace/github_cpp_makefile_star2_O1/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 $0x3c8, %rsp            # imm = 0x3C8
movq %rdx, %rbx
movq %rsi, 0xc0(%rsp)
movq %rdi, 0x90(%rsp)
leaq 0x1c8(%rsp), %r14
movq %r14, %rdi
callq 0x2180
leaq 0x5270(%rip), %rsi      # 0xc5d9
movq %r14, %rdi
movl $0x10, %edx
callq 0x2040
movq %rbx, %rdi
callq 0x3485
movl %eax, %r14d
leaq 0x148(%rsp), %rdi
movl %eax, %esi
callq 0x28c8
leaq 0x100(%rsp), %rdi
leaq 0x148(%rsp), %rdx
movq 0xc0(%rsp), %rsi
callq 0x505f
leaq 0xf0(%rsp), %rdi
leaq 0x100(%rsp), %rdx
movq %rbx, %rsi
callq 0x2b28
leaq 0xf0(%rsp), %rdi
movl $0x2, %esi
callq 0x340b
movsd %xmm0, 0x58(%rsp)
leaq 0x1c8(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
movq $0xf, 0x1d0(%rsp,%rax)
callq 0x2170
leaq 0x4ef0(%rip), %rsi      # 0xc2f4
movl $0x1, %edx
movq %rax, %rdi
callq 0x2120
leaq 0x58(%rsp), %rdx
movsd (%rdx), %xmm0
movsd %xmm0, 0x60(%rsp)
leaq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x2e64
leaq 0xe0(%rsp), %rdi
callq 0x3485
leaq 0xa0(%rsp), %rdi
movl %eax, %esi
movl %r14d, %edx
callq 0x3df8
leal 0x1(%r14), %ebx
leaq 0x80(%rsp), %rdi
movl %ebx, %esi
movl %r14d, %edx
callq 0x3df8
leaq 0xb0(%rsp), %rdi
movl %ebx, %esi
callq 0x28c8
leaq 0xb0(%rsp), %rdi
movl $0x1, %esi
callq 0x3354
movsd 0x60(%rsp), %xmm0
movsd %xmm0, (%rax)
leaq 0x70(%rsp), %rdi
movl %ebx, %esi
movl %ebx, %edx
callq 0x3df8
testl %r14d, %r14d
js 0x74cb
movq 0x70(%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 0x74bb
leaq 0x138(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x2918
leaq 0xa0(%rsp), %rdi
leaq 0x138(%rsp), %r9
movl $0x1, %esi
movq %r14, 0x50(%rsp)
movl %r14d, %edx
movl $0x1, %ecx
movl $0x1, %r8d
callq 0x49d8
leaq 0x138(%rsp), %rdi
callq 0x2970
leaq 0x188(%rsp), %r14
movq $0x0, 0x98(%rsp)
leaq 0x10(%rsp), %rbx
leaq 0x38(%rsp), %r13
leaq 0x1b8(%rsp), %r15
leaq 0x1a8(%rsp), %rbp
movq $0x0, 0x30(%rsp)
movsd 0x58(%rsp), %xmm0
ucomisd 0x4da9(%rip), %xmm0     # 0xc308
jbe 0x799a
movq %r14, 0x178(%rsp)
leaq 0x178(%rsp), %rdi
leaq 0x506a(%rip), %rsi      # 0xc5e6
leaq 0x5069(%rip), %rdx      # 0xc5ec
callq 0x3c6e
movq 0x30(%rsp), %rax
leaq 0x1(%rax), %r8
leaq 0x20(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
movl $0x1, %edx
movq 0x50(%rsp), %rcx
movq %r8, %r12
movl %r8d, %r9d
callq 0x43be
movq 0x178(%rsp), %rdi
cmpq %r14, %rdi
je 0x75c5
callq 0x2110
movq %rbx, %rdi
movq 0xc0(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x505f
movl $0x1, %r14d
leaq 0x168(%rsp), %rax
movq %rax, 0x158(%rsp)
leaq 0x158(%rsp), %rdi
leaq 0x4fe7(%rip), %rsi      # 0xc5e6
leaq 0x4fe6(%rip), %rdx      # 0xc5ec
callq 0x3c6e
movq %r13, %rdi
leaq 0xa0(%rsp), %rsi
movl $0x1, %edx
movq 0x50(%rsp), %rcx
movl %r14d, %r8d
movl %r14d, %r9d
callq 0x43be
movq 0x158(%rsp), %rdi
leaq 0x168(%rsp), %rax
cmpq %rax, %rdi
je 0x7645
callq 0x2110
movq %r13, %rdi
movq %rbx, %rsi
callq 0x2cd3
movsd %xmm0, 0xd0(%rsp)
leaq 0x80(%rsp), %rdi
movl %r14d, %esi
movl %r12d, %edx
movsd %xmm0, 0x60(%rsp)
callq 0x51ec
movsd 0x60(%rsp), %xmm0
movsd %xmm0, (%rax)
movq %r15, %rdi
leaq 0xd0(%rsp), %rsi
movq %r13, %rdx
callq 0x2dde
movq %rbp, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2b28
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x303c
movq %rbp, %rdi
callq 0x2970
movq %r15, %rdi
callq 0x2970
movq %r13, %rdi
callq 0x2970
movq 0x98(%rsp), %rax
addl %r14d, %eax
incl %eax
movl %r14d, %ecx
incl %ecx
movl %ecx, %r14d
cmpl $0x2, %eax
jne 0x75e0
movq %rbx, %rdi
movl $0x2, %esi
callq 0x340b
movsd %xmm0, 0xc8(%rsp)
movq 0x30(%rsp), %rax
leal 0x2(%rax), %esi
leaq 0x80(%rsp), %rdi
movl %esi, 0x60(%rsp)
movl %r12d, %edx
movsd %xmm0, 0x48(%rsp)
callq 0x51ec
movsd 0x48(%rsp), %xmm0
movsd %xmm0, (%rax)
movsd 0xc8(%rsp), %xmm1
movsd 0x4bdf(%rip), %xmm0     # 0xc310
movsd %xmm1, 0x110(%rsp)
ucomisd %xmm1, %xmm0
leaq 0x198(%rsp), %r14
ja 0x79a1
movq %r13, %rdi
movq %rbx, %rsi
leaq 0xc8(%rsp), %rdx
callq 0x2e64
movq %r14, %rdi
movq %r13, %rsi
callq 0x2918
movq %r14, %r9
movq 0x30(%rsp), %rax
leaq 0x2(%rax), %r14
leaq 0xa0(%rsp), %rdi
movl $0x1, %esi
movq 0x50(%rsp), %rdx
movl %r14d, %ecx
movl %r14d, %r8d
callq 0x49d8
leaq 0x198(%rsp), %rdi
callq 0x2970
movq %rbp, %rdi
leaq 0x80(%rsp), %rsi
movl $0x1, %edx
movl 0x60(%rsp), %ecx
movl $0x1, %r8d
movl %r12d, %r9d
callq 0x415c
leaq 0xd0(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl $0x1, %edx
movl %r14d, %ecx
movl $0x1, %r8d
movl %r14d, %r9d
callq 0x415c
movq %r15, %rdi
leaq 0xd0(%rsp), %r14
movq %r14, %rsi
movq %rbp, %rdx
callq 0x4eee
movq %rbp, %rdi
movq %r15, %rsi
callq 0x67e4
movq %r15, %rdi
callq 0x4016
movq %r14, %rdi
callq 0x4016
movq %rbp, %rdi
movq %r12, %r14
movl %r14d, %esi
movl %r14d, %edx
callq 0x51ec
movsd (%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movq %rbp, %rdi
movl 0x60(%rsp), %esi
movl %r14d, %edx
callq 0x51ec
movsd (%rax), %xmm5
movapd %xmm5, %xmm1
mulsd %xmm5, %xmm1
movsd 0x48(%rsp), %xmm4
movapd %xmm4, %xmm0
mulsd %xmm4, %xmm0
addsd %xmm1, %xmm0
ucomisd 0x4a92(%rip), %xmm0     # 0xc2f8
jb 0x786e
sqrtsd %xmm0, %xmm0
jmp 0x7885
movapd %xmm5, 0x60(%rsp)
callq 0x20d0
movapd 0x60(%rsp), %xmm5
movsd 0x48(%rsp), %xmm4
leaq 0x188(%rsp), %r14
xorpd 0x47ab(%rip), %xmm5     # 0xc040
divsd %xmm0, %xmm5
movl 0x7c(%rsp), %eax
testl %eax, %eax
jle 0x78f7
divsd %xmm0, %xmm4
movq 0x70(%rsp), %rdx
movq -0x8(%rdx,%r12,8), %rcx
movq 0x30(%rsp), %rsi
movq 0x8(%rdx,%rsi,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 0x78bb
mulsd 0x58(%rsp), %xmm5
andpd 0x474b(%rip), %xmm5     # 0xc050
movlpd %xmm5, 0x58(%rsp)
movq 0x1c8(%rsp), %rax
movq -0x18(%rax), %rax
movq $0xf, 0x1d0(%rsp,%rax)
leaq 0x1c8(%rsp), %rdi
movapd %xmm5, %xmm0
callq 0x2170
movl $0x1, %edx
movq %rax, %rdi
leaq 0x49b1(%rip), %rsi      # 0xc2f4
callq 0x2120
movq %rbp, %rdi
callq 0x4016
movq %r13, %rdi
callq 0x2970
movq %rbx, %rdi
callq 0x2970
leaq 0x20(%rsp), %rdi
callq 0x2970
movq 0x98(%rsp), %rax
decl %eax
movq %rax, 0x98(%rsp)
movsd 0x498c(%rip), %xmm0     # 0xc310
ucomisd 0x110(%rsp), %xmm0
movq %r12, 0x30(%rsp)
jbe 0x7551
jmp 0x79b5
movq 0x30(%rsp), %r12
jmp 0x79b5
leaq 0x10(%rsp), %rdi
callq 0x2970
leaq 0x20(%rsp), %rdi
callq 0x2970
movq %r12, %r15
leal 0x1(%r12), %ebx
leaq 0x20(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl $0x1, %edx
movl %ebx, %ecx
movl $0x1, %r8d
movl %ebx, %r9d
callq 0x415c
leaq 0x10(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
movl $0x1, %edx
movl %ebx, %ecx
callq 0x3834
movq 0x50(%rsp), %r14
leaq 0x128(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x505f
leaq 0xb0(%rsp), %rdi
leaq 0x128(%rsp), %rcx
movl $0x1, %esi
movl %ebx, %edx
callq 0x38c0
leaq 0x128(%rsp), %rdi
callq 0x2970
leaq 0x10(%rsp), %rdi
callq 0x2970
leaq 0x20(%rsp), %rdi
callq 0x4016
leaq 0x20(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl $0x1, %edx
movl %ebx, %ecx
movl $0x1, %r8d
movl %ebx, %r9d
callq 0x415c
leaq 0x10(%rsp), %rdi
leaq 0x80(%rsp), %rsi
movl $0x1, %edx
movl %ebx, %ecx
movl $0x1, %r8d
movl %r15d, %r9d
callq 0x415c
leaq 0x118(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x4eee
leaq 0x80(%rsp), %rdi
leaq 0x118(%rsp), %r9
movl $0x1, %esi
movl %ebx, %edx
movl $0x1, %ecx
movq %r15, %rbx
movl %ebx, %r8d
callq 0x4768
leaq 0x118(%rsp), %rdi
callq 0x4016
leaq 0x10(%rsp), %rdi
callq 0x4016
leaq 0x20(%rsp), %rdi
callq 0x4016
leaq 0x10(%rsp), %rdi
leaq 0x80(%rsp), %rsi
movl $0x1, %edx
movl %ebx, %ecx
movl $0x1, %r8d
movl %ebx, %r9d
callq 0x415c
leaq 0x38(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
movl $0x1, %edx
movl %ebx, %ecx
callq 0x3834
leaq 0x20(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x38(%rsp), %rdx
xorl %ecx, %ecx
callq 0x61eb
leaq 0x38(%rsp), %rdi
callq 0x2970
leaq 0x10(%rsp), %rdi
callq 0x4016
leaq 0x38(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
movl $0x1, %edx
movl %r14d, %ecx
movl $0x1, %r8d
movl %r15d, %r9d
callq 0x415c
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x505f
leaq 0x100(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movq 0x90(%rsp), %rdi
callq 0x297d
leaq 0x10(%rsp), %rdi
callq 0x2970
leaq 0x38(%rsp), %rdi
callq 0x4016
leaq 0x1c8(%rsp), %rdi
callq 0x2140
leaq 0x20(%rsp), %rdi
callq 0x2970
leaq 0x70(%rsp), %rdi
callq 0x4016
leaq 0xb0(%rsp), %rdi
callq 0x2970
leaq 0x80(%rsp), %rdi
callq 0x4016
leaq 0xa0(%rsp), %rdi
callq 0x4016
leaq 0xe0(%rsp), %rdi
callq 0x2970
leaq 0xf0(%rsp), %rdi
callq 0x2970
leaq 0x100(%rsp), %rdi
callq 0x2970
leaq 0x148(%rsp), %rdi
callq 0x2970
movq 0x838d(%rip), %rax      # 0xffc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x1d0(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x1c8(%rsp,%rcx)
callq 0x20f0
leaq 0x2c0(%rsp), %rdi
callq 0x2060
movq 0x90(%rsp), %rax
addq $0x3c8, %rsp            # imm = 0x3C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x90(%rsp), %rdi
jmp 0x7e64
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x2970
jmp 0x7ca8
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x4016
jmp 0x7e69
jmp 0x7de5
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x2970
jmp 0x7cce
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
jmp 0x7d2b
jmp 0x7dea
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
callq 0x4016
jmp 0x7cef
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x4016
jmp 0x7d26
jmp 0x7d23
jmp 0x7dea
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x2970
jmp 0x7d17
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x2970
jmp 0x7d26
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x4016
jmp 0x7e73
jmp 0x7dea
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
jmp 0x7e6e
jmp 0x7dea
jmp 0x7d51
movq %rax, %rbx
jmp 0x7e7d
movq %rax, %rbx
jmp 0x7e8a
movq %rax, %rbx
jmp 0x7e97
jmp 0x7d8f
movq %rax, %rbx
jmp 0x7ebe
movq %rax, %rbx
jmp 0x7ecb
jmp 0x7d7f
jmp 0x7d7f
movq %rax, %rbx
jmp 0x7ed8
movq %rax, %rbx
jmp 0x7ea4
movq %rax, %rbx
jmp 0x7eb1
jmp 0x7e08
jmp 0x7e52
movq %rax, %rbx
leaq 0x198(%rsp), %rdi
jmp 0x7e4b
jmp 0x7e52
jmp 0x7df4
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x4016
jmp 0x7df7
movq %rax, %rbx
movq 0x178(%rsp), %rdi
cmpq %r14, %rdi
je 0x7e73
callq 0x2110
jmp 0x7e73
movq %rax, %rbx
jmp 0x7e69
movq %rax, %rbx
jmp 0x7e73
jmp 0x7df4
movq %rax, %rbx
leaq 0x1a8(%rsp), %rdi
callq 0x4016
jmp 0x7e55
jmp 0x7e08
movq %rax, %rbx
jmp 0x7e5f
movq %rax, %rbx
movq 0x158(%rsp), %rdi
leaq 0x168(%rsp), %rax
cmpq %rax, %rdi
je 0x7e5f
callq 0x2110
jmp 0x7e5f
movq %rax, %rbx
leaq 0x1a8(%rsp), %rdi
callq 0x2970
jmp 0x7e43
jmp 0x7e52
movq %rax, %rbx
leaq 0x1b8(%rsp), %rdi
callq 0x2970
jmp 0x7e55
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x2970
leaq 0x10(%rsp), %rdi
callq 0x2970
leaq 0x20(%rsp), %rdi
callq 0x2970
leaq 0x70(%rsp), %rdi
callq 0x4016
leaq 0xb0(%rsp), %rdi
callq 0x2970
leaq 0x80(%rsp), %rdi
callq 0x4016
leaq 0xa0(%rsp), %rdi
callq 0x4016
leaq 0xe0(%rsp), %rdi
callq 0x2970
leaq 0xf0(%rsp), %rdi
callq 0x2970
leaq 0x100(%rsp), %rdi
callq 0x2970
leaq 0x148(%rsp), %rdi
callq 0x2970
leaq 0x1c8(%rsp), %rdi
callq 0x2150
movq %rbx, %rdi
callq 0x21c0