// File: /workspace/github_cpp_makefile_star2_O3/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 $0x178, %rsp            # imm = 0x178
movq %r9, 0x70(%rsp)
testl %edx, %edx
js 0xd53a
movl %r8d, %ebp
movl %ecx, %r12d
cmpl %r8d, %ecx
jg 0xd559
movl %edx, %ebx
movq %rdi, %r15
cmpl %ebp, %edx
jle 0xcf4b
movl $0xffffffff, (%r15)     # imm = 0xFFFFFFFF
movq %r15, %rdi
addq $0x8, %rdi
leaq 0x282c7(%rip), %rsi     # 0x35208
callq 0x3f7c
jmp 0xd525
movq %rsi, %r14
cmpl %ebx, %r12d
cmovlel %ebx, %r12d
leaq 0xf0(%rsp), %rdi
callq 0x12cbc
leaq 0x120(%rsp), %rdi
movq %r14, %rsi
callq 0x42ce
leaq 0x138(%rsp), %rdi
leaq 0x18(%r14), %rsi
callq 0x815a
movb 0x30(%r14), %al
leaq 0x158(%rsp), %r13
movb %al, -0x8(%r13)
leaq 0x38(%r14), %rsi
movq %r13, %rdi
callq 0x4110
movq 0x50(%r14), %rax
leaq 0x120(%rsp), %rdi
movq %rax, 0x50(%rdi)
leaq 0xf0(%rsp), %rsi
callq 0x9bd8
leaq 0x120(%rsp), %rdi
movq 0x70(%rsp), %rsi
callq 0x142b3
cmpl %ebx, %eax
jl 0xd578
cmpl %r12d, %eax
jbe 0xd0c4
movq %rax, 0xd0(%rsp)
movl %ebp, 0xc(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0x120(%rsp), %rdx
leaq 0xf0(%rsp), %rcx
movq %r14, %rsi
callq 0x13217
leaq 0x80(%rsp), %rdi
movupd (%rdi), %xmm0
movapd %xmm0, 0xb0(%rsp)
movq 0x10(%rdi), %rax
movq %rax, 0xc0(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
callq 0x6b12
movq 0xb0(%rsp), %r12
movq 0xb8(%rsp), %r14
cmpq %r14, %r12
je 0xd0ee
movq %r15, %rbp
movq %r14, %r15
subq %r12, %r15
movq %r15, %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 %r12, %rdi
movq %r14, %rsi
callq 0xec27
cmpq $0x581, %r15            # imm = 0x581
jl 0xd0e0
leaq 0x580(%r12), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0xf635
cmpq %r14, %r13
movq %rbp, %r15
je 0xd0ee
movq %r13, %rdi
callq 0xf7fc
addq $0x58, %r13
cmpq %r14, %r13
jne 0xd0b1
jmp 0xd0ee
movl %eax, (%r15)
movq %r15, %rdi
addq $0x8, %rdi
leaq 0xf0(%rsp), %rsi
callq 0x3f7c
jmp 0xd4b9
movq %r12, %rdi
movq %r14, %rsi
callq 0xf635
movq %rbp, %r15
leaq 0x10(%rsp), %rsi
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
leaq 0x80(%rsp), %rdi
movl %ebx, -0x8(%rdi)
callq 0x3f7c
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
movl 0xc(%rsp), %r13d
je 0xd12f
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0xd0(%rsp), %rax
decl %eax
cmpl %r13d, %eax
cmovgel %r13d, %eax
movl %eax, 0x3c(%rsp)
movq %r15, 0x68(%rsp)
leaq 0x8(%r15), %rax
movq %rax, 0xc8(%rsp)
xorl %r15d, %r15d
leaq 0x98(%rsp), %r14
leaq 0xd8(%rsp), %r12
movq 0xb0(%rsp), %rbp
movq 0xb8(%rsp), %rax
subq %rbp, %rax
sarq $0x3, %rax
movabsq $0x2e8ba2e8ba2e8ba3, %rcx # imm = 0x2E8BA2E8BA2E8BA3
imulq %rcx, %rax
movslq %eax, %rcx
cmpq %rcx, %r15
jge 0xd476
movl $0x0, 0x10(%rsp)
xorpd %xmm0, %xmm0
leaq 0x18(%rsp), %rcx
movupd %xmm0, (%rcx)
movq $0x0, 0x10(%rcx)
imulq $0x58, %r15, %r13
incq %r15
addq %r13, %rbp
cmpl %eax, %r15d
jge 0xd1f7
movl 0x78(%rsp), %ebx
movq %r14, %rdi
movq %rbp, %rsi
movq 0x70(%rsp), %rdx
callq 0x10850
leaq 0x40(%rsp), %rdi
movq %rbp, %rsi
movl $0x1, %edx
movl %ebx, %ecx
movl 0x3c(%rsp), %r8d
movq %r14, %r9
callq 0xc3a0
jmp 0xd227
movl 0x78(%rsp), %ebx
movq %r14, %rdi
movq %rbp, %rsi
movq 0x70(%rsp), %rdx
callq 0x10850
leaq 0x40(%rsp), %rdi
movq %rbp, %rsi
movl $0x1, %edx
movl %ebx, %ecx
movl 0x3c(%rsp), %r8d
movq %r14, %r9
callq 0xc3a0
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 0xd288
subq %rdi, %rsi
callq 0x2210
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0xd288
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0xd2a5
movq 0xa8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
movq %rcx, %rsi
subq %rax, %rsi
movq 0x27f54(%rip), %rdi     # 0x35210
movq 0x27f45(%rip), %rdx     # 0x35208
subq %rdx, %rdi
cmpq %rdi, %rsi
jne 0xd2f8
cmpq %rcx, %rax
je 0xd3d0
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 0xd2f8
addq $0x8, %rax
addq $0x8, %rdx
jmp 0xd2cb
movl 0x78(%rsp), %eax
movl 0x10(%rsp), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl %ecx, 0x78(%rsp)
movq 0xb0(%rsp), %rbx
movq %r12, %r14
movq %r12, %rdi
leaq 0x18(%rsp), %rsi
callq 0x3f7c
addq %r13, %rbx
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %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
movl 0xc(%rsp), %r13d
je 0xd390
subq %rdi, %rsi
callq 0x2210
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0xd390
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0xd8(%rsp), %rdi
testq %rdi, %rdi
je 0xd3ad
movq 0xe8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0x88(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
leaq 0x80(%rsp), %rdi
callq 0x8ecc
xorl %ebx, %ebx
jmp 0xd423
movl 0xc(%rsp), %r13d
movq 0xd0(%rsp), %rcx
cmpl %r13d, %ecx
jle 0xd405
movq 0x68(%rsp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movb $0x1, %bl
movq 0xc8(%rsp), %rdi
leaq 0x27e0a(%rip), %rsi     # 0x35208
callq 0x3f7c
jmp 0xd423
movq 0x68(%rsp), %rax
movl %ecx, (%rax)
movb $0x1, %bl
movq 0xc8(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x3f7c
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0xd43a
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
testb %bl, %bl
leaq 0x98(%rsp), %r14
je 0xd168
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
movq 0x68(%rsp), %r15
leaq 0x158(%rsp), %r13
je 0xd4ac
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
jmp 0xd4ac
movl 0x78(%rsp), %eax
cmpl %r13d, %eax
jg 0xd597
movq 0x68(%rsp), %r15
movl %eax, (%r15)
movups 0x80(%rsp), %xmm0
movups %xmm0, 0x8(%r15)
movq 0x90(%rsp), %rax
movq %rax, 0x18(%r15)
leaq 0x158(%rsp), %r13
leaq 0xb0(%rsp), %rdi
callq 0x6b12
movq %r13, %rdi
callq 0x41aa
leaq 0x138(%rsp), %rdi
callq 0x436a
movq 0x120(%rsp), %rdi
testq %rdi, %rdi
je 0xd4eb
movq 0x130(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0x108(%rsp), %rdi
testq %rdi, %rdi
je 0xd508
movq 0x118(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0xf0(%rsp), %rdi
testq %rdi, %rdi
je 0xd525
movq 0x100(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq %r15, %rax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1be0d(%rip), %rdi     # 0x2934e
leaq 0x1c298(%rip), %rsi     # 0x297e0
leaq 0x1c40f(%rip), %rcx     # 0x2995e
movl $0x64, %edx
callq 0x2140
leaq 0x1c2fb(%rip), %rdi     # 0x2985b
leaq 0x1c279(%rip), %rsi     # 0x297e0
leaq 0x1c3f0(%rip), %rcx     # 0x2995e
movl $0x65, %edx
callq 0x2140
leaq 0x1bd11(%rip), %rdi     # 0x29290
leaq 0x1c25a(%rip), %rsi     # 0x297e0
leaq 0x1c3d1(%rip), %rcx     # 0x2995e
movl $0x6f, %edx
callq 0x2140
leaq 0x1be6d(%rip), %rdi     # 0x2940b
leaq 0x1c23b(%rip), %rsi     # 0x297e0
leaq 0x1c3b2(%rip), %rcx     # 0x2995e
movl $0x8e, %edx
callq 0x2140
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xd69f
movq 0x20(%rsp), %rsi
jmp 0xd697
jmp 0xd61c
jmp 0xd61c
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
callq 0x436a
jmp 0xd5ea
movq %rax, %rbx
movq 0x120(%rsp), %rdi
testq %rdi, %rdi
je 0xd6b9
movq 0x130(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
jmp 0xd6b9
movq %rax, %rbx
jmp 0xd6b9
jmp 0xd668
jmp 0xd668
movq %rax, %rbx
jmp 0xd6ac
jmp 0xd626
movq %rax, %rbx
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0xd66b
movq 0xa8(%rsp), %rsi
jmp 0xd65e
jmp 0xd668
jmp 0xd668
jmp 0xd668
movq %rax, %rbx
movq 0xd8(%rsp), %rdi
testq %rdi, %rdi
je 0xd66b
movq 0xe8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
jmp 0xd66b
movq %rax, %rbx
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0xd682
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0xd69f
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
leaq 0xb0(%rsp), %rdi
callq 0x6b12
leaq 0x120(%rsp), %rdi
callq 0x40d8
leaq 0xf0(%rsp), %rdi
callq 0x3ff2
movq %rbx, %rdi
callq 0x2310