// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/htslib/sam.c
// Function: resolve_cigar2
static inline int resolve_cigar2(bam_pileup1_t *p, int32_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=%d\tend=%d\t(%d,%d,%d)\n", bam_get_qname(b), pos, s->end, s->k, s->x, s->y);
    if (s->k == -1) { // never processed
        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_CEQUAL || op == BAM_CDIFF) break;
                else if (op == BAM_CREF_SKIP) s->x += l;
                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) p->indel = -(int)l2;
            else if (op2 == BAM_CINS) p->indel = l2;
            else if (op2 == BAM_CPAD && s->k + 2 < c->n_cigar) { // no working for adjacent padding
                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);
    }
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%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 0x28(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x18, %rcx
andq $0xff, %rcx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
cmpl $-0x1, (%rax)
jne 0xac8be
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x30, %rax
cmpl $0x1, %eax
jne 0xac7cb
movq -0x30(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x0, %eax
je 0xac7a3
movq -0x30(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0xac7a3
movq -0x30(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x8, %eax
jne 0xac7c6
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x8(%rax)
jmp 0xac8b9
movl $0x0, -0x34(%rbp)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x8(%rax)
movl -0x34(%rbp), %eax
movq -0x28(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x30, %rcx
cmpl %ecx, %eax
jge 0xac87c
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 0xac838
cmpl $0x2, -0x38(%rbp)
je 0xac838
cmpl $0x7, -0x38(%rbp)
je 0xac838
cmpl $0x8, -0x38(%rbp)
jne 0xac83a
jmp 0xac87c
cmpl $0x3, -0x38(%rbp)
jne 0xac84f
movl -0x3c(%rbp), %ecx
movq -0x18(%rbp), %rax
addl 0x4(%rax), %ecx
movl %ecx, 0x4(%rax)
jmp 0xac86a
cmpl $0x1, -0x38(%rbp)
je 0xac85b
cmpl $0x4, -0x38(%rbp)
jne 0xac868
movl -0x3c(%rbp), %ecx
movq -0x18(%rbp), %rax
addl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
jmp 0xac86a
jmp 0xac86c
jmp 0xac86e
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xac7eb
movl -0x34(%rbp), %eax
movq -0x28(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x30, %rcx
cmpl %ecx, %eax
jge 0xac891
jmp 0xac8b0
leaq 0x380c0(%rip), %rdi     # 0xe4958
leaq 0x38077(%rip), %rsi     # 0xe4916
movl $0x603, %edx            # imm = 0x603
leaq 0x38071(%rip), %rcx     # 0xe491c
callq 0x6450
movl -0x34(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
jmp 0xacae8
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movl (%rax,%rcx,4), %eax
shrl $0x4, %eax
movl %eax, -0x44(%rbp)
movl -0xc(%rbp), %eax
movq -0x18(%rbp), %rcx
subl 0x4(%rcx), %eax
cmpl -0x44(%rbp), %eax
jl 0xacae6
movq -0x18(%rbp), %rax
movl (%rax), %eax
movq -0x28(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x30, %rcx
cmpl %ecx, %eax
jge 0xac8fd
jmp 0xac91c
leaq 0x38051(%rip), %rdi     # 0xe4955
leaq 0x3800b(%rip), %rsi     # 0xe4916
movl $0x609, %edx            # imm = 0x609
leaq 0x38005(%rip), %rcx     # 0xe491c
callq 0x6450
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 0xac953
cmpl $0x2, -0x40(%rbp)
je 0xac953
cmpl $0x3, -0x40(%rbp)
je 0xac953
cmpl $0x7, -0x40(%rbp)
je 0xac953
cmpl $0x8, -0x40(%rbp)
jne 0xac9bf
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
cmpl $0x0, %eax
je 0xac995
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0xac995
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
cmpl $0x8, %eax
jne 0xac9a2
movl -0x44(%rbp), %ecx
movq -0x18(%rbp), %rax
addl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
movl -0x44(%rbp), %ecx
movq -0x18(%rbp), %rax
addl 0x4(%rax), %ecx
movl %ecx, 0x4(%rax)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0xacaad
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
cmpl $0x0, %eax
je 0xaca01
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0xaca01
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
cmpl $0x8, %eax
jne 0xaca0e
movl -0x44(%rbp), %ecx
movq -0x18(%rbp), %rax
addl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
movl -0x44(%rbp), %ecx
movq -0x18(%rbp), %rax
addl 0x4(%rax), %ecx
movl %ecx, 0x4(%rax)
movq -0x18(%rbp), %rax
movl (%rax), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x28(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x30, %rcx
cmpl %ecx, %eax
jge 0xacaa4
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 0xaca7a
cmpl $0x2, -0x40(%rbp)
je 0xaca7a
cmpl $0x3, -0x40(%rbp)
je 0xaca7a
cmpl $0x7, -0x40(%rbp)
je 0xaca7a
cmpl $0x8, -0x40(%rbp)
jne 0xaca7c
jmp 0xacaa4
cmpl $0x1, -0x40(%rbp)
je 0xaca88
cmpl $0x4, -0x40(%rbp)
jne 0xaca95
movl -0x44(%rbp), %ecx
movq -0x18(%rbp), %rax
addl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
jmp 0xaca97
jmp 0xaca99
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xaca27
movl -0x34(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movq -0x28(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x30, %rcx
cmpl %ecx, %eax
jge 0xacac5
jmp 0xacae4
leaq 0x37e89(%rip), %rdi     # 0xe4955
leaq 0x37e43(%rip), %rsi     # 0xe4916
movl $0x619, %edx            # imm = 0x619
leaq 0x37e3d(%rip), %rcx     # 0xe491c
callq 0x6450
jmp 0xacae6
jmp 0xacae8
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
movl 0x4(%rax), %eax
addl -0x4c(%rbp), %eax
subl $0x1, %eax
cmpl -0xc(%rbp), %eax
jne 0xacc93
movq -0x18(%rbp), %rax
movl (%rax), %eax
addl $0x1, %eax
movq -0x28(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x30, %rcx
cmpl %ecx, %eax
jge 0xacc93
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 0xacbb7
xorl %ecx, %ecx
subl -0x54(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xc(%rax)
jmp 0xacc91
cmpl $0x1, -0x50(%rbp)
jne 0xacbcc
movl -0x54(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xc(%rax)
jmp 0xacc8f
cmpl $0x6, -0x50(%rbp)
jne 0xacc8d
movq -0x18(%rbp), %rax
movl (%rax), %eax
addl $0x2, %eax
movq -0x28(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x30, %rcx
cmpl %ecx, %eax
jge 0xacc8d
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
movq 0x8(%rcx), %rcx
shrq $0x30, %rcx
cmpl %ecx, %eax
jge 0xacc7b
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 0xacc4c
movl -0x54(%rbp), %eax
addl -0x58(%rbp), %eax
movl %eax, -0x58(%rbp)
jmp 0xacc6e
cmpl $0x2, -0x50(%rbp)
je 0xacc6a
cmpl $0x0, -0x50(%rbp)
je 0xacc6a
cmpl $0x3, -0x50(%rbp)
je 0xacc6a
cmpl $0x7, -0x50(%rbp)
je 0xacc6a
cmpl $0x8, -0x50(%rbp)
jne 0xacc6c
jmp 0xacc7b
jmp 0xacc6e
jmp 0xacc70
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xacc06
cmpl $0x0, -0x58(%rbp)
jle 0xacc8b
movl -0x58(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xc(%rax)
jmp 0xacc8d
jmp 0xacc8f
jmp 0xacc91
jmp 0xacc93
cmpl $0x0, -0x48(%rbp)
je 0xacca5
cmpl $0x7, -0x48(%rbp)
je 0xacca5
cmpl $0x8, -0x48(%rbp)
jne 0xaccc1
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
movl -0xc(%rbp), %eax
movq -0x18(%rbp), %rdx
subl 0x4(%rdx), %eax
addl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0xacd0e
cmpl $0x2, -0x48(%rbp)
je 0xacccd
cmpl $0x3, -0x48(%rbp)
jne 0xacd0c
movq -0x8(%rbp), %rax
movl 0x14(%rax), %ecx
andl $-0x2, %ecx
orl $0x1, %ecx
movl %ecx, 0x14(%rax)
movq -0x18(%rbp), %rax
movl 0x8(%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 0xacd0e
movl -0xc(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x4(%rcx), %eax
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)
movl -0xc(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0xc(%rcx), %eax
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)
movl $0x1, %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)