// File: /workspace/github_cpp_makefile_star2_O3/adamiaonr[P]rid-analytics/src/prob.cpp
// Function: calc_lm_prob(int, int, Prob::fp_data*, std::vector<long double, std::allocator<long double>>*, std::vector<long double, std::allocator<long double>>*, std::vector<long double, std::allocator<long double>>*)
void _calc_lm_prob(
    int f, int t,
    Prob::fp_data * iface_fp_data,
    std::vector<__float080> * log_prob_fp_neq,
    std::vector<__float080> * log_prob_fp_smeq,
    std::vector<__float080> * lmp) {

    // if f is smaller than the tp size or fp tree size t, then f *WON'T 
    // BE* the largest match for sure, so P(L_i = f) = 0.0
    if ((f < iface_fp_data->tp_size) || f < t) {

        (*lmp)[f] = 0.0;

    } else {

        // 2 sub-cases (deterministic):
        //  1) f == tp size
        //  2) f > tp size
        if (f == iface_fp_data->tp_size) {

            // 1) f == tp size
            // the prob of this event can be calculated as:
            //  * not having fp matches larger than f : log_prob_fp_smeq[f]
            (*lmp)[f] = exp((*log_prob_fp_smeq)[f]);

        } else {

            // 2) f > tp size
            if (f == t) {

                // the prob of this event can be calculated as:
                //  * not having fp matches larger than f : log_prob_fp_smeq[f]
                (*lmp)[f] = exp((*log_prob_fp_smeq)[f]);

            } else {

                // the prob of this event can be calculated as:
                //  * not having fps larger than f : log_prob_fp_smeq[f]
                //  * AND having a fp of size f : 1.0 - exp(log_prob_fp_neq[f - 1])
                (*lmp)[f] = 
                    exp((*log_prob_fp_smeq)[f]) 
                    * (1.0 - exp((*log_prob_fp_neq)[f - 1])) 
                    * ((iface_fp_data->num_entries > 0) ? 1.0 : 0.0);

                // if (iface_fp_data->on_fptree[t] && t > 0) {

                //     (*lmp)[f] = 0.0;
                
                // } else {

                //     // the prob of this event can be calculated as:
                //     //  * not having fps larger than f : log_prob_fp_smeq[f]
                //     //  * AND having a fp of size f : 1.0 - exp(log_prob_fp_neq[f - 1])
                //     (*lmp)[f] = 
                //         exp((*log_prob_fp_smeq)[f]) 
                //         * (1.0 - exp((*log_prob_fp_neq)[f - 1])) 
                //         * ((iface_fp_data->num_entries > 0) ? 1.0 : 0.0);
                // }
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %rbx
movq %rcx, %r15
movq %rdx, %r14
movl %edi, %ebp
movzbl (%rdx), %eax
cmpl %edi, %eax
setle %cl
cmpl %esi, %edi
setge %dl
testb %cl, %dl
jne 0x29daf
movslq %ebp, %r13
fldz
jmp 0x29e21
cmpl %ebp, %eax
jne 0x29dcd
movl %ebp, %r13d
movq (%r8), %rax
movq %r13, %rcx
shlq $0x4, %rcx
fldt (%rax,%rcx)
fstpt (%rsp)
callq 0x40f0
jmp 0x29e21
movl %esi, %r12d
movl %ebp, %r13d
movq (%r8), %rax
movq %r13, %rcx
shlq $0x4, %rcx
fldt (%rax,%rcx)
fstpt (%rsp)
callq 0x40f0
cmpl %r12d, %ebp
je 0x29e21
movq (%r15), %rax
movq %r13, %rcx
shlq $0x4, %rcx
fstpt 0x1c(%rsp)
fldt -0x10(%rax,%rcx)
fstpt (%rsp)
callq 0x40f0
fld1
fsub %st, %st(1)
fldt 0x1c(%rsp)
fmulp %st, %st(2)
fldt 0x10(%r14)
fldz
fxch %st(1)
fucompi %st(1), %st
fcmovnbe %st(1), %st
fstp %st(1)
fmulp %st, %st(1)
movq (%rbx), %rax
shlq $0x4, %r13
fstpt (%rax,%r13)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop