// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
testl %edx, %edx
js 0x164ac
movl %edx, %ebp
movq %rdi, %rbx
cmpl %edx, %ecx
jge 0x1612b
leaq 0x4b2f32(%rip), %rsi    # 0x4c9050
movq %rbx, %rdi
callq 0x3f7c
jmp 0x16481
movl %r9d, %r13d
movl %r8d, %r14d
movq %rsi, %r15
movq %rcx, (%rsp)
leaq 0x20(%rsp), %r12
movq %r12, %rdi
xorl %edx, %edx
callq 0x1566e
movq (%r12), %rdi
movq 0x8(%r12), %r12
subq %rdi, %r12
je 0x16181
shrq $0x2, %r12
addl $-0x3, %r12d
cmpl %ebp, %r12d
cmovlel %ebp, %r12d
movq (%rsp), %rcx
cmpl %ecx, %r12d
jbe 0x16194
leaq 0x4b2edc(%rip), %rsi    # 0x4c9050
movq %rbx, %rdi
callq 0x3f7c
jmp 0x1646a
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
jmp 0x1646f
cmpl $0x3, %r14d
jne 0x161b0
movq %rbx, %rdi
movq %r15, %rsi
movl %r12d, %edx
movl %r13d, %r8d
callq 0x16589
jmp 0x1646a
movl (%rdi), %esi
movl 0x8(%rdi), %edx
movq %r15, %rdi
callq 0x9836
cmpl $0x1, %r12d
movl %r12d, %edx
adcl $-0x1, %edx
movq (%rsp), %rax
leal -0x1(%rax), %ecx
incl %r14d
incl %r13d
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
movl %edx, %ebp
movl %r14d, 0x38(%rsp)
movl %r14d, %r8d
movl %r13d, 0x3c(%rsp)
movl %r13d, %r9d
callq 0x160f8
movq %r15, %r14
movq 0x20(%rsp), %rax
movl (%rax), %esi
movl 0x8(%rax), %edx
movq %r15, %rdi
callq 0x9b86
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, %rsi
subq %rax, %rsi
movq 0x4b2e39(%rip), %rdi    # 0x4c9058
movq 0x4b2e2a(%rip), %rdx    # 0x4c9050
subq %rdx, %rdi
cmpq %rdi, %rsi
movl %ebp, %r15d
jne 0x1625d
cmpq %rcx, %rax
je 0x162ad
xorl %esi, %esi
movl (%rax,%rsi), %edi
cmpl (%rdx,%rsi), %edi
jne 0x1625d
movl 0x4(%rdx,%rsi), %edi
cmpl %edi, 0x4(%rax,%rsi)
jne 0x1625d
leaq (%rax,%rsi), %rdi
addq $0x8, %rsi
addq $0x8, %rdi
cmpq %rcx, %rdi
jne 0x16238
jmp 0x162ad
movq 0x20(%rsp), %rax
movl (%rax), %ecx
leaq 0x40(%rsp), %rsi
movl %ecx, (%rsi)
movl 0x8(%rax), %eax
movl %eax, 0x4(%rsi)
leaq 0x8(%rsp), %rdi
callq 0xb2ae
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, %rdx
subq %rax, %rdx
shrq $0x3, %rdx
cmpl (%rsp), %edx
jg 0x16509
cmpl %edx, %r12d
jg 0x16509
je 0x1645a
decl %edx
movq %rdx, (%rsp)
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rsi
subq %rdx, %rsi
shrq $0x2, %rsi
cmpl $0x4, %esi
jl 0x1645a
movl $0x3, %ebp
movl 0x4(%rdx), %esi
movl (%rdx,%rbp,4), %edx
movq %r14, %rdi
callq 0x9836
movq (%rsp), %rax
leal -0x1(%rax), %ecx
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
movl 0x38(%rsp), %r8d
movl 0x3c(%rsp), %r9d
callq 0x160f8
movq 0x20(%rsp), %rax
movl 0x4(%rax), %esi
movl (%rax,%rbp,4), %edx
movq %r14, %rdi
callq 0x9b86
movq (%rbx), %rdi
movq 0x8(%rbx), %rax
movq %rax, %rdx
subq %rdi, %rdx
movq 0x4b2d38(%rip), %rsi    # 0x4c9058
movq 0x4b2d29(%rip), %rcx    # 0x4c9050
subq %rcx, %rsi
cmpq %rsi, %rdx
jne 0x16362
cmpq %rax, %rdi
je 0x16420
xorl %edx, %edx
movl (%rdi,%rdx), %esi
cmpl (%rcx,%rdx), %esi
jne 0x16362
movl 0x4(%rcx,%rdx), %esi
cmpl %esi, 0x4(%rdi,%rdx)
jne 0x16362
leaq (%rdi,%rdx), %rsi
addq $0x8, %rdx
addq $0x8, %rsi
cmpq %rax, %rsi
jne 0x1633a
jmp 0x16420
movq 0x20(%rsp), %rax
movl 0x4(%rax), %ecx
movl %ecx, 0x40(%rsp)
movl (%rax,%rbp,4), %eax
movl %eax, 0x44(%rsp)
movq %rbx, %rdi
leaq 0x40(%rsp), %rsi
callq 0xb2ae
movq 0x8(%rbx), %rax
subq (%rbx), %rax
movq %rax, %r13
shrq $0x3, %r13
cmpl %r13d, (%rsp)
jl 0x164cb
cmpl %r13d, %r12d
jg 0x164cb
je 0x16493
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rsi
movq %rsi, %rdx
subq %rcx, %rdx
movq 0x4b2c98(%rip), %r8     # 0x4c9058
movq 0x4b2c89(%rip), %rdi    # 0x4c9050
subq %rdi, %r8
cmpq %r8, %rdx
jne 0x16400
cmpq %rsi, %rcx
je 0x16409
xorl %r8d, %r8d
movl (%rcx,%r8), %r9d
cmpl (%rdi,%r8), %r9d
jne 0x16400
movl 0x4(%rdi,%r8), %r9d
cmpl %r9d, 0x4(%rcx,%r8)
jne 0x16400
leaq (%rcx,%r8), %r9
addq $0x8, %r8
addq $0x8, %r9
cmpq %rsi, %r9
jne 0x163d7
jmp 0x16409
cmpq %rdx, %rax
jae 0x164ea
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x1a9f4
decl %r13d
movq (%rbx), %rdi
movq %r13, (%rsp)
testq %rdi, %rdi
je 0x16431
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x2210
incq %rbp
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rax
subq %rdx, %rax
shrq $0x2, %rax
cltq
cmpq %rax, %rbp
jl 0x162cc
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rax, (%rbx)
movq %rcx, 0x8(%rbx)
movq 0x18(%rsp), %rax
movq %rax, 0x10(%rbx)
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x16481
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x1646a
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
jmp 0x1646a
leaq 0x12e9b(%rip), %rdi     # 0x2934e
leaq 0x13c5e(%rip), %rsi     # 0x2a118
leaq 0x13c63(%rip), %rcx     # 0x2a124
movl $0x17, %edx
callq 0x2140
leaq 0x13ce7(%rip), %rdi     # 0x2a1b9
leaq 0x13c3f(%rip), %rsi     # 0x2a118
leaq 0x13c44(%rip), %rcx     # 0x2a124
movl $0x36, %edx
callq 0x2140
leaq 0x13d09(%rip), %rdi     # 0x2a1fa
leaq 0x13c20(%rip), %rsi     # 0x2a118
leaq 0x13c25(%rip), %rcx     # 0x2a124
movl $0x3a, %edx
callq 0x2140
leaq 0x13c68(%rip), %rdi     # 0x2a178
leaq 0x13c01(%rip), %rsi     # 0x2a118
leaq 0x13c06(%rip), %rcx     # 0x2a124
movl $0x2a, %edx
callq 0x2140
jmp 0x16537
jmp 0x16537
jmp 0x1652e
movq %rax, %r14
jmp 0x1656a
jmp 0x1653c
jmp 0x16537
movq %rax, %r14
jmp 0x16553
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x16553
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x1656a
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x16581
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq %r14, %rdi
callq 0x2310