// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
movq %rcx, %r14
cmpl $0x0, 0x30(%rdi)
je 0x298d4
orl $-0x1, (%r14)
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, %r15
andl $0x0, (%r14)
movl 0x28(%rdi), %eax
testl %eax, %eax
je 0x298ec
movq 0x8(%r15), %rcx
cmpq 0x10(%r15), %rcx
je 0x298c3
leaq 0x8(%r15), %rcx
movq %rcx, 0x20(%rsp)
movq %r14, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
testl %eax, %eax
jne 0x2991e
movl 0x18(%r15), %eax
cmpl %eax, 0x20(%r15)
jg 0x2991e
jne 0x298c3
movl 0x24(%r15), %eax
cmpl 0x1c(%r15), %eax
jle 0x298c3
xorl %ebx, %ebx
movq 0x20(%rsp), %r12
movq (%r12), %rbp
cmpq 0x10(%r15), %rbp
je 0x29cb4
movl 0x18(%r15), %eax
cmpl %eax, (%rbp)
jl 0x2994b
jne 0x29ca8
movl 0x1c(%r15), %ecx
cmpl %ecx, 0x3c(%rbp)
jg 0x2996b
movq %r15, %rdi
movq %rbp, %rsi
callq 0x29dce
movq 0x50(%rbp), %rax
movq %rax, (%r12)
movq (%r15), %rdi
movq %rbp, %rsi
callq 0x2984d
jmp 0x29925
cmpl %ecx, 0x38(%rbp)
jg 0x29ca8
movq 0x40(%r15), %rax
cmpl 0x2c(%r15), %ebx
jne 0x299a6
leal (%rbx,%rbx), %ecx
testl %ebx, %ebx
movl $0x100, %edx            # imm = 0x100
cmovel %edx, %ecx
movl %ecx, 0x2c(%r15)
movslq %ecx, %rcx
imulq $0x18, %rcx, %rsi
movq %rax, %rdi
callq 0x37c0
movq %rax, 0x40(%r15)
movl 0x1c(%r15), %ecx
movslq %ebx, %rdx
imulq $0x18, %rdx, %rsi
movq %rbp, (%rax,%rsi)
movq 0x8(%rbp), %r8
movl %r8d, %edx
shrl $0x18, %edx
addq 0x28(%rbp), %rdx
movslq 0x40(%rbp), %rdi
cmpq $-0x1, %rdi
je 0x29a9f
movl (%rdx,%rdi,4), %r11d
movl %r11d, %r9d
shrl $0x4, %r9d
movl 0x44(%rbp), %r10d
movl %ecx, %r14d
subl %r10d, %r14d
cmpl %r9d, %r14d
jl 0x29b74
shrq $0x30, %r8
cmpl %r8d, %edi
jge 0x29d90
movl 0x4(%rdx,%rdi,4), %r13d
movl %r13d, %r14d
andl $0xf, %r14d
andl $0xf, %r11d
cmpl $0x8, %r14d
je 0x29b49
movl %r13d, %r14d
andl $0xd, %r14d
je 0x29b49
andl $0xb, %r13d
cmpl $0x3, %r13d
je 0x29b49
cmpl $0x8, %r11d
ja 0x29a43
movl $0x181, %r14d           # imm = 0x181
btl %r11d, %r14d
jae 0x29a43
addl %r9d, 0x48(%rbp)
addl %r9d, %r10d
movl %r10d, 0x44(%rbp)
incq %rdi
cmpq %r8, %rdi
jge 0x29b68
movl (%rdx,%rdi,4), %r9d
movl %r9d, %r10d
andl $0xf, %r10d
cmpl $0x8, %r10d
je 0x29b68
movl %r9d, %r11d
andl $0xd, %r11d
je 0x29b68
movl %r9d, %r11d
andl $0xb, %r11d
cmpl $0x3, %r11d
je 0x29b68
cmpl $0x4, %r10d
je 0x29a95
cmpl $0x1, %r10d
jne 0x29a4a
shrl $0x4, %r9d
addl %r9d, 0x48(%rbp)
jmp 0x29a4a
shrq $0x30, %r8
cmpl $0x1, %r8d
jne 0x29ae4
movl (%rdx), %r8d
andl $0xf, %r8d
pushq $-0x1
popq %rdi
cmpl $0x8, %r8d
ja 0x29b74
movl $0x181, %edi            # imm = 0x181
btl %r8d, %edi
pushq $-0x1
popq %rdi
jae 0x29b74
andl $0x0, 0x40(%rbp)
movl 0x4(%rbp), %edi
movl %edi, 0x44(%rbp)
andl $0x0, 0x48(%rbp)
xorl %edi, %edi
jmp 0x29b74
movl 0x4(%rbp), %r9d
movl %r9d, 0x44(%rbp)
andl $0x0, 0x48(%rbp)
xorl %r10d, %r10d
xorl %edi, %edi
cmpq %r8, %rdi
jae 0x29d71
movl (%rdx,%rdi,4), %r11d
testb $0xd, %r11b
je 0x29b44
movl %r11d, %r13d
andl $0xf, %r13d
leal -0x7(%r13), %r14d
cmpl $0x2, %r14d
jb 0x29b44
shrl $0x4, %r11d
cmpl $0x1, %r13d
je 0x29b38
cmpl $0x4, %r13d
je 0x29b38
cmpl $0x3, %r13d
jne 0x29b3f
addl %r11d, %r9d
movl %r9d, 0x44(%rbp)
jmp 0x29b3f
addl %r11d, %r10d
movl %r10d, 0x48(%rbp)
incq %rdi
jmp 0x29af5
movl %edi, 0x40(%rbp)
jmp 0x29b74
cmpl $0x8, %r11d
ja 0x29b5f
movl $0x181, %r14d           # imm = 0x181
btl %r11d, %r14d
jae 0x29b5f
addl %r9d, 0x48(%rbp)
addl %r9d, %r10d
movl %r10d, 0x44(%rbp)
incl %edi
movl %edi, 0x40(%rbp)
cmpl %r8d, %edi
jge 0x29daf
addq %rsi, %rax
movslq %edi, %rsi
movl (%rdx,%rsi,4), %edi
movl %edi, %r9d
shrl $0x4, %r9d
movl 0x14(%rax), %esi
andl $0x0, 0xc(%rax)
andl $-0xa, %esi
movl %esi, 0x14(%rax)
movl 0x44(%rbp), %r8d
addl %r8d, %r9d
decl %r9d
cmpl %ecx, %r9d
jne 0x29c32
movslq 0x40(%rbp), %r9
leal 0x1(%r9), %r10d
movq 0x8(%rbp), %r11
shrq $0x30, %r11
cmpl %r11d, %r10d
jge 0x29c32
movl 0x4(%rdx,%r9,4), %r10d
movl %r10d, %r13d
andl $0xf, %r13d
shrl $0x4, %r10d
cmpl $0x1, %r13d
je 0x29c2e
cmpl $0x6, %r13d
je 0x29be0
cmpl $0x2, %r13d
jne 0x29c32
negl %r10d
jmp 0x29c2e
addq $0x2, %r9
cmpl %r11d, %r9d
jge 0x29c32
xorl %r10d, %r10d
cmpq %r9, %r11
je 0x29c29
movl (%rdx,%r9,4), %r14d
movl %r14d, %r13d
andl $0xf, %r13d
cmpl $0x1, %r13d
jne 0x29c0b
shrl $0x4, %r14d
addl %r14d, %r10d
jmp 0x29c24
cmpl $0x8, %r13d
je 0x29c29
movl %r14d, %r13d
andl $0xd, %r13d
je 0x29c29
andl $0xb, %r14d
cmpl $0x3, %r14d
je 0x29c29
incq %r9
jmp 0x29bec
testl %r10d, %r10d
jle 0x29c32
movl %r10d, 0xc(%rax)
movl %edi, %edx
andl $0xf, %edx
cmpl $0x7, %edx
setne %r9b
testb $0x7, %dil
setne %r10b
testb %r9b, %r10b
jne 0x29c58
movl %ecx, %edx
subl %r8d, %edx
addl 0x48(%rbp), %edx
movl %edx, 0x8(%rax)
jmp 0x29c7f
andl $0xe, %edi
cmpl $0x2, %edi
jne 0x29c7f
xorl %edi, %edi
cmpl $0x3, %edx
sete %dil
movl %esi, %edx
orl $0x1, %edx
movl %edx, 0x14(%rax)
movl 0x48(%rbp), %edx
movl %edx, 0x8(%rax)
leal (%rsi,%rdi,8), %esi
incl %esi
movl %esi, 0x14(%rax)
xorl %edx, %edx
cmpl %ecx, 0x4(%rbp)
sete %dl
andl $-0x3, %esi
leal (%rsi,%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 %ebx
movq (%r12), %rbp
addq $0x50, %rbp
movq %rbp, %r12
jmp 0x29925
movq 0x18(%rsp), %r14
movl %ebx, (%r14)
movl 0x18(%r15), %eax
movq 0x8(%rsp), %rsi
movl %eax, (%rsi)
movl 0x1c(%r15), %ecx
movq 0x10(%rsp), %rdx
movl %ecx, (%rdx)
movq 0x8(%r15), %rax
cmpq %rbp, %rax
setne %dil
movl 0x18(%r15), %r10d
movl (%rax), %r9d
cmpl %r9d, %r10d
setg %r8b
andb %dil, %r8b
cmpb $0x1, %r8b
je 0x29d3f
cmpl %r9d, %r10d
jge 0x29d02
movl %r9d, 0x18(%r15)
movl 0x38(%rax), %edi
jmp 0x29d10
movl 0x38(%rax), %r8d
leal 0x1(%rcx), %edi
cmpl %r8d, %ecx
cmovll %r8d, %edi
movl %edi, 0x1c(%r15)
testl %ebx, %ebx
jne 0x29d36
cmpq %rbp, %rax
setne %cl
movl 0x28(%r15), %eax
testl %eax, %eax
sete %dil
orb %cl, %dil
jne 0x29904
jmp 0x298c3
movq 0x40(%r15), %rax
jmp 0x298c5
movq 0x292a2(%rip), %rax     # 0x52fe8
movq (%rax), %rdi
leaq 0x1909e(%rip), %rsi     # 0x42dee
leaq 0x190bc(%rip), %rdx     # 0x42e13
xorl %eax, %eax
callq 0x37f0
xorl %eax, %eax
movl $0x1, 0x30(%r15)
orl $-0x1, (%r14)
jmp 0x298c5
leaq 0x191f4(%rip), %rdi     # 0x42f6c
leaq 0x191ab(%rip), %rsi     # 0x42f2a
leaq 0x191aa(%rip), %rcx     # 0x42f30
movl $0x60d, %edx            # imm = 0x60D
callq 0x3180
leaq 0x191d2(%rip), %rdi     # 0x42f69
leaq 0x1918c(%rip), %rsi     # 0x42f2a
leaq 0x1918b(%rip), %rcx     # 0x42f30
movl $0x613, %edx            # imm = 0x613
callq 0x3180
leaq 0x191b3(%rip), %rdi     # 0x42f69
leaq 0x1916d(%rip), %rsi     # 0x42f2a
leaq 0x1916c(%rip), %rcx     # 0x42f30
movl $0x623, %edx            # imm = 0x623
callq 0x3180