// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/ecovlp.cpp
// Function: prt_ovlp_sam_0(char*, _IO_FILE*, char*, int, char*, int, char*, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, bit_extz_t*)
void prt_ovlp_sam_0(char *cm, FILE *fp, char *ref_id, int32_t ref_id_n, char *qry_id, int32_t qry_id_n, char *qry_seq, uint64_t qry_seq_n, uint64_t rs, uint64_t re, uint64_t qs, uint64_t qe, uint64_t flag, uint64_t err0, bit_extz_t *ez)
{
    uint64_t ci = 0, err1 = 0; uint16_t c; uint32_t cl, cl0 = 0; char c0 = (char)-1;
    fprintf(fp, "%.*s\t%lu\t%.*s\t%lu\t60\t", qry_id_n, qry_id, flag, ref_id_n, ref_id, rs + 1);

    if(qs) fprintf(fp, "%luS", qs);
    while (ci < ez->cigar.n) {
        ci = pop_trace(&(ez->cigar), ci, &c, &cl);
        if(c0 == cm[c]) {
            cl0 += cl;
        } else {
            if(c0 != ((char)-1)) {
                fprintf(fp, "%u%c", cl0, c0);
            }
            cl0 = cl; c0 = cm[c];
        }
        // fprintf(fp, "%u%c", cl, cm[c]);
        if(c != 0) err1 += cl;
    }
    if(cl0) fprintf(fp, "%u%c", cl0, c0);
    if(qry_seq_n > qe) fprintf(fp, "%luS", qry_seq_n - qe);
    fprintf(fp, "\t*\t0\t0\t%.*s\t", (int32_t)qry_seq_n, qry_seq);
    for (ci = 0; ci < qry_seq_n; ci++) fprintf(fp, "~");
    assert(err0 == err1);
    fprintf(fp, "\tNM:i:%lu\n", err0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, %r11
movl %ecx, %eax
movq %rdx, %r10
movq %rsi, %r12
movq %rdi, 0x10(%rsp)
movq 0xb0(%rsp), %rcx
movq %rcx, 0x18(%rsp)
movq 0xa8(%rsp), %r13
movq 0x98(%rsp), %rcx
movq %rcx, 0x30(%rsp)
movq 0x90(%rsp), %r14
movq 0x78(%rsp), %r15
movq 0x70(%rsp), %rbp
movq 0xa0(%rsp), %r8
movq 0x80(%rsp), %rbx
incq %rbx
leaq 0xb1320(%rip), %rsi     # 0x23247b
movq %r12, %rdi
movl %r9d, %edx
movq %r11, %rcx
movl %eax, %r9d
xorl %eax, %eax
pushq %rbx
pushq %r10
callq 0x22b0
addq $0x10, %rsp
testq %r14, %r14
je 0x18118e
leaq 0xb1310(%rip), %rsi     # 0x232491
movq %r12, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x22b0
movq 0x18(%rsp), %r9
movq 0xa8(%r9), %rcx
testq %rcx, %rcx
je 0x181275
movq %rbp, 0x20(%rsp)
movq %r13, 0x28(%rsp)
movq %r12, 0x8(%rsp)
movb $-0x1, %al
xorl %edx, %edx
xorl %r14d, %r14d
xorl %esi, %esi
movq 0x10(%rsp), %r8
movq 0xb8(%r9), %r10
movzwl (%r10,%rsi,2), %ebp
movl %ebp, %r12d
shrl $0xe, %r12d
movl %ebp, %r13d
andl $0x3fff, %r13d          # imm = 0x3FFF
leal 0x1(%rsi), %ebx
cmpq %rbx, %rcx
jbe 0x181201
movzwl (%r10,%rbx,2), %esi
movl %esi, %edi
shrl $0xe, %edi
cmpl %r12d, %edi
jne 0x181201
andl $0x3fff, %esi           # imm = 0x3FFF
addl %esi, %r13d
incl %ebx
jmp 0x1811e0
cmpb (%r8,%r12), %al
jne 0x18120c
addl %r13d, %edx
jmp 0x181237
cmpb $-0x1, %al
je 0x181230
movsbl %al, %ecx
movq 0x8(%rsp), %rdi
leaq 0xa503f(%rip), %rsi     # 0x22625e
xorl %eax, %eax
callq 0x22b0
movq 0x18(%rsp), %r9
movq 0x10(%rsp), %r8
movb (%r8,%r12), %al
movl %r13d, %edx
movzwl %bp, %ecx
cmpl $0x4000, %ecx           # imm = 0x4000
movl %r13d, %ecx
movl $0x0, %edi
cmovaeq %rcx, %rdi
movl %ebx, %esi
addq %rdi, %r14
movq 0xa8(%r9), %rcx
cmpq %rsi, %rcx
ja 0x1811c0
movsbl %al, %ecx
movq 0x8(%rsp), %r12
movq 0x28(%rsp), %r13
movq 0x20(%rsp), %rbp
jmp 0x18127f
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %r14d, %r14d
xorl %edx, %edx
testl %edx, %edx
je 0x181294
leaq 0xa4fd4(%rip), %rsi     # 0x22625e
movq %r12, %rdi
xorl %eax, %eax
callq 0x22b0
movq %r15, %rdx
subq 0x30(%rsp), %rdx
jbe 0x1812af
leaq 0xb11ec(%rip), %rsi     # 0x232491
movq %r12, %rdi
xorl %eax, %eax
callq 0x22b0
leaq 0xb11e0(%rip), %rsi     # 0x232496
movq %r12, %rdi
movl %r15d, %edx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x22b0
testq %r15, %r15
je 0x1812dd
movl $0x7e, %edi
movq %r12, %rsi
callq 0x2270
decq %r15
jne 0x1812cb
cmpq %r13, %r14
jne 0x181304
leaq 0xb1269(%rip), %rsi     # 0x232552
movq %r12, %rdi
movq %r13, %rdx
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x22b0
leaq 0xb1198(%rip), %rdi     # 0x2324a3
leaq 0xb0ad9(%rip), %rsi     # 0x231deb
leaq 0xb1197(%rip), %rcx     # 0x2324b0
movl $0xb6f, %edx            # imm = 0xB6F
callq 0x2110