// File: 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:
subq $0x588, %rsp            # imm = 0x588
movq %rdi, 0x78(%rsp)
movq %rdi, %rax
movq %rax, 0x80(%rsp)
movq %rdi, 0x580(%rsp)
movq %rsi, 0x578(%rsp)
movq %rdx, 0x570(%rsp)
leaq 0x370(%rsp), %rdi
callq 0x2170
leaq 0x170(%rsp), %rdi
callq 0x2170
jmp 0xa6bb
leaq 0x7ec6(%rip), %rsi      # 0x12588
leaq 0x370(%rsp), %rdi
movl $0x10, %edx
callq 0x2050
jmp 0xa6d6
leaq 0x7eb5(%rip), %rsi      # 0x12592
leaq 0x170(%rsp), %rdi
movl $0x10, %edx
callq 0x2050
jmp 0xa6f1
movb $0x0, 0x163(%rsp)
movq 0x570(%rsp), %rdi
callq 0x4090
movl %eax, 0x74(%rsp)
jmp 0xa70c
movl 0x74(%rsp), %esi
movq 0x78(%rsp), %rdi
callq 0x2d70
jmp 0xa71c
movl $0xf, %edi
callq 0x10e10
movl %eax, 0x70(%rsp)
jmp 0xa72c
movl 0x70(%rsp), %eax
movl %eax, 0x15c(%rsp)
movl 0x15c(%rsp), %esi
leaq 0x170(%rsp), %rdi
callq 0x2160
movq %rax, 0x68(%rsp)
jmp 0xa752
movq 0x78(%rsp), %rsi
movq 0x68(%rsp), %rdi
callq 0x3f00
movq %rax, 0x60(%rsp)
jmp 0xa768
movq 0x60(%rsp), %rdi
leaq 0x7b36(%rip), %rsi      # 0x122aa
callq 0x20e0
jmp 0xa77b
movq 0x78(%rsp), %rdx
movq 0x578(%rsp), %rsi
leaq 0x148(%rsp), %rdi
callq 0x6f70
jmp 0xa797
movq 0x570(%rsp), %rsi
leaq 0x138(%rsp), %rdi
leaq 0x148(%rsp), %rdx
callq 0x31a0
jmp 0xa7b6
leaq 0x128(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x2e00
jmp 0xa7cd
leaq 0x138(%rsp), %rsi
movq %rsi, %rdi
callq 0x3470
movsd %xmm0, 0x58(%rsp)
jmp 0xa7e5
movsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x120(%rsp)
movq 0x578(%rsp), %rsi
leaq 0xf8(%rsp), %rdi
leaq 0x128(%rsp), %rdx
callq 0x6f70
jmp 0xa813
leaq 0x148(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x39a0
jmp 0xa82a
leaq 0xf8(%rsp), %rdi
callq 0x2ea0
movsd 0x120(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
leaq 0x128(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0x3470
movsd %xmm0, 0x50(%rsp)
jmp 0xa863
movsd 0x50(%rsp), %xmm1
movsd 0x48(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x108(%rsp)
leaq 0xd8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
leaq 0x128(%rsp), %rdx
callq 0x3640
jmp 0xa89b
movq 0x78(%rsp), %rsi
leaq 0xe8(%rsp), %rdi
leaq 0xd8(%rsp), %rdx
callq 0x2ed0
jmp 0xa8b7
movq 0x78(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x39a0
jmp 0xa8cb
leaq 0xe8(%rsp), %rdi
callq 0x2ea0
leaq 0xd8(%rsp), %rdi
callq 0x2ea0
movl $0xf, %edi
callq 0x10e10
movl %eax, 0x44(%rsp)
jmp 0xa8f5
movl 0x44(%rsp), %eax
movl %eax, 0xd4(%rsp)
movl 0xd4(%rsp), %esi
leaq 0x170(%rsp), %rdi
callq 0x2160
movq %rax, 0x38(%rsp)
jmp 0xa91b
movq 0x78(%rsp), %rsi
movq 0x38(%rsp), %rdi
callq 0x3f00
movq %rax, 0x30(%rsp)
jmp 0xa931
movq 0x30(%rsp), %rdi
leaq 0x796d(%rip), %rsi      # 0x122aa
callq 0x20e0
jmp 0xa944
movsd 0x120(%rsp), %xmm0
movsd %xmm0, 0x118(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0x108(%rsp), %rsi
leaq 0x148(%rsp), %rdx
callq 0x3640
jmp 0xa975
leaq 0xc0(%rsp), %rdi
leaq 0x138(%rsp), %rsi
leaq 0xb0(%rsp), %rdx
callq 0x31a0
jmp 0xa994
leaq 0x138(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x39a0
jmp 0xa9ab
leaq 0xc0(%rsp), %rdi
callq 0x2ea0
leaq 0xb0(%rsp), %rdi
callq 0x2ea0
leaq 0x138(%rsp), %rsi
movq %rsi, %rdi
callq 0x3470
movsd %xmm0, 0x28(%rsp)
jmp 0xa9dd
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x120(%rsp)
movsd 0x120(%rsp), %xmm0
movsd 0x118(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x110(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x110(%rsp), %rsi
leaq 0x128(%rsp), %rdx
callq 0x3640
jmp 0xaa2a
leaq 0xa0(%rsp), %rdi
leaq 0x138(%rsp), %rsi
leaq 0x90(%rsp), %rdx
callq 0x2ed0
jmp 0xaa49
leaq 0x128(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x39a0
jmp 0xaa60
leaq 0xa0(%rsp), %rdi
callq 0x2ea0
leaq 0x90(%rsp), %rdi
callq 0x2ea0
movl $0xf, %edi
callq 0x10e10
movl %eax, 0x24(%rsp)
jmp 0xaa8a
movl 0x24(%rsp), %eax
movl %eax, 0x8c(%rsp)
movl 0x8c(%rsp), %esi
leaq 0x370(%rsp), %rdi
callq 0x2160
movq %rax, 0x18(%rsp)
jmp 0xaab0
movq 0x18(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x3f00
movq %rax, 0x10(%rsp)
jmp 0xaac9
movq 0x10(%rsp), %rdi
leaq 0x77d5(%rip), %rsi      # 0x122aa
callq 0x20e0
jmp 0xaadc
jmp 0xaade
leaq 0x138(%rsp), %rdi
movl $0x2, %esi
callq 0x3fe0
movsd %xmm0, 0x8(%rsp)
jmp 0xaaf8
movsd 0x8(%rsp), %xmm0
movsd 0x77aa(%rip), %xmm1     # 0x122b0
ucomisd %xmm1, %xmm0
ja 0xa7f4
leaq 0x370(%rsp), %rdi
callq 0x2130
jmp 0xab1f
leaq 0x170(%rsp), %rdi
callq 0x2130
jmp 0xab2e
movb $0x1, 0x163(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x2ea0
leaq 0x138(%rsp), %rdi
callq 0x2ea0
leaq 0x148(%rsp), %rdi
callq 0x2ea0
testb $0x1, 0x163(%rsp)
jne 0xad32
jmp 0xad28
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x168(%rsp)
movl %eax, 0x164(%rsp)
jmp 0xad73
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x168(%rsp)
movl %eax, 0x164(%rsp)
jmp 0xad66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x168(%rsp)
movl %eax, 0x164(%rsp)
jmp 0xad5c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x168(%rsp)
movl %eax, 0x164(%rsp)
jmp 0xad19
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x168(%rsp)
movl %eax, 0x164(%rsp)
jmp 0xad0c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x168(%rsp)
movl %eax, 0x164(%rsp)
jmp 0xacff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x168(%rsp)
movl %eax, 0x164(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x2ea0
jmp 0xacff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x168(%rsp)
movl %eax, 0x164(%rsp)
jmp 0xac63
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x168(%rsp)
movl %eax, 0x164(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x2ea0
leaq 0xd8(%rsp), %rdi
callq 0x2ea0
jmp 0xacff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x168(%rsp)
movl %eax, 0x164(%rsp)
jmp 0xacac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x168(%rsp)
movl %eax, 0x164(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x2ea0
leaq 0xb0(%rsp), %rdi
callq 0x2ea0
jmp 0xacff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x168(%rsp)
movl %eax, 0x164(%rsp)
jmp 0xacf2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x168(%rsp)
movl %eax, 0x164(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x2ea0
leaq 0x90(%rsp), %rdi
callq 0x2ea0
leaq 0x128(%rsp), %rdi
callq 0x2ea0
leaq 0x138(%rsp), %rdi
callq 0x2ea0
leaq 0x148(%rsp), %rdi
callq 0x2ea0
jmp 0xad5c
movq 0x78(%rsp), %rdi
callq 0x2ea0
leaq 0x170(%rsp), %rdi
callq 0x2140
leaq 0x370(%rsp), %rdi
callq 0x2140
movq 0x80(%rsp), %rax
addq $0x588, %rsp            # imm = 0x588
retq
movq 0x78(%rsp), %rdi
callq 0x2ea0
leaq 0x170(%rsp), %rdi
callq 0x2140
leaq 0x370(%rsp), %rdi
callq 0x2140
movq 0x168(%rsp), %rdi
callq 0x21b0
nopl (%rax)