// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x30(%rax)
je 0x4b5d9
movq -0x28(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq $0x0, -0x8(%rbp)
jmp 0x4b920
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x28(%rax)
je 0x4b60c
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x4b60c
movq $0x0, -0x8(%rbp)
jmp 0x4b920
jmp 0x4b60e
movq -0x10(%rbp), %rcx
movb $0x1, %al
cmpl $0x0, 0x28(%rcx)
movb %al, -0x41(%rbp)
jne 0x4b661
movq -0x10(%rbp), %rax
movl 0x20(%rax), %ecx
movq -0x10(%rbp), %rdx
movb $0x1, %al
cmpl 0x18(%rdx), %ecx
movb %al, -0x41(%rbp)
jg 0x4b661
movq -0x10(%rbp), %rax
movl 0x20(%rax), %ecx
movq -0x10(%rbp), %rdx
xorl %eax, %eax
cmpl 0x18(%rdx), %ecx
movb %al, -0x42(%rbp)
jne 0x4b65b
movq -0x10(%rbp), %rax
movl 0x24(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
setg %al
movb %al, -0x42(%rbp)
movb -0x42(%rbp), %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0x4b66d
jmp 0x4b918
movl $0x0, -0x2c(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
je 0x4b7e7
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl (%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jl 0x4b6ce
movq -0x40(%rbp), %rax
movl (%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jne 0x4b6ff
movq -0x40(%rbp), %rax
movl 0x3c(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jg 0x4b6ff
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x4b930
movq -0x40(%rbp), %rax
movq 0x50(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x40(%rbp), %rsi
callq 0x4b470
jmp 0x4b7e2
movq -0x40(%rbp), %rax
movl (%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jne 0x4b7d3
movq -0x40(%rbp), %rax
movl 0x38(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jg 0x4b7d3
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x2c(%rcx), %eax
jne 0x4b782
movq -0x10(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
je 0x4b74a
movq -0x10(%rbp), %rax
movl 0x2c(%rax), %eax
shll %eax
movl %eax, -0x48(%rbp)
jmp 0x4b754
movl $0x100, %eax            # imm = 0x100
movl %eax, -0x48(%rbp)
jmp 0x4b754
movl -0x48(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x10(%rbp), %rax
movslq 0x2c(%rax), %rax
imulq $0x18, %rax, %rsi
callq 0x37c0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x2c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movslq -0x2c(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %esi
movq -0x40(%rbp), %rdx
addq $0x40, %rdx
callq 0x4ba00
cmpl $0x0, %eax
je 0x4b7d1
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x4b7d3
movq -0x38(%rbp), %rax
movq (%rax), %rax
addq $0x50, %rax
movq %rax, -0x38(%rbp)
jmp 0x4b680
movl -0x2c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movl 0x18(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
je 0x4b872
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
cmpl (%rcx), %eax
jle 0x4b870
movq 0x397b2(%rip), %rax     # 0x84fe8
movq (%rax), %rdi
leaq 0x2da58(%rip), %rsi     # 0x79298
leaq 0x2da76(%rip), %rdx     # 0x792bd
movb $0x0, %al
callq 0x37f0
movq -0x10(%rbp), %rax
movl $0x1, 0x30(%rax)
movq -0x28(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq $0x0, -0x8(%rbp)
jmp 0x4b920
jmp 0x4b872
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
cmpl (%rcx), %eax
jge 0x4b8aa
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x38(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1c(%rax)
jmp 0x4b8e1
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
cmpl 0x38(%rcx), %eax
jge 0x4b8d2
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x38(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1c(%rax)
jmp 0x4b8df
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1c(%rax)
jmp 0x4b8e1
cmpl $0x0, -0x2c(%rbp)
je 0x4b8f5
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0x4b920
movq -0x10(%rbp), %rax
cmpl $0x0, 0x28(%rax)
je 0x4b913
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x4b913
jmp 0x4b918
jmp 0x4b60e
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)