// File: /workspace/github_cpp_makefile_star2_O2/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 $0x28, %rsp
movq %rcx, %r14
cmpl $0x0, 0x30(%rdi)
je 0x14904
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 0x1491c
movq 0x8(%r15), %rcx
cmpq 0x10(%r15), %rcx
je 0x148f3
leaq 0x8(%r15), %rcx
movq %rcx, 0x20(%rsp)
movq %r14, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
testl %eax, %eax
jne 0x1494e
movl 0x18(%r15), %eax
cmpl %eax, 0x20(%r15)
jg 0x1494e
jne 0x148f3
movl 0x24(%r15), %eax
cmpl 0x1c(%r15), %eax
jle 0x148f3
xorl %ebx, %ebx
movq 0x20(%rsp), %r12
movq (%r12), %rbp
cmpq 0x10(%r15), %rbp
je 0x14ce4
movl 0x18(%r15), %eax
cmpl %eax, (%rbp)
jl 0x1497b
jne 0x14cd8
movl 0x1c(%r15), %ecx
cmpl %ecx, 0x3c(%rbp)
jg 0x1499b
movq %r15, %rdi
movq %rbp, %rsi
callq 0x14dfe
movq 0x50(%rbp), %rax
movq %rax, (%r12)
movq (%r15), %rdi
movq %rbp, %rsi
callq 0x1487d
jmp 0x14955
cmpl %ecx, 0x38(%rbp)
jg 0x14cd8
movq 0x40(%r15), %rax
cmpl 0x2c(%r15), %ebx
jne 0x149d6
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 0x48c0
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 0x14acf
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 0x14ba4
shrq $0x30, %r8
cmpl %r8d, %edi
jge 0x14dc0
movl 0x4(%rdx,%rdi,4), %r13d
movl %r13d, %r14d
andl $0xf, %r14d
andl $0xf, %r11d
cmpl $0x8, %r14d
je 0x14b79
movl %r13d, %r14d
andl $0xd, %r14d
je 0x14b79
andl $0xb, %r13d
cmpl $0x3, %r13d
je 0x14b79
cmpl $0x8, %r11d
ja 0x14a73
movl $0x181, %r14d           # imm = 0x181
btl %r11d, %r14d
jae 0x14a73
addl %r9d, 0x48(%rbp)
addl %r9d, %r10d
movl %r10d, 0x44(%rbp)
incq %rdi
cmpq %r8, %rdi
jge 0x14b98
movl (%rdx,%rdi,4), %r9d
movl %r9d, %r10d
andl $0xf, %r10d
cmpl $0x8, %r10d
je 0x14b98
movl %r9d, %r11d
andl $0xd, %r11d
je 0x14b98
movl %r9d, %r11d
andl $0xb, %r11d
cmpl $0x3, %r11d
je 0x14b98
cmpl $0x4, %r10d
je 0x14ac5
cmpl $0x1, %r10d
jne 0x14a7a
shrl $0x4, %r9d
addl %r9d, 0x48(%rbp)
jmp 0x14a7a
shrq $0x30, %r8
cmpl $0x1, %r8d
jne 0x14b14
movl (%rdx), %r8d
andl $0xf, %r8d
pushq $-0x1
popq %rdi
cmpl $0x8, %r8d
ja 0x14ba4
movl $0x181, %edi            # imm = 0x181
btl %r8d, %edi
pushq $-0x1
popq %rdi
jae 0x14ba4
andl $0x0, 0x40(%rbp)
movl 0x4(%rbp), %edi
movl %edi, 0x44(%rbp)
andl $0x0, 0x48(%rbp)
xorl %edi, %edi
jmp 0x14ba4
movl 0x4(%rbp), %r9d
movl %r9d, 0x44(%rbp)
andl $0x0, 0x48(%rbp)
xorl %r10d, %r10d
xorl %edi, %edi
cmpq %r8, %rdi
jae 0x14da1
movl (%rdx,%rdi,4), %r11d
testb $0xd, %r11b
je 0x14b74
movl %r11d, %r13d
andl $0xf, %r13d
leal -0x7(%r13), %r14d
cmpl $0x2, %r14d
jb 0x14b74
shrl $0x4, %r11d
cmpl $0x1, %r13d
je 0x14b68
cmpl $0x4, %r13d
je 0x14b68
cmpl $0x3, %r13d
jne 0x14b6f
addl %r11d, %r9d
movl %r9d, 0x44(%rbp)
jmp 0x14b6f
addl %r11d, %r10d
movl %r10d, 0x48(%rbp)
incq %rdi
jmp 0x14b25
movl %edi, 0x40(%rbp)
jmp 0x14ba4
cmpl $0x8, %r11d
ja 0x14b8f
movl $0x181, %r14d           # imm = 0x181
btl %r11d, %r14d
jae 0x14b8f
addl %r9d, 0x48(%rbp)
addl %r9d, %r10d
movl %r10d, 0x44(%rbp)
incl %edi
movl %edi, 0x40(%rbp)
cmpl %r8d, %edi
jge 0x14ddf
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 0x14c62
movslq 0x40(%rbp), %r9
leal 0x1(%r9), %r10d
movq 0x8(%rbp), %r11
shrq $0x30, %r11
cmpl %r11d, %r10d
jge 0x14c62
movl 0x4(%rdx,%r9,4), %r10d
movl %r10d, %r13d
andl $0xf, %r13d
shrl $0x4, %r10d
cmpl $0x1, %r13d
je 0x14c5e
cmpl $0x6, %r13d
je 0x14c10
cmpl $0x2, %r13d
jne 0x14c62
negl %r10d
jmp 0x14c5e
addq $0x2, %r9
cmpl %r11d, %r9d
jge 0x14c62
xorl %r10d, %r10d
cmpq %r9, %r11
je 0x14c59
movl (%rdx,%r9,4), %r14d
movl %r14d, %r13d
andl $0xf, %r13d
cmpl $0x1, %r13d
jne 0x14c3b
shrl $0x4, %r14d
addl %r14d, %r10d
jmp 0x14c54
cmpl $0x8, %r13d
je 0x14c59
movl %r14d, %r13d
andl $0xd, %r13d
je 0x14c59
andl $0xb, %r14d
cmpl $0x3, %r14d
je 0x14c59
incq %r9
jmp 0x14c1c
testl %r10d, %r10d
jle 0x14c62
movl %r10d, 0xc(%rax)
movl %edi, %edx
andl $0xf, %edx
cmpl $0x7, %edx
setne %r9b
testb $0x7, %dil
setne %r10b
testb %r9b, %r10b
jne 0x14c88
movl %ecx, %edx
subl %r8d, %edx
addl 0x48(%rbp), %edx
movl %edx, 0x8(%rax)
jmp 0x14caf
andl $0xe, %edi
cmpl $0x2, %edi
jne 0x14caf
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 0x14955
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 0x14d6f
cmpl %r9d, %r10d
jge 0x14d32
movl %r9d, 0x18(%r15)
movl 0x38(%rax), %edi
jmp 0x14d40
movl 0x38(%rax), %r8d
leal 0x1(%rcx), %edi
cmpl %r8d, %ecx
cmovll %r8d, %edi
movl %edi, 0x1c(%r15)
testl %ebx, %ebx
jne 0x14d66
cmpq %rbp, %rax
setne %cl
movl 0x28(%r15), %eax
testl %eax, %eax
sete %dil
orb %cl, %dil
jne 0x14934
jmp 0x148f3
movq 0x40(%r15), %rax
jmp 0x148f5
movq 0x4225a(%rip), %rax     # 0x56fd0
movq (%rax), %rdi
leaq 0x2f9aa(%rip), %rsi     # 0x4472a
leaq 0x2f9c8(%rip), %rdx     # 0x4474f
xorl %eax, %eax
callq 0x4770
xorl %eax, %eax
movl $0x1, 0x30(%r15)
orl $-0x1, (%r14)
jmp 0x148f5
leaq 0x2fb00(%rip), %rdi     # 0x448a8
leaq 0x2fab7(%rip), %rsi     # 0x44866
leaq 0x2fab6(%rip), %rcx     # 0x4486c
movl $0x627, %edx            # imm = 0x627
callq 0x4360
leaq 0x2fade(%rip), %rdi     # 0x448a5
leaq 0x2fa98(%rip), %rsi     # 0x44866
leaq 0x2fa97(%rip), %rcx     # 0x4486c
movl $0x62d, %edx            # imm = 0x62D
callq 0x4360
leaq 0x2fabf(%rip), %rdi     # 0x448a5
leaq 0x2fa79(%rip), %rsi     # 0x44866
leaq 0x2fa78(%rip), %rcx     # 0x4486c
movl $0x63d, %edx            # imm = 0x63D
callq 0x4360