// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movq %rcx, %r13
cmpl $0x0, 0x30(%rdi)
je 0x33e00
movl $0xffffffff, (%r13)     # imm = 0xFFFFFFFF
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r12
movl $0x0, (%r13)
cmpl $0x0, 0x28(%rdi)
je 0x33e23
movq 0x8(%r12), %rax
cmpq 0x10(%r12), %rax
je 0x33def
leaq 0x8(%r12), %rax
movq %rax, 0x20(%rsp)
movq %r13, 0x8(%rsp)
movq %rbx, 0x30(%rsp)
movq %r15, 0x28(%rsp)
cmpl $0x0, 0x28(%r12)
jne 0x33e5e
movl 0x18(%r12), %eax
cmpl %eax, 0x20(%r12)
jg 0x33e5e
jne 0x33def
movl 0x24(%r12), %eax
cmpl 0x1c(%r12), %eax
jle 0x33def
movq 0x8(%r12), %rbp
movq 0x10(%r12), %rax
xorl %r14d, %r14d
cmpq %rax, %rbp
je 0x342b1
movq 0x20(%rsp), %r15
movl (%rbp), %eax
movl 0x18(%r12), %ecx
cmpl %ecx, %eax
jge 0x33ee8
movq %r12, %rdi
movq %rbp, %rsi
callq 0x343f2
movq 0x50(%rbp), %rax
movq %rax, (%r15)
movq (%r12), %rbx
decl (%rbx)
movq $0x0, 0x50(%rbp)
movl 0x8(%rbx), %eax
cmpl %eax, 0x4(%rbx)
jne 0x33ed1
leal (%rax,%rax), %ecx
testl %eax, %eax
movl $0x100, %eax            # imm = 0x100
cmovel %eax, %ecx
movl %ecx, 0x8(%rbx)
movq 0x10(%rbx), %rdi
movslq %ecx, %rsi
shlq $0x3, %rsi
callq 0x37b0
movq %rax, 0x10(%rbx)
movq 0x10(%rbx), %rax
movslq 0x4(%rbx), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x4(%rbx)
movq %rbp, (%rax,%rcx,8)
jmp 0x342a0
jne 0x34299
movl 0x3c(%rbp), %edx
cmpl 0x1c(%r12), %edx
jle 0x33e85
cmpl %ecx, %eax
jne 0x34299
movl 0x38(%rbp), %eax
cmpl 0x1c(%r12), %eax
jg 0x34299
movl 0x2c(%r12), %eax
cmpl %eax, %r14d
jne 0x33f44
leal (%rax,%rax), %ecx
testl %eax, %eax
movl $0x100, %eax            # imm = 0x100
cmovel %eax, %ecx
movl %ecx, 0x2c(%r12)
movq 0x40(%r12), %rdi
movslq %ecx, %rax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
callq 0x37b0
movq %rax, 0x40(%r12)
movq 0x40(%r12), %rdi
movslq %r14d, %rax
leaq (%rax,%rax,2), %r8
movq %rbp, (%rdi,%r8,8)
movl 0x1c(%r12), %eax
movq 0x8(%rbp), %rdx
movq 0x28(%rbp), %rsi
movl %edx, %ecx
shrl $0x18, %ecx
movq %rsi, 0x18(%rsp)
addq %rcx, %rsi
movslq 0x40(%rbp), %r9
cmpq $-0x1, %r9
je 0x34063
movl (%rsi,%r9,4), %ebx
movl %ebx, %r10d
shrl $0x4, %r10d
movl 0x44(%rbp), %r11d
movl %eax, %r13d
subl %r11d, %r13d
cmpl %r10d, %r13d
movq 0x8(%rsp), %r13
jl 0x34162
shrq $0x30, %rdx
cmpl %edx, %r9d
jge 0x34395
movl 0x4(%rsi,%r9,4), %edx
movl %edx, %r13d
andl $0xf, %r13d
andl $0xf, %ebx
cmpl $0x8, %r13d
je 0x3412f
movl %edx, %r13d
andl $0xd, %r13d
je 0x3412f
andl $0xb, %edx
cmpl $0x3, %edx
je 0x3412f
cmpl $0x8, %ebx
ja 0x33ff1
movl $0x181, %edx            # imm = 0x181
btl %ebx, %edx
jae 0x33ff1
addl %r10d, 0x48(%rbp)
addl %r10d, %r11d
movl %r11d, 0x44(%rbp)
incq %r9
movzwl 0xe(%rbp), %edx
cmpl %edx, %r9d
movq 0x8(%rsp), %r13
jge 0x34151
movl (%rsi,%r9,4), %edx
movl %edx, %r10d
andl $0xf, %r10d
cmpl $0x8, %r10d
je 0x34151
movl %edx, %r11d
andl $0xd, %r11d
je 0x34151
movl %edx, %r11d
andl $0xb, %r11d
cmpl $0x3, %r11d
je 0x34151
cmpl $0x4, %r10d
je 0x3404c
cmpl $0x1, %r10d
jne 0x34052
shrl $0x4, %edx
addl %edx, 0x48(%rbp)
incq %r9
movzwl 0xe(%rbp), %edx
cmpq %rdx, %r9
jl 0x3400d
jmp 0x34151
movq %rdx, %r9
movabsq $-0x1000000000000, %r10 # imm = 0xFFFF000000000000
andq %r10, %r9
movabsq $0x1000000000000, %r10  # imm = 0x1000000000000
cmpq %r10, %r9
jne 0x340b6
movl (%rsi), %edx
andl $0xf, %edx
cmpl $0x8, %edx
ja 0x34162
movl $0x181, %r9d            # imm = 0x181
btl %edx, %r9d
jae 0x34162
xorl %r9d, %r9d
movl %r9d, 0x40(%rbp)
movl 0x4(%rbp), %edx
movl %edx, 0x44(%rbp)
movl %r9d, 0x48(%rbp)
jmp 0x34162
movl 0x4(%rbp), %r9d
movl %r9d, 0x44(%rbp)
movl $0x0, 0x48(%rbp)
xorl %r9d, %r9d
cmpq %r10, %rdx
jb 0x3411c
leaq 0x44(%rbp), %r13
leaq 0x48(%rbp), %r11
xorl %r9d, %r9d
movl (%rsi,%r9,4), %edx
testb $0xd, %dl
je 0x34117
movl %edx, %ebx
andl $0xf, %ebx
leal -0x9(%rbx), %r10d
cmpl $-0x3, %r10d
ja 0x34117
cmpl $0x4, %ebx
je 0x34102
movq %r13, %r10
cmpl $0x3, %ebx
je 0x34105
cmpl $0x1, %ebx
jne 0x3410b
movq %r11, %r10
shrl $0x4, %edx
addl %edx, (%r10)
incq %r9
movzwl 0xe(%rbp), %edx
cmpq %rdx, %r9
jb 0x340d8
movq 0x8(%rsp), %r13
movzwl 0xe(%rbp), %edx
cmpl %edx, %r9d
jae 0x343d3
movl %r9d, 0x40(%rbp)
jmp 0x34162
cmpl $0x8, %ebx
ja 0x34142
movl $0x181, %edx            # imm = 0x181
btl %ebx, %edx
jae 0x34142
addl %r10d, 0x48(%rbp)
addl %r10d, %r11d
movl %r11d, 0x44(%rbp)
incl %r9d
movq 0x8(%rsp), %r13
movl %r9d, 0x40(%rbp)
movzwl 0xe(%rbp), %edx
cmpl %edx, %r9d
jge 0x343b4
leaq (%rdi,%r8,8), %rdi
movslq 0x40(%rbp), %rdx
movl (%rsi,%rdx,4), %r9d
movl %r9d, %edx
shrl $0x4, %edx
movl 0x14(%rdi), %r8d
movl $0x0, 0xc(%rdi)
andl $-0xa, %r8d
movl %r8d, 0x14(%rdi)
movl 0x44(%rbp), %r10d
addl %r10d, %edx
decl %edx
cmpl %eax, %edx
jne 0x34221
movslq 0x40(%rbp), %rdx
leal 0x1(%rdx), %ebx
movzwl 0xe(%rbp), %r11d
cmpl %r11d, %ebx
jge 0x34221
movl 0x4(%rsi,%rdx,4), %esi
movl %esi, %ebx
andl $0xf, %ebx
shrl $0x4, %esi
cmpl $0x1, %ebx
je 0x3421e
cmpl $0x6, %ebx
je 0x341c8
cmpl $0x2, %ebx
jne 0x34221
negl %esi
jmp 0x3421e
leaq 0x2(%rdx), %rsi
cmpl %r11d, %esi
jge 0x34221
subl %edx, %r11d
addl $-0x2, %r11d
leaq (%rcx,%rsi,4), %rcx
addq %rcx, 0x18(%rsp)
xorl %edx, %edx
xorl %esi, %esi
movq 0x18(%rsp), %rcx
movl (%rcx,%rdx,4), %ecx
movl %ecx, %ebx
andl $0xf, %ebx
cmpl $0x1, %ebx
jne 0x341fe
shrl $0x4, %ecx
addl %ecx, %esi
jmp 0x34212
cmpl $0x8, %ebx
je 0x3421a
movl %ecx, %ebx
andl $0xd, %ebx
je 0x3421a
andl $0xb, %ecx
cmpl $0x3, %ecx
je 0x3421a
incq %rdx
cmpl %edx, %r11d
jne 0x341e5
testl %esi, %esi
jle 0x34221
movl %esi, 0xc(%rdi)
movl %r9d, %ecx
andl $0xf, %ecx
cmpl $0x7, %ecx
setne %dl
testb $0x7, %r9b
setne %sil
testb %dl, %sil
jne 0x34247
movl %eax, %ecx
subl %r10d, %ecx
addl 0x48(%rbp), %ecx
movl %ecx, 0x8(%rdi)
jmp 0x34271
andl $0xe, %r9d
cmpl $0x2, %r9d
jne 0x34271
xorl %edx, %edx
cmpl $0x3, %ecx
sete %dl
movl %r8d, %ecx
orl $0x1, %ecx
movl %ecx, 0x14(%rdi)
movl 0x48(%rbp), %ecx
movl %ecx, 0x8(%rdi)
leal (%r8,%rdx,8), %ecx
incl %ecx
movl %ecx, 0x14(%rdi)
xorl %ecx, %ecx
cmpl %eax, 0x4(%rbp)
sete %cl
movl 0x14(%rdi), %edx
andl $-0x3, %edx
leal (%rdx,%rcx,2), %ecx
movl %ecx, 0x14(%rdi)
xorl %edx, %edx
cmpl %eax, 0x4c(%rbp)
sete %dl
andl $-0x5, %ecx
leal (%rcx,%rdx,4), %eax
movl %eax, 0x14(%rdi)
incl %r14d
movq (%r15), %r15
addq $0x50, %r15
movq (%r15), %rbp
movq 0x10(%r12), %rax
cmpq %rax, %rbp
jne 0x33e79
movl %r14d, (%r13)
movl 0x18(%r12), %ecx
movq 0x28(%rsp), %r15
movl %ecx, (%r15)
movl 0x1c(%r12), %ecx
movq 0x30(%rsp), %rbx
movl %ecx, (%rbx)
movq 0x8(%r12), %rcx
cmpq %rax, %rcx
je 0x342e1
movl 0x18(%r12), %edx
cmpl (%rcx), %edx
jg 0x34342
movl (%rcx), %edx
cmpl %edx, 0x18(%r12)
jge 0x342f4
movl %edx, 0x18(%r12)
movl 0x38(%rcx), %edx
jmp 0x34304
movl 0x1c(%r12), %esi
movl 0x38(%rcx), %edi
leal 0x1(%rsi), %edx
cmpl %edi, %esi
cmovll %edi, %edx
movl %edx, 0x1c(%r12)
testl %r14d, %r14d
je 0x3431f
movq 0x40(%r12), %rax
movq %rax, 0x10(%rsp)
movl $0x1, %eax
jmp 0x34338
xorl %edx, %edx
cmpl $0x0, 0x28(%r12)
setne %dl
cmpq %rax, %rcx
leal (%rdx,%rdx,2), %eax
movl $0x0, %ecx
cmovnel %ecx, %eax
testl %eax, %eax
je 0x33e3c
jmp 0x34382
movq 0x29c9f(%rip), %rax     # 0x5dfe8
movq (%rax), %rdi
leaq 0x1cb7f(%rip), %rsi     # 0x50ed2
leaq 0x1cb9d(%rip), %rdx     # 0x50ef7
xorl %eax, %eax
callq 0x37e0
movl $0x1, 0x30(%r12)
movl $0xffffffff, (%r13)     # imm = 0xFFFFFFFF
movl $0x1, %eax
movq $0x0, 0x10(%rsp)
jmp 0x34338
cmpl $0x3, %eax
je 0x33def
movq 0x10(%rsp), %rax
jmp 0x33df1
leaq 0x1ccb1(%rip), %rdi     # 0x5104d
leaq 0x1cc6b(%rip), %rsi     # 0x5100e
leaq 0x1cc6a(%rip), %rcx     # 0x51014
movl $0x613, %edx            # imm = 0x613
callq 0x3180
leaq 0x1cc92(%rip), %rdi     # 0x5104d
leaq 0x1cc4c(%rip), %rsi     # 0x5100e
leaq 0x1cc4b(%rip), %rcx     # 0x51014
movl $0x623, %edx            # imm = 0x623
callq 0x3180
leaq 0x1cc76(%rip), %rdi     # 0x51050
leaq 0x1cc2d(%rip), %rsi     # 0x5100e
leaq 0x1cc2c(%rip), %rcx     # 0x51014
movl $0x60d, %edx            # imm = 0x60D
callq 0x3180