// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x7f8, %rsp            # imm = 0x7F8
movq %rsi, %rbx
movq %rdi, %r14
callq 0x7144
testb %al, %al
je 0x7e2c
movq (%rbx), %rdi
leaq 0x395ad(%rip), %rsi     # 0x41297
callq 0x45f0
testq %rax, %rax
je 0x7dd4
movq %rax, %r15
movq %rbx, 0x8(%rsp)
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
movq %rax, %rcx
callq 0x4a20
xorl %ebx, %ebx
xorl %r13d, %r13d
movq %r15, 0x10(%rsp)
movslq (%r14), %rax
cmpq %rax, %r13
jge 0x7de0
movl $0x7e0, %edx            # imm = 0x7E0
leaq 0x18(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x42e0
movq 0x8(%r14), %rax
movb (%rax,%r13), %al
movb %al, 0x18(%rsp)
movq 0x10(%r14), %rax
movq (%rax,%rbx), %rax
movq %rax, 0x20(%rsp)
movq 0x18(%r14), %r12
movq (%r12,%rbx,4), %rsi
movl $0x3e7, %edx            # imm = 0x3E7
leaq 0x28(%rsp), %rbp
movq %rbp, %rdi
callq 0x42c0
movq (%r12,%rbx,4), %rsi
movl $0x3e7, %edx            # imm = 0x3E7
movq %rbp, %rdi
callq 0x42c0
movl $0x7e0, %esi            # imm = 0x7E0
movq %r15, %rdi
movq 0x10(%rsp), %r15
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x4a20
movq %rax, %r12
movq 0x10(%r14), %rax
movq 0x28(%r14), %rcx
movq (%rcx,%rbx), %rdi
movq (%rax,%rbx), %rdx
pushq $0x2
popq %rsi
movq %r15, %rcx
callq 0x4a20
addq %r12, %rax
movq 0x10(%r14), %rcx
movq (%rcx,%rbx), %rcx
incq %rcx
cmpq %rcx, %rax
jne 0x7dfd
incq %r13
addq $0x8, %rbx
jmp 0x7d1b
movq (%rbx), %rsi
leaq 0x3965d(%rip), %rdi     # 0x4143b
jmp 0x7e0c
movq %r15, %rdi
callq 0x4530
testl %eax, %eax
je 0x7e28
movq 0x8(%rsp), %rax
movq (%rax), %rsi
leaq 0x3979b(%rip), %rdi     # 0x41596
jmp 0x7e0c
movq 0x8(%rsp), %rax
movq (%rax), %rsi
leaq 0x3a0f2(%rip), %rdi     # 0x41efe
xorl %eax, %eax
callq 0xa428
pushq $-0x1
popq %rax
addq $0x7f8, %rsp            # imm = 0x7F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0x7e16
leaq 0x39564(%rip), %rdi     # 0x41397
leaq 0x39570(%rip), %rsi     # 0x413aa
leaq 0x3a032(%rip), %rcx     # 0x41e73
movl $0x151, %edx            # imm = 0x151
callq 0x4360
nop