// File: /workspace/github_cpp_makefile_star2_O2/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, 0x20(%rsp)
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, 0x28(%rsp)
movq 0x19f61(%rip), %rdi     # 0x3afb0
leaq 0xa3ff(%rip), %rsi      # 0x2b455
callq 0x43a0
movq %rax, %r15
leaq 0x50(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x4510
movq %r15, %rdi
movq %r12, %rsi
callq 0x4360
movq %rax, %rdi
callq 0x41e0
leaq 0x50(%rsp), %rdi
callq 0x41c0
movzbl 0x24(%r14), %r13d
movq 0x20(%rsp), %r12
movq %r12, %rdi
callq 0x1ab8a
fstpt 0xa4(%rsp)
movq %r12, %rdi
callq 0x1ab78
movq %rax, %r15
movq %r12, %rdi
callq 0x1abb4
movq %rax, %r12
fldz
fstpt 0xb0(%rsp)
leaq 0x50(%rsp), %rdi
pushq $0x3
popq %rsi
leaq 0xb0(%rsp), %rdx
leaq 0x70(%rsp), %rcx
callq 0x18df8
leaq 0x88(%rsp), %rdi
leaq 0x50(%rsp), %rdx
leaq 0x30(%rsp), %rcx
movq %r13, %rsi
callq 0x1918c
leaq 0x50(%rsp), %rdi
callq 0x195d0
movq 0x28(%rsp), %rax
movzbl (%rax), %esi
incq %rsi
fldz
fstpt 0xb0(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0xb0(%rsp), %rdx
leaq 0x30(%rsp), %rbp
movq %rbp, %rcx
callq 0x18df8
leaq 0x70(%rsp), %rdi
leaq 0x50(%rsp), %rdx
leaq 0x1f(%rsp), %rcx
movq %r13, %rsi
callq 0x1918c
leaq 0x50(%rsp), %rdi
callq 0x195d0
fldt 0xa4(%rsp)
fstpt (%rsp)
movzbl %bl, %ebx
leaq 0x88(%rsp), %r8
leaq 0x70(%rsp), %r9
movq %r14, %rdi
movl %ebx, %esi
movq %r12, %rdx
movq %r15, %rcx
callq 0x183d4
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
leaq 0xf0(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x21b9a
leaq 0xd8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x21b9a
movq %rbp, (%rsp)
leaq 0xf0(%rsp), %r8
leaq 0xd8(%rsp), %r9
movq 0x28(%rsp), %rdi
movq %r14, %rsi
movq 0x20(%rsp), %rdx
movl %ebx, %ecx
callq 0x20312
leaq 0xd8(%rsp), %rdi
callq 0x191e2
leaq 0xf0(%rsp), %rdi
callq 0x191e2
xorl %r12d, %r12d
leaq 0x50(%rsp), %rbp
leaq 0xb0(%rsp), %r15
movl %r12d, %r12d
movq 0x38(%rsp), %rax
subq 0x30(%rsp), %rax
sarq $0x5, %rax
cmpq %r12, %rax
jbe 0x212e6
movq 0x19d8e(%rip), %rdi     # 0x3afb0
leaq 0xa267(%rip), %rsi      # 0x2b490
callq 0x43a0
movq %rax, %r13
movq %rbp, %rdi
movq %r14, %rsi
callq 0x4510
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4360
movq %rax, %rdi
leaq 0xa26c(%rip), %rsi      # 0x2b4bd
callq 0x43a0
movq %rax, %r13
movq 0x30(%rsp), %rax
movq %r12, %rbx
shlq $0x5, %rbx
movq 0x8(%rax,%rbx), %rsi
movq %r15, %rdi
callq 0x4510
movq %r13, %rdi
movq %r15, %rsi
callq 0x4360
movq %rax, %rdi
leaq 0xa24f(%rip), %rsi      # 0x2b4d6
callq 0x43a0
movq %rax, %r13
movq 0x30(%rsp), %rax
movq 0x18(%rax,%rbx), %rdi
callq 0x1abc4
movq %r13, %rdi
movl %eax, %esi
callq 0x46d0
movq %rax, %rdi
callq 0x41e0
movq %r15, %rdi
callq 0x41c0
movq %rbp, %rdi
callq 0x41c0
movq 0x30(%rsp), %rax
movzbl 0x14(%rax,%rbx), %edx
movq 0x8(%rax,%rbx), %rsi
movq 0x18(%rax,%rbx), %rcx
movq 0x28(%rsp), %rdi
callq 0x21028
incl %r12d
jmp 0x21201
movq 0x20(%rsp), %rbx
leaq 0x50(%rbx), %rdi
callq 0x195d0
movl $0x90, %esi
movq %rbx, %rdi
callq 0x43d0
leaq 0x30(%rsp), %rdi
callq 0x23358
leaq 0x70(%rsp), %rdi
callq 0x191e2
leaq 0x88(%rsp), %rdi
callq 0x191e2
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 0x191e2
jmp 0x2134b
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x191e2
jmp 0x213c0
jmp 0x2139c
movq %rax, %rbx
jmp 0x213ca
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x195d0
jmp 0x213d4
movq %rax, %rbx
jmp 0x213d4
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x195d0
jmp 0x213e1
movq %rax, %rbx
jmp 0x213e1
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x41c0
jmp 0x213e1
jmp 0x2139c
jmp 0x213a1
movq %rax, %rbx
jmp 0x213c0
movq %rax, %rbx
jmp 0x213b6
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x41c0
leaq 0x50(%rsp), %rdi
callq 0x41c0
leaq 0x30(%rsp), %rdi
callq 0x23358
leaq 0x70(%rsp), %rdi
callq 0x191e2
leaq 0x88(%rsp), %rdi
callq 0x191e2
movq %rbx, %rdi
callq 0x4700
nop