// File: ynilu[P]elastic/simulator.cpp
// Function: get_distance(std::vector<int, std::allocator<int>>&, int, int, Phy_graph&)
int get_distance(Path& path, int slot_st, int slot_ed, Phy_graph& p_graph)
{
    bool zone_clear = true;
    int distance = 0;
    int search_scope = transceiver_slot_limit - (slot_ed - slot_st + 1) + transceiver_slot_limit - 1;
    for(unsigned int node_i = 0; node_i < path.size() - 1; node_i++)
    {
        int from = path[node_i];
        int to = path[node_i + 1];
        Phy_link& link = p_graph.get_link(from, to);
        int bound;
        bound = (slot_st - search_scope + 1 >= 0)? search_scope : slot_st + 1;
        for(int i = 1; i < bound; i++)
        {
            if(link.slot[slot_st - i] == 0)
            {
                distance += i;
                zone_clear = false;
                break;
            }
        }
        bound = (slot_ed + search_scope - 1 < num_slots)? search_scope : num_slots - slot_ed;
        for(int i = 1; i < bound; i++)
        {
            if(link.slot[slot_ed + i] == 0)
            {
                distance += i;
                zone_clear = false;
                break;
            }
        }
    }
    if(zone_clear){
        return transceiver_slot_limit*4*hop_limit;
    }
    return distance;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movb $0x1, -0x21(%rbp)
movl $0x0, -0x28(%rbp)
movl 0x38b65(%rip), %eax     # 0x431fc
movl -0x18(%rbp), %ecx
subl -0x14(%rbp), %ecx
addl $0x1, %ecx
subl %ecx, %eax
addl 0x38b54(%rip), %eax     # 0x431fc
subl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
callq 0xb380
movq %rax, %rcx
movq -0x58(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0xa803
movq -0x10(%rbp), %rdi
movl -0x30(%rbp), %eax
movl %eax, %esi
callq 0xb210
movl (%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rdi
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0xb210
movl (%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x20(%rbp), %rdi
movl -0x34(%rbp), %esi
movl -0x38(%rbp), %edx
callq 0x1a730
movq %rax, -0x40(%rbp)
movl -0x14(%rbp), %eax
subl -0x2c(%rbp), %eax
addl $0x1, %eax
cmpl $0x0, %eax
jl 0xa72d
movl -0x2c(%rbp), %eax
movl %eax, -0x5c(%rbp)
jmp 0xa736
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0x44(%rbp)
movl $0x1, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0xa782
movq -0x40(%rbp), %rdi
addq $0x18, %rdi
movl -0x14(%rbp), %eax
subl -0x48(%rbp), %eax
movslq %eax, %rsi
callq 0xb210
cmpl $0x0, (%rax)
jne 0xa775
movl -0x48(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movb $0x0, -0x21(%rbp)
jmp 0xa782
jmp 0xa777
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0xa743
movl -0x18(%rbp), %eax
addl -0x2c(%rbp), %eax
subl $0x1, %eax
cmpl 0x38a4f(%rip), %eax     # 0x431e0
jge 0xa79b
movl -0x2c(%rbp), %eax
movl %eax, -0x60(%rbp)
jmp 0xa7a7
movl 0x38a3f(%rip), %eax     # 0x431e0
subl -0x18(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
movl %eax, -0x44(%rbp)
movl $0x1, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0xa7f3
movq -0x40(%rbp), %rdi
addq $0x18, %rdi
movl -0x18(%rbp), %eax
addl -0x4c(%rbp), %eax
movslq %eax, %rsi
callq 0xb210
cmpl $0x0, (%rax)
jne 0xa7e6
movl -0x4c(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movb $0x0, -0x21(%rbp)
jmp 0xa7f3
jmp 0xa7e8
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0xa7b4
jmp 0xa7f5
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xa6b5
testb $0x1, -0x21(%rbp)
je 0xa81e
movl 0x389ed(%rip), %eax     # 0x431fc
shll $0x2, %eax
imull 0x389bb(%rip), %eax     # 0x431d4
movl %eax, -0x4(%rbp)
jmp 0xa824
movl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)