// File: /workspace/github_cpp_makefile_star2_O2/IlanPrice[P]Linear-Algebra-Library-in-Cplusplus/Matrix.cpp
// Function: backsubst(Matrix const&, Vector const&, int)
Vector backsubst(const Matrix& A, const Vector& b, int bwidth)
{
	int n = length(b);
	int count = 0;
	Vector x(n);
	if (bwidth==0)
	{
		for (int i=n;i>0;i--)
		{
			if (A(i,i)==0)
			{
				throw Exception("Singular Matrix",
						  "no solution to equation as coefficient matrix is singular");
			}
			x(i) = b(i);
			for (int j = (i+1); j<=n; j++)
			{
				x(i) = x(i) - A(i,j)*x(j);
				count++;
			}
			x(i) = x(i)/A(i,i);
		}
	}
	else
	{
		for (int i=n;i>0;i--)
		{
			if (A(i,i)==0)
			{
				throw Exception("Singular Matrix",
										  "no solution to equation as coefficient matrix is singular");
			}
			x(i) = b(i);
			for (int j = (i+1); j<=(i+bwidth - 1); j++)
				{
					if(j<=n)
					{
						x(i) = x(i) - A(i,j)*x(j);
						count++;
					}
				}
			x(i) = x(i)/A(i,i);
		}
	}
	std::cout<<"operation count: "<<count<<"\n";
	return x;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movl %ecx, %r13d
movq %rsi, %r15
movq %rdi, %rbx
movq %rdx, 0x20(%rsp)
movq %rdx, %rdi
callq 0x2141
movl %eax, %r12d
movq %rbx, %rdi
movl %eax, %esi
callq 0x186c
testl %r13d, %r13d
je 0x4870
decl %r13d
xorl %ebp, %ebp
movl %r12d, %r14d
movq %r15, 0x28(%rsp)
movq %r13, 0x30(%rsp)
testl %r14d, %r14d
jle 0x4992
movq %r15, %rdi
movl %r14d, %esi
movl %r14d, %edx
callq 0x3a1a
movsd (%rax), %xmm0
ucomisd 0x4b79(%rip), %xmm0     # 0x92d0
jne 0x475f
jnp 0x49d3
movq 0x20(%rsp), %rdi
movl %r14d, %esi
callq 0x1ee2
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2030
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
leal (%r14,%r13), %r15d
movl %r14d, %r13d
movl %r13d, %eax
cmpl %r15d, %eax
jge 0x4816
leal 0x1(%rax), %r13d
cmpl %r12d, %eax
movl %r13d, %eax
jge 0x4795
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2030
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x28(%rsp), %rdi
movl %r14d, %esi
movl %r13d, %edx
callq 0x3a1a
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
movl %r13d, %esi
callq 0x2030
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2030
movsd 0x10(%rsp), %xmm1
mulsd 0x18(%rsp), %xmm1
movsd 0x8(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax)
incl %ebp
jmp 0x4792
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2030
movq 0x28(%rsp), %r15
movq 0x30(%rsp), %r13
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r15, %rdi
movl %r14d, %esi
movl %r14d, %edx
callq 0x3a1a
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2030
movsd 0x8(%rsp), %xmm0
divsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
decl %r14d
jmp 0x4734
xorl %ebp, %ebp
movl %r12d, %r14d
testl %r14d, %r14d
jle 0x4992
movq %r15, %rdi
movl %r14d, %esi
movl %r14d, %edx
callq 0x3a1a
movsd (%rax), %xmm0
ucomisd 0x4a38(%rip), %xmm0     # 0x92d0
jne 0x48a0
jnp 0x4a39
movq 0x20(%rsp), %rdi
movl %r14d, %esi
callq 0x1ee2
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2030
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movl %r14d, %r13d
cmpl %r12d, %r13d
jge 0x4942
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2030
incl %r13d
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r15, %rdi
movl %r14d, %esi
movl %r13d, %edx
callq 0x3a1a
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
movl %r13d, %esi
callq 0x2030
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2030
movsd 0x10(%rsp), %xmm1
mulsd 0x18(%rsp), %xmm1
movsd 0x8(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax)
incl %ebp
jmp 0x48cf
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2030
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r15, %rdi
movl %r14d, %esi
movl %r14d, %edx
callq 0x3a1a
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2030
movsd 0x8(%rsp), %xmm0
divsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
decl %r14d
jmp 0x4875
movq 0x9637(%rip), %rdi      # 0xdfd0
leaq 0x4be6(%rip), %rsi      # 0x9586
callq 0x10e0
movq %rax, %rdi
movl %ebp, %esi
callq 0x1160
leaq 0x4914(%rip), %rsi      # 0x92ca
movq %rax, %rdi
callq 0x10e0
movq %rbx, %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x40
popq %rdi
callq 0x1080
movq %rax, %r15
leaq 0x4b57(%rip), %rsi      # 0x953c
leaq 0x58(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x1060
leaq 0x4b51(%rip), %rsi      # 0x954c
leaq 0x38(%rsp), %rdi
leaq 0x6(%rsp), %rdx
callq 0x1060
movb $0x1, %bpl
leaq 0x58(%rsp), %rsi
leaq 0x38(%rsp), %rdx
movq %r15, %rdi
callq 0x2790
xorl %ebp, %ebp
leaq 0x9378(%rip), %rsi      # 0xdda0
leaq -0x22b5(%rip), %rdx     # 0x277a
movq %r15, %rdi
callq 0x1150
jmp 0x4aa3
pushq $0x40
popq %rdi
callq 0x1080
movq %rax, %r15
leaq 0x4af1(%rip), %rsi      # 0x953c
leaq 0x98(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x1060
leaq 0x4ae8(%rip), %rsi      # 0x954c
leaq 0x78(%rsp), %rdi
leaq 0x6(%rsp), %rdx
callq 0x1060
movb $0x1, %bpl
leaq 0x98(%rsp), %rsi
leaq 0x78(%rsp), %rdx
movq %r15, %rdi
callq 0x2790
xorl %ebp, %ebp
leaq 0x930c(%rip), %rsi      # 0xdda0
leaq -0x2321(%rip), %rdx     # 0x277a
movq %r15, %rdi
callq 0x1150
movq %rax, %r14
leaq 0x78(%rsp), %rdi
callq 0x1070
jmp 0x4ab8
movq %rax, %r14
movb $0x1, %bpl
leaq 0x98(%rsp), %rdi
jmp 0x4ade
jmp 0x4aff
movq %rax, %r14
leaq 0x38(%rsp), %rdi
callq 0x1070
jmp 0x4ad9
movq %rax, %r14
movb $0x1, %bpl
leaq 0x58(%rsp), %rdi
callq 0x1070
testb %bpl, %bpl
jne 0x4aef
jmp 0x4b02
jmp 0x4aec
movq %rax, %r14
movq %r15, %rdi
callq 0x10b0
jmp 0x4b02
jmp 0x4aff
jmp 0x4aff
jmp 0x4aff
movq %rax, %r14
movq %rbx, %rdi
callq 0x1908
movq %r14, %rdi
callq 0x1180