// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
movq %rsi, %r12
movq %rdi, %rbx
movq (%rsi), %rdi
leaq 0x4746b(%rip), %rsi     # 0x51941
callq 0x47b0
movq %rax, %r14
movq %rax, %rdi
callq 0x6657
testq %r14, %r14
je 0xa6b3
movq %rax, %r15
movq %r14, 0x38(%rsp)
movq %rax, %rdi
callq 0x66a9
testl %eax, %eax
js 0xa69d
xorl %r13d, %r13d
movl $0x7f, %r12d
movq %rbx, 0x8(%rsp)
movq %r13, %r14
shlq $0x5, %r13
movq 0x18(%rbx), %rdi
addq %r13, %rdi
movq 0x10(%r15), %rbp
movq %rbp, %rsi
callq 0x4160
testl %eax, %eax
jne 0xa6c7
movq 0x10(%rbx), %rax
movq %r14, 0x40(%rsp)
movq (%rax,%r14,8), %rbp
movq 0x30(%r15), %rsi
cmpq %rsi, %rbp
jne 0xa6d8
cmpq $0x0, 0x18(%r15)
leaq 0x453f3(%rip), %r14     # 0x4f950
je 0xa5b6
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rax
cmpq $0x0, 0x8(%rax,%r13)
jne 0xa5b6
movq 0x28(%r15), %rsi
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
leaq 0x7(%rsp), %rdx
callq 0x93aa
movq 0x8(%rsp), %rax
addq 0x20(%rax), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0x4660
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xa5b6
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4540
testq %rbp, %rbp
movq 0x40(%rsp), %r13
movq 0x8(%rsp), %rbx
xorps %xmm2, %xmm2
jle 0xa68a
movq 0x28(%rbx), %rax
movq (%rax,%r13,8), %rax
xorl %ecx, %ecx
cmpl $0x0, (%rax,%rcx,4)
jne 0xa6fd
movaps %xmm2, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x40(%r15), %rdx
movsbq (%rdx,%rcx), %rdx
movzbl (%rdx,%r14), %edx
xorl %esi, %esi
movl $0x0, %edi
cmpl $0xf, %edx
je 0xa653
movq 0x30(%rbx), %rdi
xorl %r8d, %r8d
btl %r8d, %edx
jae 0xa626
movl 0x1b8(%rdi), %r9d
cmpl $0x7f, %r9d
cmovgel %r12d, %r9d
jmp 0xa629
xorl %r9d, %r9d
movl %r9d, 0x14(%rsp,%r8,4)
incq %r8
cmpq $0x4, %r8
jne 0xa60f
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, %edi
movl %edi, 0x24(%rsp)
movl $0x1, %edi
movl %esi, %r8d
shll $0x7, %r8d
movl 0x10(%rsp,%rdi,4), %esi
andl $0x7f, %esi
orl %r8d, %esi
incq %rdi
cmpq $0x5, %rdi
jne 0xa65c
shll $0x4, %esi
orl %edx, %esi
movl %esi, (%rax,%rcx,4)
incq %rcx
cmpq %rbp, %rcx
jne 0xa5d6
incq %r13
movq %r15, %rdi
callq 0x66a9
testl %eax, %eax
jns 0xa515
movq %r15, %rdi
callq 0x69be
movq 0x38(%rsp), %rdi
callq 0x4920
xorl %eax, %eax
jmp 0xa6ee
movq (%r12), %rsi
leaq 0x43eea(%rip), %rdi     # 0x4e5a8
xorl %eax, %eax
callq 0x4b3a
jmp 0xa6e9
movq 0x18(%rbx), %rax
movq (%rax,%r13), %rsi
leaq 0x43ef2(%rip), %rdi     # 0x4e5c8
jmp 0xa6df
leaq 0x43f31(%rip), %rdi     # 0x4e610
movq %rbp, %rdx
xorl %eax, %eax
callq 0x4b3a
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x43f54(%rip), %rdi     # 0x4e658
leaq 0x43c7f(%rip), %rsi     # 0x4e38a
leaq 0x44888(%rip), %rcx     # 0x4ef9a
movl $0xac, %edx
callq 0x4350