// File: ynilu[P]elastic/graph.cpp
// Function: Phy_graph::read_network_file(char*, int)
void Phy_graph::read_network_file(char* graph_file, int num_slots)
{
    int num_nodes;
    fstream fs;

    fs.open(graph_file, ios::in);
    if(!fs)
    {
        cerr << "Can't open file\"" << graph_file << "\"\n";
        cerr << "Please give network node file, program aborting...\n";
        exit(1);
    }

    fs >> num_nodes;

    // resize vectors according to the number of nodes
    node_list.resize(num_nodes);

    int node_a, node_b, distance;
    while(fs >> node_a >> node_b >> distance)
    {
        node_a--;
        node_b--;

        node_list[node_a].degree++;
        node_list[node_b].degree++;

        node_list[node_a].neighbor.push_back(node_b);
        node_list[node_b].neighbor.push_back(node_a);

        Phy_link new_link;

        new_link.source = node_a;
        new_link.destination = node_b;
        new_link.distance = distance;
        new_link.slot.resize(num_slots, -1);

        link_list[make_pair(node_a,node_b)] = new_link;

        new_link.source = node_b;
        new_link.destination = node_a;

        link_list[make_pair(node_b,node_a)] = new_link;
    }

    fs.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x310, %rsp            # imm = 0x310
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x298(%rbp)
leaq -0x228(%rbp), %rdi
movq %rdi, -0x290(%rbp)
callq 0x3260
movq -0x290(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x8, %edx
callq 0x31e0
jmp 0x1a8bb
movq -0x228(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x228(%rbp,%rax), %rdi
callq 0x30d0
movb %al, -0x299(%rbp)
jmp 0x1a8db
movb -0x299(%rbp), %al
testb $0x1, %al
jne 0x1a8ea
jmp 0x1a96a
movq 0x286ff(%rip), %rdi     # 0x42ff0
leaq 0x12dec(%rip), %rsi     # 0x2d6e4
callq 0x31f0
movq %rax, -0x2a8(%rbp)
jmp 0x1a906
movq -0x2a8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x31f0
movq %rax, -0x2b0(%rbp)
jmp 0x1a91f
movq -0x2b0(%rbp), %rdi
leaq 0x12dc8(%rip), %rsi     # 0x2d6f5
callq 0x31f0
jmp 0x1a934
movq 0x286b5(%rip), %rdi     # 0x42ff0
leaq 0x12db6(%rip), %rsi     # 0x2d6f8
callq 0x31f0
jmp 0x1a949
movl $0x1, %edi
callq 0x3270
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0x1ac61
leaq -0x228(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x3130
jmp 0x1a97c
movq -0x298(%rbp), %rdi
addq $0x8, %rdi
movslq -0x18(%rbp), %rsi
callq 0x1c5f0
jmp 0x1a992
jmp 0x1a994
leaq -0x228(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x3130
movq %rax, -0x2b8(%rbp)
jmp 0x1a9b0
movq -0x2b8(%rbp), %rdi
leaq -0x23c(%rbp), %rsi
callq 0x3130
movq %rax, -0x2c0(%rbp)
jmp 0x1a9cc
movq -0x2c0(%rbp), %rdi
leaq -0x240(%rbp), %rsi
callq 0x3130
movq %rax, -0x2c8(%rbp)
jmp 0x1a9e8
movq -0x2c8(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3280
movb %al, -0x2c9(%rbp)
jmp 0x1aa06
movb -0x2c9(%rbp), %al
testb $0x1, %al
jne 0x1aa15
jmp 0x1ac3e
movq -0x298(%rbp), %rdi
movl -0x238(%rbp), %eax
decl %eax
movl %eax, -0x238(%rbp)
movl -0x23c(%rbp), %eax
decl %eax
movl %eax, -0x23c(%rbp)
addq $0x8, %rdi
movq %rdi, -0x2d8(%rbp)
movslq -0x238(%rbp), %rsi
callq 0x1c3e0
movq -0x2d8(%rbp), %rdi
movl 0x8(%rax), %ecx
incl %ecx
movl %ecx, 0x8(%rax)
movslq -0x23c(%rbp), %rsi
callq 0x1c3e0
movq -0x2d8(%rbp), %rdi
movl 0x8(%rax), %ecx
incl %ecx
movl %ecx, 0x8(%rax)
movslq -0x238(%rbp), %rsi
callq 0x1c3e0
movq %rax, %rdi
addq $0x10, %rdi
leaq -0x23c(%rbp), %rsi
callq 0x1c1a0
jmp 0x1aa9a
movq -0x298(%rbp), %rdi
addq $0x8, %rdi
movslq -0x23c(%rbp), %rsi
callq 0x1c3e0
movq %rax, %rdi
addq $0x10, %rdi
leaq -0x238(%rbp), %rsi
callq 0x1c1a0
jmp 0x1aac6
leaq -0x270(%rbp), %rdi
callq 0x1b7f0
jmp 0x1aad4
movl -0x238(%rbp), %eax
movl %eax, -0x268(%rbp)
movl -0x23c(%rbp), %eax
movl %eax, -0x264(%rbp)
movl -0x240(%rbp), %eax
movl %eax, -0x260(%rbp)
leaq -0x258(%rbp), %rdi
movslq -0x14(%rbp), %rsi
movl $0xffffffff, -0x274(%rbp) # imm = 0xFFFFFFFF
leaq -0x274(%rbp), %rdx
callq 0xb010
jmp 0x1ab1b
movq -0x298(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x2e8(%rbp)
leaq -0x238(%rbp), %rdi
leaq -0x23c(%rbp), %rsi
callq 0x1c4e0
movq %rax, -0x2e0(%rbp)
jmp 0x1ab49
movq -0x2e8(%rbp), %rdi
movq -0x2e0(%rbp), %rax
movq %rax, -0x27c(%rbp)
leaq -0x27c(%rbp), %rsi
callq 0x1c400
movq %rax, -0x2f0(%rbp)
jmp 0x1ab73
movq -0x2f0(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x1c680
jmp 0x1ab88
movq -0x298(%rbp), %rax
movl -0x23c(%rbp), %ecx
movl %ecx, -0x268(%rbp)
movl -0x238(%rbp), %ecx
movl %ecx, -0x264(%rbp)
addq $0x20, %rax
movq %rax, -0x300(%rbp)
leaq -0x23c(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x1c4e0
movq %rax, -0x2f8(%rbp)
jmp 0x1abce
movq -0x300(%rbp), %rdi
movq -0x2f8(%rbp), %rax
movq %rax, -0x284(%rbp)
leaq -0x284(%rbp), %rsi
callq 0x1c400
movq %rax, -0x308(%rbp)
jmp 0x1abf8
movq -0x308(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x1c680
jmp 0x1ac0d
leaq -0x270(%rbp), %rdi
callq 0x1b840
jmp 0x1a994
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
leaq -0x270(%rbp), %rdi
callq 0x1b840
jmp 0x1ac61
leaq -0x228(%rbp), %rdi
callq 0x3030
jmp 0x1ac4c
leaq -0x228(%rbp), %rdi
callq 0x3070
addq $0x310, %rsp            # imm = 0x310
popq %rbp
retq
leaq -0x228(%rbp), %rdi
callq 0x3070
movq -0x230(%rbp), %rdi
callq 0x3340
nopl (%rax)