// File: /workspace/github_cpp_makefile_star2_O1/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 0x3485
movl %eax, %r12d
movq %rbx, %rdi
movl %eax, %esi
callq 0x28c8
movq %r14, 0x28(%rsp)
testl %r14d, %r14d
movq %r12, 0x30(%rsp)
je 0x6393
testl %r12d, %r12d
jle 0x64eb
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 0x51ec
movsd (%rax), %xmm0
ucomisd 0x6088(%rip), %xmm0     # 0xc2f8
jne 0x6278
jnp 0x6544
movq %r15, %rdi
movl %r12d, %esi
callq 0x31ba
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3354
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 0x6332
movl %r13d, %eax
leal 0x1(%rax), %r13d
cmpl %r14d, %eax
jge 0x632e
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3354
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x20(%rsp), %rdi
movl %r12d, %esi
movl %r13d, %edx
callq 0x51ec
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
movl %r13d, %esi
callq 0x3354
movsd (%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3354
movsd 0x18(%rsp), %xmm1
mulsd 0x38(%rsp), %xmm1
movsd 0x10(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax)
incl 0xc(%rsp)
decl %ebp
jne 0x62b5
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3354
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x20(%rsp), %rdi
movl %r12d, %esi
movl %r12d, %edx
callq 0x51ec
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3354
movsd 0x10(%rsp), %xmm0
divsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rax)
leal -0x1(%r12), %eax
cmpl $0x1, %r12d
movl %eax, %r12d
jg 0x6254
jmp 0x64f3
testl %r12d, %r12d
jle 0x64eb
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 0x51ec
movsd (%rax), %xmm0
ucomisd 0x5f2b(%rip), %xmm0     # 0xc2f8
jne 0x63d5
jnp 0x65c6
movq %r15, %rdi
movl %r12d, %esi
callq 0x31ba
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3354
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
cmpl 0x30(%rsp), %r12d
jge 0x648c
addl %r14d, 0xc(%rsp)
xorl %r15d, %r15d
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3354
leal (%r15,%rbp), %r13d
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x20(%rsp), %rdi
movl %r12d, %esi
movl %r13d, %edx
callq 0x51ec
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
movl %r13d, %esi
callq 0x3354
movsd (%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3354
movsd 0x18(%rsp), %xmm1
mulsd 0x38(%rsp), %xmm1
movsd 0x10(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax)
incl %r15d
cmpl %r15d, %r14d
jne 0x6412
movq 0x40(%rsp), %r15
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3354
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x20(%rsp), %rdi
movl %r12d, %esi
movl %r12d, %edx
callq 0x51ec
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3354
movsd 0x10(%rsp), %xmm0
divsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rax)
decl %r12d
incl %r14d
decl %ebp
cmpl 0x30(%rsp), %r14d
jne 0x63b1
jmp 0x64f3
movl $0x0, 0xc(%rsp)
movq 0x9ad6(%rip), %rdi      # 0xffd0
leaq 0x60ad(%rip), %rsi      # 0xc5ae
movl $0x11, %edx
callq 0x2120
movq 0x9abe(%rip), %rdi      # 0xffd0
movl 0xc(%rsp), %esi
callq 0x21a0
leaq 0x5dd2(%rip), %rsi      # 0xc2f4
movl $0x1, %edx
movq %rax, %rdi
callq 0x2120
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 0x78(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x6002(%rip), %rsi      # 0xc564
leaq 0x600a(%rip), %rdx      # 0xc573
leaq 0x68(%rsp), %rdi
callq 0x3c6e
leaq 0x58(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x5ff1(%rip), %rsi      # 0xc574
leaq 0x6023(%rip), %rdx      # 0xc5ad
leaq 0x48(%rsp), %rdi
callq 0x3c6e
movb $0x1, %bpl
leaq 0x68(%rsp), %rsi
leaq 0x48(%rsp), %rdx
movq %r15, %rdi
callq 0x3d00
xorl %ebp, %ebp
leaq 0x97e6(%rip), %rsi      # 0xfd98
leaq -0x2975(%rip), %rdx     # 0x3c44
movq %r15, %rdi
callq 0x2190
jmp 0x6655
movl $0x40, %edi
callq 0x2070
movq %rax, %r15
leaq 0xb8(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x5f7d(%rip), %rsi      # 0xc564
leaq 0x5f85(%rip), %rdx      # 0xc573
leaq 0xa8(%rsp), %rdi
callq 0x3c6e
leaq 0x98(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x5f66(%rip), %rsi      # 0xc574
leaq 0x5f98(%rip), %rdx      # 0xc5ad
leaq 0x88(%rsp), %rdi
callq 0x3c6e
movb $0x1, %bpl
leaq 0xa8(%rsp), %rsi
leaq 0x88(%rsp), %rdx
movq %r15, %rdi
callq 0x3d00
xorl %ebp, %ebp
leaq 0x9752(%rip), %rsi      # 0xfd98
leaq -0x2a09(%rip), %rdx     # 0x3c44
movq %r15, %rdi
callq 0x2190
movq %rax, %r14
movq 0x88(%rsp), %rdi
cmpq %r13, %rdi
je 0x6672
callq 0x2110
jmp 0x6672
movq %rax, %r14
movb $0x1, %bpl
movq 0xa8(%rsp), %rdi
jmp 0x669d
jmp 0x66c6
movq %rax, %r14
movq 0x48(%rsp), %rdi
cmpq %r13, %rdi
je 0x6698
callq 0x2110
jmp 0x6698
movq %rax, %r14
movb $0x1, %bpl
movq 0x68(%rsp), %rdi
cmpq %r12, %rdi
je 0x66b1
callq 0x2110
jmp 0x66b1
jmp 0x66ab
movq %rax, %r14
movb $0x1, %bpl
testb %bpl, %bpl
je 0x66c9
movq %r15, %rdi
callq 0x20c0
jmp 0x66c9
jmp 0x66c6
jmp 0x66c6
jmp 0x66c6
movq %rax, %r14
movq %rbx, %rdi
callq 0x2970
movq %r14, %rdi
callq 0x21c0
nop