// File: adamiaonr[P]rid-analytics/src/rid-router.cpp
// Function: RID_Router::get_fp_data(RID_Router*, unsigned char, bool)
Prob::fp_data * RID_Router::get_fp_data(
    RID_Router * router, 
    uint8_t i,
    bool iface_complement) {

    Prob::fp_data * iface_fp_data = new Prob::fp_data();

    if (!iface_complement) {

        iface_fp_data->tp_size = router->tp_sizes[i];
        iface_fp_data->num_entries = (__float080) router->fwd_table[i].num_entries;
        iface_fp_data->f_distr = router->fwd_table[i].f_distr;
        iface_fp_data->f_r_distr = router->fwd_table[i].f_r_distr;
        iface_fp_data->entry_prop = router->fwd_table[i].iface_proportion;
        iface_fp_data->tree_bitmasks = router->fwd_table[i].tree_bitmasks;
        iface_fp_data->on_fptree = router->iface_on_fptree[i];
        iface_fp_data->is_blocked = router->blocked_ifaces[i];

    } else {

        iface_fp_data->f_distr = std::vector<__float080>(this->req_size, 0.0);
        iface_fp_data->f_r_distr = std::vector<__float080>(this->req_size, 0.0);
        iface_fp_data->tree_bitmasks = router->fwd_table[i].tree_bitmasks;
        // clear iface fp data's tree bitmask
        std::map<int, std::vector<uint8_t> >::iterator itr;
        for (itr = iface_fp_data->tree_bitmasks.begin(); itr != iface_fp_data->tree_bitmasks.end(); itr++)
            std::fill(itr->second.begin(), itr->second.end(), 0x00);

        // sum all the fp data, for all ifaces other than i
        __float080 num_valid_ifaces = 0.0;
        for (uint8_t k = 1; k < router->iface_num; k++) {

            // don't consider iface i, or blocked ifaces
            if ((k == i) || (router->fwd_table[k].num_entries < 1)) continue;
            if (router->blocked_ifaces[k]) continue;

            // the tp is the max of the ifaces other than i
            iface_fp_data->tp_size = std::max(iface_fp_data->tp_size, router->tp_sizes[k]);
            // keep adding up the nr of entries
            iface_fp_data->num_entries += (__float080) router->fwd_table[k].num_entries;

            // f_distr and f_r_distr vectors
            // use std::transform() to get the elementwise sum of 2 vectors 
            // (result saved in first vector)
            std::transform(
                iface_fp_data->f_distr.begin(), iface_fp_data->f_distr.end(), 
                router->fwd_table[k].f_distr.begin(), 
                iface_fp_data->f_distr.begin(), 
                std::plus<__float080>());

            std::transform(
                iface_fp_data->f_r_distr.begin(), iface_fp_data->f_r_distr.end(), 
                router->fwd_table[k].f_r_distr.begin(), 
                iface_fp_data->f_r_distr.begin(), 
                std::plus<__float080>());

            // fill the bitmask of ~i in the old fashioned way...
            for (itr = iface_fp_data->tree_bitmasks.begin(); itr != iface_fp_data->tree_bitmasks.end(); itr++) {
                int tb_size = itr->first;
                for (unsigned int j = 0; j < router->fwd_table[k].tree_bitmasks[tb_size].size(); j++)
                    itr->second[j] |= router->fwd_table[k].tree_bitmasks[tb_size][j];
            }

            iface_fp_data->entry_prop += router->fwd_table[k].iface_proportion;

            iface_fp_data->on_fptree = std::vector<bool>(this->req_size, false);
            for (unsigned int j = 0; j < this->req_size; j++) {
                // std::cout << "RID_Router::get_fp_data() : [INFO] " << 
                //     "\n\ton_fptree[~" << (int) i << "][" << j << "] : " << iface_fp_data->on_fptree[j] << 
                //     "\n\ton_fptree[" << (int) k << "][" << j << "] : " << router->iface_on_fptree[k][j] << std::endl;
                iface_fp_data->on_fptree[j] = (iface_fp_data->on_fptree[j] || router->iface_on_fptree[k][j]);
                // std::cout << "RID_Router::get_fp_data() : [INFO] " << 
                //     "\n\ton_fptree[~" << (int) i << "][" << j << "] : " << iface_fp_data->on_fptree[j] << std::endl;
            }

            num_valid_ifaces++;
        }

        // normalize the iface_fp_data->f_distr and iface_fp_data->f_r_distr vectors
        for (uint8_t k = 0; k < iface_fp_data->f_distr.size(); k++)
            iface_fp_data->f_distr[k] /= num_valid_ifaces;
        for (uint8_t k = 0; k < iface_fp_data->f_r_distr.size(); k++)
            iface_fp_data->f_r_distr[k] /= num_valid_ifaces;
    }

    return iface_fp_data;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2a0, %rsp            # imm = 0x2A0
movb %cl, %al
movb %dl, %cl
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb %cl, -0x11(%rbp)
andb $0x1, %al
movb %al, -0x12(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x210(%rbp)
movl $0xc0, %edi
callq 0x54a0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x208(%rbp)
callq 0x34cc0
jmp 0x32a18
movq -0x208(%rbp), %rax
movq %rax, -0x20(%rbp)
testb $0x1, -0x12(%rbp)
jne 0x32b9f
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
movzbl -0x11(%rbp), %eax
movl %eax, %esi
callq 0x34d30
movb (%rax), %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
movzbl -0x11(%rbp), %eax
movl %eax, %esi
callq 0x34a20
movq 0x58(%rax), %rax
movq %rax, -0x1f8(%rbp)
testq %rax, %rax
sets %al
movzbl %al, %eax
movl %eax, %ecx
fildll -0x1f8(%rbp)
leaq 0x30b82(%rip), %rax     # 0x63600
flds (%rax,%rcx,4)
faddp %st, %st(1)
movq -0x20(%rbp), %rax
fstpt 0x10(%rax)
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
movzbl -0x11(%rbp), %eax
movl %eax, %esi
callq 0x34a20
movq %rax, %rsi
addq $0x20, %rsi
movq -0x20(%rbp), %rdi
addq $0x30, %rdi
callq 0x34d50
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
movzbl -0x11(%rbp), %eax
movl %eax, %esi
callq 0x34a20
movq %rax, %rsi
addq $0x38, %rsi
movq -0x20(%rbp), %rdi
addq $0x48, %rdi
callq 0x34d50
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
movzbl -0x11(%rbp), %eax
movl %eax, %esi
callq 0x34a20
fldt 0x10(%rax)
movq -0x20(%rbp), %rax
fstpt 0x20(%rax)
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
movzbl -0x11(%rbp), %eax
movl %eax, %esi
callq 0x34a20
movq %rax, %rsi
addq $0x60, %rsi
movq -0x20(%rbp), %rdi
addq $0x60, %rdi
callq 0x34c90
movq -0x10(%rbp), %rdi
addq $0x88, %rdi
movzbl -0x11(%rbp), %eax
movl %eax, %esi
callq 0x34fa0
movq %rax, %rsi
movq -0x20(%rbp), %rdi
addq $0x90, %rdi
callq 0x34fc0
movq -0x10(%rbp), %rdi
addq $0x60, %rdi
movzbl -0x11(%rbp), %eax
movl %eax, %esi
callq 0x35120
movq %rax, -0x40(%rbp)
movq %rdx, -0x38(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x35180
movb %al, %cl
movq -0x20(%rbp), %rax
andb $0x1, %cl
movb %cl, 0xb8(%rax)
jmp 0x33426
movq -0x208(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0xc0, %esi
callq 0x54b0
jmp 0x33433
movq -0x210(%rbp), %rax
movzbl 0x21(%rax), %eax
movq %rax, -0x220(%rbp)
fldz
fstpt -0x70(%rbp)
leaq -0x71(%rbp), %rdi
movq %rdi, -0x218(%rbp)
callq 0x34a40
movq -0x220(%rbp), %rsi
movq -0x218(%rbp), %rcx
leaq -0x58(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0x34a60
jmp 0x32be3
movq -0x20(%rbp), %rdi
addq $0x30, %rdi
leaq -0x58(%rbp), %rsi
movq %rsi, -0x238(%rbp)
callq 0x34ae0
movq -0x238(%rbp), %rdi
callq 0x34b10
leaq -0x71(%rbp), %rdi
callq 0x34b70
movq -0x210(%rbp), %rax
movzbl 0x21(%rax), %eax
movq %rax, -0x230(%rbp)
fldz
fstpt -0xa0(%rbp)
leaq -0xa1(%rbp), %rdi
movq %rdi, -0x228(%rbp)
callq 0x34a40
movq -0x230(%rbp), %rsi
movq -0x228(%rbp), %rcx
leaq -0x90(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
callq 0x34a60
jmp 0x32c60
movq -0x20(%rbp), %rdi
addq $0x48, %rdi
leaq -0x90(%rbp), %rsi
callq 0x34ae0
leaq -0x90(%rbp), %rdi
callq 0x34b10
leaq -0xa1(%rbp), %rdi
callq 0x34b70
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
movzbl -0x11(%rbp), %eax
movl %eax, %esi
callq 0x34a20
movq %rax, %rsi
addq $0x60, %rsi
movq -0x20(%rbp), %rdi
addq $0x60, %rdi
callq 0x34c90
leaq -0xb0(%rbp), %rdi
callq 0x351b0
movq -0x20(%rbp), %rdi
addq $0x60, %rdi
callq 0x351d0
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x20(%rbp), %rdi
addq $0x60, %rdi
callq 0x35230
movq %rax, -0xc0(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x35200
testb $0x1, %al
jne 0x32d11
jmp 0x32dc4
leaq -0xb0(%rbp), %rdi
callq 0x352a0
movq %rax, %rdi
addq $0x8, %rdi
callq 0x352c0
movq %rax, -0xc8(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x352a0
movq %rax, %rdi
addq $0x8, %rdi
callq 0x352f0
movq %rax, -0xd0(%rbp)
movl $0x0, -0xd4(%rbp)
movq -0xc8(%rbp), %rdi
movq -0xd0(%rbp), %rsi
leaq -0xd4(%rbp), %rdx
callq 0x35260
leaq -0xb0(%rbp), %rdi
xorl %esi, %esi
callq 0x35320
movq %rax, -0xe0(%rbp)
jmp 0x32ce1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x71(%rbp), %rdi
callq 0x34b70
jmp 0x33433
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0xa1(%rbp), %rdi
callq 0x34b70
jmp 0x33433
fldz
fstpt -0xf0(%rbp)
movb $0x1, -0xf1(%rbp)
movzbl -0xf1(%rbp), %eax
movq -0x10(%rbp), %rcx
movzbl 0x24(%rcx), %ecx
cmpl %ecx, %eax
jge 0x33346
movzbl -0xf1(%rbp), %eax
movzbl -0x11(%rbp), %ecx
cmpl %ecx, %eax
je 0x32e16
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
movzbl -0xf1(%rbp), %eax
movl %eax, %esi
callq 0x34a20
cmpq $0x1, 0x58(%rax)
jae 0x32e1b
jmp 0x33333
movq -0x10(%rbp), %rdi
addq $0x60, %rdi
movzbl -0xf1(%rbp), %eax
movl %eax, %esi
callq 0x35120
movq %rax, -0x108(%rbp)
movq %rdx, -0x100(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x35180
testb $0x1, %al
jne 0x32e51
jmp 0x32e56
jmp 0x33333
movq -0x20(%rbp), %rax
movq %rax, -0x240(%rbp)
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
movzbl -0xf1(%rbp), %eax
movl %eax, %esi
callq 0x34d30
movq -0x240(%rbp), %rdi
movq %rax, %rsi
callq 0x35360
movb (%rax), %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
movzbl -0xf1(%rbp), %eax
movl %eax, %esi
callq 0x34a20
movq 0x58(%rax), %rax
movq %rax, -0x200(%rbp)
testq %rax, %rax
sets %al
movzbl %al, %eax
movl %eax, %ecx
fildll -0x200(%rbp)
leaq 0x30739(%rip), %rax     # 0x63600
flds (%rax,%rcx,4)
faddp %st, %st(1)
movq -0x20(%rbp), %rax
fldt 0x10(%rax)
faddp %st, %st(1)
fstpt 0x10(%rax)
movq -0x20(%rbp), %rdi
addq $0x30, %rdi
callq 0x35440
movq %rax, -0x110(%rbp)
movq -0x20(%rbp), %rdi
addq $0x30, %rdi
callq 0x35470
movq %rax, -0x118(%rbp)
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
movzbl -0xf1(%rbp), %eax
movl %eax, %esi
callq 0x34a20
movq %rax, %rdi
addq $0x20, %rdi
callq 0x35440
movq %rax, -0x120(%rbp)
movq -0x20(%rbp), %rdi
addq $0x30, %rdi
callq 0x35440
movq %rax, -0x128(%rbp)
movq -0x110(%rbp), %rdi
movq -0x118(%rbp), %rsi
movq -0x120(%rbp), %rdx
movq -0x128(%rbp), %rcx
callq 0x353a0
movq %rax, -0x138(%rbp)
movq -0x20(%rbp), %rdi
addq $0x48, %rdi
callq 0x35440
movq %rax, -0x140(%rbp)
movq -0x20(%rbp), %rdi
addq $0x48, %rdi
callq 0x35470
movq %rax, -0x148(%rbp)
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
movzbl -0xf1(%rbp), %eax
movl %eax, %esi
callq 0x34a20
movq %rax, %rdi
addq $0x38, %rdi
callq 0x35440
movq %rax, -0x150(%rbp)
movq -0x20(%rbp), %rdi
addq $0x48, %rdi
callq 0x35440
movq %rax, -0x158(%rbp)
movq -0x140(%rbp), %rdi
movq -0x148(%rbp), %rsi
movq -0x150(%rbp), %rdx
movq -0x158(%rbp), %rcx
callq 0x353a0
movq %rax, -0x168(%rbp)
movq -0x20(%rbp), %rdi
addq $0x60, %rdi
callq 0x351d0
movq %rax, -0x170(%rbp)
movq -0x170(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x20(%rbp), %rdi
addq $0x60, %rdi
callq 0x35230
movq %rax, -0x178(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x35200
testb $0x1, %al
jne 0x33044
jmp 0x33152
leaq -0xb0(%rbp), %rdi
callq 0x352a0
movl (%rax), %eax
movl %eax, -0x17c(%rbp)
movl $0x0, -0x180(%rbp)
movl -0x180(%rbp), %eax
movq %rax, -0x248(%rbp)
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
movzbl -0xf1(%rbp), %eax
movl %eax, %esi
callq 0x34a20
movq %rax, %rdi
addq $0x60, %rdi
leaq -0x17c(%rbp), %rsi
callq 0x354a0
movq %rax, %rdi
callq 0x35580
movq %rax, %rcx
movq -0x248(%rbp), %rax
cmpq %rcx, %rax
jae 0x33136
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
movzbl -0xf1(%rbp), %eax
movl %eax, %esi
callq 0x34a20
movq %rax, %rdi
addq $0x60, %rdi
leaq -0x17c(%rbp), %rsi
callq 0x354a0
movq %rax, %rdi
movl -0x180(%rbp), %eax
movl %eax, %esi
callq 0x34d30
movzbl (%rax), %eax
movl %eax, -0x24c(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x352a0
movq %rax, %rdi
addq $0x8, %rdi
movl -0x180(%rbp), %eax
movl %eax, %esi
callq 0x34d30
movl -0x24c(%rbp), %edx
movzbl (%rax), %ecx
orl %edx, %ecx
movb %cl, (%rax)
movl -0x180(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x180(%rbp)
jmp 0x33062
jmp 0x33138
leaq -0xb0(%rbp), %rdi
xorl %esi, %esi
callq 0x35320
movq %rax, -0x188(%rbp)
jmp 0x33014
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
movzbl -0xf1(%rbp), %eax
movl %eax, %esi
callq 0x34a20
movq %rax, %rcx
movq -0x210(%rbp), %rax
fldt 0x10(%rcx)
movq -0x20(%rbp), %rcx
fldt 0x20(%rcx)
faddp %st, %st(1)
fstpt 0x20(%rcx)
movzbl 0x21(%rax), %eax
movq %rax, -0x260(%rbp)
movb $0x0, -0x1b1(%rbp)
leaq -0x1b2(%rbp), %rdi
movq %rdi, -0x258(%rbp)
callq 0x341b0
movq -0x260(%rbp), %rsi
movq -0x258(%rbp), %rcx
leaq -0x1b0(%rbp), %rdi
leaq -0x1b1(%rbp), %rdx
callq 0x341d0
jmp 0x331c9
movq -0x20(%rbp), %rdi
addq $0x90, %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x34250
leaq -0x1b0(%rbp), %rdi
callq 0x342c0
leaq -0x1b2(%rbp), %rdi
callq 0x342e0
movl $0x0, -0x1b8(%rbp)
movq -0x210(%rbp), %rcx
movl -0x1b8(%rbp), %eax
movzbl 0x21(%rcx), %ecx
cmpl %ecx, %eax
jae 0x33323
movq -0x20(%rbp), %rdi
addq $0x90, %rdi
movl -0x1b8(%rbp), %eax
movl %eax, %esi
callq 0x35120
movq %rax, -0x1c8(%rbp)
movq %rdx, -0x1c0(%rbp)
leaq -0x1c8(%rbp), %rdi
callq 0x35180
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x261(%rbp)
jne 0x332a5
movq -0x10(%rbp), %rdi
addq $0x88, %rdi
movzbl -0xf1(%rbp), %eax
movl %eax, %esi
callq 0x34fa0
movq %rax, %rdi
movl -0x1b8(%rbp), %eax
movl %eax, %esi
callq 0x35120
movq %rax, -0x1d8(%rbp)
movq %rdx, -0x1d0(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0x35180
movb %al, -0x261(%rbp)
movb -0x261(%rbp), %al
movb %al, -0x262(%rbp)
movq -0x20(%rbp), %rdi
addq $0x90, %rdi
movl -0x1b8(%rbp), %eax
movl %eax, %esi
callq 0x35120
movq %rax, %rcx
movb -0x262(%rbp), %al
movq %rcx, -0x1e8(%rbp)
movq %rdx, -0x1e0(%rbp)
movzbl %al, %esi
andl $0x1, %esi
leaq -0x1e8(%rbp), %rdi
callq 0x355a0
movl -0x1b8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1b8(%rbp)
jmp 0x33202
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x1b2(%rbp), %rdi
callq 0x342e0
jmp 0x33433
fldt -0xf0(%rbp)
fld1
faddp %st, %st(1)
fstpt -0xf0(%rbp)
movb -0xf1(%rbp), %al
addb $0x1, %al
movb %al, -0xf1(%rbp)
jmp 0x32dd3
movb $0x0, -0x1e9(%rbp)
movzbl -0x1e9(%rbp), %eax
movq %rax, -0x270(%rbp)
movq -0x20(%rbp), %rdi
addq $0x30, %rdi
callq 0x355f0
movq %rax, %rcx
movq -0x270(%rbp), %rax
cmpq %rcx, %rax
jae 0x333b5
fldt -0xf0(%rbp)
fstpt -0x27c(%rbp)
movq -0x20(%rbp), %rdi
addq $0x30, %rdi
movzbl -0x1e9(%rbp), %eax
movl %eax, %esi
callq 0x34c70
fldt -0x27c(%rbp)
fldt (%rax)
fdivp %st, %st(1)
fstpt (%rax)
movb -0x1e9(%rbp), %al
addb $0x1, %al
movb %al, -0x1e9(%rbp)
jmp 0x3334d
movb $0x0, -0x1ea(%rbp)
movzbl -0x1ea(%rbp), %eax
movq %rax, -0x288(%rbp)
movq -0x20(%rbp), %rdi
addq $0x48, %rdi
callq 0x355f0
movq %rax, %rcx
movq -0x288(%rbp), %rax
cmpq %rcx, %rax
jae 0x33424
fldt -0xf0(%rbp)
fstpt -0x294(%rbp)
movq -0x20(%rbp), %rdi
addq $0x48, %rdi
movzbl -0x1ea(%rbp), %eax
movl %eax, %esi
callq 0x34c70
fldt -0x294(%rbp)
fldt (%rax)
fdivp %st, %st(1)
fstpt (%rax)
movb -0x1ea(%rbp), %al
addb $0x1, %al
movb %al, -0x1ea(%rbp)
jmp 0x333bc
jmp 0x33426
movq -0x20(%rbp), %rax
addq $0x2a0, %rsp            # imm = 0x2A0
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x5920
nopl (%rax)