// File: /workspace/github_c_makefile_star2_O1/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), %r8
movq %r8, %rax
shrq $0x30, %rax
je 0x4a37
movq %r8, %r9
shrq $0x20, %r9
movl 0x10(%rsi), %eax
xorl %r11d, %r11d
testb $0x40, %r9b
sete %r11b
shrl $0x4, %r9d
movq 0x30(%rsi), %rbx
shll $0x3, %r11d
leaq 0x80(%r11), %r14
orq $0x70, %r11
xorl %r15d, %r15d
leaq 0x146bb(%rip), %r12     # 0x19010
xorl %edx, %edx
shrl $0x18, %r8d
addq %rbx, %r8
movl (%r8,%r15,4), %r13d
movl %r13d, %ecx
andl $0xf, %ecx
shrl $0x4, %r13d
decl %ecx
cmpl $0x4, %ecx
ja 0x4a18
movslq (%r12,%rcx,4), %rcx
addq %r12, %rcx
jmpq *%rcx
movl %edx, %ecx
jmp 0x4a1e
leal (%rdx,%r13), %ecx
movl %eax, %r10d
subl %ecx, %r10d
testb $0x1, %r9b
cmovel %edx, %r10d
testl %r10d, %r10d
js 0x4a73
movl 0x8(%rdi), %edx
js 0x4a41
cmpl %edx, %r10d
jge 0x4a41
movl %r10d, %edx
movq (%rdi,%r11), %r8
incq (%r8,%rdx,8)
cmpl 0x14(%rdi), %r13d
jg 0x4a1e
movq 0x60(%rdi), %rdx
incq -0x8(%rdx,%r13,8)
jmp 0x4a1e
leal -0x1(%rdx), %r8d
movl %edx, %ecx
notl %ecx
addl %eax, %ecx
testb $0x1, %r9b
cmovel %r8d, %ecx
testl %ecx, %ecx
js 0x4980
movl 0x8(%rdi), %r8d
cmpl %r8d, %ecx
jge 0x4a7e
movl %ecx, %ecx
movq (%rdi,%r14), %r8
incq (%r8,%rcx,8)
cmpl 0x14(%rdi), %r13d
jg 0x4980
movq 0x68(%rdi), %rcx
movl %r13d, %r8d
incq -0x8(%rcx,%r8,8)
jmp 0x4980
addl %edx, %r13d
movl %r13d, %ecx
incq %r15
movq 0x8(%rsi), %r8
movq %r8, %r10
shrq $0x30, %r10
movl %ecx, %edx
cmpq %r10, %r15
jb 0x4957
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
movq 0x30(%rsi), %r9
leaq 0x1480d(%rip), %rdi     # 0x19276
movl %r10d, %esi
xorl %eax, %eax
callq 0x465a
leaq 0x147db(%rip), %rdi     # 0x19255
movl %eax, %esi
jmp 0x4a8a
leaq 0x1480c(%rip), %rdi     # 0x19291
movl %ecx, %esi
movl %r8d, %edx
xorl %eax, %eax
callq 0x465a