// File: /workspace/github_c_makefile_star2_O0/c-zhou[P]oatk/levdist.c
// Function: wf_print_alignment
void wf_print_alignment(char *ts, int tl, char *qs, int ql, uint32_t *cigar, int32_t n_cigar, int lwd, FILE *fo)
{
    if (!cigar || !n_cigar)
        return;
    
    int32_t i, ti, qi;
    uint32_t cl, l;
    uint8_t c;
    kstring_t t_seq = {0, 0, 0}, q_seq = {0, 0, 0}, a_seq = {0, 0, 0};
    ti = qi = l = 0;
    for (i = 0; i < n_cigar; ++i) {
        c = "MIDNSHP=XB"[cigar[i]&0xf];
        cl = cigar[i]>>4;
        switch (c) {
            case 'I':
                kputcn_('-', cl, &t_seq);
                kputsn_(&qs[qi], cl, &q_seq);
                kputcn_(' ', cl, &a_seq);
                qi += cl;
                break;
            case 'D':
                kputsn_(&ts[ti], cl, &t_seq);
                kputcn_('-', cl, &q_seq);
                kputcn_(' ', cl, &a_seq);
                ti += cl;
                break;
            case 'M':
            case '=':
            case 'X':
                kputsn_(&ts[ti], cl, &t_seq);
                if (c == 'M')
                    for (l = 0; l < cl; ++l)
                        kputc_(ts[ti+l] == qs[qi+l]? '|' : '*', &a_seq);
                else
                    kputcn_(c == '='? '|' : '*', cl, &a_seq);
                kputsn_(&qs[qi], cl, &q_seq);
                ti += cl;
                qi += cl;
                break;
            default:
                fprintf(stderr, "[E::%s] unsupported cigar element '%c'\n", __func__, c);
                goto do_clean;
        }
    }

    if (lwd <= 0) {
        fprintf(fo, "target: %.*s\n", (int) t_seq.l, t_seq.s);
        fprintf(fo, "        %.*s\n", (int) a_seq.l, a_seq.s);
        fprintf(fo, " query: %.*s\n", (int) q_seq.l, q_seq.s);
    } else {
        uint32_t j, t_beg, t_end, q_beg, q_end;
        int b = 0;
        l = t_seq.l;
        while (l > 0) { l /= 10; ++b; }
        kstring_t pad = {0, 0, 0};
        kputcn_(' ', b + b + 14, &pad);
        l = 0;
        t_beg = q_beg = 0;
        while (l < t_seq.l) {
            cl = l;
            l += lwd;
            if (l > t_seq.l)
                l = t_seq.l;
            t_end = t_beg + l - cl;
            q_end = q_beg + l - cl;
            for (j = cl; j < l; ++j) {
                t_end -= (t_seq.s[j] == '-');
                q_end -= (q_seq.s[j] == '-');
            }
            fprintf(fo, "target [%*.u - %-*.u]: %.*s\n", b, t_beg + 1, b, t_end, (int) (l - cl), &t_seq.s[cl]);
            fprintf(fo, "%.*s%.*s\n", (int) pad.l, pad.s, (int) (l - cl), &a_seq.s[cl]);
            fprintf(fo, " query [%*.u - %-*.u]: %.*s\n", b, q_beg + 1, b, q_end, (int) (l - cl), &q_seq.s[cl]);
            fputc('\n', fo);
            t_beg = t_end;
            q_beg = q_end;
        }
        free(pad.s);
    }

do_clean:
    free(t_seq.s); free(q_seq.s); free(a_seq.s);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x1ecd5
cmpl $0x0, -0x2c(%rbp)
jne 0x1ecda
jmp 0x1f1e8
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x21f0
leaq -0x78(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x21f0
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x21f0
movl $0x0, -0x40(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x1ef22
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
leaq 0xfcb3(%rip), %rcx      # 0x2e9fd
movb (%rax,%rcx), %al
movb %al, -0x41(%rbp)
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shrl $0x4, %eax
movl %eax, -0x3c(%rbp)
movzbl -0x41(%rbp), %eax
addl $-0x3d, %eax
movl %eax, %ecx
movq %rcx, -0xc8(%rbp)
subl $0x1b, %eax
ja 0x1eeea
movq -0xc8(%rbp), %rax
leaq 0xfb58(%rip), %rcx      # 0x2e8e0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x3c(%rbp), %esi
movl $0x2d, %edi
leaq -0x60(%rbp), %rdx
callq 0x1f200
movq -0x18(%rbp), %rdi
movslq -0x38(%rbp), %rax
addq %rax, %rdi
movl -0x3c(%rbp), %esi
leaq -0x78(%rbp), %rdx
callq 0x1f340
movl -0x3c(%rbp), %esi
movl $0x20, %edi
leaq -0x90(%rbp), %rdx
callq 0x1f200
movl -0x3c(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x1ef12
movq -0x8(%rbp), %rdi
movslq -0x34(%rbp), %rax
addq %rax, %rdi
movl -0x3c(%rbp), %esi
leaq -0x60(%rbp), %rdx
callq 0x1f340
movl -0x3c(%rbp), %esi
movl $0x2d, %edi
leaq -0x78(%rbp), %rdx
callq 0x1f200
movl -0x3c(%rbp), %esi
movl $0x20, %edi
leaq -0x90(%rbp), %rdx
callq 0x1f200
movl -0x3c(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x1ef12
movq -0x8(%rbp), %rdi
movslq -0x34(%rbp), %rax
addq %rax, %rdi
movl -0x3c(%rbp), %esi
leaq -0x60(%rbp), %rdx
callq 0x1f340
movzbl -0x41(%rbp), %eax
cmpl $0x4d, %eax
jne 0x1ee9c
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jae 0x1ee9a
movq -0x8(%rbp), %rax
movl -0x34(%rbp), %ecx
addl -0x40(%rbp), %ecx
movl %ecx, %ecx
movsbl (%rax,%rcx), %ecx
movq -0x18(%rbp), %rax
movl -0x38(%rbp), %edx
addl -0x40(%rbp), %edx
movl %edx, %edx
movsbl (%rax,%rdx), %edx
movl $0x2a, %edi
movl $0x7c, %eax
cmpl %edx, %ecx
cmovel %eax, %edi
leaq -0x90(%rbp), %rsi
callq 0x1f470
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x1ee4c
jmp 0x1eebf
movzbl -0x41(%rbp), %ecx
movl $0x2a, %edi
movl $0x7c, %eax
cmpl $0x3d, %ecx
cmovel %eax, %edi
movl -0x3c(%rbp), %esi
leaq -0x90(%rbp), %rdx
callq 0x1f200
movq -0x18(%rbp), %rdi
movslq -0x38(%rbp), %rax
addq %rax, %rdi
movl -0x3c(%rbp), %esi
leaq -0x78(%rbp), %rdx
callq 0x1f340
movl -0x3c(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x3c(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x1ef12
movq 0x15107(%rip), %rax     # 0x33ff8
movq (%rax), %rdi
movzbl -0x41(%rbp), %ecx
leaq 0xfb09(%rip), %rsi      # 0x2ea08
leaq 0xfb2a(%rip), %rdx      # 0x2ea30
movb $0x0, %al
callq 0x2290
jmp 0x1f1cd
jmp 0x1ef14
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x1ed29
cmpl $0x0, 0x10(%rbp)
jg 0x1ef84
movq 0x18(%rbp), %rdi
movq -0x60(%rbp), %rax
movl %eax, %edx
movq -0x50(%rbp), %rcx
leaq 0xfb06(%rip), %rsi      # 0x2ea43
movb $0x0, %al
callq 0x2290
movq 0x18(%rbp), %rdi
movq -0x90(%rbp), %rax
movl %eax, %edx
movq -0x80(%rbp), %rcx
leaq 0xfaf5(%rip), %rsi      # 0x2ea51
movb $0x0, %al
callq 0x2290
movq 0x18(%rbp), %rdi
movq -0x78(%rbp), %rax
movl %eax, %edx
movq -0x68(%rbp), %rcx
leaq 0xfae7(%rip), %rsi      # 0x2ea5f
movb $0x0, %al
callq 0x2290
jmp 0x1f1cb
movl $0x0, -0xa8(%rbp)
movq -0x60(%rbp), %rax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
jbe 0x1efbb
movl -0x40(%rbp), %eax
movl $0xa, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, -0x40(%rbp)
movl -0xa8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa8(%rbp)
jmp 0x1ef95
leaq -0xc0(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x21f0
movl -0xa8(%rbp), %esi
addl -0xa8(%rbp), %esi
addl $0xe, %esi
movl $0x20, %edi
leaq -0xc0(%rbp), %rdx
callq 0x1f200
movl $0x0, -0x40(%rbp)
movl $0x0, -0xa0(%rbp)
movl $0x0, -0x98(%rbp)
movl -0x40(%rbp), %eax
cmpq -0x60(%rbp), %rax
jae 0x1f1bf
movl -0x40(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl 0x10(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpq -0x60(%rbp), %rax
jbe 0x1f035
movq -0x60(%rbp), %rax
movl %eax, -0x40(%rbp)
movl -0x98(%rbp), %eax
addl -0x40(%rbp), %eax
subl -0x3c(%rbp), %eax
movl %eax, -0x9c(%rbp)
movl -0xa0(%rbp), %eax
addl -0x40(%rbp), %eax
subl -0x3c(%rbp), %eax
movl %eax, -0xa4(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x94(%rbp)
movl -0x94(%rbp), %eax
cmpl -0x40(%rbp), %eax
jae 0x1f0cc
movq -0x50(%rbp), %rax
movl -0x94(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x2d, %eax
sete %al
andb $0x1, %al
movzbl %al, %ecx
movl -0x9c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x9c(%rbp)
movq -0x68(%rbp), %rax
movl -0x94(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x2d, %eax
sete %al
andb $0x1, %al
movzbl %al, %ecx
movl -0xa4(%rbp), %eax
subl %ecx, %eax
movl %eax, -0xa4(%rbp)
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x1f062
movq 0x18(%rbp), %rdi
movl -0xa8(%rbp), %edx
movl -0x98(%rbp), %ecx
addl $0x1, %ecx
movl -0xa8(%rbp), %r8d
movl -0x9c(%rbp), %r9d
movl -0x40(%rbp), %r10d
subl -0x3c(%rbp), %r10d
movq -0x50(%rbp), %rax
movl -0x3c(%rbp), %esi
addq %rsi, %rax
leaq 0xf967(%rip), %rsi      # 0x2ea6d
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x2290
movq 0x18(%rbp), %rdi
movq -0xc0(%rbp), %rax
movl %eax, %edx
movq -0xb0(%rbp), %rcx
movl -0x40(%rbp), %r8d
subl -0x3c(%rbp), %r8d
movq -0x80(%rbp), %r9
movl -0x3c(%rbp), %eax
addq %rax, %r9
leaq 0xf947(%rip), %rsi      # 0x2ea8a
movb $0x0, %al
callq 0x2290
movq 0x18(%rbp), %rdi
movl -0xa8(%rbp), %edx
movl -0xa0(%rbp), %ecx
addl $0x1, %ecx
movl -0xa8(%rbp), %r8d
movl -0xa4(%rbp), %r9d
movl -0x40(%rbp), %r10d
subl -0x3c(%rbp), %r10d
movq -0x68(%rbp), %rax
movl -0x3c(%rbp), %esi
addq %rsi, %rax
leaq 0xf910(%rip), %rsi      # 0x2ea94
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x2290
movq 0x18(%rbp), %rsi
movl $0xa, %edi
callq 0x2220
movl -0x9c(%rbp), %eax
movl %eax, -0x98(%rbp)
movl -0xa4(%rbp), %eax
movl %eax, -0xa0(%rbp)
jmp 0x1f009
movq -0xb0(%rbp), %rdi
callq 0x2060
jmp 0x1f1cd
movq -0x50(%rbp), %rdi
callq 0x2060
movq -0x68(%rbp), %rdi
callq 0x2060
movq -0x80(%rbp), %rdi
callq 0x2060
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)