// File: /workspace/github_cpp_makefile_star2_O1/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 0x28106
movq 0x17f7c(%rip), %r15     # 0x3ffb8
leaq 0xa52e(%rip), %rsi      # 0x32571
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 0x2811e
movq 0x17f29(%rip), %r12     # 0x3ffb8
leaq 0x6798(%rip), %rbp      # 0x2e82e
movl $0x4, %edx
movq %r12, %rdi
leaq 0xa4fb(%rip), %rsi      # 0x325a0
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 0x28096
jmp 0x2811e
movq 0x17eab(%rip), %rdi     # 0x3ffb8
leaq 0xa42c(%rip), %rsi      # 0x32540
movl $0x30, %edx
callq 0x4400
leaq 0x50(%rbx), %rdi
movq 0x10(%rsp), %rsi
callq 0x28380
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 0x1f2ec
movq %r14, %rdi
xorl %esi, %esi
callq 0x1f39e
fld1
fstpt (%rsp)
movq %r14, %rdi
xorl %esi, %esi
callq 0x1f3ea
fld1
fstpt (%rsp)
movq %r14, %rdi
callq 0x1f3fe
cmpb $0x0, (%rbx)
je 0x28199
movb $0x1, %bpl
movzbl %bpl, %ebp
fldz
fstpt (%rsp)
movq %r14, %rdi
movl %ebp, %esi
callq 0x1f3ea
incb %bpl
cmpb (%rbx), %bpl
jbe 0x2817e
movq 0x88(%rbx), %rax
movq 0x30(%rax), %rsi
addq $0x60, %rsi
leaq 0x18(%rsp), %r15
movq %r15, %rdi
callq 0x28aa2
movq 0x18(%r15), %r15
leaq 0x20(%rsp), %r12
cmpq %r12, %r15
je 0x281ea
movq 0x28(%r15), %rdi
movq 0x30(%r15), %rdx
cmpq %rdx, %rdi
je 0x281da
subq %rdi, %rdx
xorl %esi, %esi
callq 0x4240
movq %r15, %rdi
callq 0x42b0
movq %rax, %r15
cmpq %r12, %rax
jne 0x281c3
leaq 0x18(%rsp), %rsi
movq %r14, %rdi
callq 0x1f43a
movq %r14, %rdi
movl $0x4, %esi
callq 0x1f44a
movq 0x88(%rbx), %rsi
movq %rbx, %rdi
xorl %edx, %edx
movq %r14, %rcx
callq 0x27a9a
leaq 0x18(%rsp), %rdi
callq 0x1e9de
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 0x28250
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x1e9de
movq %rbx, %rdi
callq 0x4700