// File: /workspace/github_cpp_makefile_star2_O2/IlanPrice[P]Linear-Algebra-Library-in-Cplusplus/Matrix.cpp
// Function: GS(Matrix const&, Vector const&)
Vector GS(const Matrix& A, const Vector& b)
{
	std::ofstream GSIterates;
	GSIterates.open("GSIterates.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 sum1 = 0; double sum2 = 0;
			if (i!=1){
			for (int j=1; j<i; j++)
			{
				sum1 = sum1 + A(i,j)*xnext(j);
			}
			}
			if (i!=n){
			for (int j=i+1; j<=n; j++)
			{
				sum2 = sum2 + A(i,j)*x(j);
			}
			}
			xnext(i) = (b(i) - sum2 - sum1)/A(i,i);
			GSIterates << std::setprecision(15) << xnext(i)<< ",";
		}
		r = b - A*xnext;
		x = xnext;
		GSIterates << "\n";
		iter++;
	}
	GSIterates.close();
	return xnext;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x78(%rsp), %r14
movq %r14, %rdi
callq 0x1140
leaq 0x2627(%rip), %rsi      # 0x95e8
pushq $0x10
popq %rdx
movq %r14, %rdi
callq 0x1040
movq %r12, %rdi
callq 0x2141
movl %eax, %ebp
leaq 0x40(%rsp), %rdi
movl %eax, %esi
callq 0x186c
movq %rbx, %rdi
movl %ebp, %esi
callq 0x186c
leaq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rdx
movq %r15, %rsi
callq 0x38bd
leaq 0x50(%rsp), %rdi
leaq 0x30(%rsp), %rdx
movq %r12, %rsi
callq 0x1a3c
leaq 0x30(%rsp), %rdi
callq 0x1908
xorl %r13d, %r13d
testl %ebp, %ebp
movl $0x0, %eax
cmovgl %ebp, %eax
incl %eax
movl %eax, 0x24(%rsp)
movq %r12, 0x28(%rsp)
leaq 0x50(%rsp), %rdi
pushq $0x2
popq %rsi
callq 0x20c8
cmpl $0x270f, %r13d          # imm = 0x270F
ja 0x7259
ucomisd 0x228c(%rip), %xmm0     # 0x92e0
jbe 0x7259
movl %r13d, 0x20(%rsp)
xorl %r12d, %r12d
pushq $0x1
popq %r13
cmpl 0x24(%rsp), %r13d
je 0x71e7
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd %xmm0, 0x18(%rsp)
cmpl $0x1, %r13d
jne 0x7132
cmpl %ebp, %r13d
jne 0x718d
movq 0x28(%rsp), %rdi
movl %r13d, %esi
callq 0x1ee2
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r15, %rdi
movl %r13d, %esi
movl %r13d, %edx
callq 0x3a1a
movsd (%rax), %xmm0
movsd %xmm0, 0x60(%rsp)
movq %rbx, %rdi
movl %r13d, %esi
callq 0x2030
movsd 0x8(%rsp), %xmm0
subsd 0x10(%rsp), %xmm0
subsd 0x18(%rsp), %xmm0
divsd 0x60(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x78(%rsp), %rax
movq -0x18(%rax), %rax
movq $0xf, 0x80(%rsp,%rax)
movq %rbx, %rdi
movl %r13d, %esi
callq 0x2030
movsd (%rax), %xmm0
leaq 0x78(%rsp), %rdi
callq 0x1130
movq %rax, %rdi
leaq 0x24c4(%rip), %rsi      # 0x95e6
callq 0x10e0
incl %r13d
decl %r12d
jmp 0x7066
movsd %xmm0, 0x18(%rsp)
pushq $0x1
popq %rax
movl %eax, %r14d
leal (%r12,%r14), %eax
cmpl $0x1, %eax
je 0x708b
movq %r15, %rdi
movl %r13d, %esi
movl %r14d, %edx
callq 0x3a1a
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2030
movsd 0x8(%rsp), %xmm1
mulsd (%rax), %xmm1
movsd 0x18(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
incl %r14d
jmp 0x713e
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movl %r13d, %r14d
cmpl %ebp, %r14d
jge 0x7094
incl %r14d
movq %r15, %rdi
movl %r13d, %esi
movl %r14d, %edx
callq 0x3a1a
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x40(%rsp), %rdi
movl %r14d, %esi
callq 0x2030
movsd 0x8(%rsp), %xmm1
mulsd (%rax), %xmm1
movsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
jmp 0x719a
leaq 0x68(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x38bd
leaq 0x30(%rsp), %r14
movq %r14, %rdi
movq 0x28(%rsp), %rsi
movq %r13, %rdx
callq 0x1a3c
movl 0x20(%rsp), %r13d
leaq 0x50(%rsp), %rdi
movq %r14, %rsi
callq 0x1da0
movq %r14, %rdi
callq 0x1908
leaq 0x68(%rsp), %rdi
callq 0x1908
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
callq 0x1da0
leaq 0x78(%rsp), %rdi
leaq 0x207e(%rip), %rsi      # 0x92ca
callq 0x10e0
incl %r13d
jmp 0x7032
leaq 0x78(%rsp), %rdi
callq 0x1100
leaq 0x50(%rsp), %rdi
callq 0x1908
leaq 0x40(%rsp), %rdi
callq 0x1908
leaq 0x78(%rsp), %rdi
callq 0x1110
movq %rbx, %rax
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x72db
movq %rax, %r14
leaq 0x30(%rsp), %rdi
jmp 0x72e3
movq %rax, %r14
jmp 0x72e8
movq %rax, %r14
jmp 0x72f0
jmp 0x72b0
jmp 0x72b0
movq %rax, %r14
jmp 0x72fa
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x1908
jmp 0x72c7
movq %rax, %r14
leaq 0x68(%rsp), %rdi
callq 0x1908
jmp 0x72de
jmp 0x72db
jmp 0x72db
jmp 0x72db
jmp 0x72db
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0x1908
movq %rbx, %rdi
callq 0x1908
leaq 0x40(%rsp), %rdi
callq 0x1908
leaq 0x78(%rsp), %rdi
callq 0x1110
movq %r14, %rdi
callq 0x1180