// File: /workspace/github_cpp_makefile_star2_O2/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 0x21477
movq 0x19ba2(%rip), %r15     # 0x3afb0
leaq 0xa0fc(%rip), %rsi      # 0x2b511
movq %r15, %rdi
callq 0x43a0
movq %rax, %rdi
callq 0x41e0
movq 0x38(%rbx), %rbp
leaq 0x28(%rbx), %r14
leaq 0xa10c(%rip), %r12      # 0x2b540
leaq 0x6423(%rip), %r13      # 0x2785e
cmpq %r14, %rbp
je 0x2148a
movq %r15, %rdi
movq %r12, %rsi
callq 0x43a0
leaq 0x20(%rbp), %rsi
movq %rax, %rdi
callq 0x4360
movq %rax, %rdi
movq %r13, %rsi
callq 0x43a0
movq %rax, %rdi
callq 0x41e0
movq %rbp, %rdi
callq 0x42d0
movq %rax, %rbp
jmp 0x2143b
movq 0x19b32(%rip), %rdi     # 0x3afb0
leaq 0xa05b(%rip), %rsi      # 0x2b4e0
callq 0x43a0
leaq 0x50(%rbx), %rdi
movq 0x10(%rsp), %rsi
callq 0x2167c
movq (%rax), %rax
movq %rax, 0x88(%rbx)
movl $0x90, %edi
callq 0x43c0
movq %rax, %r14
movzbl (%rbx), %edx
movq %rax, %rdi
xorl %esi, %esi
callq 0x1aa7c
movq %r14, %rdi
xorl %esi, %esi
callq 0x1ab12
fld1
fstpt (%rsp)
movq %r14, %rdi
xorl %esi, %esi
callq 0x1ab5c
fld1
fstpt (%rsp)
movq %r14, %rdi
callq 0x1ab70
movb $0x1, %bpl
cmpb (%rbx), %bpl
ja 0x21500
movzbl %bpl, %esi
fldz
fstpt (%rsp)
movq %r14, %rdi
callq 0x1ab5c
incb %bpl
jmp 0x214e5
movq 0x88(%rbx), %rax
movq 0x30(%rax), %rsi
addq $0x60, %rsi
leaq 0x18(%rsp), %r15
movq %r15, %rdi
callq 0x21d8e
movq 0x18(%r15), %rax
leaq 0x20(%rsp), %r15
cmpq %r15, %rax
je 0x21549
movq 0x28(%rax), %rcx
movq 0x30(%rax), %rdx
cmpq %rdx, %rcx
je 0x2153f
movb $0x0, (%rcx)
incq %rcx
jmp 0x21532
movq %rax, %rdi
callq 0x42d0
jmp 0x21525
leaq 0x18(%rsp), %rsi
movq %r14, %rdi
callq 0x1abac
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x1abbc
movq 0x88(%rbx), %rsi
movq %rbx, %rdi
xorl %edx, %edx
movq %r14, %rcx
callq 0x21028
leaq 0x18(%rsp), %rdi
callq 0x19b64
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 0x43d0
jmp 0x215ad
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x19b64
movq %rbx, %rdi
callq 0x4700