// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rdx, 0x20(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdi, %r14
leaq 0xd0(%rsp), %rbx
pushq $0x2
popq %rsi
leaq 0x50(%rsp), %rdx
movq %rbx, %rdi
callq 0x21704
addq $0x98, %r14
movq %r14, 0x10(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x22568
movq %rbx, %rdi
callq 0x216e2
leaq 0xbb03(%rip), %rsi      # 0x2af95
leaq 0xd0(%rsp), %r12
leaq 0x50(%rsp), %rdx
movq %r12, %rdi
callq 0x16c66
leaq 0xf0(%rsp), %rdi
leaq 0xbae6(%rip), %rsi      # 0x2af9c
leaq 0xb0(%rsp), %rdx
callq 0x16c66
xorl %eax, %eax
leaq 0x70(%rsp), %r15
leaq 0xb0(%rsp), %r13
movq %rax, 0x18(%rsp)
cmpq $0x400, %rax            # imm = 0x400
je 0x1f684
movq %r15, %rdi
leaq 0xafd8(%rip), %rsi      # 0x2a4c5
leaq 0xf(%rsp), %rdx
callq 0x16c66
leaq 0x90(%rsp), %rdi
movq %r15, %rsi
movq 0x28(%rsp), %rdx
callq 0x21755
leaq 0x158(%rsp), %rbx
movq %rbx, %rdi
leaq 0xafa7(%rip), %rsi      # 0x2a4c5
leaq 0xe(%rsp), %rdx
callq 0x16c66
leaq 0x30(%rsp), %rdi
leaq 0x90(%rsp), %rsi
movq %rbx, %rdx
callq 0x178e0
leaq 0x138(%rsp), %r14
movq %r14, %rdi
callq 0x1f857
movq %r13, %rdi
leaq 0x30(%rsp), %rsi
movq %r14, %rdx
callq 0x178e0
leaq 0x118(%rsp), %rbx
movq %rbx, %rdi
leaq 0xba36(%rip), %rsi      # 0x2afa5
leaq 0xd(%rsp), %rdx
callq 0x16c66
leaq 0x50(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x178e0
movq %r12, %r14
movq %r12, %rdi
movq %r15, %rsi
callq 0x4790
movq %r15, %rdi
callq 0x41c0
leaq 0x118(%rsp), %rdi
callq 0x41c0
movq %r13, %rdi
callq 0x41c0
leaq 0x138(%rsp), %rdi
callq 0x41c0
leaq 0x30(%rsp), %r12
movq %r12, %rdi
callq 0x41c0
leaq 0x158(%rsp), %rdi
callq 0x41c0
leaq 0x90(%rsp), %rbp
movq %rbp, %rdi
callq 0x41c0
leaq 0x70(%rsp), %rdi
callq 0x41c0
movq 0x10(%rsp), %rax
movq (%rax), %r15
addq 0x18(%rsp), %r15
movq %r12, %rdi
leaq 0xb99b(%rip), %rsi      # 0x2afaa
movq %rbp, %rdx
callq 0x16c66
movq %r13, %rdi
movq 0x20(%rsp), %rsi
movq %r12, %rdx
callq 0x1c8d8
leaq 0x50(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %r12
movq %r13, %rsi
movq %r14, %rdx
callq 0x21755
movq %r15, %rdi
movq %rbp, %rsi
pushq $0x10
popq %rdx
callq 0x41d0
movq %rbp, %rdi
callq 0x41c0
movq %r12, %r13
movq %r12, %rdi
callq 0x41c0
leaq 0x30(%rsp), %rdi
callq 0x41c0
movq 0x18(%rsp), %rax
addq $0x200, %rax            # imm = 0x200
movq %r14, %r12
addq $0x20, %r12
leaq 0x70(%rsp), %r15
jmp 0x1f4d2
movq 0x10(%rsp), %rbx
movq (%rbx), %rdi
leaq 0xb919(%rip), %rsi      # 0x2afac
callq 0x43a0
movl $0x200, %edi            # imm = 0x200
addq (%rbx), %rdi
leaq 0xb927(%rip), %rsi      # 0x2afce
callq 0x43a0
pushq $0x20
popq %rbx
leaq (%rsp,%rbx), %rdi
addq $0xd0, %rdi
callq 0x41c0
addq $-0x20, %rbx
cmpq $-0x20, %rbx
jne 0x1f6af
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x41c0
jmp 0x1f7ce
jmp 0x1f7d6
jmp 0x1f7d6
movq %rax, %rbx
jmp 0x1f7a6
movq %rax, %rbx
jmp 0x1f733
movq %rax, %rbx
jmp 0x1f799
movq %rax, %rbx
jmp 0x1f726
movq %rax, %rbx
jmp 0x1f78c
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x41c0
leaq 0xb0(%rsp), %rdi
callq 0x41c0
leaq 0x30(%rsp), %rdi
jmp 0x1f7ab
movq %rax, %rbx
jmp 0x1f782
movq %rax, %rbx
jmp 0x1f775
movq %rax, %rbx
jmp 0x1f768
movq %rax, %rbx
jmp 0x1f75b
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x41c0
leaq 0x118(%rsp), %rdi
callq 0x41c0
leaq 0xb0(%rsp), %rdi
callq 0x41c0
leaq 0x138(%rsp), %rdi
callq 0x41c0
leaq 0x30(%rsp), %rdi
callq 0x41c0
leaq 0x158(%rsp), %rdi
callq 0x41c0
leaq 0x90(%rsp), %rdi
callq 0x41c0
leaq 0x70(%rsp), %rdi
callq 0x41c0
pushq $0x20
popq %r14
leaq (%rsp,%r14), %rdi
addq $0xd0, %rdi
callq 0x41c0
addq $-0x20, %r14
cmpq $-0x20, %r14
jne 0x1f7b4
movq %rbx, %rdi
callq 0x4700
movq %rax, %rbx
jmp 0x1f7b0
nop