// File: ynilu[P]elastic/simulator.cpp
// Function: construct_exist_path(Event&, Phy_graph&, Aux_graph&)
void construct_exist_path(Event& event, Phy_graph& p_graph, Aux_graph& a_graph)
{
    for(auto &lp : exist_OTDM_light_path_list)
    {
        if(lp->available_bitrate < event.bandwidth)
        {
            continue;
        }

        Aux_node* a_node;
        Aux_node* d_node;
        Aux_node* t_node;
        Aux_node* r_node;
        Aux_link* aux_link;

        lp->transmitting_node_list.reserve(lp->p_path.size());
        lp->receiving_node_list.reserve(lp->p_path.size());
        int n = lp->p_path.size() - 1;
        double weight = (double)n * (1 - eps) * lp->weight;

        for(unsigned int i = 0; i < lp->p_path.size(); i++)
        {
            int phy_node_id = lp->p_path[i];

            a_node = a_graph.get_adding_node(phy_node_id);
            d_node = a_graph.get_dropping_node(phy_node_id);

            t_node = a_graph.create_aux_node(phy_node_id, Aux_node::transmitting_node);

            lp->transmitting_node_list.push_back(t_node);

            r_node = a_graph.create_aux_node(phy_node_id, Aux_node::receiving_node);
            lp->receiving_node_list.push_back(r_node);

            aux_link = a_graph.create_aux_link(r_node, t_node, -weight, Aux_link::pass_through_link);
            lp->aux_link_list.push_back(aux_link);
            aux_link->light_path = lp;              // make aux_link track light path

            if(lp->transmitter_index[i] != -1)
            {
                aux_link = a_graph.create_aux_link(a_node, t_node, used_transceiver_weight, Aux_link::adding_link);
            }
            else if(p_graph.get_node(lp->p_path[i]).num_available_transmitter > 0)
            {
                aux_link = a_graph.create_aux_link(a_node, t_node, transceiver_weight, Aux_link::virtual_adding_link);
            }
            lp->aux_link_list.push_back(aux_link);
            aux_link->light_path = lp;              // make aux_link track light path


            if(lp->receiver_index[i] != -1)
            {
                aux_link = a_graph.create_aux_link(r_node, d_node, used_transceiver_weight, Aux_link::dropping_link);
            }
            else if(p_graph.get_node(lp->p_path[i]).num_available_receiver > 0)
            {
                aux_link = a_graph.create_aux_link(r_node, d_node, transceiver_weight, Aux_link::virtual_dropping_link);
            }
            lp->aux_link_list.push_back(aux_link);
            aux_link->light_path = lp;              // make aux_link track light path
        }

        for(unsigned int i = 0; i < lp->p_path.size() - 1; i++)
        {
            t_node = lp->transmitting_node_list[i];
            r_node = lp->receiving_node_list[i + 1];
            aux_link = a_graph.create_aux_link(t_node, r_node, weight, Aux_link::spectrum_link);
            // cout << "lp : " << lp << "  link: " << aux_link << "\n";
            lp->aux_link_list.push_back(aux_link);
            aux_link->light_path = lp;              // make aux_link track light path
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq 0x3e3a2(%rip), %rax     # 0x43420
movq %rax, -0x20(%rbp)
leaq 0x3e397(%rip), %rdi     # 0x43420
callq 0xb680
movq %rax, -0x28(%rbp)
leaq 0x3e387(%rip), %rdi     # 0x43420
callq 0xb6b0
movq %rax, -0x30(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xb6e0
testb $0x1, %al
jne 0x50b8
jmp 0x5510
leaq -0x28(%rbp), %rdi
callq 0xb710
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl 0x44(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x4c(%rcx), %eax
jge 0x50dd
jmp 0x5502
movq -0x38(%rbp), %rax
movq (%rax), %rax
addq $0x80, %rax
movq %rax, -0x90(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rdi
addq $0x68, %rdi
callq 0xb380
movq -0x90(%rbp), %rdi
movq %rax, %rsi
callq 0xb730
movq -0x38(%rbp), %rax
movq (%rax), %rax
addq $0x98, %rax
movq %rax, -0x88(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rdi
addq $0x68, %rdi
callq 0xb380
movq -0x88(%rbp), %rdi
movq %rax, %rsi
callq 0xb730
movq -0x38(%rbp), %rax
movq (%rax), %rdi
addq $0x68, %rdi
callq 0xb380
subq $0x1, %rax
movl %eax, -0x64(%rbp)
cvtsi2sdl -0x64(%rbp), %xmm0
movsd 0x27ea9(%rip), %xmm1    # 0x2d010
subsd 0x3e0f9(%rip), %xmm1    # 0x43268
mulsd %xmm1, %xmm0
movq -0x38(%rbp), %rax
movq (%rax), %rax
mulsd 0x48(%rax), %xmm0
movsd %xmm0, -0x70(%rbp)
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
movq %rax, -0x98(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rdi
addq $0x68, %rdi
callq 0xb380
movq %rax, %rcx
movq -0x98(%rbp), %rax
cmpq %rcx, %rax
jae 0x5432
movq -0x38(%rbp), %rax
movq (%rax), %rdi
addq $0x68, %rdi
movl -0x74(%rbp), %eax
movl %eax, %esi
callq 0xb210
movl (%rax), %eax
movl %eax, -0x78(%rbp)
movq -0x18(%rbp), %rdi
movl -0x78(%rbp), %esi
callq 0x2b950
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
movl -0x78(%rbp), %esi
callq 0x2b980
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rdi
movl -0x78(%rbp), %esi
movl $0x2, %edx
callq 0x2b460
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rdi
addq $0x80, %rdi
leaq -0x50(%rbp), %rsi
callq 0xb830
movq -0x18(%rbp), %rdi
movl -0x78(%rbp), %esi
movl $0x3, %edx
callq 0x2b460
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rdi
addq $0x98, %rdi
leaq -0x58(%rbp), %rsi
callq 0xb830
movq -0x18(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
movsd -0x70(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movl $0x5, %ecx
callq 0x2b4d0
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rdi
addq $0xb0, %rdi
leaq -0x60(%rbp), %rsi
callq 0xb8a0
movq -0x38(%rbp), %rax
movq (%rax), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rdi
addq $0xc8, %rdi
movl -0x74(%rbp), %eax
movl %eax, %esi
callq 0xb210
cmpl $-0x1, (%rax)
je 0x52e7
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x50(%rbp), %rdx
movsd 0x3e111(%rip), %xmm0    # 0x433e8
movl $0x3, %ecx
callq 0x2b4d0
movq %rax, -0x60(%rbp)
jmp 0x533f
movq -0x10(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rdi
addq $0x68, %rdi
movl -0x74(%rbp), %eax
movl %eax, %esi
callq 0xb210
movq -0xa0(%rbp), %rdi
movl (%rax), %esi
callq 0x1b450
cmpl $0x0, 0x28(%rax)
jle 0x533d
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x50(%rbp), %rdx
movsd 0x3e0b1(%rip), %xmm0    # 0x433e0
movl $0x6, %ecx
callq 0x2b4d0
movq %rax, -0x60(%rbp)
jmp 0x533f
movq -0x38(%rbp), %rax
movq (%rax), %rdi
addq $0xb0, %rdi
leaq -0x60(%rbp), %rsi
callq 0xb8a0
movq -0x38(%rbp), %rax
movq (%rax), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rdi
addq $0xe0, %rdi
movl -0x74(%rbp), %eax
movl %eax, %esi
callq 0xb210
cmpl $-0x1, (%rax)
je 0x53a6
movq -0x18(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x48(%rbp), %rdx
movsd 0x3e052(%rip), %xmm0    # 0x433e8
movl $0x4, %ecx
callq 0x2b4d0
movq %rax, -0x60(%rbp)
jmp 0x53fe
movq -0x10(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rdi
addq $0x68, %rdi
movl -0x74(%rbp), %eax
movl %eax, %esi
callq 0xb210
movq -0xa8(%rbp), %rdi
movl (%rax), %esi
callq 0x1b450
cmpl $0x0, 0x30(%rax)
jle 0x53fc
movq -0x18(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x48(%rbp), %rdx
movsd 0x3dff2(%rip), %xmm0    # 0x433e0
movl $0x7, %ecx
callq 0x2b4d0
movq %rax, -0x60(%rbp)
jmp 0x53fe
movq -0x38(%rbp), %rax
movq (%rax), %rdi
addq $0xb0, %rdi
leaq -0x60(%rbp), %rsi
callq 0xb8a0
movq -0x38(%rbp), %rax
movq (%rax), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x518b
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movq %rax, -0xb0(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rdi
addq $0x68, %rdi
callq 0xb380
movq %rax, %rcx
movq -0xb0(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x5500
movq -0x38(%rbp), %rax
movq (%rax), %rdi
addq $0x80, %rdi
movl -0x7c(%rbp), %eax
movl %eax, %esi
callq 0xb8e0
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rdi
addq $0x98, %rdi
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0xb8e0
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdx
movsd -0x70(%rbp), %xmm0
movl $0x1, %ecx
callq 0x2b4d0
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rdi
addq $0xb0, %rdi
leaq -0x60(%rbp), %rsi
callq 0xb8a0
movq -0x38(%rbp), %rax
movq (%rax), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x5439
jmp 0x5502
leaq -0x28(%rbp), %rdi
callq 0xb900
jmp 0x50a2
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax)