// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movl -0x4(%rbp), %eax
movq -0x10(%rbp), %rcx
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jl 0x5a087
movl -0x4(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x5a09d
movq -0x28(%rbp), %rdi
movslq -0x4(%rbp), %rsi
callq 0x34c70
fldz
fstpt (%rax)
jmp 0x5a1b9
movl -0x4(%rbp), %eax
movq -0x10(%rbp), %rcx
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jne 0x5a0de
movq -0x20(%rbp), %rdi
movslq -0x4(%rbp), %rsi
callq 0x34c70
fldt (%rax)
movq %rsp, %rax
fstpt (%rax)
callq 0x5d870
fstpt -0x3c(%rbp)
movq -0x28(%rbp), %rdi
movslq -0x4(%rbp), %rsi
callq 0x34c70
fldt -0x3c(%rbp)
fstpt (%rax)
jmp 0x5a1b7
movl -0x4(%rbp), %eax
cmpl -0x8(%rbp), %eax
jne 0x5a119
movq -0x20(%rbp), %rdi
movslq -0x4(%rbp), %rsi
callq 0x34c70
fldt (%rax)
movq %rsp, %rax
fstpt (%rax)
callq 0x5d870
fstpt -0x48(%rbp)
movq -0x28(%rbp), %rdi
movslq -0x4(%rbp), %rsi
callq 0x34c70
fldt -0x48(%rbp)
fstpt (%rax)
jmp 0x5a1b5
movq -0x20(%rbp), %rdi
movslq -0x4(%rbp), %rsi
callq 0x34c70
fldt (%rax)
movq %rsp, %rax
fstpt (%rax)
callq 0x5d870
fstpt -0x70(%rbp)
movq -0x18(%rbp), %rdi
movl -0x4(%rbp), %eax
decl %eax
movslq %eax, %rsi
callq 0x34c70
fldt (%rax)
movq %rsp, %rax
fstpt (%rax)
callq 0x5d870
fldt -0x70(%rbp)
fld1
fsubp %st, %st(2)
fmulp %st, %st(1)
fstpt -0x64(%rbp)
movq -0x10(%rbp), %rax
fldt 0x10(%rax)
fldz
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
movsd 0x49cb(%rip), %xmm0     # 0x5eb40
xorps %xmm1, %xmm1
movsd %xmm1, -0x58(%rbp)
movsd %xmm0, -0x50(%rbp)
ja 0x5a18e
movsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
fldt -0x64(%rbp)
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
fldl -0x30(%rbp)
fmulp %st, %st(1)
fstpt -0x7c(%rbp)
movq -0x28(%rbp), %rdi
movslq -0x4(%rbp), %rsi
callq 0x34c70
fldt -0x7c(%rbp)
fstpt (%rax)
jmp 0x5a1b7
jmp 0x5a1b9
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)