// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x288, %rsp            # imm = 0x288
movsd %xmm0, 0x30(%rsp)
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x88(%rsp), %r14
movq %r14, %rdi
callq 0x1140
leaq 0x22b4(%rip), %rsi      # 0x95f7
pushq $0x10
popq %rdx
movq %r14, %rdi
callq 0x1040
movq %r12, %rdi
callq 0x2141
movl %eax, %ebp
leaq 0x20(%rsp), %rdi
movl %eax, %esi
callq 0x186c
movq %rbx, %rdi
movl %ebp, %esi
callq 0x186c
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rdx
movq %r15, %rsi
callq 0x38bd
leaq 0x50(%rsp), %rdi
leaq 0x40(%rsp), %rdx
movq %r12, %rsi
callq 0x1a3c
leaq 0x40(%rsp), %rdi
callq 0x1908
movsd 0x1c84(%rip), %xmm0     # 0x9028
subsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
xorl %r13d, %r13d
testl %ebp, %ebp
movl $0x0, %eax
cmovgl %ebp, %eax
incl %eax
movl %eax, 0x1c(%rsp)
movq %r12, 0x38(%rsp)
leaq 0x50(%rsp), %rdi
pushq $0x2
popq %rsi
callq 0x20c8
cmpl $0x270f, %r13d          # imm = 0x270F
ja 0x7623
ucomisd 0x1ef6(%rip), %xmm0     # 0x92e0
jbe 0x7623
movl %r13d, 0x18(%rsp)
xorl %r12d, %r12d
pushq $0x1
popq %r13
cmpl 0x1c(%rsp), %r13d
je 0x75ae
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd %xmm0, 0x10(%rsp)
cmpl $0x1, %r13d
jne 0x74fd
cmpl %ebp, %r13d
jne 0x7556
leaq 0x20(%rsp), %rdi
movl %r13d, %esi
callq 0x2030
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
movq 0x38(%rsp), %rdi
movl %r13d, %esi
callq 0x1ee2
movsd (%rax), %xmm0
movsd %xmm0, 0x70(%rsp)
movq %r15, %rdi
movl %r13d, %esi
movl %r13d, %edx
callq 0x3a1a
movsd (%rax), %xmm0
movsd %xmm0, 0x68(%rsp)
movq %rbx, %rdi
movl %r13d, %esi
callq 0x2030
movsd 0x70(%rsp), %xmm1
subsd 0x8(%rsp), %xmm1
subsd 0x10(%rsp), %xmm1
movsd 0x30(%rsp), %xmm0
divsd 0x68(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd (%rsp), %xmm1
mulsd 0x60(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rax)
movq 0x88(%rsp), %rax
movq -0x18(%rax), %rax
movq $0xf, 0x90(%rsp,%rax)
movq %rbx, %rdi
movl %r13d, %esi
callq 0x2030
movsd (%rax), %xmm0
leaq 0x88(%rsp), %rdi
callq 0x1130
movq %rax, %rdi
leaq 0x20f9(%rip), %rsi      # 0x95e6
callq 0x10e0
incl %r13d
decl %r12d
jmp 0x73fc
movsd %xmm0, 0x10(%rsp)
pushq $0x1
popq %rax
movl %eax, %r14d
leal (%r12,%r14), %eax
cmpl $0x1, %eax
je 0x7421
movq %r15, %rdi
movl %r13d, %esi
movl %r14d, %edx
callq 0x3a1a
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2030
movsd (%rsp), %xmm1
mulsd (%rax), %xmm1
movsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
incl %r14d
jmp 0x7509
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movl %r13d, %r14d
cmpl %ebp, %r14d
jge 0x742a
incl %r14d
movq %r15, %rdi
movl %r13d, %esi
movl %r14d, %edx
callq 0x3a1a
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
leaq 0x20(%rsp), %rdi
movl %r14d, %esi
callq 0x2030
movsd (%rsp), %xmm1
mulsd (%rax), %xmm1
movsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
jmp 0x7563
leaq 0x78(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x38bd
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq 0x38(%rsp), %rsi
movq %r13, %rdx
callq 0x1a3c
movl 0x18(%rsp), %r13d
leaq 0x50(%rsp), %rdi
movq %r14, %rsi
callq 0x1da0
movq %r14, %rdi
callq 0x1908
leaq 0x78(%rsp), %rdi
callq 0x1908
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x1da0
leaq 0x88(%rsp), %rdi
leaq 0x1cb4(%rip), %rsi      # 0x92ca
callq 0x10e0
incl %r13d
jmp 0x73c8
leaq 0x88(%rsp), %rdi
callq 0x1100
leaq 0x50(%rsp), %rdi
callq 0x1908
leaq 0x20(%rsp), %rdi
callq 0x1908
leaq 0x88(%rsp), %rdi
callq 0x1110
movq %rbx, %rax
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x76ab
movq %rax, %r14
leaq 0x40(%rsp), %rdi
jmp 0x76b3
movq %rax, %r14
jmp 0x76b8
movq %rax, %r14
jmp 0x76c0
jmp 0x7680
jmp 0x7680
movq %rax, %r14
jmp 0x76ca
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0x1908
jmp 0x7697
movq %rax, %r14
leaq 0x78(%rsp), %rdi
callq 0x1908
jmp 0x76ae
jmp 0x76ab
jmp 0x76ab
jmp 0x76ab
jmp 0x76ab
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0x1908
movq %rbx, %rdi
callq 0x1908
leaq 0x20(%rsp), %rdi
callq 0x1908
leaq 0x88(%rsp), %rdi
callq 0x1110
movq %r14, %rdi
callq 0x1180