// File: karel-brinda[P]ococo/src/stats.h
// Function: ococo::stats_t<unsigned short, 3, 4>::export_stats(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) const
int stats_t<T, counter_size, refbase_size>::export_stats(
    const std::string &stats_fn) const {
    assert(check_allocation());

    int error_code = 0;

    FILE *fo = fopen(stats_fn.c_str(), "w+");
    if (fo == nullptr) {
        ococo::error("File with statistics could not be opened ('%s').\n",
                     stats_fn.c_str());
        return -1;
    }

    /* number of seqs */
    fwrite(&n_seqs, sizeof(int32_t), 1, fo);

    for (int seqid = 0; seqid < n_seqs; seqid++) {
        /* sequence */
        single_seq_serial_t seq_ser = {0};
        seq_ser.seq_active          = seq_active[seqid];
        seq_ser.seq_len             = seq_len[seqid];
        strncpy(seq_ser.seq_name, seq_name[seqid].c_str(), 999);
        strncpy(seq_ser.seq_name, seq_name[seqid].c_str(), 999);
        uint64_t written = 0;
        written += fwrite(&seq_ser, sizeof(single_seq_serial_t), 1, fo);
        written += fwrite(seq_stats[seqid], sizeof(T), seq_len[seqid], fo);
        if (written != 1 + static_cast<uint64_t>(seq_len[seqid])) {
            ococo::error(
                "Problem with writting to the file with statistics ('%s').\n",
                stats_fn.c_str());
            return -1;
        }
    }

    error_code = fclose(fo);
    if (error_code != 0) {
        ococo::error("File with statistics could not be closed ('%s').\n",
                     stats_fn.c_str());
        return -1;
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x830, %rsp            # imm = 0x830
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x820(%rbp)
callq 0x9440
testb $0x1, %al
jne 0xaa09
jmp 0xaa0b
jmp 0xaa2a
leaq 0x6d96d(%rip), %rdi     # 0x7837f
leaq 0x6d979(%rip), %rsi     # 0x78392
movl $0x151, %edx            # imm = 0x151
leaq 0x6e484(%rip), %rcx     # 0x78ea9
callq 0x4360
movl $0x0, -0x1c(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4200
movq %rax, %rdi
leaq 0x6d83b(%rip), %rsi     # 0x7827f
callq 0x4690
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xaa7a
movq -0x18(%rbp), %rdi
callq 0x4200
movq %rax, %rsi
leaq 0x6d9bc(%rip), %rdi     # 0x78423
movb $0x0, %al
callq 0xf460
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xac6c
movq -0x820(%rbp), %rdi
movq -0x28(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x4b20
movl $0x0, -0x2c(%rbp)
movq -0x820(%rbp), %rcx
movl -0x2c(%rbp), %eax
cmpl (%rcx), %eax
jge 0xac30
leaq -0x810(%rbp), %rdi
xorl %esi, %esi
movl $0x7e0, %edx            # imm = 0x7E0
callq 0x42d0
movq -0x820(%rbp), %rax
movq 0x8(%rax), %rcx
movslq -0x2c(%rbp), %rdx
movb (%rcx,%rdx), %cl
andb $0x1, %cl
movb %cl, -0x810(%rbp)
movq 0x10(%rax), %rcx
movslq -0x2c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq %rcx, -0x808(%rbp)
leaq -0x810(%rbp), %rcx
addq $0x10, %rcx
movq %rcx, -0x830(%rbp)
movq 0x18(%rax), %rdi
movslq -0x2c(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rdi
callq 0x4200
movq -0x830(%rbp), %rdi
movq %rax, %rsi
movl $0x3e7, %edx            # imm = 0x3E7
callq 0x42c0
movq -0x820(%rbp), %rax
leaq -0x810(%rbp), %rcx
addq $0x10, %rcx
movq %rcx, -0x828(%rbp)
movq 0x18(%rax), %rdi
movslq -0x2c(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rdi
callq 0x4200
movq -0x828(%rbp), %rdi
movq %rax, %rsi
movl $0x3e7, %edx            # imm = 0x3E7
callq 0x42c0
movq $0x0, -0x818(%rbp)
movq -0x28(%rbp), %rcx
leaq -0x810(%rbp), %rdi
movl $0x7e0, %esi            # imm = 0x7E0
movl $0x1, %edx
callq 0x4b20
movq %rax, %rcx
movq -0x820(%rbp), %rax
addq -0x818(%rbp), %rcx
movq %rcx, -0x818(%rbp)
movq 0x28(%rax), %rcx
movslq -0x2c(%rbp), %rdx
movq (%rcx,%rdx,8), %rdi
movq 0x10(%rax), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x28(%rbp), %rcx
movl $0x2, %esi
callq 0x4b20
movq -0x820(%rbp), %rcx
addq -0x818(%rbp), %rax
movq %rax, -0x818(%rbp)
movq -0x818(%rbp), %rax
movq 0x10(%rcx), %rcx
movslq -0x2c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
je 0xac20
movq -0x18(%rbp), %rdi
callq 0x4200
movq %rax, %rsi
leaq 0x6e324(%rip), %rdi     # 0x78f34
movb $0x0, %al
callq 0xf460
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xac6c
jmp 0xac22
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xaa9b
movq -0x28(%rbp), %rdi
callq 0x4590
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0xac65
movq -0x18(%rbp), %rdi
callq 0x4200
movq %rax, %rsi
leaq 0x6d929(%rip), %rdi     # 0x7857e
movb $0x0, %al
callq 0xf460
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xac6c
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x830, %rsp            # imm = 0x830
popq %rbp
retq
nopl (%rax,%rax)