// File: Laakeri[P]Triangulator/src/minfill.cpp
// Function: MinFill::SolveAtom::greedyDegree2(Graph&)
vector<pair<int, int> > greedyDegree2(Graph& G) {
	queue<int> d1;
	queue<int> d2;
	for (int i = 0; i < G.n; i++) {
		assert(G.g[i].size() > 1);
		if (G.g[i].size() == 2) {
			d2.push(i);
		}
	}
	vector<pair<int, int> > sol;
	while (!d1.empty() || !d2.empty()) {
		while (!d1.empty()) {
			int x = d1.front();
			d1.pop();
			assert(G.g[x].size() <= 1);
			if (G.g[x].size() == 0) continue;
			int n1 = G.g[x][0];
			G.remEdge(x, n1);
			if (G.g[n1].size() == 1) d1.push(n1);
			if (G.g[n1].size() == 2) d2.push(n1);
		}
		if (!d2.empty()) {
			int x = d2.front();
			d2.pop();
			assert(G.g[x].size() == 0 || G.g[x].size() == 2);
			if (G.g[x].size() == 0) continue;
			int n1 = G.g[x][0];
			int n2 = G.g[x][1];
			if (!G.hasEdge(n1, n2)) {
				sol.push_back({n1, n2});
				G.addEdge(n1, n2);
			}
			G.remEdge(x, n1);
			G.remEdge(x, n2);
			if (G.g[n1].size() == 1) d1.push(n1);
			if (G.g[n1].size() == 2) d2.push(n1);
			if (G.g[n2].size() == 1) d1.push(n2);
			if (G.g[n2].size() == 2) d2.push(n2);
		}
	}
	return sol;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0xf0(%rbp)
movq %rdi, %rax
movq %rax, -0xe8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x37340
leaq -0xb0(%rbp), %rdi
callq 0x37340
jmp 0x3396b
movl $0x0, -0xc0(%rbp)
movl -0xc0(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x50(%rcx), %eax
jge 0x33a48
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
movslq -0xc0(%rbp), %rsi
callq 0x178a0
movq %rax, %rdi
callq 0x59a0
cmpq $0x1, %rax
jbe 0x339ac
jmp 0x339e2
leaq 0x26aa0(%rip), %rdi     # 0x5a453
leaq 0x2672e(%rip), %rsi     # 0x5a0e8
movl $0x1b7, %edx            # imm = 0x1B7
leaq 0x26a9f(%rip), %rcx     # 0x5a465
callq 0x31a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x33f66
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
movslq -0xc0(%rbp), %rsi
callq 0x178a0
movq %rax, %rdi
callq 0x59a0
cmpq $0x2, %rax
jne 0x33a32
leaq -0xb0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x37370
jmp 0x33a19
jmp 0x33a32
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x33f5a
jmp 0x33a34
movl -0xc0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc0(%rbp)
jmp 0x33975
movq -0xf0(%rbp), %rdi
movb $0x0, -0xc1(%rbp)
callq 0xbd50
leaq -0x60(%rbp), %rdi
callq 0x373a0
movb %al, -0xf1(%rbp)
jmp 0x33a6c
movb -0xf1(%rbp), %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0xf2(%rbp)
jne 0x33a81
jmp 0x33aa3
leaq -0xb0(%rbp), %rdi
callq 0x373a0
movb %al, -0xf3(%rbp)
jmp 0x33a95
movb -0xf3(%rbp), %al
xorb $-0x1, %al
movb %al, -0xf2(%rbp)
movb -0xf2(%rbp), %al
testb $0x1, %al
jne 0x33ab2
jmp 0x33f19
jmp 0x33ab4
leaq -0x60(%rbp), %rdi
callq 0x373a0
movb %al, -0xf4(%rbp)
jmp 0x33ac5
movb -0xf4(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x33ad6
jmp 0x33c42
leaq -0x60(%rbp), %rdi
callq 0x373c0
movq %rax, -0x100(%rbp)
jmp 0x33ae8
movq -0x100(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xc8(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x373e0
jmp 0x33b02
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
movslq -0xc8(%rbp), %rsi
callq 0x178a0
movq %rax, %rdi
callq 0x59a0
cmpq $0x1, %rax
ja 0x33b26
jmp 0x33b68
leaq 0x2697a(%rip), %rdi     # 0x5a4a7
leaq 0x265b4(%rip), %rsi     # 0x5a0e8
movl $0x1c1, %edx            # imm = 0x1C1
leaq 0x26925(%rip), %rcx     # 0x5a465
callq 0x31a0
movq -0xf0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
callq 0x5470
jmp 0x33f5a
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
movslq -0xc8(%rbp), %rsi
callq 0x178a0
movq %rax, %rdi
callq 0x59a0
cmpq $0x0, %rax
jne 0x33b8f
jmp 0x33ab4
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
movslq -0xc8(%rbp), %rsi
callq 0x178a0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x178f0
movl (%rax), %eax
movl %eax, -0xcc(%rbp)
movq -0x10(%rbp), %rdi
movl -0xc8(%rbp), %esi
movl -0xcc(%rbp), %edx
callq 0x15e30
jmp 0x33bce
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
movslq -0xcc(%rbp), %rsi
callq 0x178a0
movq %rax, %rdi
callq 0x59a0
cmpq $0x1, %rax
jne 0x33c04
leaq -0x60(%rbp), %rdi
leaq -0xcc(%rbp), %rsi
callq 0x37370
jmp 0x33c02
jmp 0x33c04
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
movslq -0xcc(%rbp), %rsi
callq 0x178a0
movq %rax, %rdi
callq 0x59a0
cmpq $0x2, %rax
jne 0x33c3d
leaq -0xb0(%rbp), %rdi
leaq -0xcc(%rbp), %rsi
callq 0x37370
jmp 0x33c3b
jmp 0x33c3d
jmp 0x33ab4
leaq -0xb0(%rbp), %rdi
callq 0x373a0
movb %al, -0x101(%rbp)
jmp 0x33c56
movb -0x101(%rbp), %al
testb $0x1, %al
jne 0x33f14
jmp 0x33c66
leaq -0xb0(%rbp), %rdi
callq 0x373c0
movq %rax, -0x110(%rbp)
jmp 0x33c7b
movq -0x110(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xd0(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x373e0
jmp 0x33c98
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
movslq -0xd0(%rbp), %rsi
callq 0x178a0
movq %rax, %rdi
callq 0x59a0
movq %rax, %rcx
movb $0x1, %al
cmpq $0x0, %rcx
movb %al, -0x111(%rbp)
je 0x33cee
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
movslq -0xd0(%rbp), %rsi
callq 0x178a0
movq %rax, %rdi
callq 0x59a0
cmpq $0x2, %rax
sete %al
movb %al, -0x111(%rbp)
movb -0x111(%rbp), %al
testb $0x1, %al
jne 0x33cfa
jmp 0x33cfc
jmp 0x33d1b
leaq 0x267b7(%rip), %rdi     # 0x5a4ba
leaq 0x263de(%rip), %rsi     # 0x5a0e8
movl $0x1cb, %edx            # imm = 0x1CB
leaq 0x2674f(%rip), %rcx     # 0x5a465
callq 0x31a0
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
movslq -0xd0(%rbp), %rsi
callq 0x178a0
movq %rax, %rdi
callq 0x59a0
cmpq $0x0, %rax
jne 0x33d42
jmp 0x33a5b
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
movslq -0xd0(%rbp), %rsi
callq 0x178a0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x178f0
movl (%rax), %eax
movl %eax, -0xd4(%rbp)
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
movslq -0xd0(%rbp), %rsi
callq 0x178a0
movq %rax, %rdi
movl $0x1, %esi
callq 0x178f0
movl (%rax), %eax
movl %eax, -0xd8(%rbp)
movq -0x10(%rbp), %rdi
movl -0xd4(%rbp), %esi
movl -0xd8(%rbp), %edx
callq 0x16400
movb %al, -0x112(%rbp)
jmp 0x33db0
movb -0x112(%rbp), %al
testb $0x1, %al
jne 0x33e06
jmp 0x33dbc
leaq -0xe0(%rbp), %rdi
leaq -0xd4(%rbp), %rsi
leaq -0xd8(%rbp), %rdx
callq 0xdfc0
jmp 0x33dd8
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x179a0
jmp 0x33ded
movq -0x10(%rbp), %rdi
movl -0xd4(%rbp), %esi
movl -0xd8(%rbp), %edx
callq 0x15830
jmp 0x33e04
jmp 0x33e06
movq -0x10(%rbp), %rdi
movl -0xd0(%rbp), %esi
movl -0xd4(%rbp), %edx
callq 0x15e30
jmp 0x33e1d
movq -0x10(%rbp), %rdi
movl -0xd0(%rbp), %esi
movl -0xd8(%rbp), %edx
callq 0x15e30
jmp 0x33e34
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
movslq -0xd4(%rbp), %rsi
callq 0x178a0
movq %rax, %rdi
callq 0x59a0
cmpq $0x1, %rax
jne 0x33e6a
leaq -0x60(%rbp), %rdi
leaq -0xd4(%rbp), %rsi
callq 0x37370
jmp 0x33e68
jmp 0x33e6a
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
movslq -0xd4(%rbp), %rsi
callq 0x178a0
movq %rax, %rdi
callq 0x59a0
cmpq $0x2, %rax
jne 0x33ea3
leaq -0xb0(%rbp), %rdi
leaq -0xd4(%rbp), %rsi
callq 0x37370
jmp 0x33ea1
jmp 0x33ea3
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
movslq -0xd8(%rbp), %rsi
callq 0x178a0
movq %rax, %rdi
callq 0x59a0
cmpq $0x1, %rax
jne 0x33ed9
leaq -0x60(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x37370
jmp 0x33ed7
jmp 0x33ed9
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
movslq -0xd8(%rbp), %rsi
callq 0x178a0
movq %rax, %rdi
callq 0x59a0
cmpq $0x2, %rax
jne 0x33f12
leaq -0xb0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x37370
jmp 0x33f10
jmp 0x33f12
jmp 0x33f14
jmp 0x33a5b
movb $0x1, -0xc1(%rbp)
testb $0x1, -0xc1(%rbp)
jne 0x33f35
movq -0xf0(%rbp), %rdi
callq 0x5470
leaq -0xb0(%rbp), %rdi
callq 0x37400
leaq -0x60(%rbp), %rdi
callq 0x37400
movq -0xe8(%rbp), %rax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
leaq -0xb0(%rbp), %rdi
callq 0x37400
leaq -0x60(%rbp), %rdi
callq 0x37400
movq -0xb8(%rbp), %rdi
callq 0x3480
nopl (%rax,%rax)