// File: 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:
subq $0x378, %rsp            # imm = 0x378
movq %rdi, 0xb0(%rsp)
movq %rdi, %rax
movq %rax, 0xb8(%rsp)
movq %rdi, 0x370(%rsp)
movq %rsi, 0x368(%rsp)
movq %rdx, 0x360(%rsp)
leaq 0x160(%rsp), %rdi
movq %rdi, 0xc0(%rsp)
callq 0x2170
movq 0xc0(%rsp), %rdi
leaq 0x4a72(%rip), %rsi      # 0x125d8
movl $0x10, %edx
callq 0x2050
jmp 0xdb72
movq 0x360(%rsp), %rdi
callq 0x4090
movl %eax, 0xac(%rsp)
jmp 0xdb88
movl 0xac(%rsp), %eax
movl %eax, 0x150(%rsp)
movl 0x150(%rsp), %esi
leaq 0x140(%rsp), %rdi
callq 0x2d70
jmp 0xdbac
movq 0xb0(%rsp), %rdi
movb $0x0, 0x13f(%rsp)
movl 0x150(%rsp), %esi
callq 0x2d70
jmp 0xdbca
movq 0x360(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0x368(%rsp), %rsi
leaq 0x118(%rsp), %rdi
leaq 0x140(%rsp), %rdx
callq 0x6f70
jmp 0xdbf9
movq 0xa0(%rsp), %rsi
leaq 0x128(%rsp), %rdi
leaq 0x118(%rsp), %rdx
callq 0x31a0
jmp 0xdc18
leaq 0x118(%rsp), %rdi
callq 0x2ea0
movsd 0x468b(%rip), %xmm0     # 0x122b8
movsd %xmm0, 0x110(%rsp)
movl $0x0, 0x10c(%rsp)
leaq 0x128(%rsp), %rdi
movl $0x2, %esi
callq 0x3fe0
movsd %xmm0, 0x98(%rsp)
jmp 0xdc5e
movsd 0x98(%rsp), %xmm0
ucomisd 0x110(%rsp), %xmm0
seta %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x2710, 0x10c(%rsp) # imm = 0x2710
setl %cl
andb $0x1, %cl
movzbl %cl, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0xe13e
movl $0x1, 0x108(%rsp)
movl 0x108(%rsp), %eax
cmpl 0x150(%rsp), %eax
jg 0xe03c
xorps %xmm0, %xmm0
movsd %xmm0, 0x100(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xf8(%rsp)
cmpl $0x1, 0x108(%rsp)
je 0xde30
movl $0x1, 0xf4(%rsp)
movl 0xf4(%rsp), %eax
cmpl 0x108(%rsp), %eax
jge 0xde2e
movsd 0x100(%rsp), %xmm0
movsd %xmm0, 0x88(%rsp)
movq 0x368(%rsp), %rdi
movl 0x108(%rsp), %esi
movl 0xf4(%rsp), %edx
callq 0x7250
movq %rax, 0x90(%rsp)
jmp 0xdd32
movq 0xb0(%rsp), %rdi
movq 0x90(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x78(%rsp)
movl 0xf4(%rsp), %esi
callq 0x3ee0
movq %rax, 0x80(%rsp)
jmp 0xdd62
movsd 0x88(%rsp), %xmm1
movsd 0x78(%rsp), %xmm0
movq 0x80(%rsp), %rax
movsd (%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x100(%rsp)
movl 0xf4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf4(%rsp)
jmp 0xdce7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
jmp 0xe1ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
jmp 0xe1c1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
jmp 0xe1b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
leaq 0x118(%rsp), %rdi
callq 0x2ea0
jmp 0xe1b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
jmp 0xe16e
jmp 0xde30
movl 0x108(%rsp), %eax
cmpl 0x150(%rsp), %eax
je 0xdf02
movl 0x108(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf0(%rsp)
movl 0xf0(%rsp), %eax
cmpl 0x150(%rsp), %eax
jg 0xdf00
movsd 0xf8(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
movq 0x368(%rsp), %rdi
movl 0x108(%rsp), %esi
movl 0xf0(%rsp), %edx
callq 0x7250
movq %rax, 0x70(%rsp)
jmp 0xde9a
movq 0x70(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x58(%rsp)
movl 0xf0(%rsp), %esi
leaq 0x140(%rsp), %rdi
callq 0x3ee0
movq %rax, 0x60(%rsp)
jmp 0xdec4
movsd 0x68(%rsp), %xmm1
movsd 0x58(%rsp), %xmm0
movq 0x60(%rsp), %rax
movsd (%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0xf8(%rsp)
movl 0xf0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf0(%rsp)
jmp 0xde55
jmp 0xdf02
movq 0x360(%rsp), %rdi
movl 0x108(%rsp), %esi
callq 0x3c10
movq %rax, 0x50(%rsp)
jmp 0xdf1d
movq 0x50(%rsp), %rax
movsd (%rax), %xmm0
movsd 0xf8(%rsp), %xmm1
subsd %xmm1, %xmm0
movsd 0x100(%rsp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x368(%rsp), %rdi
movl 0x108(%rsp), %edx
movl %edx, %esi
callq 0x7250
movq %rax, 0x48(%rsp)
jmp 0xdf63
movq 0xb0(%rsp), %rdi
movsd 0x40(%rsp), %xmm0
movq 0x48(%rsp), %rax
movsd (%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
movl 0x108(%rsp), %esi
callq 0x3ee0
movq %rax, 0x38(%rsp)
jmp 0xdf97
movq 0x38(%rsp), %rax
movsd 0x30(%rsp), %xmm0
movsd %xmm0, (%rax)
movl $0xf, %edi
callq 0x10e10
movl %eax, 0x2c(%rsp)
jmp 0xdfb6
movl 0x2c(%rsp), %eax
movl %eax, 0xec(%rsp)
movl 0xec(%rsp), %esi
leaq 0x160(%rsp), %rdi
callq 0x2160
movq %rax, 0x20(%rsp)
jmp 0xdfdc
movq 0xb0(%rsp), %rdi
movl 0x108(%rsp), %esi
callq 0x3ee0
movq %rax, 0x18(%rsp)
jmp 0xdff7
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rax
movsd (%rax), %xmm0
callq 0x21d0
movq %rax, 0x10(%rsp)
jmp 0xe011
movq 0x10(%rsp), %rdi
leaq 0x45b9(%rip), %rsi      # 0x125d6
callq 0x20e0
jmp 0xe024
jmp 0xe026
movl 0x108(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x108(%rsp)
jmp 0xdca2
movq 0xb0(%rsp), %rdx
movq 0x360(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x368(%rsp), %rsi
leaq 0xc8(%rsp), %rdi
callq 0x6f70
jmp 0xe068
movq 0x8(%rsp), %rsi
leaq 0xd8(%rsp), %rdi
leaq 0xc8(%rsp), %rdx
callq 0x31a0
jmp 0xe084
leaq 0x128(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x39a0
jmp 0xe09b
leaq 0xd8(%rsp), %rdi
callq 0x2ea0
leaq 0xc8(%rsp), %rdi
callq 0x2ea0
movq 0xb0(%rsp), %rsi
leaq 0x140(%rsp), %rdi
callq 0x39a0
jmp 0xe0cc
leaq 0x41d7(%rip), %rsi      # 0x122aa
leaq 0x160(%rsp), %rdi
callq 0x20e0
jmp 0xe0e2
movl 0x10c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10c(%rsp)
jmp 0xdc41
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
jmp 0xe12f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x2ea0
leaq 0xc8(%rsp), %rdi
callq 0x2ea0
jmp 0xe16e
leaq 0x160(%rsp), %rdi
callq 0x2130
jmp 0xe14d
movb $0x1, 0x13f(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x2ea0
testb $0x1, 0x13f(%rsp)
jne 0xe18a
jmp 0xe17d
leaq 0x128(%rsp), %rdi
callq 0x2ea0
jmp 0xe1b4
movq 0xb0(%rsp), %rdi
callq 0x2ea0
leaq 0x140(%rsp), %rdi
callq 0x2ea0
leaq 0x160(%rsp), %rdi
callq 0x2140
movq 0xb8(%rsp), %rax
addq $0x378, %rsp            # imm = 0x378
retq
movq 0xb0(%rsp), %rdi
callq 0x2ea0
leaq 0x140(%rsp), %rdi
callq 0x2ea0
leaq 0x160(%rsp), %rdi
callq 0x2140
movq 0x158(%rsp), %rdi
callq 0x21b0
nopl (%rax,%rax)