// File: /workspace/github_cpp_makefile_star2_O1/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, 0x10(%rsp)
leaq 0x20(%rsp), %rsi
movq %rcx, (%rsi)
movq %r15, %rdi
callq 0x975c
movq (%rax), %r12
movq 0x20(%r12), %rdx
movq %rdx, 0x18(%rsp)
cmpq %r14, %rdx
je 0x5177
leaq 0xc(%rbx), %rax
movq %rax, 0x8(%rsp)
leaq 0x18(%rsp), %rbp
leaq 0xc29c(%rip), %r13      # 0x11080
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
movl 0x10(%r12), %eax
cmpq $0x7, %rax
ja 0x4fbf
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movq 0x8(%r12), %rsi
movq 0x28(%r12), %rcx
movq 0x10(%rsp), %rdi
movq %rbx, %r8
callq 0x7322
jmp 0x5156
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x5156
cmpl $0x0, 0x8(%rax)
jne 0x5156
jmp 0x514d
movq 0x8(%r12), %rax
movq 0x20(%rax), %rsi
leaq 0x18(%rax), %rcx
movq %rcx, %rdx
testq %rsi, %rsi
je 0x4e76
movq 0x8(%rsp), %rdx
movl (%rdx), %edi
movq %rcx, %rdx
xorl %r8d, %r8d
cmpl %edi, 0x20(%rsi)
setl %r8b
cmovgeq %rsi, %rdx
movq 0x10(%rsi,%r8,8), %rsi
testq %rsi, %rsi
jne 0x4e5e
movq %rcx, %rsi
cmpq %rcx, %rdx
je 0x4e8f
movq 0x8(%rsp), %rsi
movl (%rsi), %esi
cmpl 0x20(%rdx), %esi
cmovlq %rcx, %rdx
movq %rdx, %rsi
cmpq %rcx, %rsi
jne 0x5029
addq $0x8, %r12
movq 0x8(%rsp), %rcx
movslq (%rcx), %rcx
movq 0x135b5(%rip), %rdx     # 0x18460
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x4fdc
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x4fe4
incl 0x1344c(%rip)           # 0x18320
movl 0xc(%rbx), %ecx
movl 0x1330f(%rip), %eax     # 0x181ec
cltd
idivl 0x132fc(%rip)           # 0x181e0
movl %eax, %esi
movl %ecx, %eax
cltd
idivl %esi
cltq
movq 0x1348c(%rip), %rcx     # 0x18380
incl (%rcx,%rax,4)
jmp 0x5156
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x5156
cmpl $0x0, 0x8(%rax)
jne 0x5156
movq 0x68(%rax), %rcx
movq 0x70(%rax), %rsi
subq %rcx, %rsi
je 0x503b
sarq $0x2, %rsi
movl 0xc(%rdx), %edi
movl $0x1, %r9d
xorl %r8d, %r8d
cmpl (%rcx,%r8,4), %edi
je 0x503e
movl %r9d, %r8d
incl %r9d
cmpq %r8, %rsi
ja 0x4f35
jmp 0x503e
movq 0x8(%r12), %rcx
testq %rcx, %rcx
je 0x5156
cmpl $0x0, 0x8(%rcx)
jne 0x5156
jmp 0x5062
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x5156
cmpl $0x0, 0x8(%rax)
jne 0x5156
movq 0x68(%rax), %rcx
movq 0x70(%rax), %rsi
subq %rcx, %rsi
je 0x512b
sarq $0x2, %rsi
movl 0xc(%rdx), %edi
movl $0x1, %r9d
xorl %r8d, %r8d
cmpl (%rcx,%r8,4), %edi
je 0x512e
movl %r9d, %r8d
incl %r9d
cmpq %r8, %rsi
ja 0x4fa5
jmp 0x512e
movl $0x14, %edx
movq 0x13025(%rip), %rdi     # 0x17ff0
leaq 0xc254(%rip), %rsi      # 0x11226
callq 0x3250
jmp 0x5156
movq %r12, %rdx
callq 0x9c9a
movq (%r12), %rdi
addq $0x10, %rdi
movq 0x8(%rsp), %rsi
callq 0x9dd6
movl 0x4c(%rbx), %eax
movq (%r12), %rcx
subl %eax, 0x44(%rcx)
incl 0x13322(%rip)           # 0x18328
movl 0xc(%rbx), %ecx
movl 0x131dd(%rip), %eax     # 0x181ec
cltd
idivl 0x131ca(%rip)           # 0x181e0
movl %eax, %esi
movl %ecx, %eax
cltd
idivl %esi
cltq
movq 0x1338a(%rip), %rcx     # 0x183b0
incl (%rcx,%rax,4)
movsd (%rsp), %xmm0
addsd 0xbfda(%rip), %xmm0     # 0x11010
jmp 0x5151
xorl %r8d, %r8d
movq 0xe0(%rax), %rax
movl $0x1, (%rax,%r8,4)
movl 0xc(%rdx), %esi
movq 0x10(%rsp), %rdi
callq 0xb390
decl 0x30(%rax)
movq 0x8(%r12), %rcx
movq 0x70(%rcx), %rax
subq 0x68(%rcx), %rax
sarq $0x2, %rax
decq %rax
movq %rax, %xmm0
punpckldq 0xbfd2(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xbfda(%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 0x132e3(%rip), %xmm1    # 0x183c8
movsd %xmm1, 0x132db(%rip)    # 0x183c8
mulsd %xmm2, %xmm0
addsd 0x132d7(%rip), %xmm0    # 0x183d0
movsd %xmm0, 0x132cf(%rip)    # 0x183d0
mulsd %xmm2, %xmm3
addsd 0x132cb(%rip), %xmm3    # 0x183d8
movsd %xmm3, 0x132c3(%rip)    # 0x183d8
mulsd %xmm4, %xmm2
addsd 0x132bf(%rip), %xmm2    # 0x183e0
movsd %xmm2, 0x132b7(%rip)    # 0x183e0
jmp 0x5156
xorl %r8d, %r8d
movq 0xc8(%rax), %rax
movl $0x1, (%rax,%r8,4)
movl 0xc(%rdx), %esi
movq 0x10(%rsp), %rdi
callq 0xb390
decl 0x28(%rax)
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
movq %r15, %rdi
movq %rbp, %rsi
callq 0x975c
movq (%rax), %r12
movq 0x20(%r12), %rdx
movq %rdx, 0x18(%rsp)
cmpq %r14, %rdx
jne 0x4ded
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq