// File: /workspace/github_cpp_makefile_star2_O1/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 0x902a
testb %al, %al
je 0x921a
movq (%rbx), %rdi
leaq 0x4a867(%rip), %rsi     # 0x53919
callq 0x4600
testq %rax, %rax
je 0x919f
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 0x91b2
cmpl $0x0, (%r14)
jle 0x9187
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 0x91c6
movq 0x10(%rsp), %rdx
movq 0x10(%r14), %rax
movq (%rax,%r12,8), %rcx
cmpq %rcx, %rdx
jne 0x91d9
movq 0x18(%r14), %rdi
addq %r13, %rdi
leaq 0x18(%rsp), %rsi
callq 0x4160
testl %eax, %eax
jne 0x91e5
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 0x9101
movq %r15, %rdi
callq 0x4530
testl %eax, %eax
je 0x91c2
movq (%rbx), %rsi
leaq 0x473d9(%rip), %rdi     # 0x50576
jmp 0x91a9
movq (%rbx), %rsi
leaq 0x47272(%rip), %rdi     # 0x5041b
xorl %eax, %eax
callq 0x4b3a
jmp 0x9203
leaq 0x47294(%rip), %rdi     # 0x5044d
xorl %eax, %eax
callq 0x4b3a
jmp 0x9203
xorl %eax, %eax
jmp 0x9208
leaq 0x472c6(%rip), %rdi     # 0x50493
movl %r12d, %esi
xorl %eax, %eax
callq 0x4b3a
jmp 0x9203
leaq 0x472f8(%rip), %rdi     # 0x504d8
movl %r12d, %esi
jmp 0x91fc
movq 0x18(%r14), %rax
movq (%rax,%r13), %rcx
leaq 0x47333(%rip), %rdi     # 0x50527
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 0x47156(%rip), %rdi     # 0x50377
leaq 0x47162(%rip), %rsi     # 0x5038a
leaq 0x47167(%rip), %rcx     # 0x50396
movl $0x10c, %edx            # imm = 0x10C
callq 0x4350
nop