// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/sam.c
// Function: cigar_iref2iseq_set
static inline int cigar_iref2iseq_set(const uint32_t **cigar,
                                      const uint32_t *cigar_max,
                                      hts_pos_t *icig,
                                      hts_pos_t *iseq,
                                      hts_pos_t *iref)
{
    hts_pos_t pos = *iref;
    if ( pos < 0 ) return -1;
    *icig = 0;
    *iseq = 0;
    *iref = 0;
    while ( *cigar<cigar_max )
    {
        int cig  = (**cigar) & BAM_CIGAR_MASK;
        int ncig = (**cigar) >> BAM_CIGAR_SHIFT;

        if ( cig==BAM_CSOFT_CLIP ) { (*cigar)++; *iseq += ncig; *icig = 0; continue; }
        if ( cig==BAM_CHARD_CLIP || cig==BAM_CPAD ) { (*cigar)++; *icig = 0; continue; }
        if ( cig==BAM_CMATCH || cig==BAM_CEQUAL || cig==BAM_CDIFF )
        {
            pos -= ncig;
            if ( pos < 0 ) { *icig = ncig + pos; *iseq += *icig; *iref += *icig; return BAM_CMATCH; }
            (*cigar)++; *iseq += ncig; *icig = 0; *iref += ncig;
            continue;
        }
        if ( cig==BAM_CINS ) { (*cigar)++; *iseq += ncig; *icig = 0; continue; }
        if ( cig==BAM_CDEL || cig==BAM_CREF_SKIP )
        {
            pos -= ncig;
            if ( pos<0 ) pos = 0;
            (*cigar)++; *icig = 0; *iref += ncig;
            continue;
        }
        hts_log_error("Unexpected cigar %d", cig);
        return -2;
    }
    *iseq = -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 -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jge 0x48fea
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x491f6
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movq -0x30(%rbp), %rax
movq $0x0, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpq -0x18(%rbp), %rax
jae 0x491e4
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
andl $0xf, %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
shrl $0x4, %eax
movl %eax, -0x40(%rbp)
cmpl $0x4, -0x3c(%rbp)
jne 0x49069
movq -0x10(%rbp), %rax
movq (%rax), %rcx
addq $0x4, %rcx
movq %rcx, (%rax)
movslq -0x40(%rbp), %rcx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
jmp 0x4900b
cmpl $0x5, -0x3c(%rbp)
je 0x49075
cmpl $0x6, -0x3c(%rbp)
jne 0x49093
movq -0x10(%rbp), %rax
movq (%rax), %rcx
addq $0x4, %rcx
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
jmp 0x4900b
cmpl $0x0, -0x3c(%rbp)
je 0x490a9
cmpl $0x7, -0x3c(%rbp)
je 0x490a9
cmpl $0x8, -0x3c(%rbp)
jne 0x49136
movslq -0x40(%rbp), %rcx
movq -0x38(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jge 0x490fc
movslq -0x40(%rbp), %rcx
addq -0x38(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rcx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rcx
movq -0x30(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x491f6
movq -0x10(%rbp), %rax
movq (%rax), %rcx
addq $0x4, %rcx
movq %rcx, (%rax)
movslq -0x40(%rbp), %rcx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movslq -0x40(%rbp), %rcx
movq -0x30(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
jmp 0x4900b
cmpl $0x1, -0x3c(%rbp)
jne 0x49168
movq -0x10(%rbp), %rax
movq (%rax), %rcx
addq $0x4, %rcx
movq %rcx, (%rax)
movslq -0x40(%rbp), %rcx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
jmp 0x4900b
cmpl $0x2, -0x3c(%rbp)
je 0x49174
cmpl $0x3, -0x3c(%rbp)
jne 0x491be
movslq -0x40(%rbp), %rcx
movq -0x38(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jge 0x49192
movq $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rcx
addq $0x4, %rcx
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movslq -0x40(%rbp), %rcx
movq -0x30(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
jmp 0x4900b
movl -0x3c(%rbp), %ecx
movl $0x1, %edi
leaq 0xa9c6a(%rip), %rsi     # 0xf2e37
leaq 0xa9c77(%rip), %rdx     # 0xf2e4b
movb $0x0, %al
callq 0x1b030
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x491f6
movq -0x28(%rbp), %rax
movq $-0x1, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop