// File: 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
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rcx, -0x98(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x18(%rbp), %rdi
callq 0x35440
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
callq 0x35470
movq %rax, -0x30(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq -0x38(%rbp), %rdx
callq 0x5d8a0
movb $0x0, -0x39(%rbp)
movzbl -0x39(%rbp), %eax
movq %rax, -0xa0(%rbp)
movq -0x18(%rbp), %rdi
callq 0x355f0
movq %rax, %rcx
movq -0xa0(%rbp), %rax
cmpq %rcx, %rax
jae 0x59ded
movq -0x10(%rbp), %rdi
fldt 0x10(%rdi)
fstpt -0xb8(%rbp)
addq $0x30, %rdi
movzbl -0x39(%rbp), %eax
movl %eax, %esi
callq 0x34c70
fldt -0xb8(%rbp)
movq -0x98(%rbp), %rdi
fldt (%rax)
fmulp %st, %st(1)
fstpt -0xac(%rbp)
movzbl -0x39(%rbp), %eax
movl %eax, %esi
callq 0x34c70
fldt -0xac(%rbp)
fldt (%rax)
fmulp %st, %st(1)
fstpt -0x50(%rbp)
movzbl -0x39(%rbp), %eax
cmpl $0x0, %eax
jne 0x59cc8
movq -0x90(%rbp), %rax
fldt -0x50(%rbp)
fstpt -0xc4(%rbp)
fldt 0x80(%rax)
fldt 0x90(%rax)
fldt 0xa0(%rax)
movzbl -0x39(%rbp), %eax
incl %eax
movl %eax, -0x88(%rbp)
fildl -0x88(%rbp)
movq %rsp, %rax
fstpt 0x30(%rax)
fstpt 0x20(%rax)
fstpt 0x10(%rax)
fstpt (%rax)
callq 0x59a90
fld1
fsubp %st, %st(1)
movq %rsp, %rax
fstpt (%rax)
callq 0x5d8e0
fstpt -0xd0(%rbp)
movq -0x18(%rbp), %rdi
movzbl -0x39(%rbp), %eax
movl %eax, %esi
callq 0x34c70
fldt -0xd0(%rbp)
fldt -0xc4(%rbp)
fldt (%rax)
fxch %st(1)
fmulp %st, %st(2)
faddp %st, %st(1)
fstpt (%rax)
jmp 0x59dde
fldz
fstpt -0x60(%rbp)
movb $0x0, -0x61(%rbp)
movzbl -0x61(%rbp), %eax
movzbl -0x39(%rbp), %ecx
cmpl %ecx, %eax
jg 0x59d04
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
movzbl -0x61(%rbp), %eax
movl %eax, %esi
callq 0x34c70
fldt (%rax)
fldt -0x60(%rbp)
faddp %st, %st(1)
fstpt -0x60(%rbp)
movb -0x61(%rbp), %al
addb $0x1, %al
movb %al, -0x61(%rbp)
jmp 0x59cd1
movb $0x0, -0x62(%rbp)
movzbl -0x62(%rbp), %eax
movzbl -0x39(%rbp), %ecx
cmpl %ecx, %eax
jg 0x59ddc
fldt -0x50(%rbp)
fstpt -0xf4(%rbp)
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
movzbl -0x62(%rbp), %eax
movl %eax, %esi
callq 0x34c70
fldt -0xf4(%rbp)
movq %rax, %rcx
movq -0x90(%rbp), %rax
fldt (%rcx)
fldt -0x60(%rbp)
fdivrp %st, %st(1)
fmulp %st, %st(1)
fstpt -0x80(%rbp)
fldt -0x80(%rbp)
fstpt -0xdc(%rbp)
fldt 0x80(%rax)
fldt 0x90(%rax)
fldt 0xa0(%rax)
movzbl -0x62(%rbp), %eax
incl %eax
movl %eax, -0x84(%rbp)
fildl -0x84(%rbp)
movq %rsp, %rax
fxch %st(1)
fstpt 0x20(%rax)
fxch %st(1)
fstpt 0x10(%rax)
fxch %st(1)
fstpt (%rax)
fstpt 0x30(%rax)
callq 0x59a90
fld1
fsubp %st, %st(1)
movq %rsp, %rax
fstpt (%rax)
callq 0x5d8e0
fstpt -0xe8(%rbp)
movq -0x18(%rbp), %rdi
movzbl -0x39(%rbp), %eax
movl %eax, %esi
callq 0x34c70
fldt -0xe8(%rbp)
fldt -0xdc(%rbp)
fldt (%rax)
fxch %st(1)
fmulp %st, %st(2)
faddp %st, %st(1)
fstpt (%rax)
movb -0x62(%rbp), %al
addb $0x1, %al
movb %al, -0x62(%rbp)
jmp 0x59d08
jmp 0x59dde
jmp 0x59de0
movb -0x39(%rbp), %al
addb $0x1, %al
movb %al, -0x39(%rbp)
jmp 0x59bc4
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nopw %cs:(%rax,%rax)