// File: estan[P]tsp/tsp.cpp
// Function: greedy(Matrix<unsigned int> const&)
inline vector<uint16_t> greedy(const Matrix<uint32_t>& d) {
    size_t N = d.rows();
    vector<uint16_t> tour(N);
    vector<bool> used(N, false);
    tour[0] = 0;
    used[0] = true;
    for (size_t i = 1; i < N; ++i) {
        // Find k, the closest city to the (i - 1):th city in tour.
        int32_t k = -1;
        for (uint16_t j = 0; j < N; ++j) {
            if (!used[j] && (k == -1 || d[tour[i-1]][j] < d[tour[i-1]][k])) {
                k = j;
            }
        }
        tour[i] = k;
        used[k] = true;
    }
    return tour;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0xb8(%rbp)
movq %rdi, %rax
movq %rax, -0xc0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3630
movq %rax, -0x18(%rbp)
movb $0x0, -0x19(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0x1a(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
callq 0x3a20
movq -0xb8(%rbp), %rdi
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
callq 0x3a40
jmp 0x62ec
leaq -0x1a(%rbp), %rdi
callq 0x3ab0
movq -0x18(%rbp), %rax
movq %rax, -0xd0(%rbp)
movb $0x0, -0x59(%rbp)
leaq -0x5a(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0x81b0
movq -0xd0(%rbp), %rsi
movq -0xc8(%rbp), %rcx
leaq -0x58(%rbp), %rdi
leaq -0x59(%rbp), %rdx
callq 0x81d0
jmp 0x6331
leaq -0x5a(%rbp), %rdi
callq 0x8250
movq -0xb8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0xe8(%rbp)
callq 0x3ad0
movq -0xe8(%rbp), %rsi
movw $0x0, (%rax)
leaq -0x58(%rbp), %rdi
callq 0x8270
movq %rdx, -0xe0(%rbp)
movq %rax, -0xd8(%rbp)
jmp 0x6376
movq -0xe0(%rbp), %rax
movq -0xd8(%rbp), %rcx
movq %rcx, -0x70(%rbp)
movq %rax, -0x68(%rbp)
leaq -0x70(%rbp), %rdi
movl $0x1, %esi
callq 0x82d0
movq $0x1, -0x78(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x65bb
movl $0xffffffff, -0x7c(%rbp) # imm = 0xFFFFFFFF
movw $0x0, -0x7e(%rbp)
movzwl -0x7e(%rbp), %eax
cmpq -0x18(%rbp), %rax
jae 0x653b
movzwl -0x7e(%rbp), %eax
movl %eax, %esi
leaq -0x58(%rbp), %rdi
callq 0x8270
movq %rdx, -0xf8(%rbp)
movq %rax, -0xf0(%rbp)
jmp 0x63ea
movq -0xf8(%rbp), %rax
movq -0xf0(%rbp), %rcx
movq %rcx, -0x90(%rbp)
movq %rax, -0x88(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x8320
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0xf9(%rbp)
jne 0x64c5
movb $0x1, %al
cmpl $-0x1, -0x7c(%rbp)
movb %al, -0xfa(%rbp)
je 0x64b9
movq -0xb8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x78(%rbp), %rsi
subq $0x1, %rsi
callq 0x3ad0
movq -0x110(%rbp), %rdi
movzwl (%rax), %esi
callq 0x36a0
movq -0xb8(%rbp), %rdi
movzwl -0x7e(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x100(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x78(%rbp), %rsi
subq $0x1, %rsi
callq 0x3ad0
movq -0x108(%rbp), %rdi
movzwl (%rax), %esi
callq 0x36a0
movq %rax, %rcx
movl -0x100(%rbp), %eax
movslq -0x7c(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
setb %al
movb %al, -0xfa(%rbp)
movb -0xfa(%rbp), %al
movb %al, -0xf9(%rbp)
movb -0xf9(%rbp), %al
testb $0x1, %al
jne 0x64d1
jmp 0x6528
movzwl -0x7e(%rbp), %eax
movl %eax, -0x7c(%rbp)
jmp 0x6528
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x1a(%rbp), %rdi
callq 0x3ab0
jmp 0x65f6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x5a(%rbp), %rdi
callq 0x8250
jmp 0x65ea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x8350
jmp 0x65ea
jmp 0x652a
movw -0x7e(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x7e(%rbp)
jmp 0x63bd
movq -0xb8(%rbp), %rdi
movw -0x7c(%rbp), %ax
movw %ax, -0x122(%rbp)
movq -0x78(%rbp), %rsi
callq 0x3ad0
movw -0x122(%rbp), %cx
movw %cx, (%rax)
movslq -0x7c(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x8270
movq %rdx, -0x120(%rbp)
movq %rax, -0x118(%rbp)
jmp 0x657d
movq -0x120(%rbp), %rax
movq -0x118(%rbp), %rcx
movq %rcx, -0xa0(%rbp)
movq %rax, -0x98(%rbp)
leaq -0xa0(%rbp), %rdi
movl $0x1, %esi
callq 0x82d0
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x63a2
movb $0x1, -0x19(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x8350
testb $0x1, -0x19(%rbp)
jne 0x65da
movq -0xb8(%rbp), %rdi
callq 0x3c20
movq -0xc0(%rbp), %rax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
movq -0xb8(%rbp), %rdi
callq 0x3c20
movq -0x28(%rbp), %rdi
callq 0x21f0
nop