// File: /workspace/github_cpp_makefile_star2_O3/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 0x2170
leaq 0x78(%rsp), %rdi
callq 0x2170
leaq 0x5622(%rip), %rsi      # 0xc5c0
leaq 0x278(%rsp), %rdi
movl $0x10, %edx
callq 0x2040
leaq 0x5613(%rip), %rsi      # 0xc5ca
leaq 0x78(%rsp), %rdi
movl $0x10, %edx
callq 0x2040
movq %r14, %rdi
callq 0x3461
movq %rbx, %rdi
movl %eax, %esi
callq 0x28b8
leaq 0x78(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
movq $0xf, 0x80(%rsp,%rax)
movq %rbx, %rsi
callq 0x3335
leaq 0x52f5(%rip), %rsi      # 0xc2f4
movl $0x1, %edx
movq %rax, %rdi
callq 0x2110
leaq 0x40(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq 0x5071
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rdx
movq %r14, %rsi
callq 0x2af8
leaq 0x68(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x28fa
leaq 0x20(%rsp), %rdi
movq %rdi, %rsi
callq 0x2c95
movsd %xmm0, (%rsp)
leaq 0x30(%rsp), %r13
leaq 0x68(%rsp), %rbp
leaq 0x40(%rsp), %r15
leaq 0x50(%rsp), %r12
leaq 0x20(%rsp), %r14
movq %r13, %rdi
movq 0x8(%rsp), %rsi
movq %rbp, %rdx
callq 0x5071
movq %r15, %rdi
movq %r13, %rsi
callq 0x300a
movq %r13, %rdi
callq 0x294e
movq %rbp, %rdi
movq %r15, %rsi
callq 0x2c95
movsd (%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
movq %r12, %rdi
leaq 0x18(%rsp), %rsi
movq %rbp, %rdx
callq 0x2da1
movq %r13, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x295b
movq %rbx, %rdi
movq %r13, %rsi
callq 0x300a
movq %r13, %rdi
callq 0x294e
movq %r12, %rdi
callq 0x294e
movq 0x78(%rsp), %rax
movq -0x18(%rax), %rax
movq $0xf, 0x80(%rsp,%rax)
leaq 0x78(%rsp), %rdi
movq %rbx, %rsi
callq 0x3335
movl $0x1, %edx
movq %rax, %rdi
leaq 0x51e3(%rip), %rsi      # 0xc2f4
callq 0x2110
movq %r12, %rdi
leaq 0x18(%rsp), %rsi
movq %r15, %rdx
callq 0x2da1
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x2af8
movq %r14, %rdi
movq %r13, %rsi
callq 0x300a
movq %r13, %rdi
callq 0x294e
movq %r12, %rdi
callq 0x294e
movq %r14, %rdi
movq %r14, %rsi
callq 0x2c95
movsd %xmm0, 0x10(%rsp)
movsd 0x10(%rsp), %xmm0
divsd (%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movq %r12, %rdi
leaq 0x60(%rsp), %rsi
movq %rbp, %rdx
callq 0x2da1
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x295b
movq %rbp, %rdi
movq %r13, %rsi
callq 0x300a
movq %r13, %rdi
callq 0x294e
movq %r12, %rdi
callq 0x294e
movq 0x278(%rsp), %rax
movq -0x18(%rax), %rax
movq $0xf, 0x280(%rsp,%rax)
leaq 0x278(%rsp), %rdi
movq %r14, %rsi
callq 0x3335
movl $0x1, %edx
movq %rax, %rdi
leaq 0x5113(%rip), %rsi      # 0xc2f4
callq 0x2110
movq %r14, %rdi
movl $0x2, %esi
callq 0x33e7
ucomisd 0x5105(%rip), %xmm0     # 0xc300
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rsp)
ja 0x706a
leaq 0x278(%rsp), %r14
movq %r14, %rdi
callq 0x2130
leaq 0x78(%rsp), %r15
movq %r15, %rdi
callq 0x2130
leaq 0x68(%rsp), %rdi
callq 0x294e
leaq 0x20(%rsp), %rdi
callq 0x294e
leaq 0x40(%rsp), %rdi
callq 0x294e
movq 0x8d7a(%rip), %rax      # 0xffc8
movq (%rax), %r12
movq 0x18(%rax), %r13
movq %r12, 0x78(%rsp)
movq -0x18(%r12), %rax
movq %r13, 0x78(%rsp,%rax)
leaq 0x80(%rsp), %rdi
callq 0x20e0
movl $0xf8, %ebp
addq %rbp, %r15
movq %r15, %rdi
callq 0x2060
movq %r12, 0x278(%rsp)
movq -0x18(%r12), %rax
movq %r13, 0x278(%rsp,%rax)
leaq 0x280(%rsp), %rdi
callq 0x20e0
addq %rbp, %r14
movq %r14, %rdi
callq 0x2060
movq %rbx, %rax
addq $0x478, %rsp            # imm = 0x478
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x731a
movq %rax, %r14
jmp 0x7327
movq %rax, %r14
jmp 0x7331
jmp 0x72d8
movq %rax, %r14
jmp 0x734d
jmp 0x731a
movq %rax, %r14
jmp 0x733b
movq %rax, %r14
jmp 0x7343
jmp 0x731a
movq %rax, %r14
leaq 0x30(%rsp), %rdi
jmp 0x7313
jmp 0x731a
jmp 0x72fc
jmp 0x7301
jmp 0x731a
jmp 0x72fc
jmp 0x7301
jmp 0x731a
movq %rax, %r14
jmp 0x730e
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x294e
leaq 0x50(%rsp), %rdi
callq 0x294e
jmp 0x731d
movq %rax, %r14
leaq 0x68(%rsp), %rdi
callq 0x294e
leaq 0x20(%rsp), %rdi
callq 0x294e
leaq 0x40(%rsp), %rdi
callq 0x294e
movq %rbx, %rdi
callq 0x294e
leaq 0x78(%rsp), %rdi
callq 0x2140
leaq 0x278(%rsp), %rdi
callq 0x2140
movq %r14, %rdi
callq 0x21b0