// File: 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
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0xb1e0
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x38(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
je 0x5e83
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x98(%rbp)
subq $0x7, %rax
ja 0x5e4b
movq -0x98(%rbp), %rax
leaq 0x278c5(%rip), %rcx     # 0x2d070
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rdx
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x28(%rbp), %r8
callq 0x8e00
jmp 0x5e5e
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
addq $0x10, %rdi
movq -0x28(%rbp), %rsi
addq $0xc, %rsi
callq 0xbf00
movq %rax, -0x70(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
addq $0x10, %rdi
callq 0xbf40
movq %rax, -0x78(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0xbed0
testb $0x1, %al
jne 0x5826
jmp 0x58ce
movq -0x28(%rbp), %rax
movslq 0xc(%rax), %rsi
leaq 0x3dc1b(%rip), %rdi     # 0x43450
callq 0xb250
movq %rax, %rdi
movq -0x30(%rbp), %rsi
addq $0x8, %rsi
callq 0xbb90
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
addq $0x10, %rdi
movq -0x28(%rbp), %rsi
addq $0xc, %rsi
callq 0xbc00
movq %rax, -0x88(%rbp)
movb %dl, -0x80(%rbp)
movq -0x28(%rbp), %rax
movl 0x4c(%rax), %edx
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x44(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x44(%rax)
movl 0x3da8e(%rip), %eax     # 0x43318
addl $0x1, %eax
movl %eax, 0x3da85(%rip)     # 0x43318
movq -0x28(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x9c(%rbp)
movl 0x3d936(%rip), %eax     # 0x431dc
cltd
idivl 0x3d923(%rip)           # 0x431d0
movl %eax, %ecx
movl -0x9c(%rbp), %eax
cltd
idivl %ecx
movslq %eax, %rsi
leaq 0x3dade(%rip), %rdi     # 0x433a0
callq 0xb210
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movsd 0x2773a(%rip), %xmm0    # 0x2d010
addsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
jmp 0x5e5e
movl 0x3da25(%rip), %eax     # 0x43310
addl $0x1, %eax
movl %eax, 0x3da1c(%rip)     # 0x43310
movq -0x28(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0xa0(%rbp)
movl 0x3d8d5(%rip), %eax     # 0x431dc
cltd
idivl 0x3d8c2(%rip)           # 0x431d0
movl %eax, %ecx
movl -0xa0(%rbp), %eax
cltd
idivl %ecx
movslq %eax, %rsi
leaq 0x3da4d(%rip), %rdi     # 0x43370
callq 0xb210
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x5e5e
movq -0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x5944
jmp 0x5e5e
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
cmpl $0x0, 0x8(%rax)
jne 0x595a
xorps %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
jmp 0x5e5e
movq -0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x596f
jmp 0x5e5e
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
cmpl $0x0, 0x8(%rax)
jne 0x5afe
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
addq $0x68, %rdi
callq 0xb380
decq %rax
movq %rax, %xmm1
movaps 0x276af(%rip), %xmm0    # 0x2d050
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x276b3(%rip), %xmm0    # 0x2d060
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd 0x2764c(%rip), %xmm0    # 0x2d010
mulsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x60(%rbp), %xmm0
movq -0x28(%rbp), %rax
cvtsi2sdl 0x4c(%rax), %xmm1
mulsd %xmm1, %xmm0
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
cvtsi2sdl 0x40(%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x68(%rbp), %xmm0
movq -0x28(%rbp), %rax
movl 0x4c(%rax), %eax
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rcx
cltd
idivl 0x40(%rcx)
cvtsi2sd %eax, %xmm2
movsd -0x40(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x40(%rbp), %xmm0
addsd -0x48(%rbp), %xmm0
addsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
movq -0x28(%rbp), %rax
movss 0x54(%rax), %xmm1
cvtss2sd %xmm1, %xmm2
movsd 0x3d948(%rip), %xmm1    # 0x433b8
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x3d938(%rip)    # 0x433b8
movsd -0x40(%rbp), %xmm0
movq -0x28(%rbp), %rax
movss 0x54(%rax), %xmm1
cvtss2sd %xmm1, %xmm2
movsd 0x3d926(%rip), %xmm1    # 0x433c0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x3d916(%rip)    # 0x433c0
movsd -0x48(%rbp), %xmm0
movq -0x28(%rbp), %rax
movss 0x54(%rax), %xmm1
cvtss2sd %xmm1, %xmm2
movsd 0x3d904(%rip), %xmm1    # 0x433c8
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x3d8f4(%rip)    # 0x433c8
movsd -0x50(%rbp), %xmm0
movq -0x28(%rbp), %rax
movss 0x54(%rax), %xmm1
cvtss2sd %xmm1, %xmm2
movsd 0x3d8e2(%rip), %xmm1    # 0x433d0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x3d8d2(%rip)    # 0x433d0
jmp 0x5e5e
jmp 0x5e5e
movq -0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x5b18
jmp 0x5e5e
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
cmpl $0x0, 0x8(%rax)
jne 0x5bec
movl $0x0, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movq %rax, -0xa8(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
addq $0x68, %rdi
callq 0xb380
movq %rax, %rcx
movq -0xa8(%rbp), %rax
cmpq %rcx, %rax
jae 0x5ba9
movq -0x38(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0xac(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
addq $0x68, %rdi
movl -0x8c(%rbp), %eax
movl %eax, %esi
callq 0xb210
movq %rax, %rcx
movl -0xac(%rbp), %eax
cmpl (%rcx), %eax
jne 0x5b96
jmp 0x5ba9
jmp 0x5b98
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x5b34
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
addq $0xc8, %rdi
movl -0x8c(%rbp), %eax
movl %eax, %esi
callq 0xb210
movl $0x1, (%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0xc(%rax), %esi
callq 0x1b450
movl 0x28(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x28(%rax)
xorps %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
jmp 0x5e5e
movq -0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x5c01
jmp 0x5e5e
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
cmpl $0x0, 0x8(%rax)
jne 0x5e49
movl $0x0, -0x90(%rbp)
movl -0x90(%rbp), %eax
movq %rax, -0xb8(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
addq $0x68, %rdi
callq 0xb380
movq %rax, %rcx
movq -0xb8(%rbp), %rax
cmpq %rcx, %rax
jae 0x5c92
movq -0x38(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0xbc(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
addq $0x68, %rdi
movl -0x90(%rbp), %eax
movl %eax, %esi
callq 0xb210
movq %rax, %rcx
movl -0xbc(%rbp), %eax
cmpl (%rcx), %eax
jne 0x5c7f
jmp 0x5c92
jmp 0x5c81
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x5c1d
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
addq $0xe0, %rdi
movl -0x90(%rbp), %eax
movl %eax, %esi
callq 0xb210
movl $0x1, (%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0xc(%rax), %esi
callq 0x1b450
movl 0x30(%rax), %ecx
decl %ecx
movl %ecx, 0x30(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
addq $0x68, %rdi
callq 0xb380
decq %rax
movq %rax, %xmm1
movaps 0x27364(%rip), %xmm0    # 0x2d050
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x27368(%rip), %xmm0    # 0x2d060
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd 0x27301(%rip), %xmm0    # 0x2d010
mulsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x60(%rbp), %xmm0
movq -0x28(%rbp), %rax
cvtsi2sdl 0x4c(%rax), %xmm1
mulsd %xmm1, %xmm0
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
cvtsi2sdl 0x40(%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x68(%rbp), %xmm0
movq -0x28(%rbp), %rax
movl 0x4c(%rax), %eax
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rcx
cltd
idivl 0x40(%rcx)
cvtsi2sd %eax, %xmm2
movsd -0x40(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x40(%rbp), %xmm0
addsd -0x48(%rbp), %xmm0
addsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
movq -0x28(%rbp), %rax
movss 0x54(%rax), %xmm1
cvtss2sd %xmm1, %xmm2
movsd 0x3d5fd(%rip), %xmm1    # 0x433b8
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x3d5ed(%rip)    # 0x433b8
movsd -0x40(%rbp), %xmm0
movq -0x28(%rbp), %rax
movss 0x54(%rax), %xmm1
cvtss2sd %xmm1, %xmm2
movsd 0x3d5db(%rip), %xmm1    # 0x433c0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x3d5cb(%rip)    # 0x433c0
movsd -0x48(%rbp), %xmm0
movq -0x28(%rbp), %rax
movss 0x54(%rax), %xmm1
cvtss2sd %xmm1, %xmm2
movsd 0x3d5b9(%rip), %xmm1    # 0x433c8
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x3d5a9(%rip)    # 0x433c8
movsd -0x50(%rbp), %xmm0
movq -0x28(%rbp), %rax
movss 0x54(%rax), %xmm1
cvtss2sd %xmm1, %xmm2
movsd 0x3d597(%rip), %xmm1    # 0x433d0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x3d587(%rip)    # 0x433d0
jmp 0x5e5e
movq 0x3d19e(%rip), %rdi     # 0x42ff0
leaq 0x273c1(%rip), %rsi     # 0x2d21a
callq 0x31f0
movq -0x10(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0xb1e0
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x5777
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax)