// File: karel-brinda[P]ococo/ext/htslib/sam.c
// Function: cigar_iref2iseq_next
static inline int cigar_iref2iseq_next(uint32_t **cigar, uint32_t *cigar_max, int *icig, int *iseq, int *iref)
{
    while ( *cigar < cigar_max )
    {
        int cig  = (**cigar) & BAM_CIGAR_MASK;
        int ncig = (**cigar) >> BAM_CIGAR_SHIFT;

        if ( cig==BAM_CMATCH || cig==BAM_CEQUAL || cig==BAM_CDIFF )
        {
            if ( *icig >= ncig - 1 ) { *icig = 0;  (*cigar)++; continue; }
            (*iseq)++; (*icig)++; (*iref)++;
            return BAM_CMATCH;
        }
        if ( cig==BAM_CDEL || cig==BAM_CREF_SKIP ) { (*cigar)++; (*iref) += ncig; *icig = 0; continue; }
        if ( cig==BAM_CINS ) { (*cigar)++; *iseq += ncig; *icig = 0; continue; }
        if ( cig==BAM_CSOFT_CLIP ) { (*cigar)++; *iseq += ncig; *icig = 0; continue; }
        if ( cig==BAM_CHARD_CLIP || cig==BAM_CPAD ) { (*cigar)++; *icig = 0; continue; }
        fprintf(stderr,"todo: cigar %d\n", cig);
        assert(0);
    }
    *iseq = -1;
    *iref = -1;
    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpq -0x18(%rbp), %rax
jae 0x24147
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
andl $0xf, %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
shrl $0x4, %eax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x23ffd
cmpl $0x7, -0x34(%rbp)
je 0x23ffd
cmpl $0x8, -0x34(%rbp)
jne 0x24054
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl -0x38(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jl 0x24027
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rcx
addq $0x4, %rcx
movq %rcx, (%rax)
jmp 0x23fbc
movq -0x28(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x24162
cmpl $0x2, -0x34(%rbp)
je 0x24060
cmpl $0x3, -0x34(%rbp)
jne 0x24088
movq -0x10(%rbp), %rax
movq (%rax), %rcx
addq $0x4, %rcx
movq %rcx, (%rax)
movl -0x38(%rbp), %ecx
movq -0x30(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
jmp 0x23fbc
cmpl $0x1, -0x34(%rbp)
jne 0x240b6
movq -0x10(%rbp), %rax
movq (%rax), %rcx
addq $0x4, %rcx
movq %rcx, (%rax)
movl -0x38(%rbp), %ecx
movq -0x28(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
jmp 0x23fbc
cmpl $0x4, -0x34(%rbp)
jne 0x240e4
movq -0x10(%rbp), %rax
movq (%rax), %rcx
addq $0x4, %rcx
movq %rcx, (%rax)
movl -0x38(%rbp), %ecx
movq -0x28(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
jmp 0x23fbc
cmpl $0x5, -0x34(%rbp)
je 0x240f0
cmpl $0x6, -0x34(%rbp)
jne 0x2410d
movq -0x10(%rbp), %rax
movq (%rax), %rcx
addq $0x4, %rcx
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
jmp 0x23fbc
movq 0x65ebc(%rip), %rax     # 0x89fd0
movq (%rax), %rdi
movl -0x34(%rbp), %edx
leaq 0x5790e(%rip), %rsi     # 0x7ba2f
movb $0x0, %al
callq 0x4830
leaq 0x59840(%rip), %rdi     # 0x7d96f
leaq 0x5786a(%rip), %rsi     # 0x7b9a0
movl $0x6dc, %edx            # imm = 0x6DC
leaq 0x57943(%rip), %rcx     # 0x7ba85
callq 0x4360
movq -0x28(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x30(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)