// File: /workspace/github_cpp_makefile_star2_O1/karel-brinda[P]ococo/src/stats.h
// Function: ococo::stats_t<unsigned int, 7, 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 0x4936f(%rip), %rsi     # 0x53919
callq 0x47b0
movq %rax, %r14
movq %rax, %rdi
callq 0x66f7
testq %r14, %r14
je 0xa75f
movq %rax, %r15
movq %r14, 0x30(%rsp)
movq %rax, %rdi
callq 0x6751
testl %eax, %eax
js 0xa749
xorl %r13d, %r13d
leaq 0x4736b(%rip), %r12     # 0x51950
movl $0x7f, %r14d
movq %r13, %rbp
shlq $0x5, %rbp
movq 0x18(%rbx), %rdi
addq %rbp, %rdi
movq 0x10(%r15), %rsi
callq 0x4160
testl %eax, %eax
jne 0xa773
movq 0x10(%rbx), %rax
movq (%rax,%r13,8), %rdx
movq 0x30(%r15), %rsi
cmpq %rsi, %rdx
jne 0xa788
cmpq $0x0, 0x18(%r15)
je 0xa672
movq 0x20(%rbx), %rax
cmpq $0x0, 0x8(%rax,%rbp)
jne 0xa672
movq 0x28(%r15), %rsi
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x9476
addq 0x20(%rbx), %rbp
movq %rbp, %rdi
leaq 0x10(%rsp), %rsi
callq 0x4660
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xa672
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4540
movq 0x30(%r15), %rax
testq %rax, %rax
xorps %xmm0, %xmm0
jle 0xa736
movq 0x28(%rbx), %rcx
movq (%rcx,%r13,8), %rcx
xorl %edx, %edx
cmpl $0x0, (%rcx,%rdx,4)
jne 0xa7aa
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x40(%r15), %rsi
movsbq (%rsi,%rdx), %rsi
movzbl (%rsi,%r12), %esi
movb %sil, 0x10(%rsp)
cmpl $0xf, %esi
je 0xa6eb
movq 0x30(%rbx), %rdi
xorl %r8d, %r8d
btl %r8d, %esi
jae 0xa6da
movl 0x1b8(%rdi), %r9d
cmpl $0x7f, %r9d
cmovgel %r14d, %r9d
jmp 0xa6dd
xorl %r9d, %r9d
movl %r9d, 0x14(%rsp,%r8,4)
incq %r8
cmpq $0x4, %r8
jne 0xa6c3
movl 0x18(%rsp), %edi
addl 0x14(%rsp), %edi
addl 0x1c(%rsp), %edi
addl 0x20(%rsp), %edi
movl %edi, 0x24(%rsp)
xorl %edi, %edi
movl $0x1, %r8d
movl %edi, %r9d
shll $0x7, %r9d
movl 0x10(%rsp,%r8,4), %edi
andl $0x7f, %edi
orl %r9d, %edi
incq %r8
cmpq $0x5, %r8
jne 0xa707
shll $0x4, %edi
orl %esi, %edi
movl %edi, (%rcx,%rdx,4)
incq %rdx
cmpq %rax, %rdx
jne 0xa68c
incq %r13
movq %r15, %rdi
callq 0x6751
testl %eax, %eax
jns 0xa5eb
movq %r15, %rdi
callq 0x6a79
movq 0x30(%rsp), %rdi
callq 0x4920
xorl %eax, %eax
jmp 0xa79b
movq (%r12), %rsi
leaq 0x45e3e(%rip), %rdi     # 0x505a8
xorl %eax, %eax
callq 0x4b3a
jmp 0xa796
movq 0x18(%rbx), %rax
movq (%rax,%rbp), %rsi
movq 0x10(%r15), %rdx
leaq 0x45e42(%rip), %rdi     # 0x505c8
jmp 0xa78f
leaq 0x45e81(%rip), %rdi     # 0x50610
xorl %eax, %eax
callq 0x4b3a
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x45ea7(%rip), %rdi     # 0x50658
leaq 0x45bd2(%rip), %rsi     # 0x5038a
leaq 0x467db(%rip), %rcx     # 0x50f9a
movl $0xac, %edx
callq 0x4350
nop