// File: /workspace/github_cpp_makefile_star2_O3/Laakeri[P]Triangulator/src/treewidth.cpp
// Function: TreeWidth::SolveGraph::solveGraph(Graph const&, int, int, int)
pair<int, vector<pair<int, int> > > solveGraph(const Graph& G, int lowerBound, int okWidth, int upperBound) {
	assert(lowerBound >= 0);
	assert(okWidth <= upperBound);
	if (G.hasCycle()) {
		lowerBound = max(lowerBound, 2);
	}
	else {
		upperBound = min(upperBound, 1);
	}
	if (lowerBound > upperBound) return {-1, FAILSOLUTION};
	okWidth = max(okWidth, lowerBound);
	
	auto fill = MCS::MCS_MP(G);
	
	Graph gFill = G;
	gFill.addEdges(fill.F);
	
	int fillWidth = MCS::getTreeWidth(gFill);
	assert(fillWidth >= lowerBound);
	if (fillWidth <= okWidth) return {fillWidth, fill.F};
	
	if (fill.F.size() <= 1) {
		if (fillWidth > upperBound) return {-1, FAILSOLUTION};
		return {fillWidth, fill.F};
	}
	
	vector<Graph> atoms;
	int maxCliqueSeparator;
	tie(maxCliqueSeparator, atoms) = MCS::getAtoms(G, gFill, fill);
	lowerBound = max(lowerBound, maxCliqueSeparator-1);
	if (lowerBound > upperBound) return {-1, FAILSOLUTION};
	okWidth = max(okWidth, lowerBound);
	if (fillWidth <= okWidth) return {fillWidth, fill.F};
	
	auto cmp = [](const Graph& a, const Graph& b) {
		return a.n > b.n;
	};
	sort(atoms.begin(), atoms.end(), cmp);
	pair<int, vector<pair<int, int> > > sol = {lowerBound, {}};
	for (int i = 0; i < (int)atoms.size(); i++) {
		pair<int, vector<pair<int, int> > > tSol;
		if (i+1 < (int)atoms.size()) {
			tSol = SolveAtom::solveAtom0(atoms[i], 0, sol.F, min(upperBound, fillWidth-1));
		}
		else {
			tSol = SolveAtom::solveAtom0(atoms[i], 0, sol.F, min(upperBound, fillWidth-1));
		}
		if (tSol.S == FAILSOLUTION) {
			if (fillWidth <= upperBound) {
				return {fillWidth, fill.F};
			}
			else {
				return {-1, FAILSOLUTION};
			}
		}
		sol.F = max(sol.F, tSol.F);
		tSol.S = atoms[i].mapBack(tSol.S);
		sol.S.insert(sol.S.end(), tSol.S.begin(), tSol.S.end());
	}
	assert(sol.F <= upperBound);
	return sol;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rdi, 0x8(%rsp)
testl %edx, %edx
js 0x27c19
movl %r8d, %r12d
movl %ecx, %ebp
cmpl %r8d, %ecx
jg 0x27c38
movl %edx, %r15d
movq %rsi, %r14
movq %rsi, %rdi
callq 0xa5b2
cmpl $0x3, %r15d
movl $0x2, %ebx
cmovael %r15d, %ebx
testl %r12d, %r12d
movl $0x1, %r13d
cmovlel %r12d, %r13d
testb %al, %al
cmovnel %r12d, %r13d
cmovel %r15d, %ebx
cmpl %r13d, %ebx
jle 0x275f9
movq 0x8(%rsp), %rbx
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
movq %rbx, %rdi
addq $0x8, %rdi
leaq 0xc120d4(%rip), %rsi    # 0xc396c0
callq 0x3f7c
movq %rbx, %rax
jmp 0x27c07
cmpl %ebp, %ebx
cmovgl %ebx, %ebp
leaq 0xa8(%rsp), %rdi
movq %r14, %rsi
callq 0x12cbc
leaq 0xf0(%rsp), %rdi
movq %r14, %rsi
callq 0x42ce
movq 0x8(%rsp), %r15
leaq 0x108(%rsp), %rdi
leaq 0x18(%r14), %rsi
callq 0x815a
movb 0x30(%r14), %al
leaq 0x128(%rsp), %rdi
movb %al, -0x8(%rdi)
leaq 0x38(%r14), %rsi
callq 0x4110
movq 0x50(%r14), %rax
leaq 0xf0(%rsp), %rdi
movq %rax, 0x50(%rdi)
leaq 0xa8(%rsp), %rsi
callq 0x9bd8
leaq 0xf0(%rsp), %rdi
callq 0x139e9
movl %eax, %r12d
cmpl %ebx, %eax
jl 0x27c57
cmpl %ebp, %r12d
jbe 0x276c1
movq 0xb0(%rsp), %rax
subq 0xa8(%rsp), %rax
cmpq $0x8, %rax
ja 0x276dd
leaq 0x8(%r15), %rdi
cmpl %r13d, %r12d
jbe 0x27799
movl $0xffffffff, (%r15)     # imm = 0xFFFFFFFF
leaq 0xc12009(%rip), %rsi    # 0xc396c0
callq 0x3f7c
jmp 0x27b93
movl %r12d, (%r15)
movq %r15, %rdi
addq $0x8, %rdi
leaq 0xa8(%rsp), %rsi
callq 0x3f7c
jmp 0x27b93
xorpd %xmm0, %xmm0
movapd %xmm0, 0x60(%rsp)
movq $0x0, 0x70(%rsp)
leaq 0x80(%rsp), %rdi
leaq 0xf0(%rsp), %rdx
leaq 0xa8(%rsp), %rcx
movq %r14, %rsi
callq 0x13217
leaq 0x88(%rsp), %r14
movl -0x8(%r14), %r15d
movq 0x70(%rsp), %rax
movupd (%r14), %xmm0
movq 0x10(%r14), %rcx
movq %rcx, 0x70(%rsp)
movdqa 0x60(%rsp), %xmm1
movapd %xmm0, 0x60(%rsp)
leaq 0x10(%rsp), %rdi
movdqa %xmm1, (%rdi)
movq %rax, 0x10(%rdi)
xorpd %xmm0, %xmm0
movupd %xmm0, (%r14)
movq $0x0, 0x10(%r14)
callq 0x6b12
movq %r14, %rdi
callq 0x6b12
decl %r15d
cmpl %r15d, %ebx
cmovgl %ebx, %r15d
cmpl %r13d, %r15d
jbe 0x277a1
movq 0x8(%rsp), %r15
movl $0xffffffff, (%r15)     # imm = 0xFFFFFFFF
movq %r15, %rdi
addq $0x8, %rdi
leaq 0xc11f31(%rip), %rsi    # 0xc396c0
callq 0x3f7c
jmp 0x27b89
movl %r12d, (%r15)
jmp 0x276cb
cmpl %r15d, %ebp
cmovbel %r15d, %ebp
cmpl %ebp, %r12d
jbe 0x27821
movq 0x60(%rsp), %rbx
movq 0x68(%rsp), %r14
cmpq %r14, %rbx
je 0x2784d
movq %r14, %rbp
subq %rbx, %rbp
movq %rbp, %rax
sarq $0x3, %rax
movabsq $0x2e8ba2e8ba2e8ba3, %rcx # imm = 0x2E8BA2E8BA2E8BA3
imulq %rcx, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x27d86
cmpq $0x581, %rbp            # imm = 0x581
jl 0x27842
leaq 0x580(%rbx), %rbp
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x28794
cmpq %r14, %rbp
je 0x2784d
movq %rbp, %rdi
callq 0x2895b
addq $0x58, %rbp
jmp 0x2780e
movq 0x8(%rsp), %r15
movl %r12d, (%r15)
movq %r15, %rdi
addq $0x8, %rdi
leaq 0xa8(%rsp), %rsi
callq 0x3f7c
jmp 0x27b89
movq %rbx, %rdi
movq %r14, %rsi
callq 0x28794
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %rsi
movapd %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
leaq 0x88(%rsp), %rdi
movl %r15d, -0x8(%rdi)
callq 0x3f7c
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
movq 0x8(%rsp), %rbx
je 0x2788f
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
leal -0x1(%r12), %eax
cmpl %r13d, %eax
cmovgel %r13d, %eax
movl %eax, 0x3c(%rsp)
leaq 0x8(%rbx), %rax
movq %rax, 0xa0(%rsp)
xorl %r15d, %r15d
leaq 0xd8(%rsp), %rbx
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rax
subq %rsi, %rax
sarq $0x3, %rax
movabsq $0x2e8ba2e8ba2e8ba3, %rcx # imm = 0x2E8BA2E8BA2E8BA3
imulq %rcx, %rax
movslq %eax, %rcx
cmpq %rcx, %r15
jge 0x27b58
movl $0x0, 0x10(%rsp)
leaq 0x18(%rsp), %rcx
xorpd %xmm0, %xmm0
movupd %xmm0, (%rcx)
movq $0x0, 0x10(%rcx)
imulq $0x58, %r15, %rbp
incq %r15
addq %rbp, %rsi
cmpl %eax, %r15d
jge 0x27927
movl 0x80(%rsp), %ecx
leaq 0x40(%rsp), %rdi
xorl %edx, %edx
movl 0x3c(%rsp), %r8d
callq 0x271cc
jmp 0x2793f
movl 0x80(%rsp), %ecx
leaq 0x40(%rsp), %rdi
xorl %edx, %edx
movl 0x3c(%rsp), %r8d
callq 0x271cc
movl 0x40(%rsp), %eax
movl %eax, 0x10(%rsp)
movq 0x18(%rsp), %rdi
movq 0x28(%rsp), %rsi
movupd 0x48(%rsp), %xmm0
movupd %xmm0, 0x18(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x48(%rsp), %rax
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq $0x0, 0x10(%rax)
testq %rdi, %rdi
je 0x279a0
subq %rdi, %rsi
callq 0x2210
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x279a0
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
movq %rcx, %rsi
subq %rax, %rsi
movq 0xc11d11(%rip), %rdi    # 0xc396c8
movq 0xc11d02(%rip), %rdx    # 0xc396c0
subq %rdx, %rdi
cmpq %rdi, %rsi
jne 0x279f3
cmpq %rcx, %rax
je 0x27ac6
movq (%rax), %xmm0
movq (%rdx), %xmm1
pcmpeqd %xmm0, %xmm1
pshufd $0x50, %xmm1, %xmm0     # xmm0 = xmm1[0,0,1,1]
movmskpd %xmm0, %esi
cmpl $0x3, %esi
jne 0x279f3
addq $0x8, %rax
addq $0x8, %rdx
jmp 0x279c6
movl 0x80(%rsp), %eax
movl 0x10(%rsp), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl %ecx, 0x80(%rsp)
movq 0x60(%rsp), %r14
movq %rbx, %rdi
leaq 0x18(%rsp), %rsi
callq 0x3f7c
addq %rbp, %r14
leaq 0x40(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0xa2d6
movq 0x18(%rsp), %rdi
movq 0x28(%rsp), %rsi
movapd 0x40(%rsp), %xmm0
movupd %xmm0, 0x18(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x28(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
testq %rdi, %rdi
je 0x27a86
subq %rdi, %rsi
callq 0x2210
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x27a86
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0xd8(%rsp), %rdi
testq %rdi, %rdi
je 0x27aa3
movq 0xe8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0x90(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
leaq 0x88(%rsp), %rdi
callq 0x8ecc
xorl %ebx, %ebx
jmp 0x27b0d
cmpl %r13d, %r12d
jle 0x27aee
movq 0x8(%rsp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movb $0x1, %bl
movq 0xa0(%rsp), %rdi
leaq 0xc11bd9(%rip), %rsi    # 0xc396c0
callq 0x3f7c
jmp 0x27b0d
movq 0x8(%rsp), %rax
movl %r12d, (%rax)
movb $0x1, %bl
movq 0xa0(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x3f7c
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x27b24
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
testb %bl, %bl
leaq 0xd8(%rsp), %rbx
je 0x278b6
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
movq 0x8(%rsp), %r15
je 0x27b89
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
jmp 0x27b89
movl 0x80(%rsp), %eax
cmpl %r13d, %eax
jg 0x27c76
movq 0x8(%rsp), %r15
movl %eax, (%r15)
movups 0x88(%rsp), %xmm0
movups %xmm0, 0x8(%r15)
movq 0x98(%rsp), %rax
movq %rax, 0x18(%r15)
leaq 0x60(%rsp), %rdi
callq 0x6b12
leaq 0x128(%rsp), %rdi
callq 0x41aa
leaq 0x108(%rsp), %rdi
callq 0x436a
movq 0xf0(%rsp), %rdi
testq %rdi, %rdi
je 0x27bca
movq 0x100(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x27be7
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x27c04
movq 0xb8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq %r15, %rax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x172e(%rip), %rdi      # 0x2934e
leaq 0x3729(%rip), %rsi      # 0x2b350
leaq 0x387b(%rip), %rcx      # 0x2b4a9
movl $0xa3, %edx
callq 0x2140
leaq 0x1c1c(%rip), %rdi      # 0x2985b
leaq 0x370a(%rip), %rsi      # 0x2b350
leaq 0x385c(%rip), %rcx      # 0x2b4a9
movl $0xa4, %edx
callq 0x2140
leaq 0x1632(%rip), %rdi      # 0x29290
leaq 0x36eb(%rip), %rsi      # 0x2b350
leaq 0x383d(%rip), %rcx      # 0x2b4a9
movl $0xb4, %edx
callq 0x2140
leaq 0x178e(%rip), %rdi      # 0x2940b
leaq 0x36cc(%rip), %rsi      # 0x2b350
leaq 0x381e(%rip), %rcx      # 0x2b4a9
movl $0xdd, %edx
callq 0x2140
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x27d1a
movq 0x20(%rsp), %rsi
jmp 0x27d12
jmp 0x27cb6
jmp 0x27cb6
jmp 0x27d61
jmp 0x27ce3
jmp 0x27ce3
movq %rax, %rbx
jmp 0x27d1a
jmp 0x27ce3
jmp 0x27ce3
jmp 0x27ce3
movq %rax, %rbx
movq 0xd8(%rsp), %rdi
testq %rdi, %rdi
je 0x27ce6
movq 0xe8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
jmp 0x27ce6
movq %rax, %rbx
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x27cfd
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x27d1a
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
leaq 0x60(%rsp), %rdi
callq 0x6b12
jmp 0x27d64
jmp 0x27d61
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x436a
jmp 0x27d3d
movq %rax, %rbx
movq 0xf0(%rsp), %rdi
testq %rdi, %rdi
je 0x27d71
movq 0x100(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
jmp 0x27d71
movq %rax, %rbx
jmp 0x27d71
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x40d8
leaq 0xa8(%rsp), %rdi
callq 0x3ff2
movq %rbx, %rdi
callq 0x2310