// File: cauimsouza[P]rikudo-solver/src/rikudo_solver/graph.cpp
// Function: Graph::ham_cycle_bt(bool, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>> const&, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>> const&)
std::vector< std::vector<int> >&
Graph::ham_cycle_bt(bool count,
                    const std::vector< std::pair<int,int> >& map,
                    const std::vector< std::pair<int,int> >& diamonds)
{   
    int min_deg_v = INT_MAX;
    int min_deg = -1;
    for(int i = 0; i < adj_list.size(); i++){
        if(adj_list[i].size() < min_deg){
            min_deg = adj_list[i].size();
            min_deg_v = i;
        }
    }
    std::vector< std::vector<int> > sol;

    for(int source : adj_list[min_deg_v]){
        paths = ham_path_bt(source, min_deg_v, count, map, diamonds);
        for(auto candidate : paths)
            if(valid(candidate, map, diamonds)){
                sol.push_back(candidate);
                if(count) break;
            }
        if(!count && !sol.empty())  break;
    }
    
    paths = sol;
    return paths;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movb %sil, %al
movq %rdi, -0x8(%rbp)
andb $0x1, %al
movb %al, -0x9(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movl $0x7fffffff, -0x24(%rbp) # imm = 0x7FFFFFFF
movl $0xffffffff, -0x28(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x2c(%rbp)
movq -0xb8(%rbp), %rdi
movslq -0x2c(%rbp), %rax
movq %rax, -0xc0(%rbp)
addq $0x38, %rdi
callq 0x4600
movq %rax, %rcx
movq -0xc0(%rbp), %rax
cmpq %rcx, %rax
jae 0x9d33
movq -0xb8(%rbp), %rdi
addq $0x38, %rdi
movslq -0x2c(%rbp), %rsi
callq 0x4440
movq %rax, %rdi
callq 0x5460
movslq -0x28(%rbp), %rcx
cmpq %rcx, %rax
jae 0x9d23
movq -0xb8(%rbp), %rdi
addq $0x38, %rdi
movslq -0x2c(%rbp), %rsi
callq 0x4440
movq %rax, %rdi
callq 0x5460
movl %eax, -0x28(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x9d25
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x9caf
leaq -0x48(%rbp), %rdi
callq 0xb110
movq -0xb8(%rbp), %rdi
addq $0x38, %rdi
movslq -0x24(%rbp), %rsi
callq 0x4440
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0x4700
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rdi
callq 0x4730
movq %rax, -0x60(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x4760
testb $0x1, %al
jne 0x9d84
jmp 0x9f0e
leaq -0x58(%rbp), %rdi
callq 0x47a0
movq -0xb8(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %esi
movl -0x24(%rbp), %edx
movq -0x18(%rbp), %r8
movq -0x20(%rbp), %r9
movzbl -0x9(%rbp), %ecx
andl $0x1, %ecx
callq 0x9ac0
movq %rax, -0xc8(%rbp)
jmp 0x9dbc
movq -0xc8(%rbp), %rsi
movq -0xb8(%rbp), %rdi
addq $0x78, %rdi
callq 0xb1f0
jmp 0x9dd5
movq -0xb8(%rbp), %rax
addq $0x78, %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
callq 0xb460
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rdi
callq 0xb490
movq %rax, -0x90(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0xb4c0
testb $0x1, %al
jne 0x9e20
jmp 0x9ee9
leaq -0x88(%rbp), %rdi
callq 0xb500
movq %rax, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x5370
jmp 0x9e3d
movq -0xb8(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq -0xa8(%rbp), %rsi
callq 0x6890
testb $0x1, %al
jne 0x9e5e
jmp 0x9eb2
leaq -0x48(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0xaf70
jmp 0x9e70
testb $0x1, -0x9(%rbp)
je 0x9eb0
movl $0x7, -0xac(%rbp)
jmp 0x9ebc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x9f59
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x43e0
jmp 0x9f59
jmp 0x9eb2
movl $0x0, -0xac(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x43e0
movl -0xac(%rbp), %eax
testl %eax, %eax
je 0x9ed6
jmp 0x9ed4
jmp 0x9ee9
jmp 0x9ed8
leaq -0x88(%rbp), %rdi
callq 0xb520
jmp 0x9e04
testb $0x1, -0x9(%rbp)
jne 0x9efe
leaq -0x48(%rbp), %rdi
callq 0xbb30
testb $0x1, %al
jne 0x9efe
jmp 0x9f0e
jmp 0x9f00
leaq -0x58(%rbp), %rdi
callq 0x47c0
jmp 0x9d6e
movq -0xb8(%rbp), %rdi
addq $0x78, %rdi
leaq -0x48(%rbp), %rsi
callq 0xb1f0
jmp 0x9f24
movq -0xb8(%rbp), %rax
addq $0x78, %rax
movq %rax, -0xd0(%rbp)
movl $0x1, -0xac(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x4630
movq -0xd0(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
leaq -0x48(%rbp), %rdi
callq 0x4630
movq -0x70(%rbp), %rdi
callq 0x3400
nopl (%rax,%rax)