// File: /workspace/github_c_makefile_star2_O2/DReichLab[P]adna/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->next == 0) 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;
		lbnode_t *p, *q;
		// write iter->plp at iter->pos
		iter->dummy->next = iter->head;
		for (p = iter->head, q = iter->dummy; p->next; q = p, p = p->next) {
			if (p->b.core.tid < iter->tid || (p->b.core.tid == iter->tid && p->end <= iter->pos)) { // then remove
				q->next = p->next; mp_free(iter->mp, p); p = q;
			} 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...
			}
		}
		iter->head = iter->dummy->next; // dummy->next may be changed
		*_n_plp = n_plp; *_tid = iter->tid; *_pos = iter->pos;
		// update iter->tid and iter->pos
		if (iter->head->next) {
			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->next == 0) break;
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r14
cmpl $0x0, 0x3c(%rdi)
je 0xa77f
orl $-0x1, (%r14)
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, %r15
andl $0x0, (%r14)
movl 0x30(%rdi), %eax
testl %eax, %eax
je 0xa798
movq 0x8(%r15), %rcx
cmpq $0x0, 0x48(%rcx)
je 0xa76e
movq %rdx, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
testl %eax, %eax
jne 0xa7bc
movl 0x20(%r15), %eax
cmpl %eax, 0x28(%r15)
jg 0xa7bc
jne 0xa76e
movl 0x2c(%r15), %eax
cmpl 0x24(%r15), %eax
jle 0xa76e
movq 0x8(%r15), %r12
movq 0x18(%r15), %rbp
movq %r12, 0x48(%rbp)
xorl %ebx, %ebx
movq 0x48(%r12), %rax
testq %rax, %rax
je 0xab66
movl 0x20(%r15), %ecx
cmpl %ecx, (%r12)
jge 0xa7f9
movq %rax, 0x48(%rbp)
movq (%r15), %rdi
movq %r12, %rsi
callq 0xa6f8
movq %rbp, %r12
jmp 0xab59
jne 0xab59
movl 0x24(%r15), %ecx
cmpl %ecx, 0x34(%r12)
jle 0xa7e2
cmpl %ecx, 0x30(%r12)
jg 0xab59
movq 0x48(%r15), %rax
cmpl 0x38(%r15), %ebx
jne 0xa847
leal (%rbx,%rbx), %ecx
testl %ebx, %ebx
movl $0x100, %edx            # imm = 0x100
cmovel %edx, %ecx
movl %ecx, 0x38(%r15)
movslq %ecx, %rcx
imulq $0x18, %rcx, %rsi
movq %rax, %rdi
callq 0x22f0
movq %rax, 0x48(%r15)
movl 0x24(%r15), %ecx
movslq %ebx, %rdx
imulq $0x18, %rdx, %rsi
movq %r12, (%rax,%rsi)
movq 0x8(%r12), %r8
movl %r8d, %edx
shrl $0x18, %edx
addq 0x28(%r12), %rdx
movslq 0x38(%r12), %rdi
cmpq $-0x1, %rdi
je 0xa942
movl (%rdx,%rdi,4), %r11d
movl %r11d, %r9d
shrl $0x4, %r9d
movl 0x3c(%r12), %r10d
movl %ecx, %ebp
subl %r10d, %ebp
cmpl %r9d, %ebp
jl 0xaa26
shrq $0x30, %r8
cmpl %r8d, %edi
jge 0xac68
movl 0x4(%rdx,%rdi,4), %ebp
movl %ebp, %r13d
andl $0xf, %r13d
andl $0xf, %r11d
cmpl $0x8, %r13d
je 0xa9f8
movl %ebp, %r13d
andl $0xd, %r13d
je 0xa9f8
andl $0xb, %ebp
cmpl $0x3, %ebp
je 0xa9f8
cmpl $0x8, %r11d
ja 0xa8e4
movl $0x181, %ebp            # imm = 0x181
btl %r11d, %ebp
jae 0xa8e4
addl %r9d, 0x40(%r12)
addl %r9d, %r10d
movl %r10d, 0x3c(%r12)
incq %rdi
cmpq %r8, %rdi
jge 0xaa18
movl (%rdx,%rdi,4), %r9d
movl %r9d, %r10d
andl $0xf, %r10d
cmpl $0x8, %r10d
je 0xaa18
movl %r9d, %r11d
andl $0xd, %r11d
je 0xaa18
movl %r9d, %r11d
andl $0xb, %r11d
cmpl $0x3, %r11d
je 0xaa18
cmpl $0x4, %r10d
je 0xa937
cmpl $0x1, %r10d
jne 0xa8ec
shrl $0x4, %r9d
addl %r9d, 0x40(%r12)
jmp 0xa8ec
shrq $0x30, %r8
cmpl $0x1, %r8d
jne 0xa98f
movl (%rdx), %r8d
andl $0xf, %r8d
pushq $-0x1
popq %rdi
cmpl $0x8, %r8d
ja 0xaa26
movl $0x181, %edi            # imm = 0x181
btl %r8d, %edi
pushq $-0x1
popq %rdi
jae 0xaa26
andl $0x0, 0x38(%r12)
movl 0x4(%r12), %edi
movl %edi, 0x3c(%r12)
andl $0x0, 0x40(%r12)
xorl %edi, %edi
jmp 0xaa26
movl 0x4(%r12), %r9d
movl %r9d, 0x3c(%r12)
andl $0x0, 0x40(%r12)
xorl %r10d, %r10d
xorl %edi, %edi
cmpq %r8, %rdi
jae 0xac2a
movl (%rdx,%rdi,4), %r11d
testb $0xd, %r11b
je 0xa9f1
movl %r11d, %ebp
andl $0xf, %ebp
leal -0x7(%rbp), %r13d
cmpl $0x2, %r13d
jb 0xa9f1
shrl $0x4, %r11d
cmpl $0x1, %ebp
je 0xa9e4
cmpl $0x4, %ebp
je 0xa9e4
cmpl $0x3, %ebp
jne 0xa9ec
addl %r11d, %r9d
movl %r9d, 0x3c(%r12)
jmp 0xa9ec
addl %r11d, %r10d
movl %r10d, 0x40(%r12)
incq %rdi
jmp 0xa9a4
movl %edi, 0x38(%r12)
jmp 0xaa26
cmpl $0x8, %r11d
ja 0xaa0e
movl $0x181, %ebp            # imm = 0x181
btl %r11d, %ebp
jae 0xaa0e
addl %r9d, 0x40(%r12)
addl %r9d, %r10d
movl %r10d, 0x3c(%r12)
incl %edi
movl %edi, 0x38(%r12)
cmpl %r8d, %edi
jge 0xac49
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 0x3c(%r12), %r8d
addl %r8d, %r9d
decl %r9d
cmpl %ecx, %r9d
jne 0xaadf
movslq 0x38(%r12), %r9
leal 0x1(%r9), %r10d
movq 0x8(%r12), %r11
shrq $0x30, %r11
cmpl %r11d, %r10d
jge 0xaadf
movl 0x4(%rdx,%r9,4), %r10d
movl %r10d, %ebp
andl $0xf, %ebp
shrl $0x4, %r10d
cmpl $0x1, %ebp
je 0xaadb
cmpl $0x6, %ebp
je 0xaa91
cmpl $0x2, %ebp
jne 0xaadf
negl %r10d
jmp 0xaadb
addq $0x2, %r9
cmpl %r11d, %r9d
jge 0xaadf
xorl %r10d, %r10d
cmpq %r9, %r11
je 0xaad6
movl (%rdx,%r9,4), %r13d
movl %r13d, %ebp
andl $0xf, %ebp
cmpl $0x1, %ebp
jne 0xaaba
shrl $0x4, %r13d
addl %r13d, %r10d
jmp 0xaad1
cmpl $0x8, %ebp
je 0xaad6
movl %r13d, %ebp
andl $0xd, %ebp
je 0xaad6
andl $0xb, %r13d
cmpl $0x3, %r13d
je 0xaad6
incq %r9
jmp 0xaa9d
testl %r10d, %r10d
jle 0xaadf
movl %r10d, 0xc(%rax)
movl %edi, %edx
andl $0xf, %edx
cmpl $0x7, %edx
setne %r9b
testb $0x7, %dil
setne %r10b
testb %r9b, %r10b
jne 0xab07
movl %ecx, %edx
subl %r8d, %edx
addl 0x40(%r12), %edx
movl %edx, 0x8(%rax)
jmp 0xab30
andl $0xe, %edi
cmpl $0x2, %edi
jne 0xab30
xorl %edi, %edi
cmpl $0x3, %edx
sete %dil
movl %esi, %edx
orl $0x1, %edx
movl %edx, 0x14(%rax)
movl 0x40(%r12), %edx
movl %edx, 0x8(%rax)
leal (%rsi,%rdi,8), %esi
incl %esi
movl %esi, 0x14(%rax)
xorl %edx, %edx
cmpl %ecx, 0x4(%r12)
sete %dl
andl $-0x3, %esi
leal (%rsi,%rdx,2), %edx
movl %edx, 0x14(%rax)
xorl %esi, %esi
cmpl %ecx, 0x44(%r12)
sete %sil
andl $-0x5, %edx
leal (%rdx,%rsi,4), %ecx
movl %ecx, 0x14(%rax)
incl %ebx
movq %r12, %rbp
movq 0x48(%r12), %r12
jmp 0xa7ca
movq 0x18(%r15), %rax
movq 0x48(%rax), %rcx
movq %rcx, 0x8(%r15)
movl %ebx, (%r14)
movl 0x20(%r15), %eax
movq 0x8(%rsp), %rsi
movl %eax, (%rsi)
movl 0x24(%r15), %r10d
movq 0x10(%rsp), %rdx
movl %r10d, (%rdx)
movq 0x48(%rcx), %rax
testq %rax, %rax
setne %r8b
movl 0x20(%r15), %edi
movl (%rcx), %r11d
cmpl %r11d, %edi
setg %r9b
andb %r8b, %r9b
cmpb $0x1, %r9b
je 0xabf8
cmpl %r11d, %edi
jge 0xabbc
movl %r11d, 0x20(%r15)
movl 0x30(%rcx), %ecx
jmp 0xabc9
movl 0x30(%rcx), %edi
leal 0x1(%r10), %ecx
cmpl %edi, %r10d
cmovll %edi, %ecx
movl %ecx, 0x24(%r15)
testl %ebx, %ebx
jne 0xabef
testq %rax, %rax
setne %cl
movl 0x30(%r15), %eax
testl %eax, %eax
sete %dil
orb %cl, %dil
jne 0xa7a2
jmp 0xa76e
movq 0x48(%r15), %rax
jmp 0xa770
movq 0x63f9(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x1bfe(%rip), %rsi      # 0xc807
leaq 0x1c1c(%rip), %rdx      # 0xc82c
xorl %eax, %eax
callq 0x2220
xorl %eax, %eax
movl $0x1, 0x3c(%r15)
orl $-0x1, (%r14)
jmp 0xa770
leaq 0x1cd0(%rip), %rdi      # 0xc901
leaq 0x1c87(%rip), %rsi      # 0xc8bf
leaq 0x1c86(%rip), %rcx      # 0xc8c5
movl $0x38c, %edx            # imm = 0x38C
callq 0x2180
leaq 0x1cae(%rip), %rdi      # 0xc8fe
leaq 0x1c68(%rip), %rsi      # 0xc8bf
leaq 0x1c67(%rip), %rcx      # 0xc8c5
movl $0x3a2, %edx            # imm = 0x3A2
callq 0x2180
leaq 0x1c8f(%rip), %rdi      # 0xc8fe
leaq 0x1c49(%rip), %rsi      # 0xc8bf
leaq 0x1c48(%rip), %rcx      # 0xc8c5
movl $0x392, %edx            # imm = 0x392
callq 0x2180