// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/sam.c
// Function: resolve_cigar2
static inline int resolve_cigar2(bam_pileup1_t *p, hts_pos_t pos, cstate_t *s)
{
#define _cop(c) ((c)&BAM_CIGAR_MASK)
#define _cln(c) ((c)>>BAM_CIGAR_SHIFT)

    bam1_t *b = p->b;
    bam1_core_t *c = &b->core;
    uint32_t *cigar = bam_get_cigar(b);
    int k;
    // determine the current CIGAR operation
    //fprintf(stderr, "%s\tpos=%ld\tend=%ld\t(%d,%ld,%d)\n", bam_get_qname(b), pos, s->end, s->k, s->x, s->y);
    if (s->k == -1) { // never processed
        p->qpos = 0;
        if (c->n_cigar == 1) { // just one operation, save a loop
          if (_cop(cigar[0]) == BAM_CMATCH || _cop(cigar[0]) == BAM_CEQUAL || _cop(cigar[0]) == BAM_CDIFF) s->k = 0, s->x = c->pos, s->y = 0;
        } else { // find the first match or deletion
            for (k = 0, s->x = c->pos, s->y = 0; k < c->n_cigar; ++k) {
                int op = _cop(cigar[k]);
                int l = _cln(cigar[k]);
                if (op == BAM_CMATCH || op == BAM_CDEL || op == BAM_CREF_SKIP ||
                    op == BAM_CEQUAL || op == BAM_CDIFF) break;
                else if (op == BAM_CINS || op == BAM_CSOFT_CLIP) s->y += l;
            }
            assert(k < c->n_cigar);
            s->k = k;
        }
    } else { // the read has been processed before
        int op, l = _cln(cigar[s->k]);
        if (pos - s->x >= l) { // jump to the next operation
            assert(s->k < c->n_cigar); // otherwise a bug: this function should not be called in this case
            op = _cop(cigar[s->k+1]);
            if (op == BAM_CMATCH || op == BAM_CDEL || op == BAM_CREF_SKIP || op == BAM_CEQUAL || op == BAM_CDIFF) { // jump to the next without a loop
              if (_cop(cigar[s->k]) == BAM_CMATCH|| _cop(cigar[s->k]) == BAM_CEQUAL || _cop(cigar[s->k]) == BAM_CDIFF) s->y += l;
                s->x += l;
                ++s->k;
            } else { // find the next M/D/N/=/X
              if (_cop(cigar[s->k]) == BAM_CMATCH|| _cop(cigar[s->k]) == BAM_CEQUAL || _cop(cigar[s->k]) == BAM_CDIFF) s->y += l;
                s->x += l;
                for (k = s->k + 1; k < c->n_cigar; ++k) {
                    op = _cop(cigar[k]), l = _cln(cigar[k]);
                    if (op == BAM_CMATCH || op == BAM_CDEL || op == BAM_CREF_SKIP || op == BAM_CEQUAL || op == BAM_CDIFF) break;
                    else if (op == BAM_CINS || op == BAM_CSOFT_CLIP) s->y += l;
                }
                s->k = k;
            }
            assert(s->k < c->n_cigar); // otherwise a bug
        } // else, do nothing
    }
    { // collect pileup information
        int op, l;
        op = _cop(cigar[s->k]); l = _cln(cigar[s->k]);
        p->is_del = p->indel = p->is_refskip = 0;
        if (s->x + l - 1 == pos && s->k + 1 < c->n_cigar) { // peek the next operation
            int op2 = _cop(cigar[s->k+1]);
            int l2 = _cln(cigar[s->k+1]);
            if (op2 == BAM_CDEL && op != BAM_CDEL) {
                // At start of a new deletion, merge e.g. 1D2D to 3D.
                // Within a deletion (the 2D in 1D2D) we keep p->indel=0
                // and rely on is_del=1 as we would for 3D.
                p->indel = -(int)l2;
                for (k = s->k+2; k < c->n_cigar; ++k) {
                    op2 = _cop(cigar[k]); l2 = _cln(cigar[k]);
                    if (op2 == BAM_CDEL) p->indel -= l2;
                    else break;
                }
            } else if (op2 == BAM_CINS) {
                p->indel = l2;
                for (k = s->k+2; k < c->n_cigar; ++k) {
                    op2 = _cop(cigar[k]); l2 = _cln(cigar[k]);
                    if (op2 == BAM_CINS) p->indel += l2;
                    else if (op2 != BAM_CPAD) break;
                }
            } else if (op2 == BAM_CPAD && s->k + 2 < c->n_cigar) {
                int l3 = 0;
                for (k = s->k + 2; k < c->n_cigar; ++k) {
                    op2 = _cop(cigar[k]); l2 = _cln(cigar[k]);
                    if (op2 == BAM_CINS) l3 += l2;
                    else if (op2 == BAM_CDEL || op2 == BAM_CMATCH || op2 == BAM_CREF_SKIP || op2 == BAM_CEQUAL || op2 == BAM_CDIFF) break;
                }
                if (l3 > 0) p->indel = l3;
            }
        }
        if (op == BAM_CMATCH || op == BAM_CEQUAL || op == BAM_CDIFF) {
            p->qpos = s->y + (pos - s->x);
        } else if (op == BAM_CDEL || op == BAM_CREF_SKIP) {
            p->is_del = 1; p->qpos = s->y; // FIXME: distinguish D and N!!!!!
            p->is_refskip = (op == BAM_CREF_SKIP);
        } // cannot be other operations; otherwise a bug
        p->is_head = (pos == c->pos); p->is_tail = (pos == s->end);
    }
    p->cigar_ind = s->k;
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x20(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
cmpl $-0x1, (%rax)
jne 0x43e78
movq -0x8(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x28(%rbp), %rax
cmpl $0x1, 0x14(%rax)
jne 0x43da6
movq -0x30(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x0, %eax
je 0x43d7d
movq -0x30(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x43d7d
movq -0x30(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x8, %eax
jne 0x43da1
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x4(%rax)
jmp 0x43e73
movl $0x0, -0x34(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x4(%rax)
movl -0x34(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jae 0x43e3d
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
movl %eax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shrl $0x4, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x43e13
cmpl $0x2, -0x38(%rbp)
je 0x43e13
cmpl $0x3, -0x38(%rbp)
je 0x43e13
cmpl $0x7, -0x38(%rbp)
je 0x43e13
cmpl $0x8, -0x38(%rbp)
jne 0x43e15
jmp 0x43e3d
cmpl $0x1, -0x38(%rbp)
je 0x43e21
cmpl $0x4, -0x38(%rbp)
jne 0x43e2e
movl -0x3c(%rbp), %ecx
movq -0x18(%rbp), %rax
addl 0x4(%rax), %ecx
movl %ecx, 0x4(%rax)
jmp 0x43e30
jmp 0x43e32
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x43dc7
movl -0x34(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jae 0x43e4b
jmp 0x43e6a
leaq 0xaef99(%rip), %rdi     # 0xf2deb
leaq 0xae3eb(%rip), %rsi     # 0xf2244
movl $0x1588, %edx           # imm = 0x1588
leaq 0xaef48(%rip), %rcx     # 0xf2dad
callq 0x42e0
movl -0x34(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
jmp 0x44099
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movl (%rax,%rcx,4), %eax
shrl $0x4, %eax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
subq 0x8(%rcx), %rax
movslq -0x44(%rbp), %rcx
cmpq %rcx, %rax
jl 0x44097
movq -0x18(%rbp), %rax
movl (%rax), %eax
movq -0x28(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jae 0x43eb6
jmp 0x43ed5
leaq 0xaef2b(%rip), %rdi     # 0xf2de8
leaq 0xae380(%rip), %rsi     # 0xf2244
movl $0x158e, %edx           # imm = 0x158E
leaq 0xaeedd(%rip), %rcx     # 0xf2dad
callq 0x42e0
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
je 0x43f0c
cmpl $0x2, -0x40(%rbp)
je 0x43f0c
cmpl $0x3, -0x40(%rbp)
je 0x43f0c
cmpl $0x7, -0x40(%rbp)
je 0x43f0c
cmpl $0x8, -0x40(%rbp)
jne 0x43f7b
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
cmpl $0x0, %eax
je 0x43f4e
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x43f4e
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
cmpl $0x8, %eax
jne 0x43f5b
movl -0x44(%rbp), %ecx
movq -0x18(%rbp), %rax
addl 0x4(%rax), %ecx
movl %ecx, 0x4(%rax)
movslq -0x44(%rbp), %rcx
movq -0x18(%rbp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x44065
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
cmpl $0x0, %eax
je 0x43fbd
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x43fbd
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
cmpl $0x8, %eax
jne 0x43fca
movl -0x44(%rbp), %ecx
movq -0x18(%rbp), %rax
addl 0x4(%rax), %ecx
movl %ecx, 0x4(%rax)
movslq -0x44(%rbp), %rcx
movq -0x18(%rbp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl (%rax), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jae 0x4405c
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
movl %eax, -0x40(%rbp)
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shrl $0x4, %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x40(%rbp)
je 0x44032
cmpl $0x2, -0x40(%rbp)
je 0x44032
cmpl $0x3, -0x40(%rbp)
je 0x44032
cmpl $0x7, -0x40(%rbp)
je 0x44032
cmpl $0x8, -0x40(%rbp)
jne 0x44034
jmp 0x4405c
cmpl $0x1, -0x40(%rbp)
je 0x44040
cmpl $0x4, -0x40(%rbp)
jne 0x4404d
movl -0x44(%rbp), %ecx
movq -0x18(%rbp), %rax
addl 0x4(%rax), %ecx
movl %ecx, 0x4(%rax)
jmp 0x4404f
jmp 0x44051
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x43fe6
movl -0x34(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movq -0x28(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jae 0x44076
jmp 0x44095
leaq 0xaed6b(%rip), %rdi     # 0xf2de8
leaq 0xae1c0(%rip), %rsi     # 0xf2244
movl $0x159e, %edx           # imm = 0x159E
leaq 0xaed1d(%rip), %rcx     # 0xf2dad
callq 0x42e0
jmp 0x44097
jmp 0x44099
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
movl %eax, -0x48(%rbp)
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movl (%rax,%rcx,4), %eax
shrl $0x4, %eax
movl %eax, -0x4c(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %ecx
andl $-0x9, %ecx
orl $0x0, %ecx
movl %ecx, 0x14(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0xc(%rax)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %ecx
andl $-0x2, %ecx
orl $0x0, %ecx
movl %ecx, 0x14(%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x4c(%rbp), %rcx
addq %rcx, %rax
subq $0x1, %rax
cmpq -0x10(%rbp), %rax
jne 0x44302
movq -0x18(%rbp), %rax
movl (%rax), %eax
addl $0x1, %eax
movq -0x28(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jae 0x44302
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
movl %eax, -0x50(%rbp)
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
shrl $0x4, %eax
movl %eax, -0x54(%rbp)
cmpl $0x2, -0x50(%rbp)
jne 0x441ce
cmpl $0x2, -0x48(%rbp)
je 0x441ce
xorl %ecx, %ecx
subl -0x54(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x18(%rbp), %rax
movl (%rax), %eax
addl $0x2, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jae 0x441c9
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
movl %eax, -0x50(%rbp)
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shrl $0x4, %eax
movl %eax, -0x54(%rbp)
cmpl $0x2, -0x50(%rbp)
jne 0x441ba
movl -0x54(%rbp), %edx
movq -0x8(%rbp), %rax
movl 0xc(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xc(%rax)
jmp 0x441bc
jmp 0x441c9
jmp 0x441be
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x44175
jmp 0x44300
cmpl $0x1, -0x50(%rbp)
jne 0x44249
movl -0x54(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x18(%rbp), %rax
movl (%rax), %eax
addl $0x2, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jae 0x44244
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
movl %eax, -0x50(%rbp)
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shrl $0x4, %eax
movl %eax, -0x54(%rbp)
cmpl $0x1, -0x50(%rbp)
jne 0x4422d
movl -0x54(%rbp), %ecx
movq -0x8(%rbp), %rax
addl 0xc(%rax), %ecx
movl %ecx, 0xc(%rax)
jmp 0x44237
cmpl $0x6, -0x50(%rbp)
je 0x44235
jmp 0x44244
jmp 0x44237
jmp 0x44239
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x441ea
jmp 0x442fe
cmpl $0x6, -0x50(%rbp)
jne 0x442fc
movq -0x18(%rbp), %rax
movl (%rax), %eax
addl $0x2, %eax
movq -0x28(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jae 0x442fc
movl $0x0, -0x58(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
addl $0x2, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jae 0x442ea
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
movl %eax, -0x50(%rbp)
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shrl $0x4, %eax
movl %eax, -0x54(%rbp)
cmpl $0x1, -0x50(%rbp)
jne 0x442bb
movl -0x54(%rbp), %eax
addl -0x58(%rbp), %eax
movl %eax, -0x58(%rbp)
jmp 0x442dd
cmpl $0x2, -0x50(%rbp)
je 0x442d9
cmpl $0x0, -0x50(%rbp)
je 0x442d9
cmpl $0x3, -0x50(%rbp)
je 0x442d9
cmpl $0x7, -0x50(%rbp)
je 0x442d9
cmpl $0x8, -0x50(%rbp)
jne 0x442db
jmp 0x442ea
jmp 0x442dd
jmp 0x442df
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x4427c
cmpl $0x0, -0x58(%rbp)
jle 0x442fa
movl -0x58(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xc(%rax)
jmp 0x442fc
jmp 0x442fe
jmp 0x44300
jmp 0x44302
cmpl $0x0, -0x48(%rbp)
je 0x44314
cmpl $0x7, -0x48(%rbp)
je 0x44314
cmpl $0x8, -0x48(%rbp)
jne 0x44336
movq -0x18(%rbp), %rax
movslq 0x4(%rax), %rax
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %rdx
subq 0x8(%rdx), %rcx
addq %rcx, %rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0x44383
cmpl $0x2, -0x48(%rbp)
je 0x44342
cmpl $0x3, -0x48(%rbp)
jne 0x44381
movq -0x8(%rbp), %rax
movl 0x14(%rax), %ecx
andl $-0x2, %ecx
orl $0x1, %ecx
movl %ecx, 0x14(%rax)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x8(%rax)
cmpl $0x3, -0x48(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %edx
movq -0x8(%rbp), %rax
movl 0x14(%rax), %ecx
andl $0x1, %edx
shll $0x3, %edx
andl $-0x9, %ecx
orl %edx, %ecx
movl %ecx, 0x14(%rax)
jmp 0x44383
movq -0x10(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq (%rcx), %rax
sete %al
andb $0x1, %al
movzbl %al, %edx
movq -0x8(%rbp), %rax
movl 0x14(%rax), %ecx
andl $0x1, %edx
shll %edx
andl $-0x3, %ecx
orl %edx, %ecx
movl %ecx, 0x14(%rax)
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
sete %al
andb $0x1, %al
movzbl %al, %edx
movq -0x8(%rbp), %rax
movl 0x14(%rax), %ecx
andl $0x1, %edx
shll $0x2, %edx
andl $-0x5, %ecx
orl %edx, %ecx
movl %ecx, 0x14(%rax)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x20(%rax)
movl $0x1, %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)