// File: /workspace/github_cpp_makefile_star2_O1/adamiaonr[P]rid-analytics/src/rid-analytics.cpp
// Function: RID_Analytics::run_rec(RID_Router*, unsigned char, Path_State*)
int RID_Analytics::run_rec(
    RID_Router * router,
    uint8_t in_iface,
    Path_State * prev_state) {

    std::cout << "\nRID_Analytics::run_rec() : forward operation by router : " 
        << router->get_id() << std::endl;

    uint8_t iface_num = router->get_iface_num();
    __float080 in_prob = prev_state->get_in_iface_prob();
    std::vector<__float080> * in_fptree_prob = prev_state->get_in_fptree_prob();
    // tree bitmask of the path tells us which sources are accessible over 
    // the followed path.
    std::map<int, std::vector<uint8_t> > * tree_bitmasks = prev_state->get_tree_bitmasks();

    // run the forward() operation on this router & collect: 
    //  - iface probs
    //  - event probs
    //  - out fp tree probs 
    std::vector<std::vector<__float080> > iface_probs(iface_num, std::vector<__float080> (3, 0.0));
    std::vector<std::vector<__float080> > out_fptree_probs(iface_num, std::vector<__float080> (this->request_size + 1, 0.0));
    router->forward(
        in_iface,           // INPUTS
        tree_bitmasks,
        in_prob,
        in_fptree_prob,
        iface_probs,        // OUTPUTS
        out_fptree_probs);

    // make fwd decisions
    std::vector<RID_Analytics::fwd_decision> fwd_decisions;
    make_fwd_decision(router, prev_state, in_iface, iface_probs, out_fptree_probs, fwd_decisions);
    // recursively call run_rec() to resume fwd decisions
    for (unsigned int k = 0; k < fwd_decisions.size(); k++) {

        std::cout << "RID_Analytics::run_rec() : [INFO] on router[" << router->get_id() 
            << "], forwarding to router[" << fwd_decisions[k].next_router->get_id() 
            << "], ttl = " << (int) fwd_decisions[k].state->get_ttl() << std::endl;

        run_rec(fwd_decisions[k].next_router, fwd_decisions[k].in_iface, fwd_decisions[k].state);
    }

    delete prev_state;

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rcx, 0x60(%rsp)
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, 0x68(%rsp)
movq 0x184f6(%rip), %rbx     # 0x3ffb8
leaq 0xa9ec(%rip), %rsi      # 0x324b5
movl $0x3a, %edx
movq %rbx, %rdi
callq 0x4400
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq 0x10(%rsp), %r12
movq %r12, %rdi
callq 0x1c27c
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %rbx, %rdi
callq 0x4400
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4370
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42a0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x27b4d
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x43a0
movzbl 0x24(%r14), %ebp
movq 0x60(%rsp), %rbx
movq %rbx, %rdi
callq 0x1f418
fstpt 0xcc(%rsp)
movq %rbx, %rdi
callq 0x1f406
movq %rax, %r12
movq %rbx, %rdi
callq 0x1f442
movq %rax, %r13
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movl $0x30, %edi
callq 0x4390
movq %rax, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movq %rax, %rcx
addq $0x30, %rcx
movq %rcx, 0x20(%rsp)
xorl %edx, %edx
fldz
fld %st(0)
fstpt (%rax,%rdx)
addq $0x10, %rdx
cmpq $0x30, %rdx
jne 0x27bb1
fstp %st(0)
leaq 0x10(%rsp), %rdx
movq %rcx, 0x8(%rdx)
leaq 0xb0(%rsp), %rdi
leaq 0x70(%rsp), %rcx
movq %rbp, %rsi
callq 0x1e116
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x27bf7
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x43a0
movq 0x68(%rsp), %rax
movzbl (%rax), %esi
incq %rsi
fldz
fstpt 0x70(%rsp)
leaq 0x10(%rsp), %rdi
leaq 0x70(%rsp), %rdx
leaq 0x40(%rsp), %rbx
movq %rbx, %rcx
callq 0x1ddb8
leaq 0x98(%rsp), %rdi
leaq 0x10(%rsp), %rdx
leaq 0x3f(%rsp), %rcx
movq %rbp, %rsi
callq 0x1e116
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x27c50
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x43a0
fldt 0xcc(%rsp)
fstpt (%rsp)
movzbl %r15b, %ebp
leaq 0xb0(%rsp), %r8
leaq 0x98(%rsp), %r9
movq %r14, %rdi
movl %ebp, %esi
movq %r13, %rdx
movq %r12, %rcx
callq 0x1cff0
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
leaq 0xf0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x28838
leaq 0xd8(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x28838
movq %rbx, (%rsp)
leaq 0xf0(%rsp), %r8
leaq 0xd8(%rsp), %r9
movq 0x68(%rsp), %rdi
movq %r14, %rsi
movq 0x60(%rsp), %rdx
movl %ebp, %ecx
callq 0x268b2
leaq 0xd8(%rsp), %rdi
callq 0x1e1ae
leaq 0xf0(%rsp), %rdi
callq 0x1e1ae
movq 0x48(%rsp), %rax
cmpq 0x40(%rsp), %rax
je 0x27e81
movl $0x1, %ebp
leaq 0x80(%rsp), %r13
xorl %r15d, %r15d
movq 0x18296(%rip), %r12     # 0x3ffb8
movl $0x2c, %edx
movq %r12, %rdi
leaq 0xa7bf(%rip), %rsi      # 0x324f0
callq 0x4400
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq 0x10(%rsp), %rdi
callq 0x1c27c
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r12, %rdi
callq 0x4400
movq %rax, %rbx
movl $0x18, %edx
movq %rax, %rdi
leaq 0xa7a5(%rip), %rsi      # 0x3251d
callq 0x4400
movq 0x40(%rsp), %rax
shlq $0x5, %r15
movq 0x8(%rax,%r15), %rax
movq %r13, 0x70(%rsp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x70(%rsp), %rdi
callq 0x1c27c
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
movq %rbx, %rdi
callq 0x4400
movq %rax, %rbx
movl $0x9, %edx
movq %rax, %rdi
leaq 0xa76e(%rip), %rsi      # 0x32536
callq 0x4400
movq 0x40(%rsp), %rax
movq 0x18(%rax,%r15), %rdi
callq 0x1f452
movq %rbx, %rdi
movl %eax, %esi
callq 0x46d0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4370
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42a0
movq 0x70(%rsp), %rdi
cmpq %r13, %rdi
je 0x27e2a
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x43a0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x27e46
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x43a0
movq 0x40(%rsp), %rax
movzbl 0x14(%rax,%r15), %edx
movq 0x8(%rax,%r15), %rsi
movq 0x18(%rax,%r15), %rcx
movq 0x68(%rsp), %rdi
callq 0x27a9a
movq 0x48(%rsp), %rax
subq 0x40(%rsp), %rax
movl %ebp, %r15d
sarq $0x5, %rax
incl %ebp
cmpq %r15, %rax
ja 0x27d22
movq 0x60(%rsp), %rbx
movq 0x50(%rbx), %rdi
testq %rdi, %rdi
je 0x27e9b
movq 0x60(%rbx), %rsi
subq %rdi, %rsi
callq 0x43a0
movl $0x90, %esi
movq %rbx, %rdi
callq 0x43a0
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x27ebf
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x43a0
leaq 0x98(%rsp), %rdi
callq 0x1e1ae
leaq 0xb0(%rsp), %rdi
callq 0x1e1ae
xorl %eax, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x1e1ae
jmp 0x27f02
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x1e1ae
jmp 0x27fdb
jmp 0x27f9d
movq %rax, %rbx
jmp 0x27ff2
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x27fff
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x43a0
jmp 0x27fff
movq %rax, %rbx
jmp 0x27fff
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2800c
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
jmp 0x27f8d
movq %rax, %rbx
jmp 0x2800c
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x2800c
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x43a0
jmp 0x2800c
jmp 0x27f9d
jmp 0x27f98
movq %rax, %rbx
jmp 0x27fbf
movq %rax, %rbx
jmp 0x27fdb
movq %rax, %rbx
movq 0x70(%rsp), %rdi
cmpq %r13, %rdi
je 0x27fbf
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x43a0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x27fdb
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x43a0
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x27ff2
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x43a0
leaq 0x98(%rsp), %rdi
callq 0x1e1ae
leaq 0xb0(%rsp), %rdi
callq 0x1e1ae
movq %rbx, %rdi
callq 0x4700