// File: /workspace/github_cpp_makefile_star2_O1/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 $0xd8, %rsp
movq %r9, 0x88(%rsp)
movq %r8, 0x78(%rsp)
movq %rdi, %rbx
fldt 0x110(%rsp)
fstpt 0x54(%rsp)
movq %rsi, 0x90(%rsp)
movq %rcx, 0x80(%rsp)
callq 0x2b1c2
cmpb $0x0, 0xb0(%rbx)
je 0x2bd05
leaq 0x18(%rbx), %rax
movq %rax, 0x98(%rsp)
xorl %r12d, %r12d
leaq 0x38(%rsp), %r14
leaq 0xc0(%rsp), %r13
leaq 0xc(%rsp), %rbp
fldt 0x90(%rbx)
fld1
faddp %st, %st(1)
flds 0x5c59(%rip)            # 0x31800
xorl %r15d, %r15d
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 %r15b
fnstcw 0x12(%rsp)
movzwl 0x12(%rsp), %eax
orl $0xc00, %eax            # imm = 0xC00
movw %ax, 0x1a(%rsp)
fldcw 0x1a(%rsp)
fxch %st(1)
fistpll 0xb8(%rsp)
fldcw 0x12(%rsp)
shlq $0x3f, %r15
xorq 0xb8(%rsp), %r15
fstpt 0x20(%rsp)
movq %r14, %rdi
movq %r15, %rsi
leaq 0x20(%rsp), %rdx
leaq 0x60(%rsp), %rcx
callq 0x1ddb8
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x1e116
movq %rbx, %rdi
movq %r13, %rsi
callq 0x1e23e
movq %r13, %rdi
callq 0x1e1ae
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x2bc42
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x43a0
fldt 0x90(%rbx)
fld1
faddp %st, %st(1)
flds 0x5bae(%rip)            # 0x31800
xorl %r15d, %r15d
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 %r15b
fnstcw 0x10(%rsp)
movzwl 0x10(%rsp), %eax
orl $0xc00, %eax            # imm = 0xC00
movw %ax, 0x18(%rsp)
fldcw 0x18(%rsp)
fxch %st(1)
fistpll 0xb0(%rsp)
fldcw 0x10(%rsp)
shlq $0x3f, %r15
xorq 0xb0(%rsp), %r15
fstpt 0x20(%rsp)
movq %r14, %rdi
movq %r15, %rsi
leaq 0x20(%rsp), %rdx
leaq 0x60(%rsp), %rcx
callq 0x1ddb8
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x1e116
movq 0x98(%rsp), %rdi
movq %r13, %rsi
callq 0x1e23e
movq %r13, %rdi
callq 0x1e1ae
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x2bcf2
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x43a0
incl %r12d
movzbl 0xb0(%rbx), %eax
cmpl %eax, %r12d
jb 0x2bb97
movq %rbx, %rdi
movq 0x90(%rsp), %rbp
movq %rbp, %rsi
callq 0x2ab74
fldt 0x90(%rbx)
fld1
faddp %st, %st(1)
flds 0x5ad8(%rip)            # 0x31800
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 0xa8(%rsp)
fldcw 0x14(%rsp)
shlq $0x3f, %rsi
xorq 0xa8(%rsp), %rsi
fstpt 0x60(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x60(%rsp), %rdx
leaq 0xc(%rsp), %rcx
callq 0x1ddb8
leaq 0x38(%rsp), %rdi
leaq 0x20(%rsp), %rdx
leaq 0xd(%rsp), %rcx
movq %r14, %rsi
callq 0x1e116
xorps %xmm0, %xmm0
leaq 0xc0(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq 0x30(%rbx), %rax
movups 0x38(%rbx), %xmm0
leaq 0x38(%rsp), %r14
movq (%r14), %rcx
movq %rcx, 0x30(%rbx)
movq 0x8(%r14), %rcx
movq %rcx, 0x38(%rbx)
movq 0x10(%r14), %rcx
movq %rcx, 0x40(%rbx)
movq (%rdi), %rcx
movq 0x8(%rdi), %rdx
movq 0x10(%rdi), %rsi
movq %rax, (%rdi)
movups %xmm0, 0x8(%rdi)
movq %rcx, (%r14)
movq %rdx, 0x8(%r14)
movq %rsi, 0x10(%r14)
callq 0x1e1ae
movq %r14, %rdi
callq 0x1e1ae
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2be20
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x43a0
fldt 0x90(%rbx)
fld1
faddp %st, %st(1)
flds 0x59d0(%rip)            # 0x31800
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 0xa0(%rsp)
fldcw 0xe(%rsp)
shlq $0x3f, %rsi
xorq 0xa0(%rsp), %rsi
fstpt 0x60(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x60(%rsp), %rdx
leaq 0xc(%rsp), %rcx
callq 0x1ddb8
movq 0x88(%rsp), %r12
movq 0x80(%rsp), %r13
leaq 0x38(%rsp), %rdi
leaq 0x20(%rsp), %rdx
leaq 0xd(%rsp), %rcx
movq %r14, %rsi
callq 0x1e116
xorps %xmm0, %xmm0
leaq 0xc0(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq 0x48(%rbx), %rax
movaps 0x50(%rbx), %xmm0
leaq 0x38(%rsp), %r14
movq (%r14), %rcx
movq %rcx, 0x48(%rbx)
movq 0x8(%r14), %rcx
movq %rcx, 0x50(%rbx)
movq 0x10(%r14), %rcx
movq %rcx, 0x58(%rbx)
movq (%rdi), %rcx
movq 0x8(%rdi), %rdx
movq 0x10(%rdi), %rsi
movq %rax, (%rdi)
movups %xmm0, 0x8(%rdi)
movq %rcx, (%r14)
movq %rdx, 0x8(%r14)
movq %rsi, 0x10(%r14)
callq 0x1e1ae
movq %r14, %rdi
callq 0x1e1ae
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2bf38
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x43a0
cmpb $0x0, 0xb0(%rbx)
fldt 0x54(%rsp)
fstp %st(0)
je 0x2bfa3
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0x78(%rsp), %rax
movq (%rax), %r8
addq %r14, %r8
movzbl %r15b, %esi
movq %rbx, %rdi
movq %rbp, %rdx
movq %r13, %rcx
callq 0x2b5be
fldt 0x54(%rsp)
movq 0x78(%rsp), %rax
movq (%rax), %rax
movq (%rax,%r14), %rax
fldt (%rax)
fmul %st(1), %st
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 0x2bf4d
cmpb $0x0, 0xb0(%rbx)
je 0x2c029
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 0x2abe0
fldt 0x90(%rbx)
fldz
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
fldt 0x54(%rsp)
jb 0x2c018
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 0x2bfee
fstp %st(0)
incq %r14
movzbl 0xb0(%rbx), %eax
cmpq %rax, %r14
jb 0x2bfaf
movq (%rbx), %r15
movq 0x8(%rbx), %r12
cmpq %r15, %r12
je 0x2c04d
movq %r15, %r14
movq %r14, %rdi
callq 0x1e1ae
addq $0x18, %r14
cmpq %r12, %r14
jne 0x2c038
movq %r15, 0x8(%rbx)
leaq 0x30(%rbx), %r15
leaq 0x48(%rbx), %r14
movq 0x18(%rbx), %r13
movq 0x20(%rbx), %rbp
cmpq %r13, %rbp
je 0x2c07a
movq %r13, %r12
movq %r12, %rdi
callq 0x1e1ae
addq $0x18, %r12
cmpq %rbp, %r12
jne 0x2c065
movq %r13, 0x20(%rbx)
movq (%r15), %rsi
movq %r15, %rdi
callq 0x2c3d8
movq (%r14), %rsi
movq %r14, %rdi
callq 0x2c3d8
xorl %eax, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2c0a8
jmp 0x2c0c4
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2c0f5
movq 0x30(%rsp), %rsi
jmp 0x2c0ed
jmp 0x2c0c4
jmp 0x2c0c4
jmp 0x2c0c9
jmp 0x2c0ce
movq %rax, %rbx
jmp 0x2c0f5
movq %rax, %rbx
jmp 0x2c0de
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x1e1ae
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x2c0f5
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x43a0
movq %rbx, %rdi
callq 0x4700
nop