// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/src/stats.h
// Function: ococo::stats_t<unsigned short, 3, 4>::load_fasta(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
int stats_t<T, counter_size, refbase_size>::load_fasta(
    const std::string &fasta_fn) {
    gzFile fp;
    kseq_t *seq;
    int l;
    fp  = gzopen(fasta_fn.c_str(), "r");
    seq = kseq_init(fp);

    constexpr int32_t max_counter_value =
        ococo::right_full_mask<T, counter_size>();

    //if (errno != 0 || fp == nullptr) {
    if (fp == nullptr) {
        ococo::error("File '%s' could not be opened.\n", fasta_fn.c_str());
        return -1;
    }

    for (int seqid = 0; (l = kseq_read(seq)) >= 0; seqid++) {
        if (seq_name[seqid].compare(seq->name.s) != 0) {
            error(
                "Sequence names in BAM/SAM and in FASTA do not correspond "
                "('%s'!='%s').\n",
                seq_name[seqid].c_str(), seq->name.s);
            return -1;
        }

        if (seq_len[seqid] != static_cast<int64_t>(seq->seq.l)) {
            error(
                "Sequence lengths in BAM/SAM and in FASTA do not correspond "
                "(%" PRId64 "!=%" PRId64 ").\n",
                static_cast<int64_t>(seq->seq.l),
                static_cast<int64_t>(seq_len[seqid]));
            return -1;
        }

        if (seq->comment.l && seq_comment[seqid].empty()) {
            seq_comment[seqid] = std::string(seq->comment.s);
        }

        for (int64_t pos = 0; pos < static_cast<int64_t>(seq->seq.l); pos++) {
            assert(seq_stats[seqid][pos] == 0);

            pos_stats_uncompr_t psu = {0, {0, 0, 0, 0}, 0};
            psu.nt16 = nt256_nt16[static_cast<int32_t>(seq->seq.s[pos])];

            if (psu.nt16 != nt256_nt16[static_cast<int32_t>('N')]) {
                for (int32_t i = 0; i < 4; i++) {
                    psu.counters[i] = ((0x1 << i) & psu.nt16)
                                          ? std::min(params->init_ref_weight,
                                                     max_counter_value)
                                          : 0;
                }
            }

            psu.sum = psu.counters[0] + psu.counters[1] + psu.counters[2] +
                      psu.counters[3];
            seq_stats[seqid][pos] = compress_position_stats(psu);
        }
    }
    kseq_destroy(seq);  // STEP 5: destroy seq
    gzclose(fp);        // STEP 6: close the file handler
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r12
movq %rdi, %rbx
movq (%rsi), %rdi
leaq 0x3d557(%rip), %rsi     # 0x448b5
callq 0x47b0
movq %rax, %r14
movq %rax, %rdi
callq 0x4d15
testq %r14, %r14
je 0x74d0
movq %rax, %r15
movq %r14, 0x30(%rsp)
xorl %r13d, %r13d
pushq $0x7
popq %r12
movq %r15, %rdi
callq 0x4d63
testl %eax, %eax
js 0x74e4
movq %r13, %r14
shlq $0x5, %r14
movq 0x18(%rbx), %rdi
addq %r14, %rdi
movq 0x10(%r15), %rbp
movq %rbp, %rsi
callq 0x4150
testl %eax, %eax
jne 0x74fa
movq 0x10(%rbx), %rax
movq (%rax,%r13,8), %rbp
movq 0x30(%r15), %rsi
cmpq %rsi, %rbp
jne 0x750b
cmpq $0x0, 0x18(%r15)
je 0x740f
movq 0x20(%rbx), %rax
cmpq $0x0, 0x8(%rax,%r14)
jne 0x740f
movq 0x28(%r15), %rsi
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x7576
addq 0x20(%rbx), %r14
movq %r14, %rdi
leaq 0x10(%rsp), %r14
movq %r14, %rsi
callq 0x4650
movq %r14, %rdi
callq 0x4230
xorl %r14d, %r14d
cmpq %rbp, %r14
jge 0x74c8
movq 0x28(%rbx), %rax
movq (%rax,%r13,8), %rax
cmpw $0x0, (%rax,%r14,2)
jne 0x752e
andq $0x0, 0x20(%rsp)
pxor %xmm0, %xmm0
movdqa %xmm0, 0x10(%rsp)
movq 0x40(%r15), %rax
movsbq (%rax,%r14), %rax
leaq 0x3b521(%rip), %rcx     # 0x42970
movzbl (%rax,%rcx), %eax
xorl %ecx, %ecx
movb %al, 0x10(%rsp)
cmpl $0xf, %eax
je 0x74a5
movq 0x30(%rbx), %rcx
xorl %edx, %edx
cmpq $0x4, %rdx
je 0x7489
btl %edx, %eax
jae 0x747e
movl 0x1b8(%rcx), %esi
cmpl $0x7, %esi
cmovgel %r12d, %esi
jmp 0x7480
xorl %esi, %esi
movl %esi, 0x14(%rsp,%rdx,4)
incq %rdx
jmp 0x7464
movdqu 0x14(%rsp), %xmm0
pshufd $0xee, %xmm0, %xmm1     # xmm1 = xmm0[2,3,2,3]
paddd %xmm0, %xmm1
pshufd $0x55, %xmm1, %xmm0     # xmm0 = xmm1[1,1,1,1]
paddd %xmm1, %xmm0
movd %xmm0, %ecx
movl %ecx, 0x24(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x7766
movq 0x28(%rbx), %rcx
movq (%rcx,%r13,8), %rcx
movw %ax, (%rcx,%r14,2)
incq %r14
jmp 0x7412
incq %r13
jmp 0x7386
movq (%r12), %rsi
leaq 0x3a0ed(%rip), %rdi     # 0x415c8
xorl %eax, %eax
callq 0xa428
jmp 0x751c
movq %r15, %rdi
callq 0x4f48
movq 0x30(%rsp), %rdi
callq 0x4910
xorl %eax, %eax
jmp 0x751f
movq 0x18(%rbx), %rax
movq (%rax,%r14), %rsi
leaq 0x3a0df(%rip), %rdi     # 0x415e8
jmp 0x7512
leaq 0x3a11e(%rip), %rdi     # 0x41630
movq %rbp, %rdx
xorl %eax, %eax
callq 0xa428
pushq $-0x1
popq %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3a143(%rip), %rdi     # 0x41678
leaq 0x39e6e(%rip), %rsi     # 0x413aa
leaq 0x3a150(%rip), %rcx     # 0x41693
movl $0xac, %edx
callq 0x4360