// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r9d, 0xc(%rsp)
testl %edx, %edx
js 0x11014
movl %ecx, %r15d
movl %edx, %ebp
movq %rdi, %rbx
cmpl %edx, %ecx
jge 0x10d8b
leaq 0x4b32e2(%rip), %rsi    # 0x4c4060
movq %rbx, %rdi
callq 0x35f2
jmp 0x11002
movl %r8d, %r13d
movq %rsi, %r14
leaq 0x40(%rsp), %r12
movq %r12, %rdi
xorl %edx, %edx
callq 0x103e6
movq (%r12), %rax
movq 0x8(%r12), %r12
subq %rax, %r12
je 0x10dd6
shrq $0x2, %r12
addl $-0x3, %r12d
cmpl %ebp, %r12d
cmovlel %ebp, %r12d
cmpl %r15d, %r12d
jbe 0x10de6
leaq 0x4b3297(%rip), %rsi    # 0x4c4060
movq %rbx, %rdi
callq 0x35f2
jmp 0x10ff8
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
jmp 0x10ff8
cmpl $0x3, %r13d
jne 0x10e07
movq %rbx, %rdi
movq %r14, %rsi
movl %r12d, %edx
movl %r15d, %ecx
movl 0xc(%rsp), %r8d
callq 0x110b7
jmp 0x10ff8
movl (%rax), %esi
movl 0x8(%rax), %edx
movq %r14, %rdi
callq 0x7a8e
cmpl $0x1, %r12d
movl %r12d, %edx
adcl $-0x1, %edx
leal -0x1(%r15), %ecx
incl %r13d
movl 0xc(%rsp), %r9d
incl %r9d
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
movl %edx, 0x30(%rsp)
movl %r13d, 0x34(%rsp)
movl %r13d, %r8d
movl %r9d, 0xc(%rsp)
callq 0x10d50
movq 0x40(%rsp), %rax
movl (%rax), %esi
movl 0x8(%rax), %edx
movq %r14, %rdi
callq 0x7ca6
leaq 0x4b31fc(%rip), %rsi    # 0x4c4060
leaq 0x10(%rsp), %rdi
callq 0x6420
testb %al, %al
je 0x10ec9
movq 0x40(%rsp), %rax
movl (%rax), %ecx
leaq 0x38(%rsp), %rsi
movl %ecx, (%rsi)
movl 0x8(%rax), %eax
movl %eax, 0x4(%rsi)
leaq 0x10(%rsp), %rdi
callq 0x92ce
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rax, %rdx
subq %rcx, %rdx
shrq $0x3, %rdx
cmpl %r15d, %edx
jg 0x11063
cmpl %edx, %r12d
jg 0x11063
jne 0x10ec4
movq %rcx, (%rbx)
movq %rax, 0x8(%rbx)
jmp 0x10fd7
decl %edx
movl %edx, %r15d
pushq $0x3
popq %rbp
movq 0x40(%rsp), %rax
movq 0x48(%rsp), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
movslq %ecx, %rcx
cmpq %rcx, %rbp
jge 0x10fcf
movl 0x4(%rax), %esi
movl (%rax,%rbp,4), %edx
movq %r14, %rdi
callq 0x7a8e
leal -0x1(%r15), %ecx
movq %rbx, %rdi
movq %r14, %rsi
movl 0x30(%rsp), %edx
movl 0x34(%rsp), %r8d
movl 0xc(%rsp), %r9d
callq 0x10d50
movq 0x40(%rsp), %rax
movl 0x4(%rax), %esi
movl (%rax,%rbp,4), %edx
movq %r14, %rdi
callq 0x7ca6
movq %rbx, %rdi
leaq 0x4b312f(%rip), %rsi    # 0x4c4060
callq 0x6420
testb %al, %al
je 0x10fbf
movq 0x40(%rsp), %rax
movl 0x4(%rax), %ecx
movl %ecx, 0x38(%rsp)
movl (%rax,%rbp,4), %eax
movl %eax, 0x3c(%rsp)
movq %rbx, %rdi
leaq 0x38(%rsp), %rsi
callq 0x92ce
movq 0x8(%rbx), %r13
subq (%rbx), %r13
shrq $0x3, %r13
cmpl %r13d, %r15d
jl 0x1102d
cmpl %r13d, %r12d
jg 0x1102d
je 0x10fee
leaq 0x10(%rsp), %rdi
leaq 0x4b30d7(%rip), %rsi    # 0x4c4060
callq 0x6420
testb %al, %al
je 0x10fac
movq 0x8(%rbx), %rax
subq (%rbx), %rax
movq 0x18(%rsp), %rcx
subq 0x10(%rsp), %rcx
cmpq %rcx, %rax
jae 0x11046
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x140ee
decl %r13d
movl %r13d, %r15d
movq %rbx, %rdi
callq 0x3bfe
incq %rbp
jmp 0x10ecc
movaps 0x10(%rsp), %xmm0
movups %xmm0, (%rbx)
movq 0x20(%rsp), %rax
movq %rax, 0x10(%rbx)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x3bfe
leaq 0x40(%rsp), %rdi
callq 0x38e4
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf333(%rip), %rdi      # 0x2034e
leaq 0x100f6(%rip), %rsi     # 0x21118
leaq 0x100fb(%rip), %rcx     # 0x21124
pushq $0x17
jmp 0x1105d
leaq 0x10185(%rip), %rdi     # 0x211b9
leaq 0x100dd(%rip), %rsi     # 0x21118
leaq 0x100e2(%rip), %rcx     # 0x21124
pushq $0x36
jmp 0x1105d
leaq 0x101ad(%rip), %rdi     # 0x211fa
leaq 0x100c4(%rip), %rsi     # 0x21118
leaq 0x100c9(%rip), %rcx     # 0x21124
pushq $0x3a
popq %rdx
callq 0x2150
leaq 0x1010e(%rip), %rdi     # 0x21178
leaq 0x100a7(%rip), %rsi     # 0x21118
leaq 0x100ac(%rip), %rcx     # 0x21124
pushq $0x2a
jmp 0x1105d
jmp 0x1108b
jmp 0x11082
jmp 0x1108b
movq %rax, %r14
jmp 0x110a5
jmp 0x11090
jmp 0x1108b
movq %rax, %r14
jmp 0x1109b
movq %rax, %r14
movq %rbx, %rdi
callq 0x3bfe
leaq 0x10(%rsp), %rdi
callq 0x3bfe
leaq 0x40(%rsp), %rdi
callq 0x38e4
movq %r14, %rdi
callq 0x2340