// File: /workspace/github_cpp_makefile_star2_O2/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, 0x18(%rsp)
movq %rdi, 0x8(%rsp)
testl %edx, %edx
js 0xaf8b
movl %r8d, %r15d
movl %ecx, %ebp
cmpl %r8d, %ecx
jg 0xafa4
movl %edx, %ebx
cmpl %r15d, %edx
jle 0xabb1
movq 0x8(%rsp), %rbx
orl $-0x1, (%rbx)
movq %rbx, %rdi
addq $0x8, %rdi
leaq 0x25674(%rip), %rsi     # 0x30218
callq 0x35f2
movq %rbx, %rax
jmp 0xaf79
movq %rsi, %r14
cmpl %ebx, %ebp
cmovlel %ebx, %ebp
leaq 0xa8(%rsp), %rdi
callq 0xe30c
leaq 0x110(%rsp), %rdi
movq %r14, %rsi
callq 0x5152
leaq 0x110(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x7cf8
leaq 0x110(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0xf49b
cmpl %ebx, %eax
jl 0xafbd
cmpl %ebp, %eax
jbe 0xacc3
movq %rax, 0x88(%rsp)
movl %r15d, 0x10(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x110(%rsp), %rdx
leaq 0xa8(%rsp), %rcx
movq %r14, %rsi
callq 0xe775
leaq 0x28(%rsp), %rdi
movups (%rdi), %xmm0
movaps %xmm0, 0x60(%rsp)
movq 0x10(%rdi), %rax
movq %rax, 0x70(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
callq 0x52ce
movq 0x60(%rsp), %r15
movq 0x68(%rsp), %r14
cmpq %r14, %r15
je 0xaceb
movq %r14, %r12
subq %r15, %r12
movq %r12, %rax
cqto
pushq $0x58
popq %rcx
idivq %rcx
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0xbf7e
cmpq $0x581, %r12            # imm = 0x581
jl 0xace0
leaq 0x580(%r15), %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0xc378
cmpq %r14, %r13
je 0xaceb
movq %r13, %rdi
callq 0xc40e
addq $0x58, %r13
jmp 0xacb0
movq 0x8(%rsp), %rdi
movl %eax, (%rdi)
addq $0x8, %rdi
leaq 0xa8(%rsp), %rsi
callq 0x35f2
jmp 0xaf5a
movq %r15, %rdi
movq %r14, %rsi
callq 0xc378
leaq 0x40(%rsp), %rsi
xorps %xmm0, %xmm0
movaps %xmm0, (%rsi)
andq $0x0, 0x10(%rsi)
movl %ebx, 0x20(%rsp)
leaq 0x28(%rsp), %rdi
callq 0x35f2
leaq 0x40(%rsp), %rdi
callq 0x3bfe
movq 0x88(%rsp), %rax
leal -0x1(%rax), %ecx
movl 0x10(%rsp), %eax
cmpl %eax, %ecx
cmovgel %eax, %ecx
movl %ecx, 0x14(%rsp)
movq 0x8(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x80(%rsp)
xorl %r14d, %r14d
leaq 0xd8(%rsp), %r15
xorl %ebx, %ebx
movq 0x60(%rsp), %rbp
movq 0x68(%rsp), %rax
subq %rbp, %rax
cqto
pushq $0x58
popq %rcx
idivq %rcx
movslq %eax, %rcx
cmpq %rcx, %rbx
jge 0xaf0f
andl $0x0, 0x40(%rsp)
leaq 0x48(%rsp), %rcx
andq $0x0, 0x10(%rcx)
xorps %xmm0, %xmm0
movups %xmm0, (%rcx)
leal 0x1(%rbx), %ecx
addq %r14, %rbp
cmpl %eax, %ecx
jge 0xadc1
movl 0x20(%rsp), %r13d
leaq 0x90(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rsi
movq 0x18(%rsp), %rdx
callq 0xc956
movq %r15, %rdi
movq %rbp, %rsi
pushq $0x1
popq %rdx
movl %r13d, %ecx
movl 0x14(%rsp), %r8d
movq %r12, %r9
callq 0xa3fc
jmp 0xadf7
movl 0x20(%rsp), %r13d
leaq 0x90(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rsi
movq 0x18(%rsp), %rdx
callq 0xc956
movq %r15, %rdi
movq %rbp, %rsi
pushq $0x1
popq %rdx
movl %r13d, %ecx
movl 0x14(%rsp), %r8d
movq %r12, %r9
callq 0xa3fc
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0xc9e6
leaq 0xe0(%rsp), %rdi
callq 0x3bfe
movq %r12, %rdi
callq 0x38e4
leaq 0x48(%rsp), %rdi
leaq 0x253f3(%rip), %rsi     # 0x30218
callq 0x35c8
leaq 0xf8(%rsp), %r13
movl %eax, %ebp
testb %al, %al
je 0xae6b
movq 0x88(%rsp), %rcx
cmpl 0x10(%rsp), %ecx
jle 0xaed7
movq 0x8(%rsp), %rax
orl $-0x1, (%rax)
movq 0x80(%rsp), %rdi
leaq 0x253b7(%rip), %rsi     # 0x30218
callq 0x35f2
jmp 0xaef3
movl 0x20(%rsp), %eax
movl 0x40(%rsp), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl %ecx, 0x20(%rsp)
movq 0x60(%rsp), %r12
movq %r13, %rdi
leaq 0x48(%rsp), %rsi
callq 0x35f2
addq %r14, %r12
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x82b2
leaq 0x48(%rsp), %rdi
movq %r15, %rsi
callq 0x3d74
movq %r15, %rdi
callq 0x3bfe
movq %r13, %rdi
callq 0x3bfe
movq 0x30(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq 0x50(%rsp), %rcx
leaq 0x28(%rsp), %rdi
callq 0x52ae
jmp 0xaef3
movq 0x8(%rsp), %rax
movl %ecx, (%rax)
movq 0x80(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x35f2
leaq 0x48(%rsp), %rdi
callq 0x3bfe
addq $0x58, %r14
incq %rbx
testb %bpl, %bpl
je 0xad49
jmp 0xaf46
movl 0x20(%rsp), %eax
cmpl 0x10(%rsp), %eax
jg 0xafda
movq 0x8(%rsp), %rcx
movl %eax, (%rcx)
movups 0x28(%rsp), %xmm0
movups %xmm0, 0x8(%rcx)
movq 0x38(%rsp), %rax
movq %rax, 0x18(%rcx)
xorps %xmm0, %xmm0
leaq 0x28(%rsp), %rax
movups %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x28(%rsp), %rdi
callq 0x3bfe
leaq 0x60(%rsp), %rdi
callq 0x52ce
leaq 0x110(%rsp), %rdi
callq 0x36d2
leaq 0xa8(%rsp), %rdi
callq 0x3642
movq 0x8(%rsp), %rax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x153bc(%rip), %rdi     # 0x2034e
leaq 0x15847(%rip), %rsi     # 0x207e0
leaq 0x159be(%rip), %rcx     # 0x2095e
pushq $0x64
jmp 0xafd4
leaq 0x158b0(%rip), %rdi     # 0x2085b
leaq 0x1582e(%rip), %rsi     # 0x207e0
leaq 0x159a5(%rip), %rcx     # 0x2095e
pushq $0x65
jmp 0xafd4
leaq 0x152cc(%rip), %rdi     # 0x20290
leaq 0x15815(%rip), %rsi     # 0x207e0
leaq 0x1598c(%rip), %rcx     # 0x2095e
pushq $0x6f
popq %rdx
callq 0x2150
leaq 0x1542a(%rip), %rdi     # 0x2040b
leaq 0x157f8(%rip), %rsi     # 0x207e0
leaq 0x1596f(%rip), %rcx     # 0x2095e
movl $0x8e, %edx
callq 0x2150
movq %rax, %rbx
jmp 0xb05d
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
jmp 0xb058
jmp 0xb011
jmp 0xb011
movq %rax, %rbx
jmp 0xb074
movq %rax, %rbx
jmp 0xb067
jmp 0xb046
jmp 0xb046
jmp 0xb046
jmp 0xb046
jmp 0xb046
jmp 0xb022
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x38e4
jmp 0xb049
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x3bfe
jmp 0xb049
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x3bfe
leaq 0x28(%rsp), %rdi
callq 0x3bfe
leaq 0x60(%rsp), %rdi
callq 0x52ce
leaq 0x110(%rsp), %rdi
callq 0x36d2
leaq 0xa8(%rsp), %rdi
callq 0x3642
movq %rbx, %rdi
callq 0x2340