// File: /workspace/github_cpp_makefile_star2_O3/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 $0xc8, %rsp
movl %ecx, %r14d
movq %rdx, %r15
movq %rsi, 0x20(%rsp)
movq %rdi, %rbx
movq %rdx, %rdi
callq 0x3461
movl %eax, %r12d
movq %rbx, %rdi
movl %eax, %esi
callq 0x28b8
movq %r14, 0x28(%rsp)
testl %r14d, %r14d
movq %r12, 0x30(%rsp)
je 0x63b6
testl %r12d, %r12d
jle 0x650e
movq 0x28(%rsp), %rax
decl %eax
movq %rax, 0x28(%rsp)
movl $0x0, 0xc(%rsp)
movq 0x30(%rsp), %r14
movq 0x20(%rsp), %rdi
movl %r12d, %esi
movl %r12d, %edx
callq 0x5202
movsd (%rax), %xmm0
ucomisd 0x6065(%rip), %xmm0     # 0xc2f8
jne 0x629b
jnp 0x6567
movq %r15, %rdi
movl %r12d, %esi
callq 0x318c
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3330
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x28(%rsp), %rcx
leal (%rcx,%r12), %eax
movl %ecx, %ebp
movl %r12d, %r13d
cmpl %eax, %r12d
jge 0x6355
movl %r13d, %eax
leal 0x1(%rax), %r13d
cmpl %r14d, %eax
jge 0x6351
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3330
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x20(%rsp), %rdi
movl %r12d, %esi
movl %r13d, %edx
callq 0x5202
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
movl %r13d, %esi
callq 0x3330
movsd (%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3330
movsd 0x18(%rsp), %xmm1
mulsd 0x38(%rsp), %xmm1
movsd 0x10(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax)
incl 0xc(%rsp)
decl %ebp
jne 0x62d8
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3330
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x20(%rsp), %rdi
movl %r12d, %esi
movl %r12d, %edx
callq 0x5202
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3330
movsd 0x10(%rsp), %xmm0
divsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rax)
leal -0x1(%r12), %eax
cmpl $0x1, %r12d
movl %eax, %r12d
jg 0x6277
jmp 0x6516
testl %r12d, %r12d
jle 0x650e
leal 0x1(%r12), %ebp
xorl %r14d, %r14d
movl $0x0, 0xc(%rsp)
movq %r15, 0x40(%rsp)
movq 0x20(%rsp), %rdi
movl %r12d, %esi
movl %r12d, %edx
callq 0x5202
movsd (%rax), %xmm0
ucomisd 0x5f08(%rip), %xmm0     # 0xc2f8
jne 0x63f8
jnp 0x65f2
movq %r15, %rdi
movl %r12d, %esi
callq 0x318c
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3330
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
cmpl 0x30(%rsp), %r12d
jge 0x64af
addl %r14d, 0xc(%rsp)
xorl %r15d, %r15d
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3330
leal (%r15,%rbp), %r13d
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x20(%rsp), %rdi
movl %r12d, %esi
movl %r13d, %edx
callq 0x5202
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
movl %r13d, %esi
callq 0x3330
movsd (%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3330
movsd 0x18(%rsp), %xmm1
mulsd 0x38(%rsp), %xmm1
movsd 0x10(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax)
incl %r15d
cmpl %r15d, %r14d
jne 0x6435
movq 0x40(%rsp), %r15
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3330
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x20(%rsp), %rdi
movl %r12d, %esi
movl %r12d, %edx
callq 0x5202
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3330
movsd 0x10(%rsp), %xmm0
divsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rax)
decl %r12d
incl %r14d
decl %ebp
cmpl 0x30(%rsp), %r14d
jne 0x63d4
jmp 0x6516
movl $0x0, 0xc(%rsp)
movq 0x9ab3(%rip), %rdi      # 0xffd0
leaq 0x608a(%rip), %rsi      # 0xc5ae
movl $0x11, %edx
callq 0x2110
movq 0x9a9b(%rip), %rdi      # 0xffd0
movl 0xc(%rsp), %esi
callq 0x2190
leaq 0x5daf(%rip), %rsi      # 0xc2f4
movl $0x1, %edx
movq %rax, %rdi
callq 0x2110
movq %rbx, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x40, %edi
callq 0x2070
movq %rax, %r15
leaq 0x58(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x5fdf(%rip), %rsi      # 0xc564
leaq 0x5fe7(%rip), %rdx      # 0xc573
leaq 0x48(%rsp), %rdi
callq 0x3c44
leaq 0x98(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x5fcb(%rip), %rsi      # 0xc574
leaq 0x5ffd(%rip), %rdx      # 0xc5ad
leaq 0x88(%rsp), %rdi
callq 0x3c44
movb $0x1, %bpl
leaq 0x48(%rsp), %rsi
leaq 0x88(%rsp), %rdx
movq %r15, %rdi
callq 0x3cdc
xorl %ebp, %ebp
leaq 0x97ba(%rip), %rsi      # 0xfd98
leaq -0x29cb(%rip), %rdx     # 0x3c1a
movq %r15, %rdi
callq 0x2180
jmp 0x6678
movl $0x40, %edi
callq 0x2070
movq %rax, %r15
leaq 0x78(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x5f54(%rip), %rsi      # 0xc564
leaq 0x5f5c(%rip), %rdx      # 0xc573
leaq 0x68(%rsp), %rdi
callq 0x3c44
leaq 0xb8(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x5f40(%rip), %rsi      # 0xc574
leaq 0x5f72(%rip), %rdx      # 0xc5ad
leaq 0xa8(%rsp), %rdi
callq 0x3c44
movb $0x1, %bpl
leaq 0x68(%rsp), %rsi
leaq 0xa8(%rsp), %rdx
movq %r15, %rdi
callq 0x3cdc
xorl %ebp, %ebp
leaq 0x972f(%rip), %rsi      # 0xfd98
leaq -0x2a56(%rip), %rdx     # 0x3c1a
movq %r15, %rdi
callq 0x2180
movq %rax, %r14
movq 0xa8(%rsp), %rdi
cmpq %r13, %rdi
je 0x668d
callq 0x2100
movq 0x68(%rsp), %rdi
jmp 0x66ba
movq %rax, %r14
movq 0x68(%rsp), %rdi
jmp 0x66d3
jmp 0x66f4
movq %rax, %r14
movq 0x88(%rsp), %rdi
cmpq %r13, %rdi
je 0x66b5
callq 0x2100
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0x66c4
callq 0x2100
testb %bpl, %bpl
jne 0x66e4
jmp 0x66f7
movq %rax, %r14
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0x66e4
callq 0x2100
jmp 0x66e4
jmp 0x66e1
movq %rax, %r14
movq %r15, %rdi
callq 0x20c0
jmp 0x66f7
jmp 0x66f4
jmp 0x66f4
jmp 0x66f4
movq %rax, %r14
movq %rbx, %rdi
callq 0x294e
movq %r14, %rdi
callq 0x21b0
nop