// File: /workspace/github_cpp_makefile_star2_O3/adamiaonr[P]rid-analytics/src/rid-router.cpp
// Function: RID_Router::add_fwd_table_entry(int, long double, std::map<int, long double, std::less<int>, std::allocator<std::pair<int const, long double>>>*, std::map<int, std::vector<unsigned char, std::allocator<unsigned char>>, std::less<int>, std::allocator<std::pair<int const, std::vector<unsigned char, std::allocator<unsigned char>>>>>*, RID_Router*, int)
int RID_Router::add_fwd_table_entry(
    int i, 
    __float080 iface_proportion, 
    std::map<int, __float080> * f_distr,
    std::map<int, std::vector<uint8_t> > * tree_bitmasks,
    RID_Router * next_hop_router,
    int next_hop_iface) {

    if ((i < 0) || (i > (this->iface_num - 1))) {
        std::cerr << "RID_Router::add_fwd_table_entry() : [ERROR] invalid iface index: "
            << i << " vs. " << (int) this->iface_num << std::endl;
        return -1;
    }

    this->fwd_table[i].num_entries = (__float080) this->fwd_table_size * iface_proportion;
    std::cout << "RID_Router::add_fwd_table_entry() : [INFO] iface[" << i 
        << "].num_entries = " << this->fwd_table[i].num_entries << std::endl;
    
    this->fwd_table[i].iface = i;
    // iface_proportion : % of table entries associated w/ this iface
    this->fwd_table[i].iface_proportion = iface_proportion;
    // distribution of sizes among the entries associated w/ this iface
    this->fwd_table[i].f_distr = std::vector<__float080>(this->req_size, 0.0);

    for (int f = 0; f < this->req_size; f++) {
        this->fwd_table[i].f_distr[f] = (*f_distr)[f + 1];
        // set bit in the bitmask of fwd entry sizes if f_distr[f] > 0.0
        if (this->fwd_table[i].f_distr[f] > 0.0)
            this->fwd_table[i].f_bitmask |= (1 << f);
    }

    // copy the map of tree bitmasks into the router's iface
    this->fwd_table[i].tree_bitmasks = (*tree_bitmasks);

    // next hop information: remote router pointer and iface
    this->fwd_table[i].next_hop.router = next_hop_router;
    this->fwd_table[i].next_hop.iface = next_hop_iface;

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdx, 0x38(%rsp)
movl %esi, %r13d
movq %rdi, %rbx
fldt 0xd0(%rsp)
testl %esi, %esi
js 0x1c4a3
movzbl 0x24(%rbx), %eax
cmpl %r13d, %eax
jbe 0x1c4a3
movq %rcx, 0x28(%rsp)
movq %r8, 0x30(%rsp)
movl %r9d, 0x14(%rsp)
movq 0x28(%rbx), %rcx
movq 0x30(%rbx), %rax
movq %rcx, 0x40(%rsp)
xorl %edx, %edx
testq %rcx, %rcx
sets %dl
fildll 0x40(%rsp)
leaq 0x14319(%rip), %rcx     # 0x305d8
fadds (%rcx,%rdx,4)
fmul %st(1), %st
fxch %st(1)
fstpt 0x18(%rsp)
flds 0x14310(%rip)           # 0x305e0
xorl %ecx, %ecx
fxch %st(1)
fucomi %st(1), %st
fldz
fld %st(0)
fstpt 0x74(%rsp)
fcmovnb %st(2), %st
fstp %st(2)
fsubp %st, %st(1)
setae %cl
fnstcw 0xe(%rsp)
movzwl 0xe(%rsp), %edx
orl $0xc00, %edx            # imm = 0xC00
movw %dx, 0x10(%rsp)
fldcw 0x10(%rsp)
fistpll 0x48(%rsp)
fldcw 0xe(%rsp)
shlq $0x3f, %rcx
xorq 0x48(%rsp), %rcx
movl %r13d, %r12d
movq %r12, %rdx
shlq $0x5, %rdx
leaq (%rdx,%rdx,4), %r14
movq %rcx, 0x58(%rax,%r14)
movq 0x22c8e(%rip), %rbp     # 0x3efb8
leaq 0x14381(%rip), %rsi     # 0x306b2
movl $0x31, %edx
movq %rbp, %rdi
callq 0x4400
movq %rbp, %rdi
movl %r13d, %esi
callq 0x46d0
movq %rax, %rbp
leaq 0x14391(%rip), %rsi     # 0x306e4
movl $0x10, %edx
movq %rax, %rdi
callq 0x4400
movq 0x30(%rbx), %rax
movq 0x58(%rax,%r14), %rsi
movq %rbp, %rdi
callq 0x4290
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x4370
movsbl %al, %esi
movq %rbp, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42a0
movq 0x30(%rbx), %rax
movb %r13b, (%rax,%r14)
fldt 0x18(%rsp)
fstpt 0x10(%rax,%r14)
movzbl 0x21(%rbx), %esi
fldt 0x74(%rsp)
fstpt 0x80(%rsp)
leaq 0x50(%rsp), %r13
leaq 0x80(%rsp), %rdx
leaq 0x13(%rsp), %rcx
movq %r13, %rdi
callq 0x1d906
movq 0x30(%rbx), %rax
movq 0x20(%rax,%r14), %rdi
movq 0x30(%rax,%r14), %rsi
movaps (%r13), %xmm0
movups %xmm0, 0x20(%rax,%r14)
movq 0x10(%r13), %rcx
movq %r14, 0x18(%rsp)
movq %rcx, 0x30(%rax,%r14)
xorps %xmm0, %xmm0
movaps %xmm0, (%r13)
movq $0x0, 0x10(%r13)
testq %rdi, %rdi
je 0x1c430
subq %rdi, %rsi
callq 0x43a0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x1c430
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x43a0
cmpb $0x0, 0x21(%rbx)
je 0x1c51f
xorl %r15d, %r15d
leaq 0x50(%rsp), %r13
leaq (%r12,%r12,4), %r14
shlq $0x5, %r14
xorl %ebp, %ebp
leaq 0x1(%rbp), %r12
movl %r12d, 0x50(%rsp)
movq 0x38(%rsp), %rdi
movq %r13, %rsi
callq 0x1d994
fldt (%rax)
movq 0x30(%rbx), %rax
movq 0x20(%rax,%r14), %rcx
fld %st(0)
fstpt (%rcx,%r15)
fldz
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
jbe 0x1c48e
movl $0x1, %edx
movl %ebp, %ecx
shll %cl, %edx
leaq (%rax,%r14), %rcx
orw %dx, 0x50(%rcx)
movzbl 0x21(%rbx), %ecx
addq $0x10, %r15
movq %r12, %rbp
cmpq %rcx, %r12
jb 0x1c44c
jmp 0x1c523
fstp %st(0)
movq 0x22b44(%rip), %r14     # 0x3eff0
leaq 0x141b7(%rip), %rsi     # 0x3066a
movl $0x41, %edx
movq %r14, %rdi
callq 0x4400
movq %r14, %rdi
movl %r13d, %esi
callq 0x46d0
movq %rax, %r14
leaq 0x141d7(%rip), %rsi     # 0x306ac
movl $0x5, %edx
movq %rax, %rdi
callq 0x4400
movzbl 0x24(%rbx), %esi
movq %r14, %rdi
callq 0x46d0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4370
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42a0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x1c559
movq 0x30(%rbx), %rax
movq 0x18(%rsp), %r14
leaq (%rax,%r14), %rdi
addq $0x60, %rdi
movq 0x28(%rsp), %rsi
callq 0x1e168
movq 0x30(%rbx), %rax
movq 0x30(%rsp), %rcx
movq %rcx, 0x90(%rax,%r14)
movl 0x14(%rsp), %ecx
movb %cl, 0x98(%rax,%r14)
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop