// File: /workspace/github_cpp_makefile_star2_O1/karel-brinda[P]ococo/ext/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 0x1ad94
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 0x1adb7
movq 0x8(%r12), %rax
cmpq 0x10(%r12), %rax
je 0x1ad83
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 0x1adf2
movl 0x18(%r12), %eax
cmpl %eax, 0x20(%r12)
jg 0x1adf2
jne 0x1ad83
movl 0x24(%r12), %eax
cmpl 0x1c(%r12), %eax
jle 0x1ad83
movq 0x8(%r12), %rbp
movq 0x10(%r12), %rax
xorl %r14d, %r14d
cmpq %rax, %rbp
je 0x1b245
movq 0x20(%rsp), %r15
movl (%rbp), %eax
movl 0x18(%r12), %ecx
cmpl %ecx, %eax
jge 0x1ae7c
movq %r12, %rdi
movq %rbp, %rsi
callq 0x1b386
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 0x1ae65
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 0x48d0
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 0x1b234
jne 0x1b22d
movl 0x3c(%rbp), %edx
cmpl 0x1c(%r12), %edx
jle 0x1ae19
cmpl %ecx, %eax
jne 0x1b22d
movl 0x38(%rbp), %eax
cmpl 0x1c(%r12), %eax
jg 0x1b22d
movl 0x2c(%r12), %eax
cmpl %eax, %r14d
jne 0x1aed8
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 0x48d0
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 0x1aff7
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 0x1b0f6
shrq $0x30, %rdx
cmpl %edx, %r9d
jge 0x1b329
movl 0x4(%rsi,%r9,4), %edx
movl %edx, %r13d
andl $0xf, %r13d
andl $0xf, %ebx
cmpl $0x8, %r13d
je 0x1b0c3
movl %edx, %r13d
andl $0xd, %r13d
je 0x1b0c3
andl $0xb, %edx
cmpl $0x3, %edx
je 0x1b0c3
cmpl $0x8, %ebx
ja 0x1af85
movl $0x181, %edx            # imm = 0x181
btl %ebx, %edx
jae 0x1af85
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 0x1b0e5
movl (%rsi,%r9,4), %edx
movl %edx, %r10d
andl $0xf, %r10d
cmpl $0x8, %r10d
je 0x1b0e5
movl %edx, %r11d
andl $0xd, %r11d
je 0x1b0e5
movl %edx, %r11d
andl $0xb, %r11d
cmpl $0x3, %r11d
je 0x1b0e5
cmpl $0x4, %r10d
je 0x1afe0
cmpl $0x1, %r10d
jne 0x1afe6
shrl $0x4, %edx
addl %edx, 0x48(%rbp)
incq %r9
movzwl 0xe(%rbp), %edx
cmpq %rdx, %r9
jl 0x1afa1
jmp 0x1b0e5
movq %rdx, %r9
movabsq $-0x1000000000000, %r10 # imm = 0xFFFF000000000000
andq %r10, %r9
movabsq $0x1000000000000, %r10  # imm = 0x1000000000000
cmpq %r10, %r9
jne 0x1b04a
movl (%rsi), %edx
andl $0xf, %edx
cmpl $0x8, %edx
ja 0x1b0f6
movl $0x181, %r9d            # imm = 0x181
btl %edx, %r9d
jae 0x1b0f6
xorl %r9d, %r9d
movl %r9d, 0x40(%rbp)
movl 0x4(%rbp), %edx
movl %edx, 0x44(%rbp)
movl %r9d, 0x48(%rbp)
jmp 0x1b0f6
movl 0x4(%rbp), %r9d
movl %r9d, 0x44(%rbp)
movl $0x0, 0x48(%rbp)
xorl %r9d, %r9d
cmpq %r10, %rdx
jb 0x1b0b0
leaq 0x44(%rbp), %r13
leaq 0x48(%rbp), %r11
xorl %r9d, %r9d
movl (%rsi,%r9,4), %edx
testb $0xd, %dl
je 0x1b0ab
movl %edx, %ebx
andl $0xf, %ebx
leal -0x9(%rbx), %r10d
cmpl $-0x3, %r10d
ja 0x1b0ab
cmpl $0x4, %ebx
je 0x1b096
movq %r13, %r10
cmpl $0x3, %ebx
je 0x1b099
cmpl $0x1, %ebx
jne 0x1b09f
movq %r11, %r10
shrl $0x4, %edx
addl %edx, (%r10)
incq %r9
movzwl 0xe(%rbp), %edx
cmpq %rdx, %r9
jb 0x1b06c
movq 0x8(%rsp), %r13
movzwl 0xe(%rbp), %edx
cmpl %edx, %r9d
jae 0x1b367
movl %r9d, 0x40(%rbp)
jmp 0x1b0f6
cmpl $0x8, %ebx
ja 0x1b0d6
movl $0x181, %edx            # imm = 0x181
btl %ebx, %edx
jae 0x1b0d6
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 0x1b348
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 0x1b1b5
movslq 0x40(%rbp), %rdx
leal 0x1(%rdx), %ebx
movzwl 0xe(%rbp), %r11d
cmpl %r11d, %ebx
jge 0x1b1b5
movl 0x4(%rsi,%rdx,4), %esi
movl %esi, %ebx
andl $0xf, %ebx
shrl $0x4, %esi
cmpl $0x1, %ebx
je 0x1b1b2
cmpl $0x6, %ebx
je 0x1b15c
cmpl $0x2, %ebx
jne 0x1b1b5
negl %esi
jmp 0x1b1b2
leaq 0x2(%rdx), %rsi
cmpl %r11d, %esi
jge 0x1b1b5
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 0x1b192
shrl $0x4, %ecx
addl %ecx, %esi
jmp 0x1b1a6
cmpl $0x8, %ebx
je 0x1b1ae
movl %ecx, %ebx
andl $0xd, %ebx
je 0x1b1ae
andl $0xb, %ecx
cmpl $0x3, %ecx
je 0x1b1ae
incq %rdx
cmpl %edx, %r11d
jne 0x1b179
testl %esi, %esi
jle 0x1b1b5
movl %esi, 0xc(%rdi)
movl %r9d, %ecx
andl $0xf, %ecx
cmpl $0x7, %ecx
setne %dl
testb $0x7, %r9b
setne %sil
testb %dl, %sil
jne 0x1b1db
movl %eax, %ecx
subl %r10d, %ecx
addl 0x48(%rbp), %ecx
movl %ecx, 0x8(%rdi)
jmp 0x1b205
andl $0xe, %r9d
cmpl $0x2, %r9d
jne 0x1b205
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 0x1ae0d
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 0x1b275
movl 0x18(%r12), %edx
cmpl (%rcx), %edx
jg 0x1b2d6
movl (%rcx), %edx
cmpl %edx, 0x18(%r12)
jge 0x1b288
movl %edx, 0x18(%r12)
movl 0x38(%rcx), %edx
jmp 0x1b298
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 0x1b2b3
movq 0x40(%r12), %rax
movq %rax, 0x10(%rsp)
movl $0x1, %eax
jmp 0x1b2cc
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 0x1add0
jmp 0x1b316
movq 0x48ceb(%rip), %rax     # 0x63fc8
movq (%rax), %rdi
leaq 0x384a7(%rip), %rsi     # 0x5378e
leaq 0x384c5(%rip), %rdx     # 0x537b3
xorl %eax, %eax
callq 0x4770
movl $0x1, 0x30(%r12)
movl $0xffffffff, (%r13)     # imm = 0xFFFFFFFF
movl $0x1, %eax
movq $0x0, 0x10(%rsp)
jmp 0x1b2cc
cmpl $0x3, %eax
je 0x1ad83
movq 0x10(%rsp), %rax
jmp 0x1ad85
leaq 0x385d9(%rip), %rdi     # 0x53909
leaq 0x38593(%rip), %rsi     # 0x538ca
leaq 0x38592(%rip), %rcx     # 0x538d0
movl $0x62d, %edx            # imm = 0x62D
callq 0x4350
leaq 0x385ba(%rip), %rdi     # 0x53909
leaq 0x38574(%rip), %rsi     # 0x538ca
leaq 0x38573(%rip), %rcx     # 0x538d0
movl $0x63d, %edx            # imm = 0x63D
callq 0x4350
leaq 0x3859e(%rip), %rdi     # 0x5390c
leaq 0x38555(%rip), %rsi     # 0x538ca
leaq 0x38554(%rip), %rcx     # 0x538d0
movl $0x627, %edx            # imm = 0x627
callq 0x4350