// File: /workspace/github_cpp_makefile_star2_O3/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 0x8f4c
testb %al, %al
je 0x912c
movq (%rbx), %rdi
leaq 0x4897b(%rip), %rsi     # 0x51941
callq 0x4600
testq %rax, %rax
je 0x90b1
movq %rax, %r15
leaq 0x4(%rsp), %r12
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %rax, %rcx
callq 0x47d0
movl (%r12), %esi
movl (%r14), %edx
cmpl %edx, %esi
jne 0x90c4
testl %esi, %esi
jle 0x9099
xorl %r13d, %r13d
leaq 0x8(%rsp), %rbp
xorl %r12d, %r12d
movl $0x7e0, %esi            # imm = 0x7E0
movl $0x1, %edx
movq %rbp, %rdi
movq %r15, %rcx
callq 0x47d0
movb 0x8(%rsp), %al
movq 0x8(%r14), %rcx
cmpb (%rcx,%r12), %al
jne 0x90d8
movq 0x10(%rsp), %rdx
movq 0x10(%r14), %rax
movq (%rax,%r12,8), %rcx
cmpq %rcx, %rdx
jne 0x90eb
movq 0x18(%r14), %rdi
addq %r13, %rdi
leaq 0x18(%rsp), %rsi
callq 0x4160
testl %eax, %eax
jne 0x90f7
movq 0x10(%r14), %rax
movq 0x28(%r14), %rcx
movq (%rcx,%r12,8), %rdi
movq (%rax,%r12,8), %rdx
movl $0x2, %esi
movq %r15, %rcx
callq 0x47d0
incq %r12
movslq (%r14), %rax
addq $0x20, %r13
cmpq %rax, %r12
jl 0x9013
movq %r15, %rdi
callq 0x4530
testl %eax, %eax
je 0x90d4
movq (%rbx), %rsi
leaq 0x454c7(%rip), %rdi     # 0x4e576
jmp 0x90bb
movq (%rbx), %rsi
leaq 0x45360(%rip), %rdi     # 0x4e41b
xorl %eax, %eax
callq 0x4b3a
jmp 0x9115
leaq 0x45382(%rip), %rdi     # 0x4e44d
xorl %eax, %eax
callq 0x4b3a
jmp 0x9115
xorl %eax, %eax
jmp 0x911a
leaq 0x453b4(%rip), %rdi     # 0x4e493
movl %r12d, %esi
xorl %eax, %eax
callq 0x4b3a
jmp 0x9115
leaq 0x453e6(%rip), %rdi     # 0x4e4d8
movl %r12d, %esi
jmp 0x910e
movq 0x18(%r14), %rax
movq (%rax,%r13), %rcx
leaq 0x45421(%rip), %rdi     # 0x4e527
movl %r12d, %esi
leaq 0x18(%rsp), %rdx
xorl %eax, %eax
callq 0x4b3a
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x7e8, %rsp            # imm = 0x7E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x45244(%rip), %rdi     # 0x4e377
leaq 0x45250(%rip), %rsi     # 0x4e38a
leaq 0x45255(%rip), %rcx     # 0x4e396
movl $0x10c, %edx            # imm = 0x10C
callq 0x4350
nop