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

// Assembly:
subq $0x398, %rsp            # imm = 0x398
movq %rdi, 0xc8(%rsp)
movq %rdi, %rax
movq %rax, 0xd0(%rsp)
movq %rdi, 0x390(%rsp)
movq %rsi, 0x388(%rsp)
movq %rdx, 0x380(%rsp)
movsd %xmm0, 0x378(%rsp)
leaq 0x178(%rsp), %rdi
movq %rdi, 0xd8(%rsp)
callq 0x2170
movq 0xd8(%rsp), %rdi
leaq 0x4398(%rip), %rsi      # 0x125e7
movl $0x10, %edx
callq 0x2050
jmp 0xe25b
movq 0x380(%rsp), %rdi
callq 0x4090
movl %eax, 0xc4(%rsp)
jmp 0xe271
movl 0xc4(%rsp), %eax
movl %eax, 0x168(%rsp)
movl 0x168(%rsp), %esi
leaq 0x158(%rsp), %rdi
callq 0x2d70
jmp 0xe295
movq 0xc8(%rsp), %rdi
movb $0x0, 0x157(%rsp)
movl 0x168(%rsp), %esi
callq 0x2d70
jmp 0xe2b3
movq 0x380(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0x388(%rsp), %rsi
leaq 0x130(%rsp), %rdi
leaq 0x158(%rsp), %rdx
callq 0x6f70
jmp 0xe2e2
movq 0xb8(%rsp), %rsi
leaq 0x140(%rsp), %rdi
leaq 0x130(%rsp), %rdx
callq 0x31a0
jmp 0xe301
leaq 0x130(%rsp), %rdi
callq 0x2ea0
movsd 0x3fa2(%rip), %xmm0     # 0x122b8
movsd %xmm0, 0x128(%rsp)
movl $0x0, 0x124(%rsp)
leaq 0x140(%rsp), %rdi
movl $0x2, %esi
callq 0x3fe0
movsd %xmm0, 0xb0(%rsp)
jmp 0xe347
movsd 0xb0(%rsp), %xmm0
ucomisd 0x128(%rsp), %xmm0
seta %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x2710, 0x124(%rsp) # imm = 0x2710
setl %cl
andb $0x1, %cl
movzbl %cl, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0xe8a9
movl $0x1, 0x120(%rsp)
movl 0x120(%rsp), %eax
cmpl 0x168(%rsp), %eax
jg 0xe7a9
xorps %xmm0, %xmm0
movsd %xmm0, 0x118(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x110(%rsp)
cmpl $0x1, 0x120(%rsp)
je 0xe51f
movl $0x1, 0x10c(%rsp)
movl 0x10c(%rsp), %eax
cmpl 0x120(%rsp), %eax
jge 0xe51d
movsd 0x118(%rsp), %xmm0
movsd %xmm0, 0xa0(%rsp)
movq 0x388(%rsp), %rdi
movl 0x120(%rsp), %esi
movl 0x10c(%rsp), %edx
callq 0x7250
movq %rax, 0xa8(%rsp)
jmp 0xe41b
movq 0xc8(%rsp), %rdi
movq 0xa8(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x90(%rsp)
movl 0x10c(%rsp), %esi
callq 0x3ee0
movq %rax, 0x98(%rsp)
jmp 0xe44e
movsd 0xa0(%rsp), %xmm1
movsd 0x90(%rsp), %xmm0
movq 0x98(%rsp), %rax
movsd (%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x118(%rsp)
movl 0x10c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10c(%rsp)
jmp 0xe3d0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x170(%rsp)
movl %eax, 0x16c(%rsp)
jmp 0xe939
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x170(%rsp)
movl %eax, 0x16c(%rsp)
jmp 0xe92c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x170(%rsp)
movl %eax, 0x16c(%rsp)
jmp 0xe91f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x170(%rsp)
movl %eax, 0x16c(%rsp)
leaq 0x130(%rsp), %rdi
callq 0x2ea0
jmp 0xe91f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x170(%rsp)
movl %eax, 0x16c(%rsp)
jmp 0xe8d9
jmp 0xe51f
movl 0x120(%rsp), %eax
cmpl 0x168(%rsp), %eax
je 0xe5fd
movl 0x120(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x108(%rsp)
movl 0x108(%rsp), %eax
cmpl 0x168(%rsp), %eax
jg 0xe5fb
movsd 0x110(%rsp), %xmm0
movsd %xmm0, 0x80(%rsp)
movq 0x388(%rsp), %rdi
movl 0x120(%rsp), %esi
movl 0x108(%rsp), %edx
callq 0x7250
movq %rax, 0x88(%rsp)
jmp 0xe58f
movq 0x88(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x70(%rsp)
movl 0x108(%rsp), %esi
leaq 0x158(%rsp), %rdi
callq 0x3ee0
movq %rax, 0x78(%rsp)
jmp 0xe5bc
movsd 0x80(%rsp), %xmm1
movsd 0x70(%rsp), %xmm0
movq 0x78(%rsp), %rax
movsd (%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x110(%rsp)
movl 0x108(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x108(%rsp)
jmp 0xe544
jmp 0xe5fd
movsd 0x378(%rsp), %xmm1
movsd 0x3a02(%rip), %xmm0     # 0x12010
subsd %xmm1, %xmm0
movsd %xmm0, 0x60(%rsp)
movl 0x120(%rsp), %esi
leaq 0x158(%rsp), %rdi
callq 0x3ee0
movq %rax, 0x68(%rsp)
jmp 0xe633
movq 0x68(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x50(%rsp)
movq 0x380(%rsp), %rdi
movl 0x120(%rsp), %esi
callq 0x3c10
movq %rax, 0x58(%rsp)
jmp 0xe65d
movq 0x58(%rsp), %rax
movsd (%rax), %xmm0
movsd 0x110(%rsp), %xmm1
subsd %xmm1, %xmm0
movsd 0x118(%rsp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x378(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x388(%rsp), %rdi
movl 0x120(%rsp), %edx
movl %edx, %esi
callq 0x7250
movq %rax, 0x48(%rsp)
jmp 0xe6b2
movq 0xc8(%rsp), %rdi
movsd 0x50(%rsp), %xmm2
movsd 0x60(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
movsd 0x40(%rsp), %xmm3
movq 0x48(%rsp), %rax
movsd (%rax), %xmm4
divsd %xmm4, %xmm3
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
movl 0x120(%rsp), %esi
callq 0x3ee0
movq %rax, 0x30(%rsp)
jmp 0xe704
movq 0x30(%rsp), %rax
movsd 0x28(%rsp), %xmm0
movsd %xmm0, (%rax)
movl $0xf, %edi
callq 0x10e10
movl %eax, 0x24(%rsp)
jmp 0xe723
movl 0x24(%rsp), %eax
movl %eax, 0x104(%rsp)
movl 0x104(%rsp), %esi
leaq 0x178(%rsp), %rdi
callq 0x2160
movq %rax, 0x18(%rsp)
jmp 0xe749
movq 0xc8(%rsp), %rdi
movl 0x120(%rsp), %esi
callq 0x3ee0
movq %rax, 0x10(%rsp)
jmp 0xe764
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rax
movsd (%rax), %xmm0
callq 0x21d0
movq %rax, 0x8(%rsp)
jmp 0xe77e
movq 0x8(%rsp), %rdi
leaq 0x3e4c(%rip), %rsi      # 0x125d6
callq 0x20e0
jmp 0xe791
jmp 0xe793
movl 0x120(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x120(%rsp)
jmp 0xe38b
movq 0xc8(%rsp), %rdx
movq 0x380(%rsp), %rax
movq %rax, (%rsp)
movq 0x388(%rsp), %rsi
leaq 0xe0(%rsp), %rdi
callq 0x6f70
jmp 0xe7d4
movq (%rsp), %rsi
leaq 0xf0(%rsp), %rdi
leaq 0xe0(%rsp), %rdx
callq 0x31a0
jmp 0xe7ef
leaq 0x140(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x39a0
jmp 0xe806
leaq 0xf0(%rsp), %rdi
callq 0x2ea0
leaq 0xe0(%rsp), %rdi
callq 0x2ea0
movq 0xc8(%rsp), %rsi
leaq 0x158(%rsp), %rdi
callq 0x39a0
jmp 0xe837
leaq 0x3a6c(%rip), %rsi      # 0x122aa
leaq 0x178(%rsp), %rdi
callq 0x20e0
jmp 0xe84d
movl 0x124(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x124(%rsp)
jmp 0xe32a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x170(%rsp)
movl %eax, 0x16c(%rsp)
jmp 0xe89a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x170(%rsp)
movl %eax, 0x16c(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0x2ea0
leaq 0xe0(%rsp), %rdi
callq 0x2ea0
jmp 0xe8d9
leaq 0x178(%rsp), %rdi
callq 0x2130
jmp 0xe8b8
movb $0x1, 0x157(%rsp)
leaq 0x140(%rsp), %rdi
callq 0x2ea0
testb $0x1, 0x157(%rsp)
jne 0xe8f5
jmp 0xe8e8
leaq 0x140(%rsp), %rdi
callq 0x2ea0
jmp 0xe91f
movq 0xc8(%rsp), %rdi
callq 0x2ea0
leaq 0x158(%rsp), %rdi
callq 0x2ea0
leaq 0x178(%rsp), %rdi
callq 0x2140
movq 0xd0(%rsp), %rax
addq $0x398, %rsp            # imm = 0x398
retq
movq 0xc8(%rsp), %rdi
callq 0x2ea0
leaq 0x158(%rsp), %rdi
callq 0x2ea0
leaq 0x178(%rsp), %rdi
callq 0x2140
movq 0x170(%rsp), %rdi
callq 0x21b0
nopw %cs:(%rax,%rax)