// File: /workspace/github_cpp_makefile_star2_O3/ynilu[P]elastic/simulator.cpp
// Function: get_best_OTDM_light_path(int, int, Event&, Phy_graph&)
LightPath* get_best_OTDM_light_path(int source, int destination, Event& event, Phy_graph& p_graph)
{
    Phy_node& src_node = p_graph.get_node(source);
    Phy_node& dst_node = p_graph.get_node(destination);

    if(src_node.num_available_transmitter < 1)
    {
        return NULL;
    }

    if(dst_node.num_available_receiver < 1)
    {
        return NULL;
    }

    int modulation_level = 0;
    int available_bitrate = 0;
    list<CandidatePath>& c_path_list = p_graph.get_path_list(source, destination);
    Spectrum path_spectrum, best_path_spectrum;
    Path best_p_path;

    best_path_spectrum.slot_st = -1;
    best_path_spectrum.slot_ed = -1;
    best_path_spectrum.weight = DBL_MAX;

    for(auto &c_path : c_path_list)
    {
        int require_slots = num_guardband_slot * 2 + ceil(1.0 * event.bandwidth / c_path.modulation_level / slot_capacity);
        path_spectrum = find_best_spectrum(c_path.path, require_slots, p_graph);
        if(best_path_spectrum.weight > path_spectrum.weight){
            best_p_path = c_path.path;
            best_path_spectrum = path_spectrum;
            modulation_level = c_path.modulation_level;
            available_bitrate = (require_slots - num_guardband_slot * 2) * c_path.modulation_level * slot_capacity - event.bandwidth;
        }
    }
    if(best_path_spectrum.slot_st < 0){
        return NULL;
    }
    LightPath* path = new LightPath();
    path->type = LightPath::OTDM;
    path->p_path = best_p_path;
    path->modulation_level = modulation_level;
    path->available_bitrate = available_bitrate;
    path->weight = best_path_spectrum.weight;
    path->spectrum = best_path_spectrum;
    return path;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movl %esi, %ebp
movl %edi, %r12d
movq %rcx, %rdi
movl %r12d, %esi
callq 0xba88
movq %rax, %r13
movq %rbx, 0x28(%rsp)
movq %rbx, %rdi
movl %ebp, %esi
callq 0xba88
xorl %r15d, %r15d
cmpl $0x0, 0x28(%r13)
jle 0x65b0
cmpl $0x0, 0x30(%rax)
jle 0x65b0
movq 0x28(%rsp), %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0xbc76
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x10be4
leaq 0x8(%rsp), %rdi
callq 0x10be4
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
movq $-0x1, 0x10(%rsp)
movabsq $0x7fefffffffffffff, %rax # imm = 0x7FEFFFFFFFFFFFFF
movq %rax, 0x18(%rsp)
movq (%rbx), %r15
cmpq %rbx, %r15
je 0x6582
movq $0x0, 0x20(%rsp)
movq %rbx, 0x48(%rsp)
leaq 0x70(%rsp), %r12
xorl %ebx, %ebx
movl 0x11dc0(%rip), %eax     # 0x18214
addl %eax, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x50(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x4c(%r14), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x30(%r15), %xmm1
divsd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x11d84(%rip), %xmm1 # 0x18208
divsd %xmm1, %xmm0
callq 0x3070
addsd 0x50(%rsp), %xmm0
cvttsd2si %xmm0, %ebp
leaq 0x18(%r15), %r13
movq %r12, %rdi
movq %r13, %rsi
movl %ebp, %edx
movq 0x28(%rsp), %rcx
callq 0x86d9
leaq 0x78(%rsp), %rax
movups (%rax), %xmm0
leaq 0x60(%rsp), %rax
movups %xmm0, (%rax)
movq %r12, %rdi
callq 0x10bf0
movsd 0x18(%rsp), %xmm0
ucomisd 0x68(%rsp), %xmm0
jbe 0x6515
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x8c9c
leaq 0x60(%rsp), %rax
movupd (%rax), %xmm0
leaq 0x10(%rsp), %rax
movupd %xmm0, (%rax)
movl 0x30(%r15), %ecx
movl 0x11d18(%rip), %eax     # 0x18214
addl %eax, %eax
subl %eax, %ebp
movl 0x11d02(%rip), %ebx     # 0x18208
movq %rcx, 0x20(%rsp)
imull %ecx, %ebx
imull %ebp, %ebx
subl 0x4c(%r14), %ebx
movq (%r15), %r15
cmpq 0x48(%rsp), %r15
jne 0x644e
cmpl $0x0, 0x10(%rsp)
js 0x6582
movl $0xf8, %edi
callq 0x3220
movq 0x20(%rsp), %r14
movq %rax, %r15
movq %rax, %rdi
callq 0x10a4c
movl $0x0, 0x8(%r15)
movq %r15, %rdi
addq $0x68, %rdi
leaq 0x30(%rsp), %rsi
callq 0x8c9c
movl %r14d, 0x40(%r15)
movl %ebx, 0x44(%r15)
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x48(%r15)
leaq 0x10(%rsp), %rax
movupd (%rax), %xmm0
movupd %xmm0, 0x58(%r15)
jmp 0x6585
xorl %r15d, %r15d
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x659c
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x3230
leaq 0x8(%rsp), %rdi
callq 0x10bf0
leaq 0x58(%rsp), %rdi
callq 0x10bf0
movq %r15, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0xf8, %esi
movq %r15, %rdi
callq 0x3230
jmp 0x65e3
jmp 0x65e0
movq %rax, %rbx
jmp 0x6604
jmp 0x65e0
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x65fa
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x3230
leaq 0x8(%rsp), %rdi
callq 0x10bf0
leaq 0x58(%rsp), %rdi
callq 0x10bf0
movq %rbx, %rdi
callq 0x3370