// File: karel-brinda[P]ococo/src/stats.h
// Function: ococo::stats_t<unsigned short, 3, 4>::save_fasta(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) const
int stats_t<T, counter_size, refbase_size>::save_fasta(
    const std::string &fasta_fn) const {
    assert(check_allocation());

    FILE *fasta_file = nullptr;
    fasta_file       = fopen(fasta_fn.c_str(), "w+");

    char fasta_buffer[fasta_line_l];
    for (int s = 0; s < n_seqs; s++) {
        // printf("%s\n",seq_name[s]);
        if (!seq_comment[s].empty()) {
            fprintf(fasta_file, ">%s %s\n", seq_name[s].c_str(),
                    seq_comment[s].c_str());
        } else {
            fprintf(fasta_file, ">%s\n", seq_name[s].c_str());
        }

        for (int64_t i = 0, j = 0; i < seq_len[s]; i++, j++) {
            get_nucl_nt256(s, i, fasta_buffer[j]);

            if (j == fasta_line_l - 1 || i == seq_len[s] - 1) {
                fwrite(fasta_buffer, 1, j + 1, fasta_file);
                fwrite("\n", 1, 1, fasta_file);
                j = -1;
            }
        }
    }

    fclose(fasta_file);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x70(%rbp)
callq 0x9440
testb $0x1, %al
jne 0xa7e6
jmp 0xa7e8
jmp 0xa807
leaq 0x6db90(%rip), %rdi     # 0x7837f
leaq 0x6db9c(%rip), %rsi     # 0x78392
movl $0xc7, %edx
leaq 0x6e611(%rip), %rcx     # 0x78e13
callq 0x4360
movq $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4200
movq %rax, %rdi
leaq 0x6da5d(%rip), %rsi     # 0x7827f
callq 0x4690
movq %rax, -0x18(%rbp)
movl $0x0, -0x54(%rbp)
movq -0x70(%rbp), %rcx
movl -0x54(%rbp), %eax
cmpl (%rcx), %eax
jge 0xa9c1
movq -0x70(%rbp), %rax
movq 0x20(%rax), %rdi
movslq -0x54(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rdi
callq 0x49c0
testb $0x1, %al
jne 0xa8b7
movq -0x70(%rbp), %rax
movq -0x18(%rbp), %rcx
movq %rcx, -0x80(%rbp)
movq 0x18(%rax), %rdi
movslq -0x54(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rdi
callq 0x4200
movq %rax, %rcx
movq -0x70(%rbp), %rax
movq %rcx, -0x78(%rbp)
movq 0x20(%rax), %rdi
movslq -0x54(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rdi
callq 0x4200
movq -0x80(%rbp), %rdi
movq -0x78(%rbp), %rdx
movq %rax, %rcx
leaq 0x6e5ee(%rip), %rsi     # 0x78e9c
movb $0x0, %al
callq 0x4830
jmp 0xa8f2
movq -0x70(%rbp), %rax
movq -0x18(%rbp), %rcx
movq %rcx, -0x88(%rbp)
movq 0x18(%rax), %rdi
movslq -0x54(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rdi
callq 0x4200
movq -0x88(%rbp), %rdi
movq %rax, %rdx
leaq 0x6e5b9(%rip), %rsi     # 0x78ea4
movb $0x0, %al
callq 0x4830
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x70(%rbp), %rcx
movq -0x60(%rbp), %rax
movq 0x10(%rcx), %rcx
movslq -0x54(%rbp), %rdx
cmpq (%rcx,%rdx,8), %rax
jge 0xa9b1
movq -0x70(%rbp), %rdi
movl -0x54(%rbp), %esi
movq -0x60(%rbp), %rdx
leaq -0x50(%rbp), %rcx
addq -0x68(%rbp), %rcx
callq 0xad40
cmpq $0x31, -0x68(%rbp)
je 0xa958
movq -0x70(%rbp), %rcx
movq -0x60(%rbp), %rax
movq 0x10(%rcx), %rcx
movslq -0x54(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0xa992
leaq -0x50(%rbp), %rdi
movq -0x68(%rbp), %rdx
addq $0x1, %rdx
movq -0x18(%rbp), %rcx
movl $0x1, %esi
callq 0x4b20
movq -0x18(%rbp), %rcx
leaq 0x744d2(%rip), %rdi     # 0x7ee4f
movl $0x1, %edx
movq %rdx, %rsi
callq 0x4b20
movq $-0x1, -0x68(%rbp)
jmp 0xa994
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0xa902
jmp 0xa9b3
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0xa832
movq -0x18(%rbp), %rdi
callq 0x4590
xorl %eax, %eax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop