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

    // aux. arrays used in fp rate calculation:
    //  - P(|FP| =/= f) = (1.0 - P(|FP| = f)) : prob of not having an fp match of size f
    std::vector<__float080> log_prob_fp_neq(n, 0.0);
    //  - P(|FP| <= f) : prob of fp match smaller than or equal to f
    std::vector<__float080> log_prob_fp_smeq(n + 1, 0.0);

    if (iface_fp_data->is_blocked) { (*lmp)[0] = 1.0; return 0; }
    if (iface_fp_data->num_entries < 1.0) { (*lmp)[0] = 1.0; return 0; }

    // fill P(|FP| =/= f) = (1.0 - P(|FP| = f)), for all f
    std::vector<__float080> lt_ratios = std::vector<__float080>(n, 1.0);
    calc_log_prob_fp_neq(iface_fp_data, log_prob_fp_neq, lt_ratios);
    // calc P(|FP| <= f), for all f
    for (int f = (int) (this->n - 1); f >= 0; f--)
        log_prob_fp_smeq[f] = log_prob_fp_smeq[f + 1] + log_prob_fp_neq[f];

    for (int f = (int) this->n; f >= 0; f--) {

        _calc_lm_prob(
            f, t, 
            iface_fp_data, 
            &log_prob_fp_neq, &log_prob_fp_smeq,
            lmp);
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %r8, %rbx
movq %rdi, %r15
fldt 0x90(%rdi)
flds 0x6781(%rip)            # 0x305e0
fld %st(0)
fstpt 0x94(%rsp)
xorl %esi, %esi
fucomi %st(1), %st
setbe %sil
fldz
fld %st(0)
fld %st(1)
fstpt 0x88(%rsp)
fcmovbe %st(2), %st
fstp %st(2)
fxch %st(2)
fsubp %st, %st(1)
fnstcw 0xa(%rsp)
movzwl 0xa(%rsp), %eax
orl $0xc00, %eax            # imm = 0xC00
movw %ax, 0x14(%rsp)
fldcw 0x14(%rsp)
movq %rcx, %r14
movl %edx, %ebp
fistpll 0x78(%rsp)
fldcw 0xa(%rsp)
shlq $0x3f, %rsi
xorq 0x78(%rsp), %rsi
fstpt 0x40(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x40(%rsp), %rdx
leaq 0x20(%rsp), %rcx
callq 0x1d906
fldt 0x90(%r15)
fld1
faddp %st, %st(1)
xorl %esi, %esi
fldt 0x94(%rsp)
fxch %st(1)
fucomi %st(1), %st
fldt 0x88(%rsp)
fld %st(0)
fcmovnb %st(3), %st
fstp %st(3)
fxch %st(1)
fsubp %st, %st(2)
setae %sil
fnstcw 0x8(%rsp)
movzwl 0x8(%rsp), %eax
orl $0xc00, %eax            # imm = 0xC00
movw %ax, 0x12(%rsp)
fldcw 0x12(%rsp)
fxch %st(1)
fistpll 0x80(%rsp)
fldcw 0x8(%rsp)
shlq $0x3f, %rsi
xorq 0x80(%rsp), %rsi
fstpt 0x20(%rsp)
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rdx
leaq 0xa0(%rsp), %rcx
callq 0x1d906
cmpb $0x1, 0xb8(%r14)
jne 0x29f53
movq (%rbx), %rax
fld1
jmp 0x29f62
fldt 0x10(%r14)
fld1
fucomi %st(1), %st
fstp %st(1)
jbe 0x29fa6
movq (%rbx), %rax
fstpt (%rax)
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x29f7b
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x43a0
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x29f92
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x43a0
xorl %eax, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
fstp %st(0)
fldt 0x90(%r15)
flds 0x662b(%rip)            # 0x305e0
xorl %esi, %esi
fucomi %st(1), %st
setbe %sil
fldz
fcmovbe %st(1), %st
fstp %st(1)
fsubrp %st, %st(1)
fnstcw 0x6(%rsp)
movzwl 0x6(%rsp), %eax
orl $0xc00, %eax            # imm = 0xC00
movw %ax, 0x10(%rsp)
fldcw 0x10(%rsp)
fistpll 0x70(%rsp)
fldcw 0x6(%rsp)
shlq $0x3f, %rsi
xorq 0x70(%rsp), %rsi
fld1
fstpt 0xa0(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0xa0(%rsp), %rdx
leaq 0x17(%rsp), %rcx
callq 0x1d906
leaq 0xb0(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x1e0c8
leaq 0x58(%rsp), %rdx
leaq 0xb0(%rsp), %r12
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rcx
callq 0x2998e
movq (%r12), %rdi
testq %rdi, %rdi
je 0x2a053
movq 0xc0(%rsp), %rsi
subq %rdi, %rsi
callq 0x43a0
fldt 0x90(%r15)
fld1
fchs
fadd %st(1), %st
fnstcw 0x4(%rsp)
movzwl 0x4(%rsp), %eax
orl $0xc00, %eax            # imm = 0xC00
movw %ax, 0xe(%rsp)
fldcw 0xe(%rsp)
fistpl 0x1c(%rsp)
fldcw 0x4(%rsp)
movl 0x1c(%rsp), %edx
testl %edx, %edx
js 0x2a0ba
fstp %st(0)
movq 0x40(%rsp), %rax
movq 0x58(%rsp), %rcx
movl %edx, %edx
shlq $0x4, %rdx
fldt 0x10(%rax,%rdx)
fldt (%rcx,%rdx)
faddp %st, %st(1)
fld %st(0)
fstpt (%rax,%rdx)
addq $-0x10, %rdx
cmpq $-0x10, %rdx
jne 0x2a09d
fstp %st(0)
fldt 0x90(%r15)
fnstcw 0x2(%rsp)
movzwl 0x2(%rsp), %eax
orl $0xc00, %eax            # imm = 0xC00
movw %ax, 0xc(%rsp)
fldcw 0xc(%rsp)
fistpl 0x18(%rsp)
fldcw 0x2(%rsp)
movl 0x18(%rsp), %r15d
testl %r15d, %r15d
js 0x2a10d
movzbl %bpl, %ebp
leaq 0x58(%rsp), %r12
leaq 0x40(%rsp), %r13
movl %r15d, %edi
movl %ebp, %esi
movq %r14, %rdx
movq %r12, %rcx
movq %r13, %r8
movq %rbx, %r9
callq 0x29d7e
addl $-0x1, %r15d
jb 0x2a0f1
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x29f64
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x43a0
jmp 0x29f64
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2a14c
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x43a0
jmp 0x2a14c
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x2a168
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x43a0
jmp 0x2a168
movq %rax, %rbx
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x2a17f
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x43a0
movq %rbx, %rdi
callq 0x4700
nop