// File: /workspace/github_cpp_makefile_star2_O1/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 0xb390
movq %rax, %r13
movq %rbx, 0x10(%rsp)
movq %rbx, %rdi
movl %ebp, %esi
callq 0xb390
xorl %r15d, %r15d
cmpl $0x0, 0x28(%r13)
jle 0x65fb
cmpl $0x0, 0x30(%rax)
jle 0x65fb
movq 0x10(%rsp), %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0xb572
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x10504
leaq 0x18(%rsp), %rdi
callq 0x10504
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
leaq 0x20(%rsp), %rcx
movq $-0x1, (%rcx)
movabsq $0x7fefffffffffffff, %rax # imm = 0x7FEFFFFFFFFFFFFF
movq %rax, 0x8(%rcx)
movq (%rbx), %r15
cmpq %rbx, %r15
je 0x6565
movq %rbx, 0x48(%rsp)
movl $0x0, 0xc(%rsp)
leaq 0x70(%rsp), %r12
xorl %ebx, %ebx
movl 0x11d7f(%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 0x11d43(%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 0x10(%rsp), %rcx
callq 0x82e9
leaq 0x78(%rsp), %rax
movups (%rax), %xmm0
leaq 0x60(%rsp), %rax
movups %xmm0, (%rax)
movq %r12, %rdi
callq 0x10510
movsd 0x28(%rsp), %xmm0
ucomisd 0x68(%rsp), %xmm0
jbe 0x6555
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x88f4
leaq 0x60(%rsp), %rax
movupd (%rax), %xmm0
leaq 0x20(%rsp), %rax
movupd %xmm0, (%rax)
movl 0x30(%r15), %ecx
movl 0x11cd7(%rip), %eax     # 0x18214
addl %eax, %eax
subl %eax, %ebp
movl 0x11cc1(%rip), %ebx     # 0x18208
movl %ecx, 0xc(%rsp)
imull %ecx, %ebx
imull %ebp, %ebx
subl 0x4c(%r14), %ebx
movq (%r15), %r15
cmpq 0x48(%rsp), %r15
jne 0x648f
jmp 0x656f
xorl %ebx, %ebx
movl $0x0, 0xc(%rsp)
cmpl $0x0, 0x20(%rsp)
js 0x65cd
movl $0xf8, %edi
callq 0x3220
movq %rax, %r15
movq %rax, %rdi
callq 0x1036c
movl $0x0, 0x8(%r15)
movq %r15, %rdi
addq $0x68, %rdi
leaq 0x30(%rsp), %rsi
callq 0x88f4
movl 0xc(%rsp), %eax
movl %eax, 0x40(%r15)
movl %ebx, 0x44(%r15)
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x48(%r15)
leaq 0x20(%rsp), %rax
movupd (%rax), %xmm0
movupd %xmm0, 0x58(%r15)
jmp 0x65d0
xorl %r15d, %r15d
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x65e7
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x3230
leaq 0x18(%rsp), %rdi
callq 0x10510
leaq 0x58(%rsp), %rdi
callq 0x10510
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 0x662e
movq %rax, %rbx
jmp 0x664f
jmp 0x662b
jmp 0x662b
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x6645
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x3230
leaq 0x18(%rsp), %rdi
callq 0x10510
leaq 0x58(%rsp), %rdi
callq 0x10510
movq %rbx, %rdi
callq 0x3370