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

    int error_code = 0;

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

    /* number of seqs */
    int32_t n_seqs_loaded;
    fread(&n_seqs_loaded, sizeof(int32_t), 1, fo);

    if (n_seqs_loaded != n_seqs) {
        error(
            "Numbers of sequences in stats and SAM/BAM do not correspond "
            "%" PRId32 "!=%" PRId32 ").\n",
            n_seqs_loaded, n_seqs);
        return -1;
    }

    for (int seqid = 0; seqid < n_seqs; seqid++) {
        /* sequence */

        single_seq_serial_t seq_ser;
        fread(&seq_ser, sizeof(single_seq_serial_t), 1, fo);

        if (seq_ser.seq_active != seq_active[seqid]) {
            error(
                "Active sequences in stats and SAM/BAM do not correspond "
                "(seqid %" PRId32 ").\n",
                seqid);
            return -1;
        }

        if (seq_ser.seq_len != seq_len[seqid]) {
            error(
                "Sequence lengths in stats and SAM/BAM do not correspond "
                "(seqid %" PRId32 ", %" PRId64 "!=%" PRId64 ").\n",
                seqid, seq_ser.seq_len, seq_len[seqid]);
            return -1;
        }

        if (seq_name[seqid].compare(seq_ser.seq_name) != 0) {
            error(
                "Sequence names in stats and SAM/BAM do not correspond "
                "(seqid %" PRId32 ", '%s'!='%s').\n",
                seqid, seq_ser.seq_name, seq_name[seqid].c_str());
            return -1;
        }

        fread(seq_stats[seqid], sizeof(T), seq_len[seqid], fo);
    }

    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 $0x7e8, %rsp            # imm = 0x7E8
movq %rsi, %rbx
movq %rdi, %r14
callq 0x7144
testb %al, %al
je 0x7320
movq (%rbx), %rdi
leaq 0x3d6f1(%rip), %rsi     # 0x448b5
callq 0x45f0
testq %rax, %rax
je 0x728f
movq %rax, %r15
leaq 0x4(%rsp), %r12
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %r12, %rdi
movq %rax, %rcx
callq 0x47d0
movl (%r12), %esi
movl (%r14), %edx
cmpl %edx, %esi
jne 0x72a2
xorl %ebp, %ebp
pushq $0x1
popq %r13
xorl %r12d, %r12d
movslq %esi, %rax
cmpq %rax, %r12
jge 0x72b2
movl $0x7e0, %esi            # imm = 0x7E0
leaq 0x8(%rsp), %rdi
movq %r13, %rdx
movq %r15, %rcx
callq 0x47d0
movb 0x8(%rsp), %al
movq 0x8(%r14), %rcx
cmpb (%rcx,%r12), %al
jne 0x72ca
movq 0x10(%rsp), %rdx
movq 0x10(%r14), %rax
movq (%rax,%r12,8), %rcx
cmpq %rcx, %rdx
jne 0x72dd
movq 0x18(%r14), %rdi
addq %rbp, %rdi
leaq 0x18(%rsp), %rsi
callq 0x4150
testl %eax, %eax
jne 0x72e9
movq 0x10(%r14), %rax
movq 0x28(%r14), %rcx
movq (%rcx,%r12,8), %rdi
movq (%rax,%r12,8), %rdx
pushq $0x2
popq %rsi
movq %r15, %rcx
callq 0x47d0
incq %r12
movl (%r14), %esi
addq $0x20, %rbp
jmp 0x7203
movq (%rbx), %rsi
leaq 0x3a1a2(%rip), %rdi     # 0x4143b
xorl %eax, %eax
callq 0xa428
jmp 0x7307
leaq 0x3a1c4(%rip), %rdi     # 0x4146d
xorl %eax, %eax
callq 0xa428
jmp 0x7307
movq %r15, %rdi
callq 0x4530
testl %eax, %eax
je 0x731c
movq (%rbx), %rsi
leaq 0x3a2ce(%rip), %rdi     # 0x41596
jmp 0x7299
leaq 0x3a1e2(%rip), %rdi     # 0x414b3
movl %r12d, %esi
xorl %eax, %eax
callq 0xa428
jmp 0x7307
leaq 0x3a214(%rip), %rdi     # 0x414f8
movl %r12d, %esi
jmp 0x7300
movq 0x18(%r14), %rax
movq (%rax,%rbp), %rcx
leaq 0x3a24f(%rip), %rdi     # 0x41547
movl %r12d, %esi
leaq 0x18(%rsp), %rdx
xorl %eax, %eax
callq 0xa428
pushq $-0x1
popq %rax
addq $0x7e8, %rsp            # imm = 0x7E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0x730a
leaq 0x3a070(%rip), %rdi     # 0x41397
leaq 0x3a07c(%rip), %rsi     # 0x413aa
leaq 0x3a081(%rip), %rcx     # 0x413b6
movl $0x10c, %edx            # imm = 0x10C
callq 0x4360
nop