// File: /workspace/github_cpp_makefile_star2_O2/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, 0x10(%rsp)
movl %esi, %ebp
movl %edi, %r12d
movq %rcx, %rdi
movl %r12d, %esi
callq 0x98a8
movq %rax, %r13
movq %rbx, %rdi
movl %ebp, %esi
callq 0x98a8
xorl %r15d, %r15d
cmpl $0x0, 0x28(%r13)
jle 0x494a
cmpl $0x0, 0x30(%rax)
jle 0x494a
movq %rbx, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0x99d8
movq %rax, %r14
leaq 0x38(%rsp), %rdi
callq 0xe148
leaq 0x18(%rsp), %rdi
callq 0xe148
xorpd %xmm0, %xmm0
leaq 0x50(%rsp), %rax
movapd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x20(%rsp), %rcx
orq $-0x1, (%rcx)
movabsq $0x7fefffffffffffff, %rax # imm = 0x7FEFFFFFFFFFFFFF
movq %rax, 0x8(%rcx)
movl $0x0, 0xc(%rsp)
leaq 0x70(%rsp), %r13
movq %r14, %r15
movl $0x0, 0x8(%rsp)
movq (%r15), %r15
cmpq %r14, %r15
je 0x48ca
movl 0x139e9(%rip), %eax     # 0x181ec
addl %eax, %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0x10(%rsp), %rax
cvtsi2sdl 0x4c(%rax), %xmm0
cvtsi2sdl 0x30(%r15), %xmm1
divsd %xmm1, %xmm0
cvtsi2sdl 0x139b5(%rip), %xmm1 # 0x181e0
divsd %xmm1, %xmm0
callq 0x2060
addsd 0x30(%rsp), %xmm0
cvttsd2si %xmm0, %ebp
leaq 0x18(%r15), %r12
movq %r13, %rdi
movq %r12, %rsi
movl %ebp, %edx
movq %rbx, %rcx
callq 0x6390
leaq 0x78(%rsp), %rax
movups (%rax), %xmm0
leaq 0x40(%rsp), %rax
movups %xmm0, (%rax)
movq %r13, %rdi
callq 0xe154
movsd 0x28(%rsp), %xmm0
ucomisd 0x48(%rsp), %xmm0
jbe 0x47f1
leaq 0x50(%rsp), %rdi
movq %r12, %rsi
callq 0x6876
leaq 0x40(%rsp), %rax
movupd (%rax), %xmm0
leaq 0x20(%rsp), %rax
movupd %xmm0, (%rax)
movl 0x30(%r15), %edx
movl 0x13947(%rip), %eax     # 0x181ec
addl %eax, %eax
subl %eax, %ebp
movl 0x13931(%rip), %ecx     # 0x181e0
movl %edx, 0x8(%rsp)
imull %edx, %ecx
imull %ebp, %ecx
movq 0x10(%rsp), %rax
subl 0x4c(%rax), %ecx
movl %ecx, 0xc(%rsp)
jmp 0x47f1
cmpl $0x0, 0x20(%rsp)
js 0x4929
movl $0xf8, %edi
callq 0x21f0
movq %rax, %r15
movq %rax, %rdi
callq 0xe020
andl $0x0, 0x8(%r15)
movq %r15, %rdi
addq $0x68, %rdi
leaq 0x50(%rsp), %rsi
callq 0x6876
movl 0x8(%rsp), %eax
movl %eax, 0x40(%r15)
movl 0xc(%rsp), %eax
movl %eax, 0x44(%r15)
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x48(%r15)
leaq 0x20(%rsp), %rax
movupd (%rax), %xmm0
movupd %xmm0, 0x58(%r15)
jmp 0x492c
xorl %r15d, %r15d
leaq 0x50(%rsp), %rdi
callq 0x6f54
leaq 0x18(%rsp), %rdi
callq 0xe154
leaq 0x38(%rsp), %rdi
callq 0xe154
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 0x2200
jmp 0x497d
jmp 0x497a
movq %rax, %rbx
jmp 0x4991
jmp 0x497a
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x6f54
leaq 0x18(%rsp), %rdi
callq 0xe154
leaq 0x38(%rsp), %rdi
callq 0xe154
movq %rbx, %rdi
callq 0x2320