// File: /workspace/github_cpp_makefile_star2_O3/IlanPrice[P]Linear-Algebra-Library-in-Cplusplus/Matrix.cpp
// Function: jacobi(Matrix const&, Vector const&)
Vector jacobi(const Matrix& A, const Vector& b)
{
	std::ofstream JacobiIterates;
	JacobiIterates.open("JacobiIterates.txt");
	int n = length(b);
	Vector x(n);
	Vector xnext(n);
	Vector r = b - A*x;
	double Tol = 1e-14;
	int iter = 0;
	while (norm(r) > Tol & iter < 10000)
	{
		for (int i = 1; i<=n; i++)
		{
			double sum = 0;
			for (int j=1; j<=n; j++)
			{
				if (i != j) { sum = sum + A(i,j)*x(j);}
				else if (i==j) {}
			}
			xnext(i) = (b(i) - sum)/A(i,i);
			JacobiIterates << std::setprecision(15) << xnext(i)<< ",";
		}
		r = b - A*xnext;
		x = xnext;
		JacobiIterates << "\n";
		iter++;
	}

	JacobiIterates.close();
	return xnext;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, 0x8(%rsp)
leaq 0x78(%rsp), %r14
movq %r14, %rdi
callq 0x2170
leaq 0x3a16(%rip), %rsi      # 0xc5fb
movq %r14, %rdi
movl $0x10, %edx
callq 0x2040
movq %rbx, %rdi
callq 0x3461
movl %eax, %r12d
movq %rbx, %r14
leaq 0x48(%rsp), %rdi
movl %eax, %esi
callq 0x28b8
movq 0x8(%rsp), %rdi
movl %r12d, %esi
callq 0x28b8
leaq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %rdx
movq %r15, %rsi
callq 0x5071
leaq 0x38(%rsp), %rdi
leaq 0x28(%rsp), %rdx
movq %r14, %rsi
callq 0x2af8
leaq 0x28(%rsp), %rdi
callq 0x294e
movl %r12d, %ebp
negl %ebp
movl $0x0, 0x10(%rsp)
leaq 0x48(%rsp), %r13
movq %r14, 0x58(%rsp)
movl %r12d, 0x14(%rsp)
leaq 0x38(%rsp), %rdi
movl $0x2, %esi
callq 0x33e7
cmpl $0x270f, 0x10(%rsp)     # imm = 0x270F
ja 0x8e2e
ucomisd 0x3680(%rip), %xmm0     # 0xc308
jbe 0x8e2e
testl %r12d, %r12d
jle 0x8db6
movl $0x1, %r12d
xorl %ebx, %ebx
xorpd %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
movl $0x1, %r14d
leal (%rbx,%r14), %eax
cmpl $0x1, %eax
je 0x8cf5
movq %r15, %rdi
movl %r12d, %esi
movl %r14d, %edx
callq 0x5202
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %r13, %rdi
movl %r14d, %esi
callq 0x3330
movsd 0x18(%rsp), %xmm1
mulsd (%rax), %xmm1
movsd 0x20(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
leal (%r14,%rbp), %eax
incl %eax
movl %r14d, %ecx
incl %ecx
movl %ecx, %r14d
cmpl $0x1, %eax
jne 0x8caf
movq 0x58(%rsp), %r14
movq %r14, %rdi
movl %r12d, %esi
callq 0x318c
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %r15, %rdi
movl %r12d, %esi
movl %r12d, %edx
callq 0x5202
movsd (%rax), %xmm0
movsd %xmm0, 0x60(%rsp)
movq 0x8(%rsp), %rdi
movl %r12d, %esi
callq 0x3330
movsd 0x18(%rsp), %xmm0
subsd 0x20(%rsp), %xmm0
divsd 0x60(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x78(%rsp), %rax
movq -0x18(%rax), %rax
movq $0xf, 0x80(%rsp,%rax)
movq 0x8(%rsp), %rdi
movl %r12d, %esi
callq 0x3330
movsd (%rax), %xmm0
leaq 0x78(%rsp), %rdi
callq 0x2160
movl $0x1, %edx
movq %rax, %rdi
leaq 0x3872(%rip), %rsi      # 0xc60e
callq 0x2110
leal 0x1(%r12), %eax
decl %ebx
cmpl 0x14(%rsp), %r12d
movl %eax, %r12d
jne 0x8c9f
leaq 0x68(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq 0x8(%rsp), %rdx
callq 0x5071
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x2af8
movl 0x14(%rsp), %r12d
leaq 0x38(%rsp), %rdi
movq %rbx, %rsi
callq 0x300a
movq %rbx, %rdi
callq 0x294e
leaq 0x68(%rsp), %rdi
callq 0x294e
movq %r13, %rdi
movq 0x8(%rsp), %rsi
callq 0x300a
movl $0x1, %edx
leaq 0x78(%rsp), %rdi
leaq 0x34d4(%rip), %rsi      # 0xc2f4
callq 0x2110
incl 0x10(%rsp)
jmp 0x8c63
leaq 0x78(%rsp), %rdi
callq 0x2130
leaq 0x38(%rsp), %rdi
callq 0x294e
leaq 0x48(%rsp), %rdi
callq 0x294e
movq 0x7175(%rip), %rax      # 0xffc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x170(%rsp), %r14
movq %rcx, -0xf8(%r14)
movq -0x18(%rcx), %rcx
movq %rax, 0x78(%rsp,%rcx)
leaq 0x80(%rsp), %rdi
callq 0x20e0
movq %r14, %rdi
callq 0x2060
movq 0x8(%rsp), %rax
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x8ee1
movq %rax, %r14
leaq 0x28(%rsp), %rdi
jmp 0x8ee9
movq %rax, %r14
jmp 0x8eee
movq %rax, %r14
jmp 0x8ef8
jmp 0x8eb8
jmp 0x8eb8
movq %rax, %r14
jmp 0x8f02
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x294e
jmp 0x8ecf
movq %rax, %r14
leaq 0x68(%rsp), %rdi
callq 0x294e
jmp 0x8ee4
jmp 0x8ee1
jmp 0x8ee1
jmp 0x8ee1
movq %rax, %r14
leaq 0x38(%rsp), %rdi
callq 0x294e
movq 0x8(%rsp), %rdi
callq 0x294e
leaq 0x48(%rsp), %rdi
callq 0x294e
movq 0x70bf(%rip), %rax      # 0xffc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x80(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x78(%rsp,%rcx)
callq 0x20e0
leaq 0x170(%rsp), %rdi
callq 0x2060
movq %r14, %rdi
callq 0x21b0