// File: Laakeri[P]Triangulator/src/minfill.cpp
// Function: MinFill::BackTrack::searchNaive(Graph&, int, int, int, int)
vector<pair<int, int> > searchNaive(Graph& G, int lowerBound, int upperBound, int step, int depth) {
	assert(lowerBound >= 0);
	if (upperBound < lowerBound) return FAILSOLUTION;
	vector<int> cycle = MCS::getChordlessCycle(G);
	if (cycle.size() == 0) {
		return {};
	}
	lowerBound = max(lowerBound, (int)cycle.size()-3);
	if (lowerBound > upperBound) return FAILSOLUTION;
	
	if (step == 3) {
		auto sol = SolveGraph::solveGraph(G, lowerBound, upperBound, depth);
		return sol;
	}
	
	G.addEdge(cycle[0], cycle[2]);
	auto sol1 = searchNaive(G, max(0, lowerBound-1), upperBound-1, step+1, depth+1);
	G.popEdge(cycle[0], cycle[2]);
	if (sol1 != FAILSOLUTION) {
		sol1.push_back({cycle[0], cycle[2]});
		assert((int)sol1.size() <= upperBound && (int)sol1.size() >= lowerBound);
		upperBound = min(upperBound, (int)sol1.size()-1);
		if ((int)sol1.size() == lowerBound) return sol1;
	}
	
	for (int i = 3; i < (int)cycle.size(); i++) {
		G.addEdge(cycle[1], cycle[i]);
		auto sol0 = searchNaive(G, max(0, lowerBound-1), upperBound-1, step+1, depth+1);
		G.popEdge(cycle[1], cycle[i]);
		
		if (sol0 != FAILSOLUTION) {
			sol0.push_back({cycle[1], cycle[i]});
			assert((int)sol0.size() <= upperBound && (int)sol0.size() >= lowerBound);
			upperBound = min(upperBound, (int)sol0.size()-1);
			if ((int)sol0.size() == lowerBound) return sol0;
			if (sol1 != FAILSOLUTION) {
				assert(sol0.size() < sol1.size());
			}
			sol1 = sol0;
		}
	}
	return sol1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0xa8(%rbp)
movq %rdi, %rax
movq %rax, -0xa0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movl %r9d, -0x20(%rbp)
cmpl $0x0, -0x14(%rbp)
jl 0x2fc4a
jmp 0x2fc69
leaq 0x296d1(%rip), %rdi     # 0x59322
leaq 0x2a490(%rip), %rsi     # 0x5a0e8
movl $0x17, %edx
leaq 0x2a490(%rip), %rcx     # 0x5a0f4
callq 0x31a0
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x2fc89
movq -0xa8(%rbp), %rdi
leaq 0x4de4b1(%rip), %rsi    # 0x50e130
callq 0x56a0
jmp 0x30352
movq -0x10(%rbp), %rsi
leaq -0x38(%rbp), %rdi
xorl %edx, %edx
callq 0x2cb80
leaq -0x38(%rbp), %rdi
callq 0x59a0
cmpq $0x0, %rax
jne 0x2fcd2
movq -0xa8(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x3130
movq -0xa8(%rbp), %rdi
callq 0xbd50
movl $0x1, -0x3c(%rbp)
jmp 0x3033c
leaq -0x38(%rbp), %rdi
callq 0x59a0
addl $-0x3, %eax
movl %eax, -0x40(%rbp)
leaq -0x14(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x23c80
movq %rax, -0xb0(%rbp)
jmp 0x2fcf7
movq -0xb0(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x18(%rbp), %eax
jle 0x2fd3d
movq -0xa8(%rbp), %rdi
leaq 0x4de417(%rip), %rsi    # 0x50e130
callq 0x56a0
jmp 0x2fd20
movl $0x1, -0x3c(%rbp)
jmp 0x3033c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x30347
cmpl $0x3, -0x1c(%rbp)
jne 0x2fd85
movq -0xa8(%rbp), %rdi
movb $0x0, -0x4d(%rbp)
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
movl -0x20(%rbp), %r8d
callq 0x30370
jmp 0x2fd63
movb $0x1, -0x4d(%rbp)
movl $0x1, -0x3c(%rbp)
testb $0x1, -0x4d(%rbp)
jne 0x2fd80
movq -0xa8(%rbp), %rdi
callq 0x5470
jmp 0x3033c
movq -0x10(%rbp), %rax
movq %rax, -0xc0(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x38(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0x178f0
movq -0xc8(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0xb4(%rbp)
movl $0x2, %esi
callq 0x178f0
movq -0xc0(%rbp), %rdi
movl -0xb4(%rbp), %esi
movl (%rax), %edx
callq 0x15830
jmp 0x2fdd3
movq -0x10(%rbp), %rax
movq %rax, -0xd8(%rbp)
movl $0x0, -0x6c(%rbp)
movl -0x14(%rbp), %eax
decl %eax
movl %eax, -0x70(%rbp)
leaq -0x6c(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x23c80
movq %rax, -0xd0(%rbp)
jmp 0x2fe03
movq -0xd8(%rbp), %rsi
movq -0xd0(%rbp), %rax
movl (%rax), %edx
movl -0x18(%rbp), %ecx
decl %ecx
movl -0x1c(%rbp), %r8d
incl %r8d
movl -0x20(%rbp), %r9d
incl %r9d
leaq -0x68(%rbp), %rdi
callq 0x2fc10
jmp 0x2fe31
movq -0x10(%rbp), %rax
movq %rax, -0xe8(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x38(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0x178f0
movq -0xf0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0xdc(%rbp)
movl $0x2, %esi
callq 0x178f0
movq -0xe8(%rbp), %rdi
movl -0xdc(%rbp), %esi
movl (%rax), %edx
callq 0x15d00
jmp 0x2fe7f
leaq 0x4de2aa(%rip), %rsi    # 0x50e130
leaq -0x68(%rbp), %rdi
callq 0xe160
movb %al, -0xf1(%rbp)
jmp 0x2fe97
movb -0xf1(%rbp), %al
testb $0x1, %al
jne 0x2fea6
jmp 0x2ffbd
xorl %eax, %eax
movl %eax, %esi
leaq -0x38(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x178f0
movq -0x108(%rbp), %rdi
movq %rax, -0x100(%rbp)
movl $0x2, %esi
callq 0x178f0
movq -0x100(%rbp), %rsi
movq %rax, %rdx
leaq -0x78(%rbp), %rdi
callq 0xdfc0
jmp 0x2fee7
leaq -0x68(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x179a0
jmp 0x2fef6
leaq -0x68(%rbp), %rdi
callq 0x5680
movl %eax, %ecx
xorl %eax, %eax
cmpl -0x18(%rbp), %ecx
movb %al, -0x109(%rbp)
jg 0x2ff23
leaq -0x68(%rbp), %rdi
callq 0x5680
cmpl -0x14(%rbp), %eax
setge %al
movb %al, -0x109(%rbp)
movb -0x109(%rbp), %al
testb $0x1, %al
jne 0x2ff2f
jmp 0x2ff31
jmp 0x2ff61
leaq 0x2a210(%rip), %rdi     # 0x5a148
leaq 0x2a1a9(%rip), %rsi     # 0x5a0e8
movl $0x2a, %edx
leaq 0x2a1a9(%rip), %rcx     # 0x5a0f4
callq 0x31a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x30331
leaq -0x68(%rbp), %rdi
callq 0x5680
decl %eax
movl %eax, -0x7c(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x7c(%rbp), %rsi
callq 0x23e40
movq %rax, -0x118(%rbp)
jmp 0x2ff85
movq -0x118(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x18(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x5680
cmpl -0x14(%rbp), %eax
jne 0x2ffbb
movq -0xa8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xf320
movl $0x1, -0x3c(%rbp)
jmp 0x30326
jmp 0x2ffbd
movl $0x3, -0x80(%rbp)
movl -0x80(%rbp), %eax
movl %eax, -0x11c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x59a0
movq %rax, %rcx
movl -0x11c(%rbp), %eax
cmpl %ecx, %eax
jge 0x3030f
movq -0x10(%rbp), %rax
movq %rax, -0x128(%rbp)
leaq -0x38(%rbp), %rdi
movq %rdi, -0x130(%rbp)
movl $0x1, %esi
callq 0x178f0
movq -0x130(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x120(%rbp)
movslq -0x80(%rbp), %rsi
callq 0x178f0
movq -0x128(%rbp), %rdi
movl -0x120(%rbp), %esi
movl (%rax), %edx
callq 0x15830
jmp 0x30035
movb $0x0, -0x81(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x140(%rbp)
movl $0x0, -0x88(%rbp)
movl -0x14(%rbp), %eax
decl %eax
movl %eax, -0x8c(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x8c(%rbp), %rsi
callq 0x23c80
movq %rax, -0x138(%rbp)
jmp 0x30078
movq -0x140(%rbp), %rsi
movq -0xa8(%rbp), %rdi
movq -0x138(%rbp), %rax
movl (%rax), %edx
movl -0x18(%rbp), %ecx
decl %ecx
movl -0x1c(%rbp), %r8d
incl %r8d
movl -0x20(%rbp), %r9d
incl %r9d
callq 0x2fc10
jmp 0x300a9
movq -0x10(%rbp), %rax
movq %rax, -0x150(%rbp)
leaq -0x38(%rbp), %rdi
movq %rdi, -0x158(%rbp)
movl $0x1, %esi
callq 0x178f0
movq -0x158(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x144(%rbp)
movslq -0x80(%rbp), %rsi
callq 0x178f0
movq -0x150(%rbp), %rdi
movl -0x144(%rbp), %esi
movl (%rax), %edx
callq 0x15d00
jmp 0x300f7
movq -0xa8(%rbp), %rdi
leaq 0x4de02b(%rip), %rsi    # 0x50e130
callq 0xe160
movb %al, -0x159(%rbp)
jmp 0x30112
movb -0x159(%rbp), %al
testb $0x1, %al
jne 0x30121
jmp 0x302da
leaq -0x38(%rbp), %rdi
movq %rdi, -0x170(%rbp)
movl $0x1, %esi
callq 0x178f0
movq -0x170(%rbp), %rdi
movq %rax, -0x168(%rbp)
movslq -0x80(%rbp), %rsi
callq 0x178f0
movq -0x168(%rbp), %rsi
movq %rax, %rdx
leaq -0x94(%rbp), %rdi
callq 0xdfc0
jmp 0x30165
movq -0xa8(%rbp), %rdi
leaq -0x94(%rbp), %rsi
callq 0x179a0
jmp 0x3017a
movq -0xa8(%rbp), %rdi
callq 0x5680
movl %eax, %ecx
xorl %eax, %eax
cmpl -0x18(%rbp), %ecx
movb %al, -0x171(%rbp)
jg 0x301ad
movq -0xa8(%rbp), %rdi
callq 0x5680
cmpl -0x14(%rbp), %eax
setge %al
movb %al, -0x171(%rbp)
movb -0x171(%rbp), %al
testb $0x1, %al
jne 0x301b9
jmp 0x301bb
jmp 0x301f7
leaq 0x29fc7(%rip), %rdi     # 0x5a189
leaq 0x29f1f(%rip), %rsi     # 0x5a0e8
movl $0x36, %edx
leaq 0x29f1f(%rip), %rcx     # 0x5a0f4
callq 0x31a0
movq -0xa8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x5470
jmp 0x30331
movq -0xa8(%rbp), %rdi
callq 0x5680
decl %eax
movl %eax, -0x98(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x23e40
movq %rax, -0x180(%rbp)
jmp 0x30224
movq -0xa8(%rbp), %rdi
movq -0x180(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x18(%rbp)
callq 0x5680
cmpl -0x14(%rbp), %eax
jne 0x30254
movb $0x1, -0x81(%rbp)
movl $0x1, -0x3c(%rbp)
jmp 0x302e1
leaq 0x4dded5(%rip), %rsi    # 0x50e130
leaq -0x68(%rbp), %rdi
callq 0xe160
movb %al, -0x181(%rbp)
jmp 0x3026c
movb -0x181(%rbp), %al
testb $0x1, %al
jne 0x30278
jmp 0x302c6
movq -0xa8(%rbp), %rdi
callq 0x5680
movq %rax, -0x190(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x5680
movq %rax, %rcx
movq -0x190(%rbp), %rax
cmpq %rcx, %rax
jae 0x302a5
jmp 0x302c4
leaq 0x29f1e(%rip), %rdi     # 0x5a1ca
leaq 0x29e35(%rip), %rsi     # 0x5a0e8
movl $0x3a, %edx
leaq 0x29e35(%rip), %rcx     # 0x5a0f4
callq 0x31a0
jmp 0x302c6
movq -0xa8(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x36cd0
jmp 0x302d8
jmp 0x302da
movl $0x0, -0x3c(%rbp)
testb $0x1, -0x81(%rbp)
jne 0x302f6
movq -0xa8(%rbp), %rdi
callq 0x5470
movl -0x3c(%rbp), %eax
testl %eax, %eax
jne 0x30326
jmp 0x302ff
jmp 0x30301
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x2ffc4
movq -0xa8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xf320
movl $0x1, -0x3c(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x5470
jmp 0x3033c
leaq -0x68(%rbp), %rdi
callq 0x5470
jmp 0x30347
leaq -0x38(%rbp), %rdi
callq 0x6d30
jmp 0x30352
leaq -0x38(%rbp), %rdi
callq 0x6d30
jmp 0x30362
movq -0xa0(%rbp), %rax
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x3480
nopl (%rax,%rax)