// File: adamiaonr[P]rid-analytics/src/rid-analytics.cpp
// Function: RID_Analytics::handle_llm(RID_Router*, std::vector<std::vector<long double, std::allocator<long double>>, std::allocator<std::vector<long double, std::allocator<long double>>>>&, std::vector<long double, std::allocator<long double>>&, Path_State*)
int RID_Analytics::handle_llm(
    RID_Router * router,
    std::vector<std::vector<__float080> > & iface_probs,
    std::vector<__float080> & events,
    Path_State * prev_state) {

    // LLM : 'local link match' i.e. a delivery to a cache
    std::cout << "RID_Analytics::handle_llm() : analyzing LLM event" 
        << std::endl;

    // update the events array
    events[EVENT_LLM] = iface_probs[0][2];

    // don't continue if prob of llm is 0.0
    if (iface_probs[0][2] == 0.0) return 0;
    
    // assess correctness of local delivery
    if (this->tp_sizes[router->get_id()][0] > 0) {

        // add record of correct delivery
        add_outcome(router, OUTCOME_CORRECT_DELIVERY, iface_probs[0][2], prev_state->get_length());

    } else {

        // add record of incorrect delivery
        add_outcome(router, OUTCOME_INCORRECT_DELIVERY, iface_probs[0][2], prev_state->get_length());

        // handling incorrect deliveries if resolution is on
        if (this->mode & 0x04) {

            if (this->mode == MMH_FLOOD) {

                add_outcome(
                    router, 
                    OUTCOME_FEEDBACK_DELIVERY,
                    iface_probs[0][2], 
                    prev_state->get_length() + get_origin_distance(this->start_router));

            } 
            // else if ((this->mode & 0x03) == HARD_FALLBACK) {

            //     add_outcome(
            //         router, 
            //         OUTCOME_HARD_FALLBACK_DELIVERY, 
            //         iface_probs[0][0],
            //         prev_state->get_length() + get_origin_distance(router));

            // }
        }
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x90(%rbp)
movq 0x33227(%rip), %rdi     # 0x81fb8
leaq 0x1544a(%rip), %rsi     # 0x641e2
callq 0x5480
movq %rax, %rdi
movq 0x331e9(%rip), %rsi     # 0x81f90
callq 0x54f0
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0x78(%rbp)
callq 0x358a0
movq %rax, %rdi
movl $0x2, %esi
movq %rsi, -0x70(%rbp)
callq 0x34c70
movq -0x70(%rbp), %rsi
fldt (%rax)
fstpt -0x84(%rbp)
movq -0x28(%rbp), %rdi
callq 0x34c70
fldt -0x84(%rbp)
movq -0x78(%rbp), %rsi
fstpt (%rax)
movq -0x20(%rbp), %rdi
callq 0x358a0
movq -0x70(%rbp), %rsi
movq %rax, %rdi
callq 0x34c70
fldt (%rax)
fldz
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
jne 0x4ee20
jp 0x4ee20
jmp 0x4ee14
movl $0x0, -0x4(%rbp)
jmp 0x4f02c
movq -0x90(%rbp), %rax
addq $0x20, %rax
movq %rax, -0xa8(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x50(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
callq 0x35650
movq -0xa8(%rbp), %rdi
movq -0xa0(%rbp), %rsi
callq 0x52810
movq %rax, -0x98(%rbp)
jmp 0x4ee62
movq -0x98(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x34d30
movzbl (%rax), %eax
movl %eax, -0xac(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x52f0
movl -0xac(%rbp), %eax
cmpl $0x0, %eax
jle 0x4ef13
movq -0x18(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x358a0
movq %rax, %rdi
movl $0x2, %esi
callq 0x34c70
fldt (%rax)
fstpt -0xc4(%rbp)
movq -0x30(%rbp), %rdi
callq 0x3f5c0
fldt -0xc4(%rbp)
movq -0x90(%rbp), %rdi
movq -0xb8(%rbp), %rsi
movl %eax, -0x68(%rbp)
fildl -0x68(%rbp)
xorl %eax, %eax
movq %rsp, %rax
fstpt 0x10(%rax)
fstpt (%rax)
xorl %edx, %edx
callq 0x4e440
jmp 0x4f025
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x52f0
jmp 0x4f038
movq -0x18(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x358a0
movq %rax, %rdi
movl $0x2, %esi
callq 0x34c70
fldt (%rax)
fstpt -0xdc(%rbp)
movq -0x30(%rbp), %rdi
callq 0x3f5c0
fldt -0xdc(%rbp)
movq -0xd0(%rbp), %rsi
movq -0x90(%rbp), %rdi
movl %eax, -0x60(%rbp)
fildl -0x60(%rbp)
movq %rsp, %rax
fstpt 0x10(%rax)
fstpt (%rax)
movl $0x1, %edx
callq 0x4e440
movq -0x90(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x4f023
movq -0x90(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x4f021
movq -0x18(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x358a0
movq %rax, %rdi
movl $0x2, %esi
callq 0x34c70
fldt (%rax)
fstpt -0xf4(%rbp)
movq -0x30(%rbp), %rdi
callq 0x3f5c0
movq -0x90(%rbp), %rdi
movl %eax, -0xe0(%rbp)
movq 0x88(%rdi), %rsi
callq 0x4e0e0
fldt -0xf4(%rbp)
movq -0x90(%rbp), %rdi
movq -0xe8(%rbp), %rsi
movl %eax, %ecx
movl -0xe0(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x64(%rbp)
fildl -0x64(%rbp)
movq %rsp, %rax
fstpt 0x10(%rax)
fstpt (%rax)
movl $0x3, %edx
callq 0x4e440
jmp 0x4f023
jmp 0x4f025
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0x5920
nopw %cs:(%rax,%rax)