// File: /workspace/github_cpp_makefile_star2_O1/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 $0x88, %rsp
movq %rdx, 0x30(%rsp)
movl %esi, %r13d
movq %rdi, %rbx
fldt 0xc0(%rsp)
testl %esi, %esi
js 0x1c9bf
movzbl 0x24(%rbx), %eax
cmpl %r13d, %eax
jle 0x1c9bf
movq %rcx, 0x20(%rsp)
movq %r8, 0x28(%rsp)
movl %r9d, 0xc(%rsp)
movq 0x28(%rbx), %rcx
movq 0x30(%rbx), %rax
movq %rcx, 0x38(%rsp)
xorl %edx, %edx
testq %rcx, %rcx
sets %dl
fildll 0x38(%rsp)
leaq 0x1501d(%rip), %rcx     # 0x317f8
fadds (%rcx,%rdx,4)
fmul %st(1), %st
fxch %st(1)
fstpt 0x10(%rsp)
flds 0x15014(%rip)           # 0x31800
xorl %ecx, %ecx
fxch %st(1)
fucomi %st(1), %st
fldz
fld %st(0)
fstpt 0x4c(%rsp)
fcmovnb %st(2), %st
fstp %st(2)
fsubp %st, %st(1)
setae %cl
fnstcw 0x6(%rsp)
movzwl 0x6(%rsp), %edx
orl $0xc00, %edx            # imm = 0xC00
movw %dx, 0x8(%rsp)
fldcw 0x8(%rsp)
fistpll 0x40(%rsp)
fldcw 0x6(%rsp)
shlq $0x3f, %rcx
xorq 0x40(%rsp), %rcx
movl %r13d, %r12d
movq %r12, %rdx
shlq $0x5, %rdx
leaq (%rdx,%rdx,4), %r14
movq %rcx, 0x58(%rax,%r14)
movq 0x23772(%rip), %rbp     # 0x3ffb8
leaq 0x15085(%rip), %rsi     # 0x318d2
movl $0x31, %edx
movq %rbp, %rdi
callq 0x4400
movq %rbp, %rdi
movl %r13d, %esi
callq 0x46d0
movq %rax, %rbp
leaq 0x15095(%rip), %rsi     # 0x31904
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 0x10(%rsp)
fstpt 0x10(%rax,%r14)
movzbl 0x21(%rbx), %esi
fldt 0x4c(%rsp)
fstpt 0x70(%rsp)
leaq 0x58(%rsp), %r13
leaq 0x70(%rsp), %rdx
leaq 0xb(%rsp), %rcx
movq %r13, %rdi
callq 0x1ddb8
movq 0x30(%rbx), %rax
movq %r14, 0x10(%rsp)
leaq (%rax,%r14), %rdi
addq $0x20, %rdi
movq %r13, %rsi
callq 0x1ed30
movq (%r13), %rdi
testq %rdi, %rdi
je 0x1c91a
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x43a0
cmpb $0x0, 0x21(%rbx)
je 0x1c983
xorl %r15d, %r15d
leaq 0x58(%rsp), %r13
leaq (%r12,%r12,4), %r14
shlq $0x5, %r14
xorl %ebp, %ebp
leaq 0x1(%rbp), %r12
movl %r12d, 0x58(%rsp)
movq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x1de3c
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 0x1c973
movl $0x1, %edx
movl %ebp, %ecx
shll %cl, %edx
addq %r14, %rax
orw %dx, 0x50(%rax)
movzbl 0x21(%rbx), %eax
addq $0x10, %r15
movq %r12, %rbp
cmpq %rax, %r12
jb 0x1c932
movq 0x30(%rbx), %rax
movq 0x10(%rsp), %r14
leaq (%rax,%r14), %rdi
addq $0x60, %rdi
movq 0x20(%rsp), %rsi
callq 0x1e5e8
movq 0x30(%rbx), %rax
movq 0x28(%rsp), %rcx
movq %rcx, 0x90(%rax,%r14)
movl 0xc(%rsp), %ecx
movb %cl, 0x98(%rax,%r14)
xorl %eax, %eax
jmp 0x1ca39
fstp %st(0)
movq 0x23628(%rip), %r14     # 0x3fff0
leaq 0x14ebb(%rip), %rsi     # 0x3188a
movl $0x41, %edx
movq %r14, %rdi
callq 0x4400
movq %r14, %rdi
movl %r13d, %esi
callq 0x46d0
movq %rax, %r14
leaq 0x14edb(%rip), %rsi     # 0x318cc
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
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop