// File: /workspace/github_cpp_makefile_star2_O2/IlanPrice[P]Linear-Algebra-Library-in-Cplusplus/Matrix.cpp
// Function: CG(Matrix const&, Vector const&)
Vector CG(const Matrix& A, const Vector& b)
{
	std::ofstream CGres;
	std::ofstream CGIterates;
	CGres.open("CGres.txt");
	CGIterates.open("CGIterates.txt");
	Vector x(length(b));
	CGIterates << std::setprecision(15) << x << "\n";
	Vector temp1 = A*x;
	Vector r = b - temp1;
	Vector p = r;
	double temp2 = r*r;
	double temp3, beta, alpha;
	do {
		temp1 = A*p;
		alpha = (temp2)/(p*temp1);
		x = x + alpha*p;
		CGIterates << std::setprecision(15) << x << "\n";
		temp3 = temp2;
		r = r - alpha*temp1;
		temp2 = r*r;
		beta = temp2/temp3;
		p = r + beta*p;
		CGres << std::setprecision(15) << r << "\n";
	}while(norm(r)>1e-15);
	CGres.close();
	CGIterates.close();
	return x;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x478, %rsp            # imm = 0x478
movq %rdx, %r14
movq %rsi, 0x8(%rsp)
movq %rdi, %rbx
leaq 0x278(%rsp), %rdi
callq 0x1140
leaq 0x78(%rsp), %rdi
callq 0x1140
leaq 0x424d(%rip), %rsi      # 0x9598
leaq 0x278(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x1040
leaq 0x4240(%rip), %rsi      # 0x95a2
leaq 0x78(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x1040
movq %r14, %rdi
callq 0x2141
movq %rbx, %rdi
movl %eax, %esi
callq 0x186c
leaq 0x78(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
movq $0xf, 0x80(%rsp,%rax)
movq %rbx, %rsi
callq 0x2035
leaq 0x3f22(%rip), %rsi      # 0x92ca
movq %rax, %rdi
callq 0x10e0
leaq 0x40(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq 0x38bd
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rdx
movq %r14, %rsi
callq 0x1a3c
leaq 0x68(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x18bc
leaq 0x20(%rsp), %rdi
movq %rdi, %rsi
callq 0x1b63
movsd %xmm0, (%rsp)
leaq 0x30(%rsp), %r15
leaq 0x68(%rsp), %r12
leaq 0x40(%rsp), %r13
leaq 0x50(%rsp), %rbp
leaq 0x20(%rsp), %r14
movq %r15, %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rdx
callq 0x38bd
movq %r13, %rdi
movq %r15, %rsi
callq 0x1da0
movq %r15, %rdi
callq 0x1908
movq %r12, %rdi
movq %r13, %rsi
callq 0x1b63
movsd (%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
movq %rbp, %rdi
leaq 0x18(%rsp), %rsi
movq %r12, %rdx
callq 0x1c1c
movq %r15, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x1915
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1da0
movq %r15, %rdi
callq 0x1908
movq %rbp, %rdi
callq 0x1908
movq 0x78(%rsp), %rax
movq -0x18(%rax), %rax
movq $0xf, 0x80(%rsp,%rax)
leaq 0x78(%rsp), %rdi
movq %rbx, %rsi
callq 0x2035
movq %rax, %rdi
leaq 0x3e1a(%rip), %rsi      # 0x92ca
callq 0x10e0
movq %rbp, %rdi
leaq 0x18(%rsp), %rsi
movq %r13, %rdx
callq 0x1c1c
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x1a3c
movq %r14, %rdi
movq %r15, %rsi
callq 0x1da0
movq %r15, %rdi
callq 0x1908
movq %rbp, %rdi
callq 0x1908
movq %r14, %rdi
movq %r14, %rsi
callq 0x1b63
movsd %xmm0, 0x10(%rsp)
movsd 0x10(%rsp), %xmm0
divsd (%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movq %rbp, %rdi
leaq 0x60(%rsp), %rsi
movq %r12, %rdx
callq 0x1c1c
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x1915
movq %r12, %rdi
movq %r15, %rsi
callq 0x1da0
movq %r15, %rdi
callq 0x1908
movq %rbp, %rdi
callq 0x1908
movq 0x278(%rsp), %rax
movq -0x18(%rax), %rax
movq $0xf, 0x280(%rsp,%rax)
leaq 0x278(%rsp), %rdi
movq %r14, %rsi
callq 0x2035
movq %rax, %rdi
leaq 0x3d4f(%rip), %rsi      # 0x92ca
callq 0x10e0
movq %r14, %rdi
pushq $0x2
popq %rsi
callq 0x20c8
ucomisd 0x3d45(%rip), %xmm0     # 0x92d8
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rsp)
ja 0x540e
leaq 0x278(%rsp), %rdi
callq 0x1100
leaq 0x78(%rsp), %rdi
callq 0x1100
leaq 0x68(%rsp), %rdi
callq 0x1908
leaq 0x20(%rsp), %rdi
callq 0x1908
leaq 0x40(%rsp), %rdi
callq 0x1908
leaq 0x78(%rsp), %rdi
callq 0x1110
leaq 0x278(%rsp), %rdi
callq 0x1110
movq %rbx, %rax
addq $0x478, %rsp            # imm = 0x478
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x565c
movq %rax, %r14
jmp 0x5669
movq %rax, %r14
jmp 0x5673
jmp 0x561a
movq %rax, %r14
jmp 0x568f
jmp 0x565c
movq %rax, %r14
jmp 0x567d
movq %rax, %r14
jmp 0x5685
jmp 0x565c
movq %rax, %r14
leaq 0x30(%rsp), %rdi
jmp 0x5655
jmp 0x565c
jmp 0x563e
jmp 0x5643
jmp 0x565c
jmp 0x563e
jmp 0x5643
jmp 0x565c
movq %rax, %r14
jmp 0x5650
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x1908
leaq 0x50(%rsp), %rdi
callq 0x1908
jmp 0x565f
movq %rax, %r14
leaq 0x68(%rsp), %rdi
callq 0x1908
leaq 0x20(%rsp), %rdi
callq 0x1908
leaq 0x40(%rsp), %rdi
callq 0x1908
movq %rbx, %rdi
callq 0x1908
leaq 0x78(%rsp), %rdi
callq 0x1110
leaq 0x278(%rsp), %rdi
callq 0x1110
movq %r14, %rdi
callq 0x1180