// File: adamiaonr[P]rid-analytics/src/rid-analytics.cpp
// Function: RID_Analytics::init_output(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::init_output(
    std::string label,
    std::string output_dir) {

    // we create 4 .tsv files:
    //  -# events.tsv       : probs of events (LLM, SLM, NLM, MLM) per router
    //  -# outcomes.tsv     : probs + latency + router of outcome
    //  -# forwarding.tsv   : description of fwding events, including next router probs
    //  -# ifaces.tsv       : description of fwding events, including iface probs per router

    // file names follow the convention <type>.<label>.<unix-timestamp>.tsv
    // this->output_file = std::vector<std::ofstream> (3);
    // std::string filename[3] = {"events", "outcomes", "forwarding"};
    // for (int i = 0; i < 3; i++) {
    //     filename[i] += std::string(".") + label + std::string(".") + get_unix_timestamp() + std::string(".tsv");
    //     this->output_file[i].open(output_dir + std::string("/") + filename[i]);
    // }
    this->output_file = std::vector<std::ofstream> (2);
    std::string filename[2] = {"events", "outcomes"};
    for (int i = 0; i < 2; i++) {
        filename[i] += std::string(".") + label + std::string(".") + get_unix_timestamp() + std::string(".tsv");
        this->output_file[i].open(output_dir + std::string("/") + filename[i]);
    }

    // events header
    this->output_file[0] << "router\tnlm\tmlm\tllm\tslmc\tslmi\tfpd\n";
    // outcome header
    this->output_file[1] << "router\ttype\tprob\tlatency\n";
    // // forwarding header
    // this->output_file[2] << "from\tinprob\tinto";
    // for (auto const& r : this->routers)
    //     this->output_file[2] << "\t" << r.second->get_id();
    // this->output_file[2] << "\n";
    
    // ifaces header
    // determine router w/ largest iface_num
    uint8_t iface_num = 0;
    for (auto const& r : this->routers) {
        iface_num = std::max(iface_num, r.second->get_iface_num());
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x310, %rsp            # imm = 0x310
movq %rsi, -0x268(%rbp)
movq %rdx, -0x260(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x258(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0x250(%rbp)
callq 0x51cc0
movq -0x250(%rbp), %rdx
leaq -0x30(%rbp), %rdi
movl $0x2, %esi
callq 0x51ce0
jmp 0x4d7d7
movq -0x258(%rbp), %rdi
addq $0x98, %rdi
leaq -0x30(%rbp), %rsi
movq %rsi, -0x280(%rbp)
callq 0x51d50
movq -0x280(%rbp), %rdi
callq 0x51b40
leaq -0x31(%rbp), %rdi
callq 0x51d80
movb $0x1, -0x9b(%rbp)
leaq -0x90(%rbp), %rax
movq %rax, -0x278(%rbp)
movq %rax, -0x98(%rbp)
leaq -0x99(%rbp), %rdi
movq %rdi, -0x270(%rbp)
callq 0x5930
movq -0x278(%rbp), %rdi
movq -0x270(%rbp), %rdx
leaq 0x1668e(%rip), %rsi     # 0x63edc
callq 0x30320
jmp 0x4d855
leaq -0x70(%rbp), %rax
movq %rax, -0x290(%rbp)
movq %rax, -0x98(%rbp)
leaq -0x9a(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0x5930
movq -0x290(%rbp), %rdi
movq -0x288(%rbp), %rdx
leaq 0x16654(%rip), %rsi     # 0x63ee3
callq 0x30320
jmp 0x4d896
movb $0x0, -0x9b(%rbp)
leaq -0x9a(%rbp), %rdi
callq 0x5510
leaq -0x99(%rbp), %rdi
callq 0x5510
movl $0x0, -0xa0(%rbp)
cmpl $0x2, -0xa0(%rbp)
jge 0x4dd93
leaq -0x141(%rbp), %rdi
movq %rdi, -0x298(%rbp)
callq 0x5930
movq -0x298(%rbp), %rdx
leaq 0x159d8(%rip), %rsi     # 0x632c5
leaq -0x140(%rbp), %rdi
callq 0x30320
jmp 0x4d8fb
movq -0x268(%rbp), %rdx
leaq -0x120(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x51da0
jmp 0x4d917
leaq -0x169(%rbp), %rdi
movq %rdi, -0x2a0(%rbp)
callq 0x5930
movq -0x2a0(%rbp), %rdx
leaq 0x1598d(%rip), %rsi     # 0x632c5
leaq -0x168(%rbp), %rdi
callq 0x30320
jmp 0x4d946
leaq -0x100(%rbp), %rdi
leaq -0x120(%rbp), %rsi
leaq -0x168(%rbp), %rdx
callq 0x31ae0
jmp 0x4d962
leaq -0x190(%rbp), %rdi
callq 0x4e030
jmp 0x4d970
leaq -0xe0(%rbp), %rdi
leaq -0x100(%rbp), %rsi
leaq -0x190(%rbp), %rdx
callq 0x31ae0
jmp 0x4d98c
leaq -0x1b1(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
callq 0x5930
movq -0x2a8(%rbp), %rdx
leaq 0x1653f(%rip), %rsi     # 0x63eec
leaq -0x1b0(%rbp), %rdi
callq 0x30320
jmp 0x4d9bb
leaq -0xc0(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
leaq -0x1b0(%rbp), %rdx
callq 0x31ae0
jmp 0x4d9d7
movslq -0xa0(%rbp), %rax
shlq $0x5, %rax
leaq -0x90(%rbp,%rax), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x5650
jmp 0x4d9f8
leaq -0xc0(%rbp), %rdi
callq 0x52f0
leaq -0x1b0(%rbp), %rdi
callq 0x52f0
leaq -0x1b1(%rbp), %rdi
callq 0x5510
leaq -0xe0(%rbp), %rdi
callq 0x52f0
leaq -0x190(%rbp), %rdi
callq 0x52f0
leaq -0x100(%rbp), %rdi
callq 0x52f0
leaq -0x168(%rbp), %rdi
callq 0x52f0
leaq -0x169(%rbp), %rdi
callq 0x5510
leaq -0x120(%rbp), %rdi
callq 0x52f0
leaq -0x140(%rbp), %rdi
callq 0x52f0
leaq -0x141(%rbp), %rdi
callq 0x5510
movq -0x258(%rbp), %rdi
addq $0x98, %rdi
movslq -0xa0(%rbp), %rsi
callq 0x51df0
movq %rax, -0x2b8(%rbp)
leaq -0x219(%rbp), %rdi
movq %rdi, -0x2b0(%rbp)
callq 0x5930
movq -0x2b0(%rbp), %rdx
leaq 0x16433(%rip), %rsi     # 0x63ef1
leaq -0x218(%rbp), %rdi
callq 0x30320
jmp 0x4dacc
movq -0x260(%rbp), %rsi
leaq -0x1f8(%rbp), %rdi
leaq -0x218(%rbp), %rdx
callq 0x43910
jmp 0x4dae8
movslq -0xa0(%rbp), %rax
shlq $0x5, %rax
leaq -0x90(%rbp,%rax), %rdx
leaq -0x1d8(%rbp), %rdi
leaq -0x1f8(%rbp), %rsi
callq 0x51da0
jmp 0x4db10
movq -0x2b8(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
movl $0x10, %edx
callq 0x5220
jmp 0x4db2a
leaq -0x1d8(%rbp), %rdi
callq 0x52f0
leaq -0x1f8(%rbp), %rdi
callq 0x52f0
leaq -0x218(%rbp), %rdi
callq 0x52f0
leaq -0x219(%rbp), %rdi
callq 0x5510
movl -0xa0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa0(%rbp)
jmp 0x4d8bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x31(%rbp), %rdi
callq 0x51d80
jmp 0x4df5f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4dbae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x9a(%rbp), %rdi
callq 0x5510
leaq -0x99(%rbp), %rdi
callq 0x5510
testb $0x1, -0x9b(%rbp)
jne 0x4dbc5
jmp 0x4dc12
movq -0x98(%rbp), %rax
leaq -0x90(%rbp), %rcx
cmpq %rax, %rcx
movq %rax, -0x2c0(%rbp)
je 0x4dc10
movq -0x2c0(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x2c8(%rbp)
callq 0x52f0
movq -0x2c8(%rbp), %rax
leaq -0x90(%rbp), %rcx
cmpq %rcx, %rax
movq %rax, -0x2c0(%rbp)
jne 0x4dbdf
jmp 0x4dc12
jmp 0x4df5f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4dd17
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4dd0b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4dcf3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4dce7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4dcdb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4dccf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4dcb7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4dcab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x52f0
leaq -0x1b0(%rbp), %rdi
callq 0x52f0
leaq -0x1b1(%rbp), %rdi
callq 0x5510
leaq -0xe0(%rbp), %rdi
callq 0x52f0
leaq -0x190(%rbp), %rdi
callq 0x52f0
leaq -0x100(%rbp), %rdi
callq 0x52f0
leaq -0x168(%rbp), %rdi
callq 0x52f0
leaq -0x169(%rbp), %rdi
callq 0x5510
leaq -0x120(%rbp), %rdi
callq 0x52f0
leaq -0x140(%rbp), %rdi
callq 0x52f0
leaq -0x141(%rbp), %rdi
callq 0x5510
jmp 0x4df13
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4dd82
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4dd76
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4dd6a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0x52f0
leaq -0x1f8(%rbp), %rdi
callq 0x52f0
leaq -0x218(%rbp), %rdi
callq 0x52f0
leaq -0x219(%rbp), %rdi
callq 0x5510
jmp 0x4df13
movq -0x258(%rbp), %rdi
addq $0x98, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x51df0
movq %rax, %rdi
leaq 0x1613f(%rip), %rsi     # 0x63ef3
callq 0x5480
jmp 0x4ddbb
movq -0x258(%rbp), %rdi
addq $0x98, %rdi
movl $0x1, %esi
callq 0x51df0
movq %rax, %rdi
leaq 0x16138(%rip), %rsi     # 0x63f15
callq 0x5480
jmp 0x4dde4
movq -0x258(%rbp), %rax
movb $0x0, -0x21a(%rbp)
addq $0x50, %rax
movq %rax, -0x228(%rbp)
movq -0x228(%rbp), %rdi
callq 0x51be0
movq %rax, -0x230(%rbp)
movq -0x228(%rbp), %rdi
callq 0x51c40
movq %rax, -0x238(%rbp)
leaq -0x230(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x51c10
testb $0x1, %al
jne 0x4de3f
jmp 0x4dec0
leaq -0x230(%rbp), %rdi
callq 0x51c70
movq %rax, -0x240(%rbp)
movq -0x240(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x51e10
movb %al, -0x2c9(%rbp)
jmp 0x4de6a
movb -0x2c9(%rbp), %al
movb %al, -0x241(%rbp)
leaq -0x21a(%rbp), %rdi
leaq -0x241(%rbp), %rsi
callq 0x35360
movq %rax, -0x2d8(%rbp)
jmp 0x4de92
movq -0x2d8(%rbp), %rax
movb (%rax), %al
movb %al, -0x21a(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x51c90
jmp 0x4de23
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4df13
leaq -0x90(%rbp), %rax
movq %rax, -0x2e8(%rbp)
addq $0x40, %rax
movq %rax, -0x2e0(%rbp)
movq -0x2e0(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x2f0(%rbp)
callq 0x52f0
movq -0x2e8(%rbp), %rcx
movq -0x2f0(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x2e0(%rbp)
jne 0x4ded9
addq $0x310, %rsp            # imm = 0x310
popq %rbp
retq
leaq -0x90(%rbp), %rax
movq %rax, -0x300(%rbp)
addq $0x40, %rax
movq %rax, -0x2f8(%rbp)
movq -0x2f8(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x308(%rbp)
callq 0x52f0
movq -0x300(%rbp), %rcx
movq -0x308(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x2f8(%rbp)
jne 0x4df2c
jmp 0x4df5f
movq -0x40(%rbp), %rdi
callq 0x5920
nopl (%rax,%rax)