// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/src/stats.h
// Function: ococo::stats_t<unsigned short, 3, 4>::print_pileup_line(_IO_FILE*, int, long, ococo::pos_stats_uncompr_t const&) const
int stats_t<T, counter_size, refbase_size>::print_pileup_line(
    FILE *pileup_file, int32_t seqid, int64_t pos,
    const pos_stats_uncompr_t &psu) const {
    assert(check_allocation());
    assert(pileup_file != nullptr);

    // todo: fix situation when depth is larger (use the printing buffer more
    // timess)

    const int32_t max_depth = 1000;

    assert(psu.sum < max_depth);
    char bases[max_depth];
    char qualities[max_depth];

    char ref_nt256 = nt16_nt256[psu.nt16];

    if (psu.sum == 0) {
        return 0;
    }

    if (ref_nt256 == '=') {
        ref_nt256 = 'N';
    }

    int32_t j = 0;

    for (int32_t nt4 = 0; nt4 < 4; nt4++) {
        const char filling_char =
            nt4_nt16[nt4] == psu.nt16 ? '.' : nt4_nt256[nt4];
        for (int32_t i = 0; i < psu.counters[nt4]; i++, j++) {
            bases[j]     = filling_char;
            qualities[j] = '~';
        }
    }

    if (psu.sum >= max_depth) {
        ococo::error("Too high coverage at position %" PRId64
                     ". Pileup does not support coverage higher than %" PRId32
                     ".",
                     pos, max_depth);
        return -1;
    }

    bases[j]     = '\0';
    qualities[j] = '\0';

    fprintf(pileup_file, "%s\t%" PRId64 "\t%c\t%" PRId32 "\t%s\t%s\n",
            seq_name[seqid].c_str(), pos + 1, ref_nt256, psu.sum, bases,
            qualities);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x7e8, %rsp            # imm = 0x7E8
movq %r8, %r12
movq %rcx, %rbx
movl %edx, 0xc(%rsp)
movq %rsi, %r14
movq %rdi, %r15
callq 0x7144
testb %al, %al
je 0x80d2
testq %r14, %r14
je 0x80f1
movl 0x14(%r12), %r9d
cmpl $0x3e8, %r9d            # imm = 0x3E8
jge 0x8110
testl %r9d, %r9d
je 0x80be
movzbl (%r12), %eax
leaq 0x3ab76(%rip), %rcx     # 0x42b80
movb (%rax,%rcx), %cl
xorl %esi, %esi
leaq 0x3ab5a(%rip), %rdi     # 0x42b70
leaq 0x39d24(%rip), %r8      # 0x41d41
xorl %r10d, %r10d
xorl %edx, %edx
cmpq $0x4, %r10
je 0x8064
movb $0x2e, %r11b
cmpb %al, (%r10,%rdi)
je 0x8035
movb (%r10,%r8), %r11b
movslq %edx, %r13
movl 0x4(%r12,%r10,4), %ebp
testl %ebp, %ebp
cmovlel %esi, %ebp
addl %ebp, %edx
movslq %edx, %rbp
cmpq %r13, %rbp
je 0x805f
movb %r11b, 0x400(%rsp,%r13)
movb $0x7e, 0x10(%rsp,%r13)
incq %r13
jmp 0x8047
incq %r10
jmp 0x8022
testb %al, %al
movzbl %cl, %eax
pushq $0x4e
popq %rcx
cmovnel %eax, %ecx
movslq %edx, %rax
xorl %edx, %edx
movb %dl, 0x400(%rsp,%rax)
movb %dl, 0x10(%rsp,%rax)
movq 0x18(%r15), %rax
movslq 0xc(%rsp), %rdx
shlq $0x5, %rdx
movq (%rax,%rdx), %rdx
incq %rbx
movsbl %cl, %r8d
leaq 0x10(%rsp), %r10
leaq 0x400(%rsp), %r11
leaq 0x39c9c(%rip), %rsi     # 0x41d47
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
pushq %r10
pushq %r11
callq 0x4770
popq %rcx
popq %rdx
xorl %eax, %eax
addq $0x7e8, %rsp            # imm = 0x7E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x392be(%rip), %rdi     # 0x41397
leaq 0x392ca(%rip), %rsi     # 0x413aa
leaq 0x39b7d(%rip), %rcx     # 0x41c64
movl $0x211, %edx            # imm = 0x211
callq 0x4360
leaq 0x39c1e(%rip), %rdi     # 0x41d16
leaq 0x392ab(%rip), %rsi     # 0x413aa
leaq 0x39b5e(%rip), %rcx     # 0x41c64
movl $0x212, %edx            # imm = 0x212
callq 0x4360
leaq 0x39c16(%rip), %rdi     # 0x41d2d
leaq 0x3928c(%rip), %rsi     # 0x413aa
leaq 0x39b3f(%rip), %rcx     # 0x41c64
movl $0x219, %edx            # imm = 0x219
callq 0x4360
nop