// File: /workspace/github_cpp_makefile_star2_O3/adamiaonr[P]rid-analytics/src/prob.cpp
// Function: Prob::calc_probs(std::vector<std::vector<Prob::fp_data*, std::allocator<Prob::fp_data*>>, std::allocator<std::vector<Prob::fp_data*, std::allocator<Prob::fp_data*>>>>*, std::map<int, std::vector<unsigned char, std::allocator<unsigned char>>, std::less<int>, std::allocator<std::pair<int const, std::vector<unsigned char, std::allocator<unsigned char>>>>>*, long double, std::vector<long double, std::allocator<long double>>*, std::vector<std::vector<long double, std::allocator<long double>>, std::allocator<std::vector<long double, std::allocator<long double>>>>&, std::vector<std::vector<long double, std::allocator<long double>>, std::allocator<std::vector<long double, std::allocator<long double>>>>&)
int Prob::calc_probs(
    std::vector<std::vector<Prob::fp_data *> > * iface_fp_data,
    std::map<int, std::vector<uint8_t> > * tree_bitmasks,    // tree bitmasks from prev router
    __float080 in_prob,
    std::vector<__float080> * in_fptree_prob,
    std::vector<std::vector<__float080> > & iface_probs,
    std::vector<std::vector<__float080> > & out_fptree_probs) {

    // calc P(P_i = p) and P(P_{~i} = p)
    // time complexity : O(N * I)
    if (calc_fptree_probs(iface_fp_data, tree_bitmasks, in_fptree_prob) < 0)
        return -1;
    // if (calc_fptree_probs(iface_fp_data, tree_bitmask, in_fptree_prob, true) < 0)
    //     return -1;

    // calc P(L_i = l | P_i = p) and P(L_{~i} = l | P_{~i} = p)
    // time complexity : O(N^2 * I)
    for (unsigned i = 0; i < this->iface_num; i++) {
        this->lm_cond_prob.push_back(std::vector<std::vector<__float080> > ((n + 1), std::vector<__float080> ((n + 1), 0.0)));
        this->lm_complement_cond_prob.push_back(std::vector<std::vector<__float080> > ((n + 1), std::vector<__float080> ((n + 1), 0.0)));
    }

    if (calc_lm_probs(iface_fp_data, tree_bitmasks) < 0) 
        return -1;

    // calc P(iface = i)
    // time complexity : O(N^2 * I)

    //  - P(L_i = l) and P(L_{~i} = l)
    this->lm_marg_prob = std::vector<std::vector<__float080> >((this->iface_num), std::vector<__float080> ((this->n + 1), 0.0));
    this->lm_complement_marg_prob = std::vector<std::vector<__float080> >((this->iface_num), std::vector<__float080> ((this->n + 1), 0.0));

    for (uint8_t i = 0; i < this->iface_num; i++) {

        calc_iface_prob(i, iface_fp_data, in_fptree_prob, iface_probs[i]);
        // for joint event '& got into this router'
        iface_probs[i][0] *= in_prob;
        iface_probs[i][1] *= in_prob;
        iface_probs[i][2] *= in_prob;
    }

    // calc P(T_{out,i} = t)
    // for joint event '& got into this router
    for (uint8_t i = 0; i < this->iface_num; i++) {

        // std::fill(out_fptree_probs[i].begin(), out_fptree_probs[i].end(), 0.0);
        // out_fptree_probs[i][0] = 1.0;
        calc_out_fptree_prob(i, (*iface_fp_data)[0][i], tree_bitmasks, in_fptree_prob, out_fptree_probs);

        // std::cout << "Prob::calc_out_fptree_prob() : P(T_{out," << (int) i << "} = t) :" << std::endl;
        for (uint8_t t = 0; t <= this->n; t++) {
            out_fptree_probs[i][t] *= in_prob;
            // std::cout << "\tP(T_{out," << (int) i << "} = " << (int) t << ") = " << out_fptree_probs[i][t] << std::endl;
        }
    }

    // clear the conditional and marginal probability placeholder vectors
    this->lm_cond_prob.clear();
    this->lm_complement_cond_prob.clear();
    this->lm_marg_prob.clear();
    this->lm_complement_marg_prob.clear();

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %r9, 0x98(%rsp)
movq %r8, 0x88(%rsp)
movq %rdi, %rbx
fldt 0x120(%rsp)
fstpt 0x64(%rsp)
movq %rsi, 0xa0(%rsp)
movq %rcx, 0x90(%rsp)
callq 0x2acbc
cmpb $0x0, 0xb0(%rbx)
je 0x2b7d6
leaq 0x18(%rbx), %rax
movq %rax, 0xa8(%rsp)
xorl %r15d, %r15d
leaq 0x40(%rsp), %r14
leaq 0xd0(%rsp), %r12
leaq 0xc(%rsp), %rbp
fldt 0x90(%rbx)
fld1
faddp %st, %st(1)
flds 0x4f68(%rip)            # 0x305e0
xorl %r13d, %r13d
fxch %st(1)
fucomi %st(1), %st
fldz
fld %st(0)
fcmovnb %st(3), %st
fstp %st(3)
fxch %st(1)
fsubp %st, %st(2)
setae %r13b
fnstcw 0x12(%rsp)
movzwl 0x12(%rsp), %eax
orl $0xc00, %eax            # imm = 0xC00
movw %ax, 0x1a(%rsp)
fldcw 0x1a(%rsp)
fxch %st(1)
fistpll 0xc8(%rsp)
fldcw 0x12(%rsp)
shlq $0x3f, %r13
xorq 0xc8(%rsp), %r13
fstpt 0x20(%rsp)
movq %r14, %rdi
movq %r13, %rsi
leaq 0x20(%rsp), %rdx
leaq 0x70(%rsp), %rcx
callq 0x1d906
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x1dca0
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1ddd4
movq %r12, %rdi
callq 0x1dd38
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x2b713
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x43a0
fldt 0x90(%rbx)
fld1
faddp %st, %st(1)
flds 0x4ebd(%rip)            # 0x305e0
xorl %r13d, %r13d
fxch %st(1)
fucomi %st(1), %st
fldz
fld %st(0)
fcmovnb %st(3), %st
fstp %st(3)
fxch %st(1)
fsubp %st, %st(2)
setae %r13b
fnstcw 0x10(%rsp)
movzwl 0x10(%rsp), %eax
orl $0xc00, %eax            # imm = 0xC00
movw %ax, 0x18(%rsp)
fldcw 0x18(%rsp)
fxch %st(1)
fistpll 0xc0(%rsp)
fldcw 0x10(%rsp)
shlq $0x3f, %r13
xorq 0xc0(%rsp), %r13
fstpt 0x20(%rsp)
movq %r14, %rdi
movq %r13, %rsi
leaq 0x20(%rsp), %rdx
leaq 0x70(%rsp), %rcx
callq 0x1d906
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x1dca0
movq 0xa8(%rsp), %rdi
movq %r12, %rsi
callq 0x1ddd4
movq %r12, %rdi
callq 0x1dd38
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x2b7c3
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x43a0
incl %r15d
movzbl 0xb0(%rbx), %eax
cmpl %eax, %r15d
jb 0x2b668
movq %rbx, %rdi
movq 0xa0(%rsp), %rbp
movq %rbp, %rsi
callq 0x2a674
fldt 0x90(%rbx)
fld1
faddp %st, %st(1)
flds 0x4de7(%rip)            # 0x305e0
xorl %esi, %esi
fxch %st(1)
fucomi %st(1), %st
fldz
fld %st(0)
fcmovnb %st(3), %st
fstp %st(3)
movzbl 0xb0(%rbx), %r14d
fxch %st(1)
fsubp %st, %st(2)
setae %sil
fnstcw 0x14(%rsp)
movzwl 0x14(%rsp), %eax
orl $0xc00, %eax            # imm = 0xC00
movw %ax, 0x1c(%rsp)
fldcw 0x1c(%rsp)
fxch %st(1)
fistpll 0xb8(%rsp)
fldcw 0x14(%rsp)
shlq $0x3f, %rsi
xorq 0xb8(%rsp), %rsi
fstpt 0x70(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x70(%rsp), %rdx
leaq 0xc(%rsp), %rcx
callq 0x1d906
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rdx
leaq 0xd(%rsp), %rcx
movq %r14, %rsi
callq 0x1dca0
movq 0x40(%rbx), %rax
leaq 0x40(%rsp), %r14
movaps (%r14), %xmm0
movq 0x10(%r14), %rcx
movq %rcx, 0x40(%rbx)
movaps 0x30(%rbx), %xmm1
movaps %xmm0, 0x30(%rbx)
leaq 0xd0(%rsp), %rdi
movaps %xmm1, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
movq $0x0, 0x10(%r14)
callq 0x1dd38
movq %r14, %rdi
callq 0x1dd38
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2b8d5
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x43a0
fldt 0x90(%rbx)
fld1
faddp %st, %st(1)
flds 0x4cfb(%rip)            # 0x305e0
xorl %esi, %esi
fxch %st(1)
fucomi %st(1), %st
fldz
fld %st(0)
fcmovnb %st(3), %st
fstp %st(3)
movzbl 0xb0(%rbx), %r14d
fxch %st(1)
fsubp %st, %st(2)
setae %sil
fnstcw 0xe(%rsp)
movzwl 0xe(%rsp), %eax
orl $0xc00, %eax            # imm = 0xC00
movw %ax, 0x16(%rsp)
fldcw 0x16(%rsp)
fxch %st(1)
fistpll 0xb0(%rsp)
fldcw 0xe(%rsp)
shlq $0x3f, %rsi
xorq 0xb0(%rsp), %rsi
fstpt 0x70(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x70(%rsp), %rdx
leaq 0xc(%rsp), %rcx
callq 0x1d906
movq 0x98(%rsp), %r12
movq 0x90(%rsp), %r13
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rdx
leaq 0xd(%rsp), %rcx
movq %r14, %rsi
callq 0x1dca0
movq 0x58(%rbx), %rax
leaq 0x40(%rsp), %r14
movaps (%r14), %xmm0
movq 0x10(%r14), %rcx
movq %rcx, 0x58(%rbx)
movups 0x48(%rbx), %xmm1
movups %xmm0, 0x48(%rbx)
leaq 0xd0(%rsp), %rdi
movaps %xmm1, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
movq $0x0, 0x10(%r14)
callq 0x1dd38
movq %r14, %rdi
callq 0x1dd38
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2b9d1
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x43a0
cmpb $0x0, 0xb0(%rbx)
je 0x2bac9
movq 0x88(%rsp), %rax
movq (%rax), %r8
xorl %r14d, %r14d
xorl %r15d, %r15d
fldt 0x64(%rsp)
fstp %st(0)
addq %r14, %r8
movzbl %r15b, %esi
movq %rbx, %rdi
movq %rbp, %rdx
movq %r13, %rcx
callq 0x2b0aa
movq 0x88(%rsp), %rax
movq (%rax), %r8
movq (%r8,%r14), %rax
fldt (%rax)
fldt 0x64(%rsp)
fmul %st, %st(1)
fxch %st(1)
fstpt (%rax)
fldt 0x10(%rax)
fmul %st(1), %st
fstpt 0x10(%rax)
fldt 0x20(%rax)
fmulp %st, %st(1)
fstpt 0x20(%rax)
incq %r15
movzbl 0xb0(%rbx), %eax
addq $0x18, %r14
cmpq %rax, %r15
jb 0x2b9f5
testb %al, %al
je 0x2bac9
xorl %r14d, %r14d
movq (%rbp), %rax
movq (%rax), %rax
movq (%rax,%r14,8), %rdx
movzbl %r14b, %esi
movq %rbx, %rdi
movq %r13, %r8
movq %r12, %r9
callq 0x2a6e0
fldt 0x90(%rbx)
fldz
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
fldt 0x64(%rsp)
jb 0x2bab8
movq (%r12), %rax
leaq (%r14,%r14,2), %rcx
movq (%rax,%rcx,8), %rax
xorl %ecx, %ecx
movzbl %cl, %ecx
movl %ecx, %edx
shll $0x4, %edx
fldt (%rax,%rdx)
fmul %st(1), %st
fstpt (%rax,%rdx)
incb %cl
movzbl %cl, %edx
movw %dx, 0x1e(%rsp)
filds 0x1e(%rsp)
fldt 0x90(%rbx)
fucompi %st(1), %st
fstp %st(0)
jae 0x2ba8e
fstp %st(0)
incq %r14
movzbl 0xb0(%rbx), %eax
cmpq %rax, %r14
jb 0x2ba4f
movq (%rbx), %r15
movq 0x8(%rbx), %r12
cmpq %r15, %r12
je 0x2baed
movq %r15, %r14
movq %r14, %rdi
callq 0x1dd38
addq $0x18, %r14
cmpq %r12, %r14
jne 0x2bad8
movq %r15, 0x8(%rbx)
leaq 0x30(%rbx), %r15
leaq 0x48(%rbx), %r14
movq 0x18(%rbx), %r13
movq 0x20(%rbx), %rbp
cmpq %r13, %rbp
je 0x2bb1a
movq %r13, %r12
movq %r12, %rdi
callq 0x1dd38
addq $0x18, %r12
cmpq %rbp, %r12
jne 0x2bb05
movq %r13, 0x20(%rbx)
movq (%r15), %rsi
movq %r15, %rdi
callq 0x2be8a
movq (%r14), %rsi
movq %r14, %rdi
callq 0x2be8a
xorl %eax, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2bb48
jmp 0x2bb64
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2bb95
movq 0x30(%rsp), %rsi
jmp 0x2bb8d
jmp 0x2bb64
jmp 0x2bb64
jmp 0x2bb69
jmp 0x2bb6e
movq %rax, %rbx
jmp 0x2bb95
movq %rax, %rbx
jmp 0x2bb7e
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x1dd38
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x2bb95
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x43a0
movq %rbx, %rdi
callq 0x4700
nop