// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/misc/bamcheck.c
// Function: count_indels
void count_indels(stats_t *stats,bam1_t *bam_line) 
{
    int is_fwd = IS_REVERSE(bam_line) ? 0 : 1;
    int is_1st = IS_READ1(bam_line) ? 1 : 0;
    int icig;
    int icycle = 0;
    int read_len = bam_line->core.l_qseq;
    for (icig=0; icig<bam_line->core.n_cigar; icig++) 
    {
        // Conversion from uint32_t to MIDNSHP
        //  0123456
        //  MIDNSHP
        int cig  = bam1_cigar(bam_line)[icig] & BAM_CIGAR_MASK;
        int ncig = bam1_cigar(bam_line)[icig] >> BAM_CIGAR_SHIFT;

        if ( cig==1 )
        {
            int idx = is_fwd ? icycle : read_len-icycle-ncig;
            if ( idx<0 ) 
                error("FIXME: read_len=%d vs icycle=%d\n", read_len,icycle);
            if ( idx >= stats->nbases || idx<0 ) error("FIXME: %d vs %d, %s:%d %s\n", idx,stats->nbases, stats->sam->header->target_name[bam_line->core.tid],bam_line->core.pos+1,bam1_qname(bam_line));
            if ( is_1st ) 
                stats->ins_cycles_1st[idx]++;
            else
                stats->ins_cycles_2nd[idx]++;
            icycle += ncig;
            if ( ncig<=stats->nindels )
                stats->insertions[ncig-1]++;
            continue;
        }
        if ( cig==2 )
        {
            int idx = is_fwd ? icycle-1 : read_len-icycle-1;
            if ( idx<0 ) continue;  // discard meaningless deletions
            if ( idx >= stats->nbases ) error("FIXME: %d vs %d\n", idx,stats->nbases);
            if ( is_1st )
                stats->del_cycles_1st[idx]++;
            else
                stats->del_cycles_2nd[idx]++;
            if ( ncig<=stats->nindels )
                stats->deletions[ncig-1]++;
            continue;
        }
        if ( cig!=3 && cig!=5 )
            icycle += ncig;
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq 0x8(%rsi), %rcx
movq %rcx, %rax
shrq $0x30, %rax
je 0x4ce8
movq %rcx, %r11
shrq $0x20, %r11
movl 0x10(%rsi), %eax
xorl %ebx, %ebx
testb $0x40, %r11b
sete %bl
movq 0x30(%rsi), %r9
shll $0x3, %ebx
leaq 0x80(%rbx), %r14
orq $0x70, %rbx
xorl %r15d, %r15d
leaq 0x15401(%rip), %r12     # 0x1a010
xorl %edx, %edx
shrl $0x18, %ecx
addq %r9, %rcx
movl (%rcx,%r15,4), %r13d
movl %r13d, %ecx
andl $0xf, %ecx
shrl $0x4, %r13d
decl %ecx
cmpl $0x4, %ecx
ja 0x4cc8
movslq (%r12,%rcx,4), %rcx
addq %r12, %rcx
jmpq *%rcx
movl %edx, %r8d
jmp 0x4cce
leal (%rdx,%r13), %r8d
movl %eax, %r10d
subl %r8d, %r10d
testb $0x10, %r11b
cmovel %edx, %r10d
testl %r10d, %r10d
js 0x4d20
movl 0x8(%rdi), %edx
cmpl %edx, %r10d
jge 0x4cf2
movl %r10d, %ecx
movq (%rdi,%rbx), %rdx
incq (%rdx,%rcx,8)
cmpl 0x14(%rdi), %r13d
jg 0x4cce
movq 0x60(%rdi), %rcx
incq -0x8(%rcx,%r13,8)
jmp 0x4cce
leal -0x1(%rdx), %r8d
movl %edx, %ecx
notl %ecx
addl %eax, %ecx
testb $0x10, %r11b
cmovel %r8d, %ecx
testl %ecx, %ecx
js 0x4c39
movl 0x8(%rdi), %r8d
cmpl %r8d, %ecx
jge 0x4d2b
movl %ecx, %ecx
movq (%rdi,%r14), %r8
incq (%r8,%rcx,8)
cmpl 0x14(%rdi), %r13d
jg 0x4c39
movq 0x68(%rdi), %rcx
movl %r13d, %r8d
incq -0x8(%rcx,%r8,8)
jmp 0x4c39
addl %edx, %r13d
movl %r13d, %r8d
incq %r15
movq 0x8(%rsi), %rcx
movq %rcx, %r10
shrq $0x30, %r10
movl %r8d, %edx
cmpq %r10, %r15
jb 0x4c11
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq 0x1c8(%rdi), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movslq (%rsi), %rcx
movq (%rax,%rcx,8), %rcx
movl 0x4(%rsi), %r8d
incl %r8d
leaq 0x15610(%rip), %rdi     # 0x1a326
movl %r10d, %esi
xorl %eax, %eax
callq 0x4926
leaq 0x155de(%rip), %rdi     # 0x1a305
movl %eax, %esi
jmp 0x4d37
leaq 0x1560f(%rip), %rdi     # 0x1a341
movl %ecx, %esi
movl %r8d, %edx
xorl %eax, %eax
callq 0x4926