// File: /workspace/github_cpp_makefile_star2_O3/ynilu[P]elastic/simulator.cpp
// Function: path_parsing(Phy_graph&, std::unordered_map<Aux_node*, Aux_link*, std::hash<Aux_node*>, std::equal_to<Aux_node*>, std::allocator<std::pair<Aux_node* const, Aux_link*>>>&, Aux_node*, Aux_node*, Event&)
void path_parsing(Phy_graph& p_graph, Aux_node2Aux_link& result, Aux_node* aux_source, Aux_node* aux_destination, Event& event)
{
    Aux_link* aux_link = result[aux_destination];
    Aux_node* aux_node = aux_link->from;
    double used_bandwidth;
    double wasted_bandwidth;
    double guardband_bandwidth;
    double total_bandwidth;
    double num_links = 0;
    double num_links_a_lp;
    while(aux_node != aux_source)
    {
        switch(aux_link->type)
        {
        case Aux_link::candidate_link:
            build_light_path(p_graph, aux_link->light_path, aux_link->from, aux_link->to, event);
            break;
        case Aux_link::spectrum_link:
            if(aux_link->light_path->requests.find(event.request_id) == aux_link->light_path->requests.end())
            {
                request2lightpath[event.request_id].push_back(aux_link->light_path);
                aux_link->light_path->requests.insert(event.request_id);
                aux_link->light_path->available_bitrate -= event.bandwidth;
                num_OTDM_lightpath_use++;
                num_OTDM_lightpath_use_BM[(int)event.request_id/(num_requests/num_batch)]++;
            }
            num_links += 1;
            break;
        case Aux_link::grooming_link:
            num_OEO++;
            num_OEO_BM[(int)event.request_id/(num_requests/num_batch)]++;
            break;
        case Aux_link::adding_link:
            if(aux_link->light_path == NULL) // not aux_link for candidate light path layer
            {
                break;
            }
            if(aux_link->light_path->type == LightPath::OTDM) // aux_link to OTDM grooming layer
            {
                num_links = 0;
            }
            break;
        case Aux_link::dropping_link:
            if(aux_link->light_path == NULL) // not aux_link for candidate light path layer
            {
                break;
            }
            if(aux_link->light_path->type == LightPath::OTDM) // aux_link to OTDM grooming layer
            {
                num_links_a_lp = 1.0 * (aux_link->light_path->p_path.size() - 1);
                used_bandwidth = num_links * event.bandwidth / aux_link->light_path->modulation_level;
                wasted_bandwidth = num_links_a_lp * (event.bandwidth / aux_link->light_path->modulation_level) - used_bandwidth;
                guardband_bandwidth = 0;
                total_bandwidth = used_bandwidth + wasted_bandwidth + guardband_bandwidth;
                total_bandwidth_utilization += total_bandwidth * event.holding_time;
                used_bandwidth_utilization += used_bandwidth * event.holding_time;
                wasted_bandwidth_utilization += wasted_bandwidth * event.holding_time;
                guardband_bandwidth_utilization += guardband_bandwidth * event.holding_time;
            }
            break;
        case Aux_link::pass_through_link:
            break;
        case Aux_link::virtual_adding_link:
            if(aux_link->light_path == NULL) // not aux_link for candidate light path layer
            {
                break;
            }
            if(aux_link->light_path->type == LightPath::OTDM) // aux_link to OTDM grooming layer
            {
                unsigned int i;
                for(i = 0; i < aux_link->light_path->p_path.size(); i++)
                {
                    if(aux_node->phy_id == aux_link->light_path->p_path[i])
                    {
                        break;
                    }
                }
                aux_link->light_path->transmitter_index[i] = 1;
                p_graph.get_node(aux_node->phy_id).num_available_transmitter--;
                num_links = 0;
            }
            break;
        case Aux_link::virtual_dropping_link:
            if(aux_link->light_path == NULL) // not aux_link for candidate light path layer
            {
                break;
            }
            if(aux_link->light_path->type == LightPath::OTDM) // aux_link to OTDM grooming layer
            {
                unsigned int i;
                for(i = 0; i < aux_link->light_path->p_path.size(); i++)
                {
                    if(aux_node->phy_id == aux_link->light_path->p_path[i])
                    {
                        break;
                    }
                }
                aux_link->light_path->receiver_index[i] = 1;
                p_graph.get_node(aux_node->phy_id).num_available_receiver--;

                num_links_a_lp = 1.0 * (aux_link->light_path->p_path.size() - 1);
                used_bandwidth = num_links * event.bandwidth / aux_link->light_path->modulation_level;
                wasted_bandwidth = num_links_a_lp * (event.bandwidth / aux_link->light_path->modulation_level) - used_bandwidth;
                guardband_bandwidth = 0;
                total_bandwidth = used_bandwidth + wasted_bandwidth + guardband_bandwidth;
                total_bandwidth_utilization += total_bandwidth * event.holding_time;
                used_bandwidth_utilization += used_bandwidth * event.holding_time;
                wasted_bandwidth_utilization += wasted_bandwidth * event.holding_time;
                guardband_bandwidth_utilization += guardband_bandwidth * event.holding_time;
            }
            break;
        default:
            cerr << "aux_link type error\n";
            break;
        }
        aux_link = result[aux_node];
        aux_node = aux_link->from;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %rbx
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, 0x8(%rsp)
leaq 0x20(%rsp), %rsi
movq %rcx, (%rsi)
movq %r15, %rdi
callq 0x9edc
movq (%rax), %r12
movq 0x20(%r12), %rdx
movq %rdx, 0x18(%rsp)
cmpq %r14, %rdx
je 0x5135
leaq 0xc(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x18(%rsp), %rbp
leaq 0xc2f4(%rip), %r13      # 0x110b0
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
movl 0x10(%r12), %eax
cmpq $0x7, %rax
ja 0x4f7d
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movq 0x8(%r12), %rsi
movq 0x28(%r12), %rcx
movq 0x8(%rsp), %rdi
movq %rbx, %r8
callq 0x72ac
jmp 0x5114
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x5114
cmpl $0x0, 0x8(%rax)
jne 0x5114
jmp 0x510b
movq 0x8(%r12), %rax
movq 0x20(%rax), %rdx
movq 0x10(%rsp), %rcx
movslq (%rcx), %rcx
testq %rdx, %rdx
je 0x4e5a
leaq 0x18(%rax), %rdi
movq %rdi, %rsi
xorl %r8d, %r8d
cmpl %ecx, 0x20(%rdx)
setl %r8b
cmovgeq %rdx, %rsi
movq 0x10(%rdx,%r8,8), %rdx
testq %rdx, %rdx
jne 0x4e34
cmpq %rdi, %rsi
je 0x4e5a
cmpl 0x20(%rsi), %ecx
jge 0x4fe7
addq $0x8, %r12
movq 0x135fb(%rip), %rdx     # 0x18460
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x4f9a
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x4fa2
incl 0x13492(%rip)           # 0x18320
movq 0x10(%rsp), %rax
movl (%rax), %ecx
movl 0x13351(%rip), %eax     # 0x181ec
cltd
idivl 0x1333e(%rip)           # 0x181e0
movl %eax, %esi
movl %ecx, %eax
cltd
idivl %esi
cltq
movq 0x134ce(%rip), %rcx     # 0x18380
incl (%rcx,%rax,4)
jmp 0x5114
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x5114
cmpl $0x0, 0x8(%rax)
jne 0x5114
movq 0x68(%rax), %rcx
movq 0x70(%rax), %rsi
subq %rcx, %rsi
je 0x4ff9
sarq $0x2, %rsi
movl 0xc(%rdx), %edi
movl $0x1, %r9d
xorl %r8d, %r8d
cmpl (%rcx,%r8,4), %edi
je 0x4ffc
movl %r9d, %r8d
incl %r9d
cmpq %r8, %rsi
ja 0x4ef3
jmp 0x4ffc
movq 0x8(%r12), %rcx
testq %rcx, %rcx
je 0x5114
cmpl $0x0, 0x8(%rcx)
jne 0x5114
jmp 0x5020
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x5114
cmpl $0x0, 0x8(%rax)
jne 0x5114
movq 0x68(%rax), %rcx
movq 0x70(%rax), %rsi
subq %rcx, %rsi
je 0x50e9
sarq $0x2, %rsi
movl 0xc(%rdx), %edi
movl $0x1, %r9d
xorl %r8d, %r8d
cmpl (%rcx,%r8,4), %edi
je 0x50ec
movl %r9d, %r8d
incl %r9d
cmpq %r8, %rsi
ja 0x4f63
jmp 0x50ec
movl $0x14, %edx
movq 0x13067(%rip), %rdi     # 0x17ff0
leaq 0xc2c6(%rip), %rsi      # 0x11256
callq 0x3250
jmp 0x5114
movq %r12, %rdx
callq 0xa3ea
movq (%r12), %rdi
addq $0x10, %rdi
movq 0x10(%rsp), %rsi
callq 0xa526
movl 0x4c(%rbx), %eax
movq (%r12), %rcx
subl %eax, 0x44(%rcx)
incl 0x13364(%rip)           # 0x18328
movl 0xc(%rbx), %ecx
movl 0x1321f(%rip), %eax     # 0x181ec
cltd
idivl 0x1320c(%rip)           # 0x181e0
movl %eax, %esi
movl %ecx, %eax
cltd
idivl %esi
cltq
movq 0x133cc(%rip), %rcx     # 0x183b0
incl (%rcx,%rax,4)
movsd (%rsp), %xmm0
addsd 0xc01c(%rip), %xmm0     # 0x11010
jmp 0x510f
xorl %r8d, %r8d
movq 0xe0(%rax), %rax
movl $0x1, (%rax,%r8,4)
movl 0xc(%rdx), %esi
movq 0x8(%rsp), %rdi
callq 0xba88
decl 0x30(%rax)
movq 0x8(%r12), %rcx
movq 0x70(%rcx), %rax
subq 0x68(%rcx), %rax
sarq $0x2, %rax
decq %rax
movq %rax, %xmm0
punpckldq 0xc014(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xc01c(%rip), %xmm0     # 0x11060
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movl 0x4c(%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd (%rsp), %xmm0
movl 0x40(%rcx), %ecx
xorps %xmm2, %xmm2
cvtsi2sd %ecx, %xmm2
cltd
idivl %ecx
xorps %xmm3, %xmm3
cvtsi2sd %eax, %xmm3
divsd %xmm2, %xmm0
mulsd %xmm1, %xmm3
subsd %xmm0, %xmm3
movapd %xmm0, %xmm1
addsd %xmm3, %xmm1
xorpd %xmm4, %xmm4
addsd %xmm4, %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x54(%rbx), %xmm2
mulsd %xmm2, %xmm1
addsd 0x13325(%rip), %xmm1    # 0x183c8
movsd %xmm1, 0x1331d(%rip)    # 0x183c8
mulsd %xmm2, %xmm0
addsd 0x13319(%rip), %xmm0    # 0x183d0
movsd %xmm0, 0x13311(%rip)    # 0x183d0
mulsd %xmm2, %xmm3
addsd 0x1330d(%rip), %xmm3    # 0x183d8
movsd %xmm3, 0x13305(%rip)    # 0x183d8
mulsd %xmm4, %xmm2
addsd 0x13301(%rip), %xmm2    # 0x183e0
movsd %xmm2, 0x132f9(%rip)    # 0x183e0
jmp 0x5114
xorl %r8d, %r8d
movq 0xc8(%rax), %rax
movl $0x1, (%rax,%r8,4)
movl 0xc(%rdx), %esi
movq 0x8(%rsp), %rdi
callq 0xba88
decl 0x28(%rax)
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
movq %r15, %rdi
movq %rbp, %rsi
callq 0x9edc
movq (%rax), %r12
movq 0x20(%r12), %rdx
movq %rdx, 0x18(%rsp)
cmpq %r14, %rdx
jne 0x4dc5
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq