// File: /workspace/github_cpp_makefile_star2_O2/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 0x7a7a
movq (%rax), %r12
leaq 0xc(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x18(%rsp), %rbp
leaq 0xb7ab(%rip), %r13      # 0xf080
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
movq 0x20(%r12), %rdx
movq %rdx, 0x18(%rsp)
cmpq %r14, %rdx
je 0x3bc9
movl 0x10(%r12), %eax
cmpq $0x7, %rax
ja 0x3ba3
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 0x5593
jmp 0x3bb6
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x3bb6
cmpl $0x0, 0x8(%rax)
jne 0x3bb6
jmp 0x3b98
movq 0x8(%r12), %rdi
addq $0x10, %rdi
movq 0x10(%rsp), %rsi
callq 0x8536
movq 0x8(%r12), %rcx
addq $0x18, %rcx
cmpq %rcx, %rax
jne 0x39c4
addq $0x8, %r12
movslq 0xc(%rbx), %rax
imulq $0x18, %rax, %rdi
addq 0x14ac1(%rip), %rdi     # 0x18438
movq %r12, %rsi
callq 0x6858
movq (%r12), %rdi
addq $0x10, %rdi
movq 0x10(%rsp), %rsi
callq 0x840e
movl 0x4c(%rbx), %eax
movq (%r12), %rcx
subl %eax, 0x44(%rcx)
incl 0x1495f(%rip)           # 0x18300
movl 0xc(%rbx), %ecx
movl 0x1481a(%rip), %eax     # 0x181c4
cltd
idivl 0x14807(%rip)           # 0x181b8
movl %eax, %esi
movl %ecx, %eax
cltd
idivl %esi
cltq
movq 0x149c7(%rip), %rcx     # 0x18388
incl (%rcx,%rax,4)
movsd (%rsp), %xmm0
addsd 0xb63f(%rip), %xmm0     # 0xf010
jmp 0x3b9c
incl 0x1491c(%rip)           # 0x182f8
movq 0x10(%rsp), %rax
movl (%rax), %ecx
movl 0x147db(%rip), %eax     # 0x181c4
cltd
idivl 0x147c8(%rip)           # 0x181b8
movl %eax, %esi
movl %ecx, %eax
cltd
idivl %esi
cltq
movq 0x14958(%rip), %rcx     # 0x18358
incl (%rcx,%rax,4)
jmp 0x3bb6
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x3bb6
cmpl $0x0, 0x8(%rax)
jne 0x3bb6
movq 0x68(%rax), %rcx
movq 0x70(%rax), %rsi
subq %rcx, %rsi
sarq $0x2, %rsi
xorl %r8d, %r8d
movl %r8d, %edi
cmpq %rdi, %rsi
jbe 0x3a48
movl 0xc(%rdx), %r9d
leal 0x1(%rdi), %r8d
cmpl (%rcx,%rdi,4), %r9d
jne 0x3a32
movq 0xe0(%rax), %rax
movl $0x1, (%rax,%rdi,4)
movl 0xc(%rdx), %esi
movq 0x8(%rsp), %rdi
callq 0x98a8
decl 0x30(%rax)
movq 0x8(%r12), %rcx
jmp 0x3a85
movq 0x8(%r12), %rcx
testq %rcx, %rcx
je 0x3bb6
cmpl $0x0, 0x8(%rcx)
jne 0x3bb6
movq 0x70(%rcx), %rax
subq 0x68(%rcx), %rax
sarq $0x2, %rax
decq %rax
movq %rax, %xmm0
punpckldq 0xb5af(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xb5b7(%rip), %xmm0     # 0xf060
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movl 0x4c(%rbx), %eax
cvtsi2sd %eax, %xmm0
mulsd (%rsp), %xmm0
movl 0x40(%rcx), %ecx
cvtsi2sd %ecx, %xmm2
cltd
idivl %ecx
cvtsi2sd %eax, %xmm3
divsd %xmm2, %xmm0
mulsd %xmm1, %xmm3
subsd %xmm0, %xmm3
movapd %xmm0, %xmm1
addsd %xmm3, %xmm1
xorpd %xmm4, %xmm4
addsd %xmm4, %xmm1
cvtss2sd 0x54(%rbx), %xmm2
mulsd %xmm2, %xmm1
addsd 0x148a4(%rip), %xmm1    # 0x183a0
movsd %xmm1, 0x1489c(%rip)    # 0x183a0
mulsd %xmm2, %xmm0
addsd 0x14898(%rip), %xmm0    # 0x183a8
movsd %xmm0, 0x14890(%rip)    # 0x183a8
mulsd %xmm2, %xmm3
addsd 0x1488c(%rip), %xmm3    # 0x183b0
movsd %xmm3, 0x14884(%rip)    # 0x183b0
mulsd %xmm4, %xmm2
addsd 0x14880(%rip), %xmm2    # 0x183b8
movsd %xmm2, 0x14878(%rip)    # 0x183b8
jmp 0x3bb6
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x3bb6
cmpl $0x0, 0x8(%rax)
jne 0x3bb6
movq 0x68(%rax), %rcx
movq 0x70(%rax), %rsi
subq %rcx, %rsi
sarq $0x2, %rsi
xorl %r8d, %r8d
movl %r8d, %edi
cmpq %rdi, %rsi
jbe 0x3b7a
movl 0xc(%rdx), %r9d
leal 0x1(%rdi), %r8d
cmpl (%rcx,%rdi,4), %r9d
jne 0x3b64
movq 0xc8(%rax), %rax
movl $0x1, (%rax,%rdi,4)
movl 0xc(%rdx), %esi
movq 0x8(%rsp), %rdi
callq 0x98a8
decl 0x28(%rax)
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
jmp 0x3bb6
movq 0x14446(%rip), %rdi     # 0x17ff0
leaq 0xb675(%rip), %rsi      # 0xf226
callq 0x21e0
movq %r15, %rdi
movq %rbp, %rsi
callq 0x7a7a
movq (%rax), %r12
jmp 0x38de
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq