// File: /workspace/github_cpp_makefile_star2_O1/Laakeri[P]Triangulator/src/hyper.cpp
// Function: Hyper::SolveGraph::solveGraph(Graph const&, int, int, int, std::vector<int, std::allocator<int>> const&)
pair<int, vector<pair<int, int> > > solveGraph(const Graph& G, int lowerBound, int okWidth, int upperBound, const vector<int>& vertMap) {
	assert(lowerBound >= 0);
	assert(okWidth <= upperBound);
	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::getHyperTreeWidth(gFill, vertMap);
	assert(fillWidth >= lowerBound);
	
	if (fillWidth <= okWidth) return {fillWidth, fill.F};
	
	vector<Graph> atoms = MCS::getAtoms(G, gFill, fill).S;
	
	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::solveAtom(atoms[i], 1, sol.F, min(upperBound, fillWidth-1), atoms[i].mapTableInto(vertMap));
		}
		else {
			tSol = SolveAtom::solveAtom(atoms[i], 1, sol.F, min(upperBound, fillWidth-1), atoms[i].mapTableInto(vertMap));
		}
		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 $0x168, %rsp            # imm = 0x168
movq %r9, 0x80(%rsp)
movq %rdi, 0x20(%rsp)
testl %edx, %edx
js 0xd4dd
movl %r8d, %ebp
movl %ecx, %r15d
cmpl %r8d, %ecx
jg 0xd4fc
movl %edx, %ebx
cmpl %ebp, %edx
jle 0xcee2
movq 0x20(%rsp), %rbx
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
movq %rbx, %rdi
addq $0x8, %rdi
leaq 0x29333(%rip), %rsi     # 0x36208
callq 0x402a
movq %rbx, %rax
jmp 0xd4cb
movq %rsi, %r14
cmpl %ebx, %r15d
cmovlel %ebx, %r15d
leaq 0xe0(%rsp), %rdi
callq 0x12a60
leaq 0x110(%rsp), %rdi
movq %r14, %rsi
callq 0x431c
movl %ebp, 0x2c(%rsp)
leaq 0x128(%rsp), %r12
leaq 0x18(%r14), %rsi
movq %r12, %rdi
callq 0x7e36
movb 0x30(%r14), %al
leaq 0x148(%rsp), %r13
movb %al, -0x8(%r13)
leaq 0x38(%r14), %rsi
movq %r13, %rdi
callq 0x4164
movq 0x50(%r14), %rax
leaq 0x110(%rsp), %rdi
movq %rax, 0x50(%rdi)
leaq 0xe0(%rsp), %rsi
callq 0x9880
leaq 0x110(%rsp), %rdi
movq 0x80(%rsp), %rsi
callq 0x14010
cmpl %ebx, %eax
jl 0xd51b
cmpl %r15d, %eax
jle 0xd052
movq %rax, 0xa8(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x110(%rsp), %rdx
leaq 0xe0(%rsp), %rcx
movq %r14, %rsi
callq 0x12fba
leaq 0x68(%rsp), %rdi
movq (%rdi), %rax
movq %rax, 0xb0(%rsp)
movups 0x8(%rdi), %xmm0
movups %xmm0, 0xb8(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
callq 0x69a0
movq 0xb0(%rsp), %r15
movq 0xb8(%rsp), %r14
cmpq %r14, %r15
movl 0x2c(%rsp), %ebp
je 0xd07a
movq %r14, %r12
subq %r15, %r12
movq %r12, %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 %r15, %rdi
movq %r14, %rsi
callq 0xebdb
cmpq $0x581, %r12            # imm = 0x581
jl 0xd06f
leaq 0x580(%r15), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0xf44f
cmpq %r14, %r12
je 0xd07a
movq %r12, %rdi
callq 0xf648
addq $0x58, %r12
jmp 0xd03f
movq 0x20(%rsp), %rdi
movl %eax, (%rdi)
addq $0x8, %rdi
leaq 0xe0(%rsp), %rsi
callq 0x402a
jmp 0xd45f
movq %r15, %rdi
movq %r14, %rsi
callq 0xf44f
movq %rsp, %rsi
xorps %xmm0, %xmm0
movaps %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
movl %ebx, 0x60(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x402a
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xd0af
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0xa8(%rsp), %rax
decl %eax
cmpl %ebp, %eax
cmovgel %ebp, %eax
movl %eax, 0x5c(%rsp)
movq 0x20(%rsp), %rax
addq $0x8, %rax
movq %rax, 0xa0(%rsp)
xorl %r13d, %r13d
leaq 0x88(%rsp), %r14
leaq 0xc8(%rsp), %r15
movq 0xb0(%rsp), %r12
movq 0xb8(%rsp), %rax
subq %r12, %rax
sarq $0x3, %rax
movabsq $0x2e8ba2e8ba2e8ba3, %rcx # imm = 0x2E8BA2E8BA2E8BA3
imulq %rcx, %rax
movslq %eax, %rcx
cmpq %rcx, %r13
jge 0xd3e8
movl $0x0, (%rsp)
xorps %xmm0, %xmm0
leaq 0x8(%rsp), %rcx
movups %xmm0, (%rcx)
movq $0x0, 0x10(%rcx)
imulq $0x58, %r13, %rbx
incq %r13
addq %rbx, %r12
cmpl %eax, %r13d
jge 0xd175
movl 0x60(%rsp), %ebp
movq %r14, %rdi
movq %r12, %rsi
movq 0x80(%rsp), %rdx
callq 0x104a6
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
movl $0x1, %edx
movl %ebp, %ecx
movl 0x5c(%rsp), %r8d
movq %r14, %r9
callq 0xc2dc
jmp 0xd1a8
movl 0x60(%rsp), %ebp
movq %r14, %rdi
movq %r12, %rsi
movq 0x80(%rsp), %rdx
callq 0x104a6
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
movl $0x1, %edx
movl %ebp, %ecx
movl 0x5c(%rsp), %r8d
movq %r14, %r9
callq 0xc2dc
movl 0x30(%rsp), %eax
movl %eax, (%rsp)
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rsi
movq 0x38(%rsp), %rcx
movq %rcx, 0x8(%rsp)
movups 0x40(%rsp), %xmm0
movups %xmm0, 0x10(%rsp)
movq %rdi, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movq %rsi, 0x48(%rsp)
leaq 0x38(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
testq %rdi, %rdi
je 0xd201
subq %rdi, %rsi
callq 0x2210
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0xd218
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0xd235
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rax
movq %rax, %rsi
subq %rcx, %rsi
movq 0x28fc4(%rip), %rdi     # 0x36210
movq 0x28fb5(%rip), %rdx     # 0x36208
subq %rdx, %rdi
cmpq %rdi, %rsi
jne 0xd2a2
cmpq %rax, %rcx
sete %bpl
je 0xd2a4
movl (%rcx), %esi
xorl %ebp, %ebp
cmpl (%rdx), %esi
jne 0xd2a4
movl 0x4(%rdx), %esi
cmpl %esi, 0x4(%rcx)
jne 0xd2a4
addq $0x8, %rcx
addq $0xc, %rdx
cmpq %rax, %rcx
sete %bpl
je 0xd2a4
movl (%rcx), %esi
xorl %ebp, %ebp
cmpl -0x4(%rdx), %esi
jne 0xd2a4
leaq 0x8(%rcx), %rsi
movl (%rdx), %edi
addq $0x8, %rdx
cmpl %edi, 0x4(%rcx)
movq %rsi, %rcx
je 0xd27c
jmp 0xd2a4
xorl %ebp, %ebp
testb %bpl, %bpl
je 0xd2df
movq 0xa8(%rsp), %rcx
cmpl 0x2c(%rsp), %ecx
jle 0xd3a2
movq 0x20(%rsp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq 0xa0(%rsp), %rdi
leaq 0x28f33(%rip), %rsi     # 0x36208
callq 0x402a
jmp 0xd3be
movl 0x60(%rsp), %eax
movl (%rsp), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl %ecx, 0x60(%rsp)
movq 0xb0(%rsp), %r12
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
callq 0x402a
addq %rbx, %r12
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x9f86
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, 0x10(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
testq %rdi, %rdi
je 0xd353
subq %rdi, %rsi
callq 0x2210
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0xd36a
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0xd387
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0x70(%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %rcx
leaq 0x68(%rsp), %rdi
callq 0x8bb4
jmp 0xd3be
movq 0x20(%rsp), %rax
movl %ecx, (%rax)
movq 0xa0(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x402a
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0xd3d5
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
testb %bpl, %bpl
leaq 0x88(%rsp), %r14
je 0xd0e6
jmp 0xd42b
movl 0x60(%rsp), %eax
cmpl 0x2c(%rsp), %eax
jg 0xd53a
movq 0x20(%rsp), %rcx
movl %eax, (%rcx)
movq 0x68(%rsp), %rax
movq %rax, 0x8(%rcx)
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rcx)
movq 0x78(%rsp), %rax
movq %rax, 0x18(%rcx)
xorps %xmm0, %xmm0
leaq 0x68(%rsp), %rax
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0xd442
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
leaq 0xb0(%rsp), %rdi
callq 0x69a0
leaq 0x128(%rsp), %r12
leaq 0x148(%rsp), %r13
movq %r13, %rdi
callq 0x41fe
movq %r12, %rdi
callq 0x43b8
movq 0x110(%rsp), %rdi
testq %rdi, %rdi
je 0xd48c
movq 0x120(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0xf8(%rsp), %rdi
testq %rdi, %rdi
je 0xd4a9
movq 0x108(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0xe0(%rsp), %rdi
testq %rdi, %rdi
je 0xd4c6
movq 0xf0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0x20(%rsp), %rax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1ce5a(%rip), %rdi     # 0x2a33e
leaq 0x1d2e5(%rip), %rsi     # 0x2a7d0
leaq 0x1d45c(%rip), %rcx     # 0x2a94e
movl $0x64, %edx
callq 0x2140
leaq 0x1d348(%rip), %rdi     # 0x2a84b
leaq 0x1d2c6(%rip), %rsi     # 0x2a7d0
leaq 0x1d43d(%rip), %rcx     # 0x2a94e
movl $0x65, %edx
callq 0x2140
leaq 0x1cd5e(%rip), %rdi     # 0x2a280
leaq 0x1d2a7(%rip), %rsi     # 0x2a7d0
leaq 0x1d41e(%rip), %rcx     # 0x2a94e
movl $0x6f, %edx
callq 0x2140
leaq 0x1ceba(%rip), %rdi     # 0x2a3fb
leaq 0x1d288(%rip), %rsi     # 0x2a7d0
leaq 0x1d3ff(%rip), %rcx     # 0x2a94e
movl $0x8e, %edx
callq 0x2140
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xd636
movq 0x10(%rsp), %rsi
jmp 0xd62e
jmp 0xd5b5
jmp 0xd5b5
movq %rax, %rbx
movq %r12, %rdi
callq 0x43b8
jmp 0xd587
movq %rax, %rbx
movq 0x110(%rsp), %rdi
testq %rdi, %rdi
je 0xd650
movq 0x120(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
jmp 0xd650
movq %rax, %rbx
jmp 0xd650
movq %rax, %rbx
jmp 0xd643
jmp 0xd5c7
jmp 0xd5c7
jmp 0xd5c7
jmp 0xd5c7
jmp 0xd5c7
movq %rax, %rbx
jmp 0xd608
jmp 0xd5ce
movq %rax, %rbx
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0xd608
movq 0x98(%rsp), %rsi
jmp 0xd600
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0xd608
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0xd61f
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0xd636
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
leaq 0xb0(%rsp), %rdi
callq 0x69a0
leaq 0x110(%rsp), %rdi
callq 0x412c
leaq 0xe0(%rsp), %rdi
callq 0x40a0
movq %rbx, %rdi
callq 0x2310