// File: 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
movq %rsp, %rbp
subq $0x280, %rsp            # imm = 0x280
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1b8(%rbp)
movq 0x310fa(%rip), %rdi     # 0x81fb8
leaq 0x134d7(%rip), %rsi     # 0x6439c
callq 0x5480
movq %rax, -0x1b0(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x40(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0x35650
movq -0x1b0(%rbp), %rdi
movq -0x1a8(%rbp), %rsi
callq 0x5430
movq %rax, -0x1a0(%rbp)
jmp 0x50f01
movq -0x1a0(%rbp), %rdi
movq 0x31081(%rip), %rsi     # 0x81f90
callq 0x54f0
jmp 0x50f16
leaq -0x40(%rbp), %rdi
callq 0x52f0
movq -0x10(%rbp), %rdi
callq 0x51e10
movb %al, -0x4d(%rbp)
movq -0x20(%rbp), %rdi
callq 0x3f790
fstpt -0x60(%rbp)
movq -0x20(%rbp), %rdi
callq 0x3f740
movq %rax, -0x68(%rbp)
movq -0x20(%rbp), %rdi
callq 0x3f880
movq %rax, -0x70(%rbp)
movzbl -0x4d(%rbp), %eax
movq %rax, -0x1c8(%rbp)
fldz
fstpt -0xb0(%rbp)
leaq -0xb1(%rbp), %rdi
movq %rdi, -0x1c0(%rbp)
callq 0x34a40
movq -0x1c0(%rbp), %rcx
leaq -0xa0(%rbp), %rdi
movl $0x3, %esi
leaq -0xb0(%rbp), %rdx
callq 0x34a60
jmp 0x50f98
leaq -0xb2(%rbp), %rdi
movq %rdi, -0x1d0(%rbp)
callq 0x35a40
movq -0x1c8(%rbp), %rsi
movq -0x1d0(%rbp), %rcx
leaq -0x88(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
callq 0x35a60
jmp 0x50fce
leaq -0xb2(%rbp), %rdi
callq 0x35b40
leaq -0xa0(%rbp), %rdi
callq 0x34b10
leaq -0xb1(%rbp), %rdi
callq 0x34b70
movq -0x1b8(%rbp), %rax
movzbl -0x4d(%rbp), %ecx
movq %rcx, -0x1e8(%rbp)
movzbl (%rax), %eax
incl %eax
movq %rax, -0x1e0(%rbp)
fldz
fstpt -0x100(%rbp)
leaq -0x101(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0x34a40
movq -0x1e0(%rbp), %rsi
movq -0x1d8(%rbp), %rcx
leaq -0xe8(%rbp), %rdi
leaq -0x100(%rbp), %rdx
callq 0x34a60
jmp 0x5104e
leaq -0x102(%rbp), %rdi
movq %rdi, -0x1f0(%rbp)
callq 0x35a40
movq -0x1e8(%rbp), %rsi
movq -0x1f0(%rbp), %rcx
leaq -0xd0(%rbp), %rdi
leaq -0xe8(%rbp), %rdx
callq 0x35a60
jmp 0x51084
leaq -0x102(%rbp), %rdi
callq 0x35b40
leaq -0xe8(%rbp), %rdi
callq 0x34b10
leaq -0x101(%rbp), %rdi
callq 0x34b70
movq -0x10(%rbp), %rdi
movzbl -0x11(%rbp), %esi
movq -0x70(%rbp), %rdx
fldt -0x60(%rbp)
movq -0x68(%rbp), %rcx
movq %rsp, %rax
fstpt (%rax)
leaq -0x88(%rbp), %r8
leaq -0xd0(%rbp), %r9
callq 0x33440
jmp 0x510d5
leaq -0x120(%rbp), %rdi
callq 0x52b00
movq -0x10(%rbp), %rax
movq %rax, -0x208(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x200(%rbp)
movb -0x11(%rbp), %al
movb %al, -0x1f1(%rbp)
leaq -0x138(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x52a10
jmp 0x51115
leaq -0x150(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x52a10
jmp 0x5112a
movq -0x200(%rbp), %rdx
movq -0x208(%rbp), %rsi
movq -0x1b8(%rbp), %rdi
movb -0x1f1(%rbp), %al
movq %rsp, %rcx
leaq -0x120(%rbp), %r8
movq %r8, (%rcx)
movzbl %al, %ecx
leaq -0x138(%rbp), %r8
leaq -0x150(%rbp), %r9
callq 0x4f510
jmp 0x5116a
leaq -0x150(%rbp), %rdi
callq 0x35ae0
leaq -0x138(%rbp), %rdi
callq 0x35ae0
movl $0x0, -0x154(%rbp)
movl -0x154(%rbp), %eax
movq %rax, -0x210(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x52590
movq %rax, %rcx
movq -0x210(%rbp), %rax
cmpq %rcx, %rax
jae 0x514a3
movq 0x30df9(%rip), %rdi     # 0x81fb8
leaq 0x13211(%rip), %rsi     # 0x643d7
callq 0x5480
movq %rax, -0x218(%rbp)
jmp 0x511d4
movq -0x10(%rbp), %rsi
leaq -0x178(%rbp), %rdi
callq 0x35650
jmp 0x511e6
movq -0x218(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x5430
movq %rax, -0x220(%rbp)
jmp 0x51202
movq -0x220(%rbp), %rdi
leaq 0x131f4(%rip), %rsi     # 0x64404
callq 0x5480
movq %rax, -0x228(%rbp)
jmp 0x5121e
movl -0x154(%rbp), %eax
movl %eax, %esi
leaq -0x120(%rbp), %rdi
callq 0x525b0
movq 0x8(%rax), %rsi
leaq -0x198(%rbp), %rdi
callq 0x35650
jmp 0x51244
movq -0x228(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x5430
movq %rax, -0x230(%rbp)
jmp 0x51260
movq -0x230(%rbp), %rdi
leaq 0x131af(%rip), %rsi     # 0x6441d
callq 0x5480
movq %rax, -0x238(%rbp)
jmp 0x5127c
movl -0x154(%rbp), %eax
movl %eax, %esi
leaq -0x120(%rbp), %rdi
callq 0x525b0
movq 0x18(%rax), %rdi
callq 0x3f8c0
movl %eax, -0x23c(%rbp)
jmp 0x512a1
movl -0x23c(%rbp), %esi
movq -0x238(%rbp), %rdi
callq 0x58f0
movq %rax, -0x248(%rbp)
jmp 0x512bc
movq -0x248(%rbp), %rdi
movq 0x30cc6(%rip), %rsi     # 0x81f90
callq 0x54f0
jmp 0x512d1
leaq -0x198(%rbp), %rdi
callq 0x52f0
leaq -0x178(%rbp), %rdi
callq 0x52f0
movl -0x154(%rbp), %eax
movl %eax, %esi
leaq -0x120(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0x525b0
movq -0x260(%rbp), %rdi
movq 0x8(%rax), %rax
movq %rax, -0x258(%rbp)
movl -0x154(%rbp), %eax
movl %eax, %esi
callq 0x525b0
movq -0x260(%rbp), %rdi
movzbl 0x14(%rax), %eax
movl %eax, -0x24c(%rbp)
movl -0x154(%rbp), %eax
movl %eax, %esi
callq 0x525b0
movq -0x1b8(%rbp), %rdi
movq -0x258(%rbp), %rsi
movl -0x24c(%rbp), %edx
movq 0x18(%rax), %rcx
callq 0x50e90
jmp 0x51360
jmp 0x51362
movl -0x154(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x154(%rbp)
jmp 0x5118c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x52f0
jmp 0x51524
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x513c2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xb2(%rbp), %rdi
callq 0x35b40
leaq -0xa0(%rbp), %rdi
callq 0x34b10
leaq -0xb1(%rbp), %rdi
callq 0x34b70
jmp 0x51524
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x51405
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x102(%rbp), %rdi
callq 0x35b40
leaq -0xe8(%rbp), %rdi
callq 0x34b10
leaq -0x101(%rbp), %rdi
callq 0x34b70
jmp 0x51518
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x5150c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x51500
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x5145e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x35ae0
leaq -0x138(%rbp), %rdi
callq 0x35ae0
jmp 0x51500
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x51495
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x52f0
leaq -0x178(%rbp), %rdi
callq 0x52f0
jmp 0x51500
movq -0x20(%rbp), %rax
movq %rax, -0x268(%rbp)
cmpq $0x0, %rax
je 0x514d1
movq -0x268(%rbp), %rdi
callq 0x529b0
movq -0x268(%rbp), %rdi
movl $0x90, %esi
callq 0x54b0
leaq -0x120(%rbp), %rdi
callq 0x52b20
leaq -0xd0(%rbp), %rdi
callq 0x35ae0
leaq -0x88(%rbp), %rdi
callq 0x35ae0
xorl %eax, %eax
addq $0x280, %rsp            # imm = 0x280
popq %rbp
retq
leaq -0x120(%rbp), %rdi
callq 0x52b20
leaq -0xd0(%rbp), %rdi
callq 0x35ae0
leaq -0x88(%rbp), %rdi
callq 0x35ae0
movq -0x48(%rbp), %rdi
callq 0x5920
nopl (%rax)