// File: /workspace/github_c_makefile_star2_O3/zhou-lab[P]tbmate/htslib/sam.c
// Function: bam_plp_next
const bam_pileup1_t *bam_plp_next(bam_plp_t iter, int *_tid, int *_pos, int *_n_plp)
{
    if (iter->error) { *_n_plp = -1; return 0; }
    *_n_plp = 0;
    if (iter->is_eof && iter->head == iter->tail) return 0;
    while (iter->is_eof || iter->max_tid > iter->tid || (iter->max_tid == iter->tid && iter->max_pos > iter->pos)) {
        int n_plp = 0;
        // write iter->plp at iter->pos
        lbnode_t **pptr = &iter->head;
        while (*pptr != iter->tail) {
            lbnode_t *p = *pptr;
            if (p->b.core.tid < iter->tid || (p->b.core.tid == iter->tid && p->end <= iter->pos)) { // then remove
                overlap_remove(iter, &p->b);
                *pptr = p->next; mp_free(iter->mp, p);
            }
            else {
                if (p->b.core.tid == iter->tid && p->beg <= iter->pos) { // here: p->end > pos; then add to pileup
                    if (n_plp == iter->max_plp) { // then double the capacity
                        iter->max_plp = iter->max_plp? iter->max_plp<<1 : 256;
                        iter->plp = (bam_pileup1_t*)realloc(iter->plp, sizeof(bam_pileup1_t) * iter->max_plp);
                    }
                    iter->plp[n_plp].b = &p->b;
                    if (resolve_cigar2(iter->plp + n_plp, iter->pos, &p->s)) ++n_plp; // actually always true...
                }
                pptr = &(*pptr)->next;
            }
        }
        *_n_plp = n_plp; *_tid = iter->tid; *_pos = iter->pos;
        // update iter->tid and iter->pos
        if (iter->head != iter->tail) {
            if (iter->tid > iter->head->b.core.tid) {
                fprintf(stderr, "[%s] unsorted input. Pileup aborts.\n", __func__);
                iter->error = 1;
                *_n_plp = -1;
                return 0;
            }
        }
        if (iter->tid < iter->head->b.core.tid) { // come to a new reference sequence
            iter->tid = iter->head->b.core.tid; iter->pos = iter->head->beg; // jump to the next reference
        } else if (iter->pos < iter->head->beg) { // here: tid == head->b.core.tid
            iter->pos = iter->head->beg; // jump to the next position
        } else ++iter->pos; // scan contiguously
        // return
        if (n_plp) return iter->plp;
        if (iter->is_eof && iter->head == iter->tail) break;
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, %r12
cmpl $0x0, 0x30(%rdi)
je 0x33939
movl $0xffffffff, (%r12)     # imm = 0xFFFFFFFF
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, %r15
movl $0x0, (%r12)
movl 0x28(%rdi), %eax
testl %eax, %eax
je 0x33955
movq 0x8(%r15), %rcx
cmpq 0x10(%r15), %rcx
je 0x33928
movq %rdx, 0x38(%rsp)
leaq 0x8(%r15), %rbx
movq %rsi, 0x30(%rsp)
movq %rbx, 0x28(%rsp)
testl %eax, %eax
jne 0x33982
movl 0x18(%r15), %eax
cmpl %eax, 0x20(%r15)
jg 0x33982
jne 0x33928
movl 0x24(%r15), %eax
cmpl 0x1c(%r15), %eax
jle 0x33928
movq 0x8(%r15), %rax
cmpq 0x10(%r15), %rax
je 0x33e94
xorl %r14d, %r14d
movq %rax, %rbp
movl 0x18(%r15), %eax
cmpl %eax, (%rbp)
jge 0x339ff
movq %r14, %r13
movq 0x60(%r15), %rdi
movq %rbp, %rsi
callq 0x33fa6
movq 0x50(%rbp), %rax
movq %rax, (%rbx)
movq (%r15), %r14
decl (%r14)
movq $0x0, 0x50(%rbp)
movl 0x4(%r14), %ecx
cmpl 0x8(%r14), %ecx
jne 0x33b73
leal (%rcx,%rcx), %eax
testl %ecx, %ecx
movl $0x100, %ecx            # imm = 0x100
cmovel %ecx, %eax
movl %eax, 0x8(%r14)
movq 0x10(%r14), %rdi
movslq %eax, %rsi
shlq $0x3, %rsi
callq 0x37b0
movq %rax, 0x10(%r14)
movl 0x4(%r14), %ecx
jmp 0x33b77
jne 0x33e61
movl 0x1c(%r15), %ecx
cmpl %ecx, 0x3c(%rbp)
jle 0x3399f
cmpl %ecx, 0x38(%rbp)
jg 0x33e61
movq 0x40(%r15), %rax
cmpl 0x2c(%r15), %r14d
jne 0x33a4f
leal (%r14,%r14), %ecx
testl %r14d, %r14d
movl $0x100, %edx            # imm = 0x100
cmovel %edx, %ecx
movl %ecx, 0x2c(%r15)
movslq %ecx, %rcx
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
movq %rax, %rdi
callq 0x37b0
movq %rax, 0x40(%r15)
movl 0x1c(%r15), %ecx
movslq %r14d, %rdx
leaq (%rdx,%rdx,2), %rsi
movq %rbp, (%rax,%rsi,8)
movq 0x8(%rbp), %r10
movq 0x28(%rbp), %r13
movl %r10d, %edx
shrl $0x18, %edx
movq %rdx, 0x40(%rsp)
leaq (%rdx,%r13), %rdi
movslq 0x40(%rbp), %r9
cmpq $-0x1, %r9
movq %r14, 0x18(%rsp)
je 0x33b8d
movl (%rdi,%r9,4), %r14d
movl %r14d, %edx
shrl $0x4, %edx
movl 0x44(%rbp), %r11d
movl %ecx, %r8d
subl %r11d, %r8d
cmpl %edx, %r8d
jl 0x33d0a
movq %rsi, 0x10(%rsp)
shrq $0x30, %r10
cmpl %r10d, %r9d
jge 0x33f49
movq %r13, %rsi
movq %r12, %r13
movl 0x4(%rdi,%r9,4), %r8d
movl %r8d, %r12d
andl $0xf, %r12d
andl $0xf, %r14d
cmpl $0x8, %r12d
je 0x33c19
movl %r8d, %r12d
andl $0xd, %r12d
je 0x33c19
andl $0xb, %r8d
cmpl $0x3, %r8d
je 0x33c19
cmpl $0x8, %r14d
ja 0x33b03
movl $0x181, %r8d            # imm = 0x181
btl %r14d, %r8d
jae 0x33b03
addl %edx, 0x48(%rbp)
addl %edx, %r11d
movl %r11d, 0x44(%rbp)
incq %r9
cmpl %r10d, %r9d
movq %r13, %r12
movq %rsi, %r13
movq 0x10(%rsp), %rsi
jge 0x33c43
movl (%rdi,%r9,4), %edx
movl %edx, %r8d
andl $0xf, %r8d
cmpl $0x8, %r8d
je 0x33c43
movl %edx, %r11d
andl $0xd, %r11d
je 0x33c43
movl %edx, %r11d
andl $0xb, %r11d
cmpl $0x3, %r11d
je 0x33c43
cmpl $0x4, %r8d
je 0x33b60
cmpl $0x1, %r8d
jne 0x33b66
shrl $0x4, %edx
addl %edx, 0x48(%rbp)
incq %r9
cmpq %r10, %r9
jl 0x33b21
jmp 0x33c43
movq 0x10(%r14), %rax
leal 0x1(%rcx), %edx
movl %edx, 0x4(%r14)
movslq %ecx, %rcx
movq %rbp, (%rax,%rcx,8)
movq %r13, %r14
jmp 0x33e68
movq %r12, %r8
movq %rax, %r12
movq %rsi, %rax
movq %r10, %rdx
movabsq $-0x1000000000000, %rsi # imm = 0xFFFF000000000000
andq %rsi, %rdx
movabsq $0x1000000000000, %rsi  # imm = 0x1000000000000
cmpq %rsi, %rdx
jne 0x33bf6
movl (%rdi), %edx
andl $0xf, %edx
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
cmpl $0x8, %edx
ja 0x33e77
movl $0x181, %esi            # imm = 0x181
btl %edx, %esi
movq %rax, %rsi
movq %r12, %rax
movq %r8, %r12
jae 0x33d0a
xorl %r9d, %r9d
movl %r9d, 0x40(%rbp)
movl 0x4(%rbp), %edx
movl %edx, 0x44(%rbp)
movl %r9d, 0x48(%rbp)
jmp 0x33d0a
movl 0x4(%rbp), %edx
movl %edx, 0x44(%rbp)
movl $0x0, 0x48(%rbp)
xorl %r9d, %r9d
cmpq %rsi, %r10
jae 0x33c55
movq %rax, %rsi
movq %r12, %rax
movq %r8, %r12
jmp 0x33cf9
cmpl $0x8, %r14d
ja 0x33c2e
movl $0x181, %r8d            # imm = 0x181
btl %r14d, %r8d
jae 0x33c2e
addl %edx, 0x48(%rbp)
addl %edx, %r11d
movl %r11d, 0x44(%rbp)
incl %r9d
movq %r13, %r12
movq %rsi, %r13
movq 0x10(%rsp), %rsi
movl %r9d, 0x40(%rbp)
cmpl %r10d, %r9d
jl 0x33d0a
jmp 0x33f68
movl %edx, 0xc(%rsp)
movl (%rdi), %edx
movl %edx, %r11d
andl $0xf, %r11d
testb $0xd, %dl
sete %sil
leal -0x7(%r11), %r14d
cmpl $0x2, %r14d
setb %r14b
orb %sil, %r14b
movq %rax, %rsi
movq %r12, %rax
movq %r8, %r12
jne 0x33cf9
movq %r12, 0x20(%rsp)
movq %r10, %r8
shrq $0x30, %r8
movq %r8, 0x10(%rsp)
xorl %r12d, %r12d
movl $0x1, %r8d
movq %r8, %r9
shrl $0x4, %edx
cmpl $0x1, %r11d
je 0x33cc8
cmpl $0x4, %r11d
je 0x33cc8
cmpl $0x3, %r11d
jne 0x33ccf
movl 0xc(%rsp), %r8d
addl %edx, %r8d
movl %r8d, 0xc(%rsp)
movl %r8d, 0x44(%rbp)
jmp 0x33ccf
addl %edx, %r12d
movl %r12d, 0x48(%rbp)
cmpq 0x10(%rsp), %r9
jae 0x33cf4
movl (%rdi,%r9,4), %edx
testb $0xd, %dl
je 0x33cf4
movl %edx, %r11d
andl $0xf, %r11d
leal -0x7(%r11), %r14d
leaq 0x1(%r9), %r8
cmpl $0x2, %r14d
jae 0x33c9d
movq 0x20(%rsp), %r12
shrq $0x30, %r10
cmpl %r10d, %r9d
jae 0x33f87
movl %r9d, 0x40(%rbp)
leaq (%rax,%rsi,8), %rax
movslq %r9d, %rdx
movl (%rdi,%rdx,4), %r9d
movl %r9d, %edx
shrl $0x4, %edx
movl 0x14(%rax), %r8d
movl $0x0, 0xc(%rax)
andl $-0xa, %r8d
movl %r8d, 0x14(%rax)
movl 0x44(%rbp), %r10d
addl %r10d, %edx
decl %edx
cmpl %ecx, %edx
jne 0x33dd8
movslq 0x40(%rbp), %rdx
leal 0x1(%rdx), %r14d
movzwl 0xe(%rbp), %r11d
cmpl %r11d, %r14d
jge 0x33dd8
movl 0x4(%rdi,%rdx,4), %edi
movl %edi, %r14d
andl $0xf, %r14d
shrl $0x4, %edi
cmpl $0x1, %r14d
je 0x33dd5
cmpl $0x6, %r14d
je 0x33d79
cmpl $0x2, %r14d
jne 0x33dd8
negl %edi
jmp 0x33dd5
leaq 0x2(%rdx), %rdi
cmpl %r11d, %edi
jge 0x33dd8
subl %edx, %r11d
addl $-0x2, %r11d
movq 0x40(%rsp), %rdx
leaq (%rdx,%rdi,4), %rdx
addq %rdx, %r13
xorl %edx, %edx
xorl %edi, %edi
movl (%r13,%rdx,4), %esi
movl %esi, %r14d
andl $0xf, %r14d
cmpl $0x1, %r14d
jne 0x33db2
shrl $0x4, %esi
addl %esi, %edi
jmp 0x33dc9
cmpl $0x8, %r14d
je 0x33dd1
movl %esi, %r14d
andl $0xd, %r14d
je 0x33dd1
andl $0xb, %esi
cmpl $0x3, %esi
je 0x33dd1
incq %rdx
cmpl %edx, %r11d
jne 0x33d99
testl %edi, %edi
jle 0x33dd8
movl %edi, 0xc(%rax)
movl %r9d, %edx
andl $0xf, %edx
cmpl $0x7, %edx
setne %sil
testb $0x7, %r9b
setne %dil
testb %sil, %dil
jne 0x33e04
movl %ecx, %edx
subl %r10d, %edx
addl 0x48(%rbp), %edx
movl %edx, 0x8(%rax)
movq 0x18(%rsp), %r14
jmp 0x33e36
andl $0xe, %r9d
cmpl $0x2, %r9d
movq 0x18(%rsp), %r14
jne 0x33e36
xorl %esi, %esi
cmpl $0x3, %edx
sete %sil
movl %r8d, %edx
orl $0x1, %edx
movl %edx, 0x14(%rax)
movl 0x48(%rbp), %edx
movl %edx, 0x8(%rax)
leal (%r8,%rsi,8), %r8d
incl %r8d
movl %r8d, 0x14(%rax)
xorl %edx, %edx
cmpl %ecx, 0x4(%rbp)
sete %dl
andl $-0x3, %r8d
leal (%r8,%rdx,2), %edx
movl %edx, 0x14(%rax)
xorl %esi, %esi
cmpl %ecx, 0x4c(%rbp)
sete %sil
andl $-0x5, %edx
leal (%rdx,%rsi,4), %ecx
movl %ecx, 0x14(%rax)
incl %r14d
movq (%rbx), %rbp
addq $0x50, %rbp
movq %rbp, %rbx
movq (%rbx), %rbp
cmpq 0x10(%r15), %rbp
jne 0x33996
jmp 0x33e85
movq %rax, %rsi
movq %r12, %rax
movq %r8, %r12
jmp 0x33d0a
movq 0x28(%rsp), %rbx
movq (%rbx), %rax
movq 0x30(%rsp), %rsi
jmp 0x33e9a
xorl %r14d, %r14d
movq %rax, %rbp
movl %r14d, (%r12)
movl 0x18(%r15), %ecx
movl %ecx, (%rsi)
movl 0x1c(%r15), %ecx
movq 0x38(%rsp), %rdx
movl %ecx, (%rdx)
cmpq %rbp, %rax
setne %dil
movl 0x18(%r15), %r9d
movl (%rax), %edx
cmpl %edx, %r9d
setg %r8b
andb %dil, %r8b
cmpb $0x1, %r8b
je 0x33f13
cmpl %edx, %r9d
jge 0x33eda
movl %edx, 0x18(%r15)
movl 0x38(%rax), %edx
jmp 0x33ee5
movl 0x38(%rax), %edi
leal 0x1(%rcx), %edx
cmpl %edi, %ecx
cmovll %edi, %edx
movl %edx, 0x1c(%r15)
testl %r14d, %r14d
jne 0x33f0a
cmpq %rbp, %rax
setne %cl
movl 0x28(%r15), %eax
testl %eax, %eax
sete %dl
orb %cl, %dl
jne 0x33968
jmp 0x33928
movq 0x40(%r15), %rax
jmp 0x3392a
movq 0x2b0ce(%rip), %rax     # 0x5efe8
movq (%rax), %rdi
leaq 0x1d176(%rip), %rsi     # 0x5109a
leaq 0x1d194(%rip), %rdx     # 0x510bf
xorl %eax, %eax
callq 0x37e0
xorl %eax, %eax
movl $0x1, 0x30(%r15)
movl $0xffffffff, (%r12)     # imm = 0xFFFFFFFF
jmp 0x3392a
leaq 0x1d2c5(%rip), %rdi     # 0x51215
leaq 0x1d27f(%rip), %rsi     # 0x511d6
leaq 0x1d27e(%rip), %rcx     # 0x511dc
movl $0x613, %edx            # imm = 0x613
callq 0x3180
leaq 0x1d2a6(%rip), %rdi     # 0x51215
leaq 0x1d260(%rip), %rsi     # 0x511d6
leaq 0x1d25f(%rip), %rcx     # 0x511dc
movl $0x623, %edx            # imm = 0x623
callq 0x3180
leaq 0x1d28a(%rip), %rdi     # 0x51218
leaq 0x1d241(%rip), %rsi     # 0x511d6
leaq 0x1d240(%rip), %rcx     # 0x511dc
movl $0x60d, %edx            # imm = 0x60D
callq 0x3180