// File: Laakeri[P]Triangulator/src/minfill.cpp
// Function: MinFill::SolveGraph::solveGraph(Graph const&, int, int, int)
vector<pair<int, int> > solveGraph(const Graph& G, int lowerBound, int upperBound, int depth) {
	assert(lowerBound >= 0);
	if (lowerBound > upperBound) return FAILSOLUTION;
	auto fill = MCS::MCS_MP(G);
	if (fill.F.size() <= 1 || (int)fill.F.size() <= lowerBound) {
		assert((int)fill.F.size() >= lowerBound);
		if ((int)fill.F.size() > upperBound) return FAILSOLUTION;
		return fill.F;
	}
	lowerBound = max(lowerBound, 1);
	upperBound = min(upperBound, (int)fill.F.size());
	if (lowerBound > upperBound) return FAILSOLUTION;
	
	Graph gFill = G;
	gFill.addEdges(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);
	vector<pair<int, int> > sol;
	for (int i = 0; i < (int)atoms.size(); i++) {
		vector<pair<int, int> > tSol;
		if (i+1 < (int)atoms.size()) {
			tSol = SolveAtom::solveAtom0(atoms[i], 0, upperBound - (int)sol.size(), depth);
		}
		else {
			tSol = SolveAtom::solveAtom0(atoms[i], max(0, lowerBound - (int)sol.size()), upperBound - (int)sol.size(), depth);
		}
		if (tSol == FAILSOLUTION) return FAILSOLUTION;
		tSol = atoms[i].mapBack(tSol);
		sol.insert(sol.end(), tSol.begin(), tSol.end());
	}
	assert((int)sol.size() >= lowerBound);
	assert((int)sol.size() <= upperBound);
	return sol;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movq %rdi, -0x1f0(%rbp)
movq %rdi, %rax
movq %rax, -0x1e8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
cmpl $0x0, -0x14(%rbp)
jl 0x303a6
jmp 0x303c5
leaq 0x28f75(%rip), %rdi     # 0x59322
leaq 0x29d34(%rip), %rsi     # 0x5a0e8
movl $0x232, %edx            # imm = 0x232
leaq 0x2a1f7(%rip), %rcx     # 0x5a5b7
callq 0x31a0
movl -0x14(%rbp), %eax
cmpl -0x18(%rbp), %eax
jle 0x303e5
movq -0x1f0(%rbp), %rdi
leaq 0x4ddd55(%rip), %rsi    # 0x50e130
callq 0x56a0
jmp 0x30a48
movq -0x10(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x28a90
leaq -0x50(%rbp), %rdi
callq 0x5680
cmpq $0x1, %rax
jbe 0x30413
leaq -0x50(%rbp), %rdi
callq 0x5680
cmpl -0x14(%rbp), %eax
jg 0x304a0
leaq -0x50(%rbp), %rdi
callq 0x5680
cmpl -0x14(%rbp), %eax
jl 0x30423
jmp 0x30442
leaq 0x29e55(%rip), %rdi     # 0x5a27f
leaq 0x29cb7(%rip), %rsi     # 0x5a0e8
movl $0x236, %edx            # imm = 0x236
leaq 0x2a17a(%rip), %rcx     # 0x5a5b7
callq 0x31a0
leaq -0x50(%rbp), %rdi
callq 0x5680
cmpl -0x18(%rbp), %eax
jle 0x30482
movq -0x1f0(%rbp), %rdi
leaq 0x4ddcd2(%rip), %rsi    # 0x50e130
callq 0x56a0
jmp 0x30465
movl $0x1, -0x60(%rbp)
jmp 0x30a32
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x30a3d
movq -0x1f0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x56a0
jmp 0x30494
movl $0x1, -0x60(%rbp)
jmp 0x30a32
movl $0x1, -0x64(%rbp)
leaq -0x14(%rbp), %rdi
leaq -0x64(%rbp), %rsi
callq 0x23c80
movq %rax, -0x1f8(%rbp)
jmp 0x304bd
movq -0x1f8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x5680
movl %eax, -0x68(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x23e40
movq %rax, -0x200(%rbp)
jmp 0x304eb
movq -0x200(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x18(%rbp), %eax
jle 0x30520
movq -0x1f0(%rbp), %rdi
leaq 0x4ddc23(%rip), %rsi    # 0x50e130
callq 0x56a0
jmp 0x30514
movl $0x1, -0x60(%rbp)
jmp 0x30a32
movq -0x10(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0xb8b0
jmp 0x30532
leaq -0xc0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x15db0
jmp 0x30544
movq -0x10(%rbp), %rsi
leaq -0xf8(%rbp), %rdi
leaq -0xc0(%rbp), %rdx
leaq -0x50(%rbp), %rcx
callq 0x292b0
jmp 0x30561
leaq -0xf0(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
movq %rdi, -0x208(%rbp)
callq 0xbca0
leaq -0xf8(%rbp), %rdi
callq 0xbcd0
movq -0x208(%rbp), %rdi
callq 0xbcf0
movq -0x208(%rbp), %rdi
movq %rax, -0x108(%rbp)
callq 0xbd20
movq %rax, -0x110(%rbp)
movq -0x108(%rbp), %rdi
movq -0x110(%rbp), %rsi
callq 0x348e0
jmp 0x305c2
leaq -0x130(%rbp), %rdi
callq 0xbd50
movl $0x0, -0x134(%rbp)
movl -0x134(%rbp), %eax
movl %eax, -0x20c(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0xbd70
movq %rax, %rcx
movl -0x20c(%rbp), %eax
cmpl %ecx, %eax
jge 0x30974
leaq -0x150(%rbp), %rdi
callq 0xbd50
movl -0x134(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x210(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0xbd70
movq %rax, %rcx
movl -0x210(%rbp), %eax
cmpl %ecx, %eax
jge 0x306e2
movslq -0x134(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0xbde0
movq %rax, -0x218(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x21c(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x5680
movl -0x21c(%rbp), %ecx
movq -0x218(%rbp), %rsi
subl %eax, %ecx
movl -0x1c(%rbp), %r8d
leaq -0x168(%rbp), %rdi
xorl %edx, %edx
callq 0x34250
jmp 0x3068b
leaq -0x150(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x5790
leaq -0x168(%rbp), %rdi
callq 0x5470
jmp 0x307b2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x30a24
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x30a18
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x30957
movslq -0x134(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0xbde0
movq %rax, -0x238(%rbp)
movl $0x0, -0x184(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x22c(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x5680
movq %rax, %rcx
movl -0x22c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x188(%rbp)
leaq -0x184(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x23c80
movq %rax, -0x228(%rbp)
jmp 0x30748
movq -0x228(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x23c(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x240(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x5680
movl -0x240(%rbp), %ecx
movq -0x238(%rbp), %rsi
movl -0x23c(%rbp), %edx
subl %eax, %ecx
movl -0x1c(%rbp), %r8d
leaq -0x180(%rbp), %rdi
callq 0x34250
jmp 0x30793
leaq -0x150(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x5790
leaq -0x180(%rbp), %rdi
callq 0x5470
leaq 0x4dd977(%rip), %rsi    # 0x50e130
leaq -0x150(%rbp), %rdi
callq 0x5600
movb %al, -0x241(%rbp)
jmp 0x307cd
movb -0x241(%rbp), %al
testb $0x1, %al
jne 0x307d9
jmp 0x307fa
movq -0x1f0(%rbp), %rdi
leaq 0x4dd949(%rip), %rsi    # 0x50e130
callq 0x56a0
jmp 0x307ee
movl $0x1, -0x60(%rbp)
jmp 0x30910
movslq -0x134(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0xbde0
movq %rax, -0x250(%rbp)
leaq -0x1b8(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x56a0
jmp 0x30829
movq -0x250(%rbp), %rsi
leaq -0x1a0(%rbp), %rdi
leaq -0x1b8(%rbp), %rdx
callq 0x16aa0
jmp 0x30845
leaq -0x150(%rbp), %rdi
movq %rdi, -0x268(%rbp)
leaq -0x1a0(%rbp), %rsi
movq %rsi, -0x270(%rbp)
callq 0x5790
movq -0x270(%rbp), %rdi
callq 0x5470
leaq -0x1b8(%rbp), %rdi
callq 0x5470
leaq -0x130(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0xc040
movq %rax, -0x1c8(%rbp)
leaq -0x1c0(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
callq 0xc070
movq -0x268(%rbp), %rdi
callq 0xc0b0
movq -0x268(%rbp), %rdi
movq %rax, -0x1d0(%rbp)
callq 0xc040
movq -0x260(%rbp), %rdi
movq %rax, -0x1d8(%rbp)
movq -0x1c0(%rbp), %rsi
movq -0x1d0(%rbp), %rdx
movq -0x1d8(%rbp), %rcx
callq 0xbf90
movq %rax, -0x258(%rbp)
jmp 0x308fb
movq -0x258(%rbp), %rax
movq %rax, -0x1e0(%rbp)
movl $0x0, -0x60(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x5470
movl -0x60(%rbp), %eax
testl %eax, %eax
jne 0x309f2
jmp 0x30929
jmp 0x3092b
movl -0x134(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x134(%rbp)
jmp 0x305d8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x5470
leaq -0x150(%rbp), %rdi
callq 0x5470
leaq -0x130(%rbp), %rdi
callq 0x5470
jmp 0x30a18
leaq -0x130(%rbp), %rdi
callq 0x5680
cmpl -0x14(%rbp), %eax
jl 0x30987
jmp 0x309a6
leaq 0x29c7e(%rip), %rdi     # 0x5a60c
leaq 0x29753(%rip), %rsi     # 0x5a0e8
movl $0x252, %edx            # imm = 0x252
leaq 0x29c16(%rip), %rcx     # 0x5a5b7
callq 0x31a0
leaq -0x130(%rbp), %rdi
callq 0x5680
cmpl -0x18(%rbp), %eax
jg 0x309b9
jmp 0x309d8
leaq 0x29bce(%rip), %rdi     # 0x5a58e
leaq 0x29721(%rip), %rsi     # 0x5a0e8
movl $0x253, %edx            # imm = 0x253
leaq 0x29be4(%rip), %rcx     # 0x5a5b7
callq 0x31a0
movq -0x1f0(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0xf320
movl $0x1, -0x60(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x5470
leaq -0xd8(%rbp), %rdi
callq 0xc120
leaq -0xc0(%rbp), %rdi
callq 0x59e0
jmp 0x30a32
leaq -0xd8(%rbp), %rdi
callq 0xc120
leaq -0xc0(%rbp), %rdi
callq 0x59e0
jmp 0x30a3d
leaq -0x50(%rbp), %rdi
callq 0x57e0
jmp 0x30a48
leaq -0x50(%rbp), %rdi
callq 0x57e0
jmp 0x30a58
movq -0x1e8(%rbp), %rax
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0x3480
nopw %cs:(%rax,%rax)