// File: /workspace/github_cpp_makefile_star2_O1/adamiaonr[P]rid-analytics/src/prob.cpp
// Function: Prob::calc_log_prob_fp_neq(Prob::fp_data*, std::vector<long double, std::allocator<long double>>&, std::vector<long double, std::allocator<long double>>)
void Prob::calc_log_prob_fp_neq(
    Prob::fp_data * iface_fp_data,
    std::vector<__float080> & log_prob_fp_neq,
    std::vector<__float080> lt_ratios) {

    // as a precaution, reset log_prob_fp_neq to 0.0
    std::fill(log_prob_fp_neq.begin(), log_prob_fp_neq.end(), 0.0);

    for (uint8_t f = 0; f < log_prob_fp_neq.size(); f++) {

        // total nr. of entries w/ size f
        __float080 num_entries = iface_fp_data->num_entries * iface_fp_data->f_distr[f] * lt_ratios[f];
        // std::cout << "Prob::calc_log_prob_fp_neq() : num_entries[" << f << "] = " 
        //     << num_entries << " (out of " << iface_fp_data->num_entries << ")" << std::endl;

        if (f == 0) {
            
            log_prob_fp_neq[f] += num_entries * log(1.0 - fp_rate(this->m, this->n, this->k, (__float080) (f + 1)));

        } else {

            // for entries w/ size f, we can have entries w/ |f\r| in the 
            // interval [1, f]. remember: the fp rates vary w/ |f\r|.
            __float080 subtotal_f_r = 0.0;
            // % of entries (of those w/ size = f) which have |f\r| <= f
            for (uint8_t j = 0; j <= f; j++) 
                subtotal_f_r += iface_fp_data->f_r_distr[j];

            for (uint8_t j = 0; j <= f; j++) {
                // total nr. of entries w/ size f and |f\r| = j
                __float080 num_fr_entries = (__float080) num_entries * (iface_fp_data->f_r_distr[j] / subtotal_f_r);
                // fp rate for size f, |f\r| = j
                log_prob_fp_neq[f] += num_fr_entries * log(1.0 - fp_rate(this->m, this->n, this->k, (__float080) (j + 1)));
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rcx, 0x48(%rsp)
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
movq (%rdx), %rax
movq 0x8(%rdx), %rcx
cmpq %rcx, %rax
fldz
je 0x29e9f
fstp %st(0)
fldz
fld %st(0)
fstpt (%rax)
addq $0x10, %rax
cmpq %rcx, %rax
jne 0x29e92
fstp %st(0)
movq 0x8(%r14), %rax
cmpq (%r14), %rax
je 0x2a036
movb $0x1, %cl
xorl %ebx, %ebx
xorl %r13d, %r13d
movb %cl, 0x2b(%rsp)
movzbl %cl, %eax
cmpq $0x1, %rax
adcq $0x0, %rax
fldt 0x10(%r15)
movq 0x30(%r15), %rcx
shlq $0x4, %rbx
fldt (%rcx,%rbx)
fmulp %st, %st(1)
movq 0x48(%rsp), %rcx
movq (%rcx), %rcx
fldt (%rcx,%rbx)
fmulp %st, %st(1)
testb %r13b, %r13b
fld %st(0)
fstpt 0x3c(%rsp)
je 0x29fac
shll $0x4, %eax
movq 0x48(%r15), %rcx
xorl %edx, %edx
fldz
fldt (%rcx,%rdx)
faddp %st, %st(1)
addq $0x10, %rdx
cmpq %rdx, %rax
jne 0x29efc
xorl %ebp, %ebp
fld %st(0)
fstpt 0x50(%rsp)
movzbl %bpl, %ebp
movq 0x48(%r15), %rax
movl %ebp, %ecx
shll $0x4, %ecx
fldt (%rax,%rcx)
fdivp %st, %st(1)
fmulp %st, %st(1)
fstpt 0x30(%rsp)
fldt 0x80(%r12)
fldt 0x90(%r12)
fldt 0xa0(%r12)
fld %st(0)
fstpt 0x5c(%rsp)
leal 0x1(%rbp), %eax
movl %eax, 0x2c(%rsp)
fxch %st(1)
fchs
fdivp %st, %st(2)
fmulp %st, %st(1)
fstpt (%rsp)
callq 0x40f0
fld1
fsubp %st, %st(1)
fldt 0x5c(%rsp)
fimull 0x2c(%rsp)
fstpt 0x10(%rsp)
fstpt (%rsp)
callq 0x4670
fld1
fsubp %st, %st(1)
fstpt (%rsp)
callq 0x41e0
fldt 0x50(%rsp)
movq (%r14), %rax
fldt (%rax,%rbx)
fldt 0x30(%rsp)
fmulp %st, %st(3)
faddp %st, %st(2)
fldt 0x3c(%rsp)
fxch %st(2)
fstpt (%rax,%rbx)
incb %bpl
cmpb %r13b, %bpl
jbe 0x29f12
jmp 0x2a011
fstp %st(0)
fldt 0x80(%r12)
fldt 0x90(%r12)
fldt 0xa0(%r12)
fld %st(0)
fstpt 0x30(%rsp)
fxch %st(1)
fchs
fdivp %st, %st(2)
fmulp %st, %st(1)
fstpt (%rsp)
callq 0x40f0
fld1
fsubp %st, %st(1)
fldt 0x30(%rsp)
fstpt 0x10(%rsp)
fstpt (%rsp)
callq 0x4670
fld1
fsubp %st, %st(1)
fstpt (%rsp)
callq 0x41e0
movq (%r14), %rax
fldt (%rax,%rbx)
fldt 0x3c(%rsp)
fmulp %st, %st(2)
faddp %st, %st(1)
fstpt (%rax,%rbx)
fldz
fldz
fstp %st(1)
fstp %st(0)
incb %r13b
movq 0x8(%r14), %rax
subq (%r14), %rax
movzbl %r13b, %ebx
sarq $0x4, %rax
movb 0x2b(%rsp), %cl
incb %cl
cmpq %rbx, %rax
ja 0x29eb5
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq