// File: /workspace/github_cpp_makefile_star2_O1/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 $0x298, %rsp            # imm = 0x298
movsd %xmm0, 0x40(%rsp)
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x98(%rsp), %r14
movq %r14, %rdi
callq 0x2180
leaq 0x325f(%rip), %rsi      # 0xc61f
movq %r14, %rdi
movl $0x10, %edx
callq 0x2040
movq %r12, %rdi
callq 0x3485
movl %eax, %r14d
leaq 0x30(%rsp), %rdi
movl %eax, %esi
callq 0x28c8
movq %rbx, %rdi
movl %r14d, %esi
callq 0x28c8
leaq 0x50(%rsp), %rdi
leaq 0x30(%rsp), %rdx
movq %r15, %rsi
callq 0x505f
leaq 0x60(%rsp), %rdi
leaq 0x50(%rsp), %rdx
movq %r12, %rsi
callq 0x2b28
leaq 0x50(%rsp), %rdi
callq 0x2970
movsd 0x2c03(%rip), %xmm0     # 0xc028
subsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
movl %r14d, %ebp
negl %ebp
movl $0x0, 0x18(%rsp)
movq %r12, 0x48(%rsp)
movl %r14d, 0xc(%rsp)
leaq 0x60(%rsp), %rdi
movl $0x2, %esi
callq 0x340b
cmpl $0x270f, 0x18(%rsp)     # imm = 0x270F
ja 0x96d8
ucomisd 0x2e9b(%rip), %xmm0     # 0xc308
jbe 0x96d8
testl %r14d, %r14d
jle 0x9657
movl $0x1, %r13d
xorl %r12d, %r12d
movl $0x2, 0x1c(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
movsd %xmm0, 0x28(%rsp)
cmpl $0x2, %r13d
jb 0x94ff
movsd %xmm0, 0x28(%rsp)
movl $0x1, %r14d
movq %r15, %rdi
movl %r13d, %esi
movl %r14d, %edx
callq 0x51ec
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
movl %r14d, %esi
callq 0x3354
movsd 0x10(%rsp), %xmm1
mulsd (%rax), %xmm1
movsd 0x28(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
leal (%r12,%r14), %eax
incl %eax
movl %r14d, %ecx
incl %ecx
movl %ecx, %r14d
cmpl $0x1, %eax
jne 0x94af
cmpl 0xc(%rsp), %r13d
jge 0x9569
xorpd %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, %r14d
movq %r15, %rdi
movl %r13d, %esi
movl %r14d, %edx
callq 0x51ec
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x30(%rsp), %rdi
movl %r14d, %esi
callq 0x3354
movsd 0x10(%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 0x9517
leaq 0x30(%rsp), %rdi
movl %r13d, %esi
callq 0x3354
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x48(%rsp), %rdi
movl %r13d, %esi
callq 0x31ba
movsd (%rax), %xmm0
movsd %xmm0, 0x80(%rsp)
movq %r15, %rdi
movl %r13d, %esi
movl %r13d, %edx
callq 0x51ec
movsd (%rax), %xmm0
movsd %xmm0, 0x78(%rsp)
movq %rbx, %rdi
movl %r13d, %esi
callq 0x3354
movsd 0x80(%rsp), %xmm1
subsd 0x20(%rsp), %xmm1
subsd 0x28(%rsp), %xmm1
movsd 0x40(%rsp), %xmm0
divsd 0x78(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd 0x10(%rsp), %xmm1
mulsd 0x70(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rax)
movq 0x98(%rsp), %rax
movq -0x18(%rax), %rax
movq $0xf, 0xa0(%rsp,%rax)
movq %rbx, %rdi
movl %r13d, %esi
callq 0x3354
movsd (%rax), %xmm0
leaq 0x98(%rsp), %rdi
callq 0x2170
movl $0x1, %edx
movq %rax, %rdi
leaq 0x2fd5(%rip), %rsi      # 0xc60e
callq 0x2120
leal 0x1(%r13), %eax
decl %r12d
incl 0x1c(%rsp)
cmpl 0xc(%rsp), %r13d
movl %eax, %r13d
jne 0x948d
leaq 0x88(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x505f
leaq 0x50(%rsp), %r13
movq %r13, %rdi
movq 0x48(%rsp), %rsi
movq %r14, %rdx
callq 0x2b28
movl 0xc(%rsp), %r14d
leaq 0x60(%rsp), %rdi
movq %r13, %rsi
callq 0x303c
movq %r13, %rdi
callq 0x2970
leaq 0x88(%rsp), %rdi
callq 0x2970
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x303c
movl $0x1, %edx
leaq 0x98(%rsp), %rdi
leaq 0x2c2a(%rip), %rsi      # 0xc2f4
callq 0x2120
incl 0x18(%rsp)
jmp 0x9448
leaq 0x98(%rsp), %rdi
callq 0x2140
leaq 0x60(%rsp), %rdi
callq 0x2970
leaq 0x30(%rsp), %rdi
callq 0x2970
movq 0x68c8(%rip), %rax      # 0xffc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0xa0(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x98(%rsp,%rcx)
callq 0x20f0
leaq 0x190(%rsp), %rdi
callq 0x2060
movq %rbx, %rax
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x978e
movq %rax, %r14
leaq 0x50(%rsp), %rdi
jmp 0x9796
movq %rax, %r14
jmp 0x979b
movq %rax, %r14
jmp 0x97a3
jmp 0x9760
jmp 0x9760
movq %rax, %r14
jmp 0x97ad
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0x2970
jmp 0x9777
movq %rax, %r14
leaq 0x88(%rsp), %rdi
callq 0x2970
jmp 0x9791
jmp 0x978e
jmp 0x978e
jmp 0x978e
jmp 0x978e
movq %rax, %r14
leaq 0x60(%rsp), %rdi
callq 0x2970
movq %rbx, %rdi
callq 0x2970
leaq 0x30(%rsp), %rdi
callq 0x2970
movq 0x6814(%rip), %rax      # 0xffc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0xa0(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x98(%rsp,%rcx)
callq 0x20f0
leaq 0x190(%rsp), %rdi
callq 0x2060
movq %r14, %rdi
callq 0x21c0