// File: /workspace/github_cpp_makefile_star2_O3/adamiaonr[P]rid-analytics/src/rid-analytics.cpp
// Function: RID_Analytics::run(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void RID_Analytics::run(
    std::string nw_filename,
    std::string start_router_id) {

    if (this->tp_sizes.empty())
        std::cout << "RID_Analytics::run() : [INFO] TP sizes is empty!";
    else {

        std::cout << "RID_Analytics::run() : [INFO] TP sizes keys : " << std::endl;
        RID_TPMap::iterator itr;
        for (itr = this->tp_sizes.begin(); itr != this->tp_sizes.end(); itr++)
            std::cout << "\tTP[" << itr->first << "]" << std::endl;
    }

    this->start_router = this->routers[start_router_id];

    // FIXME: not sure if it is ok to set the rid_router arg on Path_State() as NULL
    Path_State * init_state = new Path_State(NULL, request_size);
    init_state->set_length(0);

    // set the initial ingress probabilities: ptree_size = 0 gets 1.0 
    // probability, i.e. initially the request isn't bound to any prefix tree
    init_state->set_in_fptree_prob(0, 1.0);
    init_state->set_in_iface_prob(1.0);

    // all other prefix tree sizes get 0.0 probability
    for (uint8_t p = 1; p <= this->request_size; p++)
        init_state->set_in_fptree_prob(p, 0.0);

    // we first supply an empty tree bitmask for the path
    std::map<int, std::vector<uint8_t> > tree_bitmasks =
        (*this->start_router->get_tree_bitmasks(0));
    // fill the path tree bitmask w/ 0s
    std::map<int, std::vector<uint8_t> >::iterator itr;
    for (itr = tree_bitmasks.begin(); itr != tree_bitmasks.end(); itr++)
        std::fill(itr->second.begin(), itr->second.end(), 0x00);

    // set the path tree bitmask on path state
    init_state->set_tree_bitmasks(&tree_bitmasks);
    // set initial ttl to dist. from starting router to the origin server
    init_state->set_ttl(4);

    // we always start at the ingress iface, so that we don't have a local 
    // match at the initial router (not sure if this can work directly like this)
    run_rec(this->start_router, 0, init_state);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, 0x10(%rsp)
movq %rdi, %rbx
cmpq $0x0, 0x48(%rdi)
je 0x27c14
movq 0x1746e(%rip), %r15     # 0x3efb8
leaq 0x9800(%rip), %rsi      # 0x31351
movl $0x2e, %edx
movq %r15, %rdi
callq 0x4400
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x4370
movsbl %al, %esi
movq %r15, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42a0
movq 0x38(%rbx), %r15
leaq 0x28(%rbx), %r13
cmpq %r13, %r15
je 0x27c2c
movq 0x1741b(%rip), %r12     # 0x3efb8
leaq 0x5cba(%rip), %rbp      # 0x2d85e
movl $0x4, %edx
movq %r12, %rdi
leaq 0x97cd(%rip), %rsi      # 0x31380
callq 0x4400
movq 0x20(%r15), %rsi
movq 0x28(%r15), %rdx
movq %r12, %rdi
callq 0x4400
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x4400
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x4370
movsbl %al, %esi
movq %r14, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42a0
movq %r15, %rdi
callq 0x42b0
movq %rax, %r15
cmpq %r13, %rax
jne 0x27ba4
jmp 0x27c2c
movq 0x1739d(%rip), %rdi     # 0x3efb8
leaq 0x96fe(%rip), %rsi      # 0x31320
movl $0x30, %edx
callq 0x4400
leaq 0x50(%rbx), %rdi
movq 0x10(%rsp), %rsi
callq 0x27e8e
movq (%rax), %rax
movq %rax, 0x88(%rbx)
movl $0x90, %edi
callq 0x4390
movq %rax, %r14
movzbl (%rbx), %edx
movq %rax, %rdi
xorl %esi, %esi
callq 0x1ee30
movq %r14, %rdi
xorl %esi, %esi
callq 0x1ef0c
fld1
fstpt (%rsp)
movq %r14, %rdi
xorl %esi, %esi
callq 0x1ef58
fld1
fstpt (%rsp)
movq %r14, %rdi
callq 0x1ef6c
cmpb $0x0, (%rbx)
je 0x27ca7
movb $0x1, %bpl
movzbl %bpl, %ebp
fldz
fstpt (%rsp)
movq %r14, %rdi
movl %ebp, %esi
callq 0x1ef58
incb %bpl
cmpb (%rbx), %bpl
jbe 0x27c8c
movq 0x88(%rbx), %rax
movq 0x30(%rax), %rsi
addq $0x60, %rsi
leaq 0x18(%rsp), %r15
movq %r15, %rdi
callq 0x285c6
movq 0x18(%r15), %r15
leaq 0x20(%rsp), %r12
cmpq %r12, %r15
je 0x27cf8
movq 0x28(%r15), %rdi
movq 0x30(%r15), %rdx
cmpq %rdx, %rdi
je 0x27ce8
subq %rdi, %rdx
xorl %esi, %esi
callq 0x4240
movq %r15, %rdi
callq 0x42b0
movq %rax, %r15
cmpq %r12, %rax
jne 0x27cd1
leaq 0x18(%rsp), %rsi
movq %r14, %rdi
callq 0x1efa8
movq %r14, %rdi
movl $0x4, %esi
callq 0x1efb8
movq 0x88(%rbx), %rsi
movq %rbx, %rdi
xorl %edx, %edx
movq %r14, %rcx
callq 0x275ac
leaq 0x18(%rsp), %rdi
callq 0x1e55c
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x90, %esi
movq %r14, %rdi
callq 0x43a0
jmp 0x27d5e
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x1e55c
movq %rbx, %rdi
callq 0x4700