// File: /workspace/github_cpp_makefile_star2_O1/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 0x2180
leaq 0x78(%rsp), %rdi
callq 0x2180
leaq 0x5651(%rip), %rsi      # 0xc5c0
leaq 0x278(%rsp), %rdi
movl $0x10, %edx
callq 0x2040
leaq 0x5642(%rip), %rsi      # 0xc5ca
leaq 0x78(%rsp), %rdi
movl $0x10, %edx
callq 0x2040
movq %r14, %rdi
callq 0x3485
movq %rbx, %rdi
movl %eax, %esi
callq 0x28c8
leaq 0x78(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
movq $0xf, 0x80(%rsp,%rax)
movq %rbx, %rsi
callq 0x3359
leaq 0x5324(%rip), %rsi      # 0xc2f4
movl $0x1, %edx
movq %rax, %rdi
callq 0x2120
leaq 0x40(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq 0x505f
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rdx
movq %r14, %rsi
callq 0x2b28
leaq 0x68(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x2918
leaq 0x20(%rsp), %rdi
movq %rdi, %rsi
callq 0x2cd3
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 0x505f
movq %r13, %rdi
movq %r15, %rsi
callq 0x303c
movq %r15, %rdi
callq 0x2970
movq %r12, %rdi
movq %r13, %rsi
callq 0x2cd3
movsd (%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
movq %rbp, %rdi
leaq 0x18(%rsp), %rsi
movq %r12, %rdx
callq 0x2dde
movq %r15, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x297d
movq %rbx, %rdi
movq %r15, %rsi
callq 0x303c
movq %r15, %rdi
callq 0x2970
movq %rbp, %rdi
callq 0x2970
movq 0x78(%rsp), %rax
movq -0x18(%rax), %rax
movq $0xf, 0x80(%rsp,%rax)
leaq 0x78(%rsp), %rdi
movq %rbx, %rsi
callq 0x3359
movl $0x1, %edx
movq %rax, %rdi
leaq 0x5212(%rip), %rsi      # 0xc2f4
callq 0x2120
movq %rbp, %rdi
leaq 0x18(%rsp), %rsi
movq %r13, %rdx
callq 0x2dde
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x2b28
movq %r14, %rdi
movq %r15, %rsi
callq 0x303c
movq %r15, %rdi
callq 0x2970
movq %rbp, %rdi
callq 0x2970
movq %r14, %rdi
movq %r14, %rsi
callq 0x2cd3
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 0x2dde
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x297d
movq %r12, %rdi
movq %r15, %rsi
callq 0x303c
movq %r15, %rdi
callq 0x2970
movq %rbp, %rdi
callq 0x2970
movq 0x278(%rsp), %rax
movq -0x18(%rax), %rax
movq $0xf, 0x280(%rsp,%rax)
leaq 0x278(%rsp), %rdi
movq %r14, %rsi
callq 0x3359
movl $0x1, %edx
movq %rax, %rdi
leaq 0x5142(%rip), %rsi      # 0xc2f4
callq 0x2120
movq %r14, %rdi
movl $0x2, %esi
callq 0x340b
ucomisd 0x5134(%rip), %xmm0     # 0xc300
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rsp)
ja 0x703b
leaq 0x278(%rsp), %r14
movq %r14, %rdi
callq 0x2140
leaq 0x78(%rsp), %r15
movq %r15, %rdi
callq 0x2140
leaq 0x68(%rsp), %rdi
callq 0x2970
leaq 0x20(%rsp), %rdi
callq 0x2970
leaq 0x40(%rsp), %rdi
callq 0x2970
movq 0x8da9(%rip), %rax      # 0xffc8
movq (%rax), %r12
movq 0x18(%rax), %r13
leaq 0x80(%rsp), %rdi
movq %r12, -0x8(%rdi)
movq -0x18(%r12), %rax
movq %r13, 0x78(%rsp,%rax)
callq 0x20f0
movl $0xf8, %ebp
addq %rbp, %r15
movq %r15, %rdi
callq 0x2060
leaq 0x280(%rsp), %rdi
movq %r12, -0x8(%rdi)
movq -0x18(%r12), %rax
movq %r13, 0x278(%rsp,%rax)
callq 0x20f0
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 0x72e6
movq %rax, %r14
jmp 0x72f3
movq %rax, %r14
jmp 0x72fd
jmp 0x72a4
movq %rax, %r14
jmp 0x7319
jmp 0x72e6
movq %rax, %r14
jmp 0x7307
movq %rax, %r14
jmp 0x730f
jmp 0x72e6
movq %rax, %r14
leaq 0x30(%rsp), %rdi
jmp 0x72df
jmp 0x72e6
jmp 0x72c8
jmp 0x72cd
jmp 0x72e6
jmp 0x72c8
jmp 0x72cd
jmp 0x72e6
movq %rax, %r14
jmp 0x72da
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x2970
leaq 0x50(%rsp), %rdi
callq 0x2970
jmp 0x72e9
movq %rax, %r14
leaq 0x68(%rsp), %rdi
callq 0x2970
leaq 0x20(%rsp), %rdi
callq 0x2970
leaq 0x40(%rsp), %rdi
callq 0x2970
movq %rbx, %rdi
callq 0x2970
leaq 0x78(%rsp), %rdi
callq 0x2150
leaq 0x278(%rsp), %rdi
callq 0x2150
movq %r14, %rdi
callq 0x21c0