// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, %r15
movq %rcx, %r13
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r14
movq 0x19178(%rip), %rbp     # 0x3efb8
leaq 0xb294(%rip), %rsi      # 0x310db
movl $0x31, %edx
movq %rbp, %rdi
callq 0x4400
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x4370
movsbl %al, %esi
movq %rbp, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42a0
movq (%r12), %rax
movq (%rax), %rax
fldt 0x20(%rax)
movq (%r13), %rax
fld %st(0)
fstpt 0x20(%rax)
fldz
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
jne 0x25e9f
jnp 0x25f2f
leaq 0x20(%r14), %r13
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %rbp
movq %rbp, %rdi
callq 0x1bdb4
movq %r13, %rdi
movq %rbp, %rsi
callq 0x282e0
movq (%rax), %rax
movb (%rax), %r13b
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x25ef0
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x43a0
xorl %ebp, %ebp
testb %r13b, %r13b
sete %bpl
movq (%r12), %rax
movq (%rax), %rax
fldt 0x20(%rax)
fstpt 0x4c(%rsp)
movq %r15, %rdi
callq 0x1ef10
movl %eax, 0x24(%rsp)
fildl 0x24(%rsp)
fstpt 0x10(%rsp)
fldt 0x4c(%rsp)
fstpt (%rsp)
movq %r14, %rdi
movq %rbx, %rsi
movl %ebp, %edx
callq 0x2574a
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x25f5f
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x43a0
movq %rbx, %rdi
callq 0x4700
nop