// File: adamiaonr[P]rid-analytics/src/rid-analytics.cpp
// Function: RID_Analytics::add_fwd(RID_Router*, int, Path_State*, std::vector<RID_Analytics::fwd_decision, std::allocator<RID_Analytics::fwd_decision>>)
void RID_Analytics::add_fwd(
    RID_Router * router,
    int in_iface,
    Path_State * state,
    std::vector<RID_Analytics::fwd_decision> fwd_decisions) {

    // forwarding file
    // forwarding header : 'from\tinprob\tinto\t<router-0>\t<router-1>\t....\t<router-n>\n'
    this->output_file[2] << router->get_id() 
        << "\t" << state->get_in_iface_prob() 
        << "\t" << router->get_next_hop(in_iface).router->get_id();

    // add routers attached to ifaces of router
    std::map<std::string, __float080> neighbor_probs;
    for (unsigned int i = 0; i < fwd_decisions.size(); i++) {

        std::string neighbor_id = fwd_decisions[i].next_router->get_id();
        neighbor_probs[neighbor_id] = fwd_decisions[i].state->get_in_iface_prob();
    }

    // add line to forwarding file
    for (auto const& r : this->routers) {
        if (neighbor_probs.count(r.second->get_id()) > 0)
            this->output_file[2] << "\t" << neighbor_probs[r.second->get_id()];
        else
            this->output_file[2] << "\t" << 0.0;
    }
    this->output_file[2] << "\n";
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1f0, %rsp            # imm = 0x1F0
movq %r8, -0x168(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x160(%rbp)
addq $0x98, %rdi
movl $0x2, %esi
callq 0x51df0
movq %rax, -0x158(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x48(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x35650
movq -0x158(%rbp), %rdi
movq -0x150(%rbp), %rsi
callq 0x5430
movq %rax, -0x148(%rbp)
jmp 0x4e928
movq -0x148(%rbp), %rdi
leaq 0x14bd1(%rip), %rsi     # 0x63507
callq 0x5480
movq %rax, -0x170(%rbp)
jmp 0x4e944
movq -0x20(%rbp), %rdi
callq 0x3f790
fstpt -0x17c(%rbp)
jmp 0x4e955
movq -0x170(%rbp), %rdi
fldt -0x17c(%rbp)
movq %rsp, %rax
fstpt (%rax)
callq 0x55b0
movq %rax, -0x188(%rbp)
jmp 0x4e975
movq -0x188(%rbp), %rdi
leaq 0x14b84(%rip), %rsi     # 0x63507
callq 0x5480
movq %rax, -0x190(%rbp)
jmp 0x4e991
movq -0x10(%rbp), %rdi
movzbl -0x14(%rbp), %esi
callq 0x35610
movb %dl, -0x199(%rbp)
movq %rax, -0x198(%rbp)
jmp 0x4e9ad
movb -0x199(%rbp), %al
movq -0x198(%rbp), %rcx
movq %rcx, -0x88(%rbp)
movb %al, -0x80(%rbp)
movq -0x88(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x35650
jmp 0x4e9d6
movq -0x190(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x5430
jmp 0x4e9e8
leaq -0x78(%rbp), %rdi
callq 0x52f0
leaq -0x48(%rbp), %rdi
callq 0x52f0
leaq -0xb8(%rbp), %rdi
callq 0x52570
movl $0x0, -0xbc(%rbp)
movq -0x168(%rbp), %rdi
movl -0xbc(%rbp), %eax
movq %rax, -0x1a8(%rbp)
callq 0x52590
movq %rax, %rcx
movq -0x1a8(%rbp), %rax
cmpq %rcx, %rax
jae 0x4eb31
movq -0x168(%rbp), %rdi
movl -0xbc(%rbp), %eax
movl %eax, %esi
callq 0x525b0
movq 0x8(%rax), %rsi
leaq -0xe0(%rbp), %rdi
callq 0x35650
jmp 0x4ea62
movq -0x168(%rbp), %rdi
movl -0xbc(%rbp), %eax
movl %eax, %esi
callq 0x525b0
movq 0x18(%rax), %rdi
callq 0x3f790
fstpt -0x1b4(%rbp)
jmp 0x4ea87
leaq -0xb8(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x525d0
movq %rax, -0x1c0(%rbp)
jmp 0x4eaa3
movq -0x1c0(%rbp), %rax
fldt -0x1b4(%rbp)
fstpt (%rax)
leaq -0xe0(%rbp), %rdi
callq 0x52f0
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xbc(%rbp)
jmp 0x4ea10
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x4eaf5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x52f0
leaq -0x48(%rbp), %rdi
callq 0x52f0
jmp 0x4ed53
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x4ed47
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x52f0
jmp 0x4ed47
movq -0x160(%rbp), %rax
addq $0x50, %rax
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rdi
callq 0x51be0
movq %rax, -0xf0(%rbp)
movq -0xe8(%rbp), %rdi
callq 0x51c40
movq %rax, -0xf8(%rbp)
leaq -0xf0(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x51c10
testb $0x1, %al
jne 0x4eb85
jmp 0x4ed09
leaq -0xf0(%rbp), %rdi
callq 0x51c70
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rax
movq 0x20(%rax), %rsi
leaq -0x120(%rbp), %rdi
callq 0x35650
jmp 0x4ebb1
leaq -0xb8(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x526b0
movq %rax, -0x1c8(%rbp)
jmp 0x4ebcd
leaq -0x120(%rbp), %rdi
callq 0x52f0
movq -0x1c8(%rbp), %rax
cmpq $0x0, %rax
jbe 0x4ecb3
movq -0x160(%rbp), %rdi
addq $0x98, %rdi
movl $0x2, %esi
callq 0x51df0
movq %rax, %rdi
leaq 0x148fb(%rip), %rsi     # 0x63507
callq 0x5480
movq %rax, -0x1d0(%rbp)
jmp 0x4ec1a
movq -0x100(%rbp), %rax
movq 0x20(%rax), %rsi
leaq -0x140(%rbp), %rdi
callq 0x35650
jmp 0x4ec33
leaq -0xb8(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x52710
movq %rax, -0x1d8(%rbp)
jmp 0x4ec4f
movq -0x1d0(%rbp), %rdi
movq -0x1d8(%rbp), %rax
fldt (%rax)
movq %rsp, %rax
fstpt (%rax)
callq 0x55b0
jmp 0x4ec6b
leaq -0x140(%rbp), %rdi
callq 0x52f0
jmp 0x4ecf6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x52f0
jmp 0x4ed47
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x52f0
jmp 0x4ed47
movq -0x160(%rbp), %rdi
addq $0x98, %rdi
movl $0x2, %esi
callq 0x51df0
movq %rax, %rdi
leaq 0x14832(%rip), %rsi     # 0x63507
callq 0x5480
movq %rax, -0x1e0(%rbp)
jmp 0x4ece3
movq -0x1e0(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x59e0
jmp 0x4ecf4
jmp 0x4ecf6
jmp 0x4ecf8
leaq -0xf0(%rbp), %rdi
callq 0x51c90
jmp 0x4eb69
movq -0x160(%rbp), %rdi
addq $0x98, %rdi
movl $0x2, %esi
callq 0x51df0
movq %rax, %rdi
leaq 0x14798(%rip), %rsi     # 0x634c3
callq 0x5480
jmp 0x4ed32
leaq -0xb8(%rbp), %rdi
callq 0x527f0
addq $0x1f0, %rsp            # imm = 0x1F0
popq %rbp
retq
leaq -0xb8(%rbp), %rdi
callq 0x527f0
movq -0x50(%rbp), %rdi
callq 0x5920
nopl (%rax)