// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
movq %rcx, %r12
cmpl $0x0, 0x30(%rdi)
je 0x1ab37
movl $0xffffffff, (%r12)     # imm = 0xFFFFFFFF
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, %r15
movl $0x0, (%r12)
movl 0x28(%rdi), %eax
testl %eax, %eax
je 0x1ab53
movq 0x8(%r15), %rcx
cmpq 0x10(%r15), %rcx
je 0x1ab26
movq %rdx, 0x38(%rsp)
leaq 0x8(%r15), %rbx
movq %rsi, 0x30(%rsp)
movq %rbx, 0x28(%rsp)
testl %eax, %eax
jne 0x1ab80
movl 0x18(%r15), %eax
cmpl %eax, 0x20(%r15)
jg 0x1ab80
jne 0x1ab26
movl 0x24(%r15), %eax
cmpl 0x1c(%r15), %eax
jle 0x1ab26
movq 0x8(%r15), %rax
cmpq 0x10(%r15), %rax
je 0x1b092
xorl %r14d, %r14d
movq %rax, %rbp
movl 0x18(%r15), %eax
cmpl %eax, (%rbp)
jge 0x1abfd
movq %r14, %r13
movq 0x60(%r15), %rdi
movq %rbp, %rsi
callq 0x1b1a4
movq 0x50(%rbp), %rax
movq %rax, (%rbx)
movq (%r15), %r14
decl (%r14)
movq $0x0, 0x50(%rbp)
movl 0x4(%r14), %ecx
cmpl 0x8(%r14), %ecx
jne 0x1ad71
leal (%rcx,%rcx), %eax
testl %ecx, %ecx
movl $0x100, %ecx            # imm = 0x100
cmovel %ecx, %eax
movl %eax, 0x8(%r14)
movq 0x10(%r14), %rdi
movslq %eax, %rsi
shlq $0x3, %rsi
callq 0x48d0
movq %rax, 0x10(%r14)
movl 0x4(%r14), %ecx
jmp 0x1ad75
jne 0x1b05f
movl 0x1c(%r15), %ecx
cmpl %ecx, 0x3c(%rbp)
jle 0x1ab9d
cmpl %ecx, 0x38(%rbp)
jg 0x1b05f
movq 0x40(%r15), %rax
cmpl 0x2c(%r15), %r14d
jne 0x1ac4d
leal (%r14,%r14), %ecx
testl %r14d, %r14d
movl $0x100, %edx            # imm = 0x100
cmovel %edx, %ecx
movl %ecx, 0x2c(%r15)
movslq %ecx, %rcx
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
movq %rax, %rdi
callq 0x48d0
movq %rax, 0x40(%r15)
movl 0x1c(%r15), %ecx
movslq %r14d, %rdx
leaq (%rdx,%rdx,2), %rsi
movq %rbp, (%rax,%rsi,8)
movq 0x8(%rbp), %r10
movq 0x28(%rbp), %r13
movl %r10d, %edx
shrl $0x18, %edx
movq %rdx, 0x40(%rsp)
leaq (%rdx,%r13), %rdi
movslq 0x40(%rbp), %r9
cmpq $-0x1, %r9
movq %r14, 0x18(%rsp)
je 0x1ad8b
movl (%rdi,%r9,4), %r14d
movl %r14d, %edx
shrl $0x4, %edx
movl 0x44(%rbp), %r11d
movl %ecx, %r8d
subl %r11d, %r8d
cmpl %edx, %r8d
jl 0x1af08
movq %rsi, 0x10(%rsp)
shrq $0x30, %r10
cmpl %r10d, %r9d
jge 0x1b147
movq %r13, %rsi
movq %r12, %r13
movl 0x4(%rdi,%r9,4), %r8d
movl %r8d, %r12d
andl $0xf, %r12d
andl $0xf, %r14d
cmpl $0x8, %r12d
je 0x1ae17
movl %r8d, %r12d
andl $0xd, %r12d
je 0x1ae17
andl $0xb, %r8d
cmpl $0x3, %r8d
je 0x1ae17
cmpl $0x8, %r14d
ja 0x1ad01
movl $0x181, %r8d            # imm = 0x181
btl %r14d, %r8d
jae 0x1ad01
addl %edx, 0x48(%rbp)
addl %edx, %r11d
movl %r11d, 0x44(%rbp)
incq %r9
cmpl %r10d, %r9d
movq %r13, %r12
movq %rsi, %r13
movq 0x10(%rsp), %rsi
jge 0x1ae41
movl (%rdi,%r9,4), %edx
movl %edx, %r8d
andl $0xf, %r8d
cmpl $0x8, %r8d
je 0x1ae41
movl %edx, %r11d
andl $0xd, %r11d
je 0x1ae41
movl %edx, %r11d
andl $0xb, %r11d
cmpl $0x3, %r11d
je 0x1ae41
cmpl $0x4, %r8d
je 0x1ad5e
cmpl $0x1, %r8d
jne 0x1ad64
shrl $0x4, %edx
addl %edx, 0x48(%rbp)
incq %r9
cmpq %r10, %r9
jl 0x1ad1f
jmp 0x1ae41
movq 0x10(%r14), %rax
leal 0x1(%rcx), %edx
movl %edx, 0x4(%r14)
movslq %ecx, %rcx
movq %rbp, (%rax,%rcx,8)
movq %r13, %r14
jmp 0x1b066
movq %r12, %r8
movq %rax, %r12
movq %rsi, %rax
movq %r10, %rdx
movabsq $-0x1000000000000, %rsi # imm = 0xFFFF000000000000
andq %rsi, %rdx
movabsq $0x1000000000000, %rsi  # imm = 0x1000000000000
cmpq %rsi, %rdx
jne 0x1adf4
movl (%rdi), %edx
andl $0xf, %edx
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
cmpl $0x8, %edx
ja 0x1b075
movl $0x181, %esi            # imm = 0x181
btl %edx, %esi
movq %rax, %rsi
movq %r12, %rax
movq %r8, %r12
jae 0x1af08
xorl %r9d, %r9d
movl %r9d, 0x40(%rbp)
movl 0x4(%rbp), %edx
movl %edx, 0x44(%rbp)
movl %r9d, 0x48(%rbp)
jmp 0x1af08
movl 0x4(%rbp), %edx
movl %edx, 0x44(%rbp)
movl $0x0, 0x48(%rbp)
xorl %r9d, %r9d
cmpq %rsi, %r10
jae 0x1ae53
movq %rax, %rsi
movq %r12, %rax
movq %r8, %r12
jmp 0x1aef7
cmpl $0x8, %r14d
ja 0x1ae2c
movl $0x181, %r8d            # imm = 0x181
btl %r14d, %r8d
jae 0x1ae2c
addl %edx, 0x48(%rbp)
addl %edx, %r11d
movl %r11d, 0x44(%rbp)
incl %r9d
movq %r13, %r12
movq %rsi, %r13
movq 0x10(%rsp), %rsi
movl %r9d, 0x40(%rbp)
cmpl %r10d, %r9d
jl 0x1af08
jmp 0x1b166
movl %edx, 0xc(%rsp)
movl (%rdi), %edx
movl %edx, %r11d
andl $0xf, %r11d
testb $0xd, %dl
sete %sil
leal -0x7(%r11), %r14d
cmpl $0x2, %r14d
setb %r14b
orb %sil, %r14b
movq %rax, %rsi
movq %r12, %rax
movq %r8, %r12
jne 0x1aef7
movq %r12, 0x20(%rsp)
movq %r10, %r8
shrq $0x30, %r8
movq %r8, 0x10(%rsp)
xorl %r12d, %r12d
movl $0x1, %r8d
movq %r8, %r9
shrl $0x4, %edx
cmpl $0x1, %r11d
je 0x1aec6
cmpl $0x4, %r11d
je 0x1aec6
cmpl $0x3, %r11d
jne 0x1aecd
movl 0xc(%rsp), %r8d
addl %edx, %r8d
movl %r8d, 0xc(%rsp)
movl %r8d, 0x44(%rbp)
jmp 0x1aecd
addl %edx, %r12d
movl %r12d, 0x48(%rbp)
cmpq 0x10(%rsp), %r9
jae 0x1aef2
movl (%rdi,%r9,4), %edx
testb $0xd, %dl
je 0x1aef2
movl %edx, %r11d
andl $0xf, %r11d
leal -0x7(%r11), %r14d
leaq 0x1(%r9), %r8
cmpl $0x2, %r14d
jae 0x1ae9b
movq 0x20(%rsp), %r12
shrq $0x30, %r10
cmpl %r10d, %r9d
jae 0x1b185
movl %r9d, 0x40(%rbp)
leaq (%rax,%rsi,8), %rax
movslq %r9d, %rdx
movl (%rdi,%rdx,4), %r9d
movl %r9d, %edx
shrl $0x4, %edx
movl 0x14(%rax), %r8d
movl $0x0, 0xc(%rax)
andl $-0xa, %r8d
movl %r8d, 0x14(%rax)
movl 0x44(%rbp), %r10d
addl %r10d, %edx
decl %edx
cmpl %ecx, %edx
jne 0x1afd6
movslq 0x40(%rbp), %rdx
leal 0x1(%rdx), %r14d
movzwl 0xe(%rbp), %r11d
cmpl %r11d, %r14d
jge 0x1afd6
movl 0x4(%rdi,%rdx,4), %edi
movl %edi, %r14d
andl $0xf, %r14d
shrl $0x4, %edi
cmpl $0x1, %r14d
je 0x1afd3
cmpl $0x6, %r14d
je 0x1af77
cmpl $0x2, %r14d
jne 0x1afd6
negl %edi
jmp 0x1afd3
leaq 0x2(%rdx), %rdi
cmpl %r11d, %edi
jge 0x1afd6
subl %edx, %r11d
addl $-0x2, %r11d
movq 0x40(%rsp), %rdx
leaq (%rdx,%rdi,4), %rdx
addq %rdx, %r13
xorl %edx, %edx
xorl %edi, %edi
movl (%r13,%rdx,4), %esi
movl %esi, %r14d
andl $0xf, %r14d
cmpl $0x1, %r14d
jne 0x1afb0
shrl $0x4, %esi
addl %esi, %edi
jmp 0x1afc7
cmpl $0x8, %r14d
je 0x1afcf
movl %esi, %r14d
andl $0xd, %r14d
je 0x1afcf
andl $0xb, %esi
cmpl $0x3, %esi
je 0x1afcf
incq %rdx
cmpl %edx, %r11d
jne 0x1af97
testl %edi, %edi
jle 0x1afd6
movl %edi, 0xc(%rax)
movl %r9d, %edx
andl $0xf, %edx
cmpl $0x7, %edx
setne %sil
testb $0x7, %r9b
setne %dil
testb %sil, %dil
jne 0x1b002
movl %ecx, %edx
subl %r10d, %edx
addl 0x48(%rbp), %edx
movl %edx, 0x8(%rax)
movq 0x18(%rsp), %r14
jmp 0x1b034
andl $0xe, %r9d
cmpl $0x2, %r9d
movq 0x18(%rsp), %r14
jne 0x1b034
xorl %esi, %esi
cmpl $0x3, %edx
sete %sil
movl %r8d, %edx
orl $0x1, %edx
movl %edx, 0x14(%rax)
movl 0x48(%rbp), %edx
movl %edx, 0x8(%rax)
leal (%r8,%rsi,8), %r8d
incl %r8d
movl %r8d, 0x14(%rax)
xorl %edx, %edx
cmpl %ecx, 0x4(%rbp)
sete %dl
andl $-0x3, %r8d
leal (%r8,%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 %r14d
movq (%rbx), %rbp
addq $0x50, %rbp
movq %rbp, %rbx
movq (%rbx), %rbp
cmpq 0x10(%r15), %rbp
jne 0x1ab94
jmp 0x1b083
movq %rax, %rsi
movq %r12, %rax
movq %r8, %r12
jmp 0x1af08
movq 0x28(%rsp), %rbx
movq (%rbx), %rax
movq 0x30(%rsp), %rsi
jmp 0x1b098
xorl %r14d, %r14d
movq %rax, %rbp
movl %r14d, (%r12)
movl 0x18(%r15), %ecx
movl %ecx, (%rsi)
movl 0x1c(%r15), %ecx
movq 0x38(%rsp), %rdx
movl %ecx, (%rdx)
cmpq %rbp, %rax
setne %dil
movl 0x18(%r15), %r9d
movl (%rax), %edx
cmpl %edx, %r9d
setg %r8b
andb %dil, %r8b
cmpb $0x1, %r8b
je 0x1b111
cmpl %edx, %r9d
jge 0x1b0d8
movl %edx, 0x18(%r15)
movl 0x38(%rax), %edx
jmp 0x1b0e3
movl 0x38(%rax), %edi
leal 0x1(%rcx), %edx
cmpl %edi, %ecx
cmovll %edi, %edx
movl %edx, 0x1c(%r15)
testl %r14d, %r14d
jne 0x1b108
cmpq %rbp, %rax
setne %cl
movl 0x28(%r15), %eax
testl %eax, %eax
sete %dl
orb %cl, %dl
jne 0x1ab66
jmp 0x1ab26
movq 0x40(%r15), %rax
jmp 0x1ab28
movq 0x46eb0(%rip), %rax     # 0x61fc8
movq (%rax), %rdi
leaq 0x36694(%rip), %rsi     # 0x517b6
leaq 0x366b2(%rip), %rdx     # 0x517db
xorl %eax, %eax
callq 0x4770
xorl %eax, %eax
movl $0x1, 0x30(%r15)
movl $0xffffffff, (%r12)     # imm = 0xFFFFFFFF
jmp 0x1ab28
leaq 0x367e3(%rip), %rdi     # 0x51931
leaq 0x3679d(%rip), %rsi     # 0x518f2
leaq 0x3679c(%rip), %rcx     # 0x518f8
movl $0x62d, %edx            # imm = 0x62D
callq 0x4350
leaq 0x367c4(%rip), %rdi     # 0x51931
leaq 0x3677e(%rip), %rsi     # 0x518f2
leaq 0x3677d(%rip), %rcx     # 0x518f8
movl $0x63d, %edx            # imm = 0x63D
callq 0x4350
leaq 0x367a8(%rip), %rdi     # 0x51934
leaq 0x3675f(%rip), %rsi     # 0x518f2
leaq 0x3675e(%rip), %rcx     # 0x518f8
movl $0x627, %edx            # imm = 0x627
callq 0x4350