// File: /workspace/github_cpp_makefile_star2_O2/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 $0xc8, %rsp
movq %r9, 0x88(%rsp)
movq %r8, 0xa0(%rsp)
movq %rdi, %r15
fldt 0x100(%rsp)
fstpt 0x54(%rsp)
movq %rsi, 0x98(%rsp)
movq %rcx, 0x90(%rsp)
callq 0x24434
leaq 0x18(%r15), %rax
movq %rax, 0x48(%rsp)
xorl %r14d, %r14d
leaq 0x30(%rsp), %r13
leaq 0x60(%rsp), %r12
leaq 0xd(%rsp), %rbp
movzbl 0xb0(%r15), %eax
cmpl %eax, %r14d
jae 0x24dbc
fldt 0x90(%r15)
fld1
faddp %st, %st(1)
flds 0x5b13(%rip)            # 0x2a7a0
xorl %ebx, %ebx
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 %bl
fnstcw 0x12(%rsp)
movzwl 0x12(%rsp), %eax
orl $0xc00, %eax            # imm = 0xC00
movw %ax, 0x1a(%rsp)
fldcw 0x1a(%rsp)
fxch %st(1)
fistpll 0xb0(%rsp)
fldcw 0x12(%rsp)
shlq $0x3f, %rbx
xorq 0xb0(%rsp), %rbx
fstpt 0x20(%rsp)
movq %r13, %rdi
movq %rbx, %rsi
leaq 0x20(%rsp), %rdx
leaq 0xc(%rsp), %rcx
callq 0x18df8
movq %r12, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %rbp, %rcx
callq 0x1918c
movq %r15, %rdi
movq %r12, %rsi
callq 0x19226
movq %r12, %rdi
callq 0x191e2
movq %r13, %rdi
callq 0x195d0
fldt 0x90(%r15)
fld1
faddp %st, %st(1)
flds 0x5a78(%rip)            # 0x2a7a0
xorl %ebx, %ebx
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 %bl
fnstcw 0x10(%rsp)
movzwl 0x10(%rsp), %eax
orl $0xc00, %eax            # imm = 0xC00
movw %ax, 0x18(%rsp)
fldcw 0x18(%rsp)
fxch %st(1)
fistpll 0xa8(%rsp)
fldcw 0x10(%rsp)
shlq $0x3f, %rbx
xorq 0xa8(%rsp), %rbx
fstpt 0x20(%rsp)
movq %r13, %rdi
movq %rbx, %rsi
leaq 0x20(%rsp), %rdx
leaq 0xc(%rsp), %rcx
callq 0x18df8
movq %r12, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %rbp, %rcx
callq 0x1918c
movq 0x48(%rsp), %rdi
movq %r12, %rsi
callq 0x19226
movq %r12, %rdi
callq 0x191e2
movq %r13, %rdi
callq 0x195d0
incl %r14d
jmp 0x24c6b
movq %r15, %rdi
movq 0x98(%rsp), %rbp
movq %rbp, %rsi
callq 0x23ee6
fldt 0x90(%r15)
fld1
faddp %st, %st(1)
flds 0x59c0(%rip)            # 0x2a7a0
xorl %esi, %esi
fxch %st(1)
fucomi %st(1), %st
fldz
fld %st(0)
fcmovnb %st(3), %st
fstp %st(3)
movzbl 0xb0(%r15), %ebx
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 0xc0(%rsp)
fldcw 0x14(%rsp)
shlq $0x3f, %rsi
xorq 0xc0(%rsp), %rsi
fstpt 0x20(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x20(%rsp), %rdx
leaq 0xc(%rsp), %rcx
callq 0x18df8
leaq 0x60(%rsp), %rdi
leaq 0x30(%rsp), %rdx
leaq 0xd(%rsp), %rcx
movq %rbx, %rsi
callq 0x1918c
movq 0x90(%rsp), %r13
leaq 0x30(%r15), %r14
leaq 0x60(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x252fc
movq %rbx, %rdi
callq 0x191e2
leaq 0x30(%rsp), %rdi
callq 0x195d0
fldt 0x90(%r15)
fld1
faddp %st, %st(1)
flds 0x5904(%rip)            # 0x2a7a0
xorl %esi, %esi
fxch %st(1)
fucomi %st(1), %st
fldz
fld %st(0)
fcmovnb %st(3), %st
fstp %st(3)
movzbl 0xb0(%r15), %ebx
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 0xb8(%rsp)
fldcw 0xe(%rsp)
shlq $0x3f, %rsi
xorq 0xb8(%rsp), %rsi
fstpt 0x20(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x20(%rsp), %rdx
leaq 0xc(%rsp), %rcx
callq 0x18df8
movq %r14, 0x80(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x30(%rsp), %rdx
leaq 0xd(%rsp), %rcx
movq %rbx, %rsi
callq 0x1918c
leaq 0x48(%r15), %rdi
leaq 0x60(%rsp), %r14
movq %rdi, 0x78(%rsp)
movq %r14, %rsi
callq 0x252fc
movq %r14, %rdi
callq 0x191e2
leaq 0x30(%rsp), %rdi
callq 0x195d0
xorl %r14d, %r14d
xorl %r12d, %r12d
movq 0xa0(%rsp), %rbx
movzbl 0xb0(%r15), %eax
cmpq %rax, %r12
jae 0x24fa8
movq (%rbx), %r8
addq %r14, %r8
movzbl %r12b, %esi
movq %r15, %rdi
movq %rbp, %rdx
movq %r13, %rcx
callq 0x247a6
movq (%rbx), %rax
movq (%rax,%r14), %rax
fldt (%rax)
fldt 0x54(%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 %r12
addq $0x18, %r14
jmp 0x24f57
xorl %r14d, %r14d
movq 0x88(%rsp), %r12
movzbl %al, %eax
cmpq %rax, %r14
jae 0x25021
movq (%rbp), %rax
movq (%rax), %rax
movq (%rax,%r14,8), %rdx
movzbl %r14b, %esi
movq %r15, %rdi
movq %r13, %r8
movq %r12, %r9
callq 0x23f4c
fldt 0x54(%rsp)
imulq $0x18, %r14, %rax
addq (%r12), %rax
xorl %ecx, %ecx
movzbl %cl, %ecx
movw %cx, 0x1e(%rsp)
filds 0x1e(%rsp)
fldt 0x90(%r15)
fucompi %st(1), %st
fstp %st(0)
jb 0x25013
movq (%rax), %rdx
movl %ecx, %esi
shll $0x4, %esi
fldt (%rdx,%rsi)
fmul %st(1), %st
fstpt (%rdx,%rsi)
incb %cl
jmp 0x24fe6
fstp %st(0)
incq %r14
movb 0xb0(%r15), %al
jmp 0x24fb3
movq %r15, %rdi
callq 0x252ec
movq 0x48(%rsp), %rdi
callq 0x252ec
movq 0x80(%rsp), %rdi
callq 0x252f4
movq 0x78(%rsp), %rdi
callq 0x252f4
xorl %eax, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x25080
jmp 0x2506c
jmp 0x25080
jmp 0x2506c
jmp 0x2506c
jmp 0x25071
jmp 0x25080
movq %rax, %rbx
jmp 0x2508d
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x191e2
jmp 0x25083
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x195d0
movq %rbx, %rdi
callq 0x4700
nop