// File: /workspace/github_cpp_makefile_star2_O2/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 $0x158, %rsp            # imm = 0x158
movq %rdi, 0x8(%rsp)
testl %edx, %edx
js 0x1f4d1
movl %r8d, %r12d
movl %ecx, %ebp
cmpl %r8d, %ecx
jg 0x1f4f0
movl %edx, %r15d
movq %rsi, %r14
movq %rsi, %rdi
callq 0x84e0
cmpl $0x3, %r15d
pushq $0x2
popq %r13
cmovael %r15d, %r13d
testl %r12d, %r12d
pushq $0x1
popq %rbx
cmovlel %r12d, %ebx
testb %al, %al
cmovnel %r12d, %ebx
cmovel %r15d, %r13d
cmpl %ebx, %r13d
jle 0x1f06f
movq 0x8(%rsp), %rbx
orl $-0x1, (%rbx)
movq %rbx, %rdi
addq $0x8, %rdi
leaq 0xc1566e(%rip), %rsi    # 0xc346d0
callq 0x35f2
movq %rbx, %rax
jmp 0x1f4bf
cmpl %ebp, %r13d
cmovgl %r13d, %ebp
leaq 0x98(%rsp), %rdi
movq %r14, %rsi
callq 0xe30c
leaq 0x100(%rsp), %rdi
movq %r14, %rsi
callq 0x5152
movq 0x8(%rsp), %r12
leaq 0x100(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x7cf8
leaq 0x100(%rsp), %rdi
callq 0xed88
movl %eax, %r15d
cmpl %r13d, %eax
jl 0x1f50f
cmpl %ebp, %r15d
jbe 0x1f108
movq 0xa0(%rsp), %rax
subq 0x98(%rsp), %rax
cmpq $0x8, %rax
ja 0x1f125
leaq 0x8(%r12), %rdi
cmpl %ebx, %r15d
jbe 0x1f1b1
orl $-0x1, (%r12)
leaq 0xc155d2(%rip), %rsi    # 0xc346d0
callq 0x35f2
jmp 0x1f4a2
movl %r15d, (%r12)
movq %r12, %rdi
addq $0x8, %rdi
leaq 0x98(%rsp), %rsi
callq 0x35f2
jmp 0x1f4a2
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
andq $0x0, 0x50(%rsp)
leaq 0x18(%rsp), %rdi
leaq 0x100(%rsp), %rdx
leaq 0x98(%rsp), %rcx
movq %r14, %rsi
callq 0xe775
leaq 0x40(%rsp), %rax
leaq 0x60(%rsp), %rdi
movq %rax, (%rdi)
leaq 0x94(%rsp), %r14
movq %r14, 0x8(%rdi)
leaq 0x18(%rsp), %rsi
callq 0x1fab0
leaq 0x20(%rsp), %rdi
callq 0x52ce
movl (%r14), %r12d
decl %r12d
cmpl %r12d, %r13d
cmovgl %r13d, %r12d
cmpl %ebx, %r12d
jbe 0x1f1ba
movq 0x8(%rsp), %r12
orl $-0x1, (%r12)
movq %r12, %rdi
addq $0x8, %rdi
leaq 0xc15529(%rip), %rsi    # 0xc346d0
callq 0x35f2
jmp 0x1f498
movl %r15d, (%r12)
jmp 0x1f113
cmpl %r12d, %ebp
cmovbel %r12d, %ebp
cmpl %ebp, %r15d
jbe 0x1f232
movq 0x40(%rsp), %rbp
movq 0x48(%rsp), %r14
cmpq %r14, %rbp
je 0x1f25f
movq %r14, %r13
subq %rbp, %r13
movq %r13, %rax
cqto
pushq $0x58
popq %rcx
idivq %rcx
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %rbp, %rdi
movq %r14, %rsi
callq 0x1f5cf
cmpq $0x581, %r13            # imm = 0x581
jl 0x1f254
leaq 0x580(%rbp), %r13
movq %rbp, %rdi
movq %r13, %rsi
callq 0x1f9c9
jmp 0x1f22b
movq %r13, %rdi
callq 0x1fa5f
addq $0x58, %r13
cmpq %r14, %r13
jne 0x1f21f
jmp 0x1f25f
movq 0x8(%rsp), %r12
movl %r15d, (%r12)
movq %r12, %rdi
addq $0x8, %rdi
leaq 0x98(%rsp), %rsi
callq 0x35f2
jmp 0x1f498
movq %rbp, %rdi
movq %r14, %rsi
callq 0x1f9c9
xorps %xmm0, %xmm0
leaq 0x60(%rsp), %rsi
movaps %xmm0, (%rsi)
andq $0x0, 0x10(%rsi)
movl %r12d, 0x18(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x35f2
leaq 0x60(%rsp), %rdi
callq 0x3bfe
leaq 0x68(%rsp), %rbp
leal -0x1(%r15), %eax
cmpl %ebx, %eax
cmovgel %ebx, %eax
movl %eax, 0x14(%rsp)
movq 0x8(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x80(%rsp)
xorl %r13d, %r13d
leaq 0xc1541b(%rip), %rax    # 0xc346d0
xorl %r12d, %r12d
movq %r15, 0x88(%rsp)
movq %rax, %r15
movl %ebx, 0x3c(%rsp)
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rax
subq %rsi, %rax
cqto
pushq $0x58
popq %rcx
idivq %rcx
movslq %eax, %rcx
cmpq %rcx, %r12
jge 0x1f454
andl $0x0, 0x60(%rsp)
andq $0x0, 0x10(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, (%rbp)
leal 0x1(%r12), %ecx
addq %r13, %rsi
cmpl %eax, %ecx
jge 0x1f322
movl 0x18(%rsp), %ecx
leaq 0xc8(%rsp), %r14
movq %r14, %rdi
xorl %edx, %edx
movl 0x14(%rsp), %r8d
callq 0x1ecc5
jmp 0x1f33d
movl 0x18(%rsp), %ecx
leaq 0xc8(%rsp), %r14
movq %r14, %rdi
xorl %edx, %edx
movl 0x14(%rsp), %r8d
callq 0x1ecc5
leaq 0x60(%rsp), %rdi
movq %r14, %rsi
callq 0xc9e6
leaq 0xd0(%rsp), %rdi
callq 0x3bfe
movq %rbp, %rdi
movq %r15, %rsi
callq 0x35c8
movl %eax, %r14d
testb %al, %al
je 0x1f396
movq 0x88(%rsp), %rcx
cmpl %ebx, %ecx
jle 0x1f41e
movq 0x8(%rsp), %rax
orl $-0x1, (%rax)
movq 0x80(%rsp), %rdi
movq %r15, %rsi
callq 0x35f2
jmp 0x1f43a
movl 0x18(%rsp), %eax
movl 0x60(%rsp), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl %ecx, 0x18(%rsp)
movq %rbp, %rsi
movq 0x40(%rsp), %rbp
leaq 0xe8(%rsp), %rbx
movq %rbx, %rdi
callq 0x35f2
addq %r13, %rbp
leaq 0xc8(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x82b2
leaq 0x68(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
callq 0x3d74
movq %r15, %rdi
callq 0x3bfe
movq %rbx, %rdi
callq 0x3bfe
movq 0x28(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq 0x70(%rsp), %rcx
leaq 0x20(%rsp), %rdi
callq 0x52ae
leaq 0xc152b8(%rip), %r15    # 0xc346d0
movl 0x3c(%rsp), %ebx
jmp 0x1f43a
movq 0x8(%rsp), %rax
movl %ecx, (%rax)
movq 0x80(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x35f2
movq %rbp, %rdi
callq 0x3bfe
addq $0x58, %r13
incq %r12
testb %r14b, %r14b
je 0x1f2c7
jmp 0x1f489
movl 0x18(%rsp), %eax
cmpl %ebx, %eax
jg 0x1f52e
movq 0x8(%rsp), %rcx
movl %eax, (%rcx)
movups 0x20(%rsp), %xmm0
movups %xmm0, 0x8(%rcx)
movq 0x30(%rsp), %rax
movq %rax, 0x18(%rcx)
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rax
movups %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x20(%rsp), %rdi
callq 0x3bfe
movq 0x8(%rsp), %r12
leaq 0x40(%rsp), %rdi
callq 0x52ce
leaq 0x100(%rsp), %rdi
callq 0x36d2
leaq 0x98(%rsp), %rdi
callq 0x3642
movq %r12, %rax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xe76(%rip), %rdi       # 0x2034e
leaq 0x2e71(%rip), %rsi      # 0x22350
leaq 0x2fc3(%rip), %rcx      # 0x224a9
movl $0xa3, %edx
callq 0x2150
leaq 0x1364(%rip), %rdi      # 0x2085b
leaq 0x2e52(%rip), %rsi      # 0x22350
leaq 0x2fa4(%rip), %rcx      # 0x224a9
movl $0xa4, %edx
callq 0x2150
leaq 0xd7a(%rip), %rdi       # 0x20290
leaq 0x2e33(%rip), %rsi      # 0x22350
leaq 0x2f85(%rip), %rcx      # 0x224a9
movl $0xb4, %edx
callq 0x2150
leaq 0xed6(%rip), %rdi       # 0x2040b
leaq 0x2e14(%rip), %rsi      # 0x22350
leaq 0x2f66(%rip), %rcx      # 0x224a9
movl $0xdd, %edx
callq 0x2150
jmp 0x1f561
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
jmp 0x1f599
jmp 0x1f561
jmp 0x1f561
jmp 0x1f5aa
jmp 0x1f587
movq %rax, %rbx
jmp 0x1f59e
jmp 0x1f587
jmp 0x1f587
jmp 0x1f587
jmp 0x1f587
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0x3bfe
jmp 0x1f58a
jmp 0x1f5aa
movq %rax, %rbx
jmp 0x1f5ba
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x3bfe
leaq 0x20(%rsp), %rdi
callq 0x3bfe
leaq 0x40(%rsp), %rdi
callq 0x52ce
jmp 0x1f5ad
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0x36d2
leaq 0x98(%rsp), %rdi
callq 0x3642
movq %rbx, %rdi
callq 0x2340