// File: /workspace/github_cpp_makefile_star2_O3/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, 0x40(%rsp)
movq (%rdx), %rax
movq 0x8(%rdx), %rcx
cmpq %rcx, %rax
je 0x29b57
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
fldz
movq %rax, %rdx
fld %st(0)
fstpt (%rdx)
addq $0x10, %rdx
cmpq %rcx, %rdx
jne 0x299bf
fstp %st(0)
cmpq %rcx, %rax
je 0x29b57
movb $0x1, %dl
xorl %ebx, %ebx
movzbl %dl, %edx
fldt 0x10(%r15)
movq 0x30(%r15), %rax
movq %rbx, %rbp
shlq $0x4, %rbp
fldt (%rax,%rbp)
fmulp %st, %st(1)
movq 0x40(%rsp), %rax
movq (%rax), %rax
fldt (%rax,%rbp)
fmulp %st, %st(1)
testq %rbx, %rbx
movq %rdx, 0x48(%rsp)
fld %st(0)
fstpt 0x34(%rsp)
je 0x29ad2
movq 0x48(%r15), %rax
movq %rdx, %rcx
fldz
fldt (%rax)
faddp %st, %st(1)
addq $0x10, %rax
decq %rcx
jne 0x29a1c
xorl %r13d, %r13d
fld %st(0)
fstpt 0x50(%rsp)
movzbl %r13b, %r13d
movq 0x48(%r15), %rax
movl %r13d, %ecx
shll $0x4, %ecx
fldt (%rax,%rcx)
fdivp %st, %st(1)
fmulp %st, %st(1)
fstpt 0x28(%rsp)
fldt 0x80(%r12)
fldt 0x90(%r12)
fldt 0xa0(%r12)
fld %st(0)
fstpt 0x5c(%rsp)
leal 0x1(%r13), %eax
movl %eax, 0x24(%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 0x24(%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,%rbp)
fldt 0x28(%rsp)
fmulp %st, %st(3)
faddp %st, %st(2)
fldt 0x34(%rsp)
fxch %st(2)
fstpt (%rax,%rbp)
incb %r13b
movzbl %r13b, %ecx
cmpq %rcx, %rbx
jae 0x29a32
jmp 0x29b35
fstp %st(0)
fldt 0x80(%r12)
fldt 0x90(%r12)
fldt 0xa0(%r12)
fld %st(0)
fstpt 0x28(%rsp)
fxch %st(1)
fchs
fdivp %st, %st(2)
fmulp %st, %st(1)
fstpt (%rsp)
callq 0x40f0
fld1
fsubp %st, %st(1)
fldt 0x28(%rsp)
fstpt 0x10(%rsp)
fstpt (%rsp)
callq 0x4670
fld1
fsubp %st, %st(1)
fstpt (%rsp)
callq 0x41e0
movq (%r14), %rax
fldt (%rax)
fldt 0x34(%rsp)
fmulp %st, %st(2)
faddp %st, %st(1)
fstpt (%rax)
fldz
fldz
fstp %st(1)
fstp %st(0)
incq %rbx
movq 0x8(%r14), %rcx
subq %rax, %rcx
sarq $0x4, %rcx
movq 0x48(%rsp), %rdx
incb %dl
cmpq %rbx, %rcx
ja 0x299db
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq