// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/bam_pileup.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 $0x28, %rsp
movq %rcx, %rbx
cmpl $0x0, 0x3c(%rdi)
je 0x114bd
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
movl $0x0, (%rbx)
cmpl $0x0, 0x30(%rdi)
je 0x114de
movq 0x8(%r12), %rax
cmpq $0x0, 0x50(%rax)
je 0x114ac
movl $0x100, %ebp            # imm = 0x100
movq %rbx, 0x20(%rsp)
movq %r14, 0x18(%rsp)
movq %r15, 0x10(%rsp)
cmpl $0x0, 0x30(%r12)
jne 0x11514
movl 0x20(%r12), %eax
cmpl %eax, 0x28(%r12)
jg 0x11514
jne 0x114ac
movl 0x2c(%r12), %eax
cmpl 0x24(%r12), %eax
jle 0x114ac
movq 0x8(%r12), %r15
movq 0x18(%r12), %r14
movq %r15, 0x50(%r14)
movq 0x50(%r15), %rax
testq %rax, %rax
je 0x11957
leaq 0x50(%r15), %rcx
xorl %r13d, %r13d
movl (%r15), %edx
movl 0x20(%r12), %esi
cmpl %esi, %edx
jge 0x11594
movq %rax, 0x50(%r14)
movq (%r12), %rbx
decl (%rbx)
movq $0x0, (%rcx)
movl 0x8(%rbx), %eax
cmpl %eax, 0x4(%rbx)
jne 0x1157a
leal (%rax,%rax), %ecx
testl %eax, %eax
cmovel %ebp, %ecx
movl %ecx, 0x8(%rbx)
movq 0x10(%rbx), %rdi
movslq %ecx, %rsi
shlq $0x3, %rsi
callq 0x3430
movq %rax, 0x10(%rbx)
movq 0x10(%rbx), %rax
movslq 0x4(%rbx), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x4(%rbx)
movq %r15, (%rax,%rcx,8)
movq %r14, %r15
jmp 0x1193d
jne 0x1193d
movl 0x3c(%r15), %edi
cmpl 0x24(%r12), %edi
jbe 0x11542
cmpl %esi, %edx
jne 0x1193d
movl 0x38(%r15), %eax
cmpl 0x24(%r12), %eax
ja 0x1193d
movl 0x38(%r12), %eax
cmpl %eax, %r13d
jne 0x115ed
leal (%rax,%rax), %ecx
testl %eax, %eax
cmovel %ebp, %ecx
movl %ecx, 0x38(%r12)
movq 0x48(%r12), %rdi
movslq %ecx, %rax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
callq 0x3430
movq %rax, 0x48(%r12)
movq 0x48(%r12), %rdi
movslq %r13d, %rax
leaq (%rax,%rax,2), %r8
movq %r15, (%rdi,%r8,8)
movl 0x24(%r12), %eax
movq 0x8(%r15), %rdx
movq 0x30(%r15), %rcx
movl %edx, %ebx
shrl $0x18, %ebx
movq %rcx, 0x8(%rsp)
leaq (%rcx,%rbx), %rsi
movslq 0x40(%r15), %r9
cmpq $-0x1, %r9
je 0x116fe
movl (%rsi,%r9,4), %r14d
movl %r14d, %r10d
shrl $0x4, %r10d
movl 0x44(%r15), %r11d
movl %eax, %ecx
subl %r11d, %ecx
cmpl %r10d, %ecx
jb 0x117fd
shrq $0x30, %rdx
cmpl %edx, %r9d
jge 0x11a4b
movl 0x4(%rsi,%r9,4), %edx
movl %edx, %ecx
andl $0xf, %ecx
andl $0xf, %r14d
cmpl $0x8, %ecx
je 0x117cc
movl %edx, %ecx
andl $0xd, %ecx
je 0x117cc
andl $0xb, %edx
cmpl $0x3, %edx
je 0x117cc
cmpl $0x8, %r14d
ja 0x11693
movl $0x181, %ecx            # imm = 0x181
btl %r14d, %ecx
jae 0x11693
addl %r10d, 0x48(%r15)
addl %r10d, %r11d
movl %r11d, 0x44(%r15)
incq %r9
movzwl 0xe(%r15), %ecx
cmpl %ecx, %r9d
jge 0x117eb
movl (%rsi,%r9,4), %edx
movl %edx, %r10d
andl $0xf, %r10d
cmpl $0x8, %r10d
je 0x117eb
movl %edx, %ecx
andl $0xd, %ecx
je 0x117eb
movl %edx, %ecx
andl $0xb, %ecx
cmpl $0x3, %ecx
je 0x117eb
cmpl $0x4, %r10d
je 0x116e5
cmpl $0x1, %r10d
jne 0x116ec
shrl $0x4, %edx
addl %edx, 0x48(%r15)
incq %r9
movzwl 0xe(%r15), %ecx
cmpq %rcx, %r9
jl 0x116ab
jmp 0x117eb
movq %rdx, %rcx
movabsq $-0x1000000000000, %r9  # imm = 0xFFFF000000000000
andq %r9, %rcx
movabsq $0x1000000000000, %r10  # imm = 0x1000000000000
cmpq %r10, %rcx
jne 0x11750
movl (%rsi), %ecx
andl $0xf, %ecx
cmpl $0x8, %ecx
ja 0x117fd
movl $0x181, %edx            # imm = 0x181
btl %ecx, %edx
jae 0x117fd
xorl %edx, %edx
movl %edx, 0x40(%r15)
movl 0x4(%r15), %ecx
movl %ecx, 0x44(%r15)
movl %edx, 0x48(%r15)
jmp 0x117fd
movl 0x4(%r15), %ecx
movl %ecx, 0x44(%r15)
movl $0x0, 0x48(%r15)
xorl %r9d, %r9d
cmpq %r10, %rdx
jb 0x117b8
leaq 0x44(%r15), %rcx
leaq 0x48(%r15), %r11
xorl %r9d, %r9d
movl (%rsi,%r9,4), %edx
testb $0xd, %dl
je 0x117b8
movl %edx, %r14d
andl $0xf, %r14d
leal -0x9(%r14), %r10d
cmpl $-0x3, %r10d
ja 0x117b8
cmpl $0x4, %r14d
je 0x117a2
movq %rcx, %r10
cmpl $0x3, %r14d
je 0x117a5
cmpl $0x1, %r14d
jne 0x117ab
movq %r11, %r10
shrl $0x4, %edx
addl %edx, (%r10)
incq %r9
movzwl 0xe(%r15), %edx
cmpq %rdx, %r9
jb 0x11773
movzwl 0xe(%r15), %ecx
cmpl %ecx, %r9d
jae 0x11a89
movl %r9d, 0x40(%r15)
jmp 0x117fd
cmpl $0x8, %r14d
ja 0x117e1
movl $0x181, %ecx            # imm = 0x181
btl %r14d, %ecx
jae 0x117e1
addl %r10d, 0x48(%r15)
addl %r10d, %r11d
movl %r11d, 0x44(%r15)
incl %r9d
movl %r9d, 0x40(%r15)
movzwl 0xe(%r15), %ecx
cmpl %ecx, %r9d
jge 0x11a6a
leaq (%rdi,%r8,8), %rdi
movslq 0x40(%r15), %rcx
movl (%rsi,%rcx,4), %r9d
movl %r9d, %ecx
shrl $0x4, %ecx
movl 0x14(%rdi), %r8d
movl $0x0, 0xc(%rdi)
andl $-0xa, %r8d
movl %r8d, 0x14(%rdi)
movl 0x44(%r15), %r10d
addl %r10d, %ecx
decl %ecx
cmpl %eax, %ecx
jne 0x118c1
movslq 0x40(%r15), %rdx
leal 0x1(%rdx), %ecx
movzwl 0xe(%r15), %r11d
cmpl %r11d, %ecx
jge 0x118c1
movl 0x4(%rsi,%rdx,4), %esi
movl %esi, %r14d
andl $0xf, %r14d
shrl $0x4, %esi
cmpl $0x1, %r14d
je 0x118be
cmpl $0x6, %r14d
je 0x11868
cmpl $0x2, %r14d
jne 0x118c1
negl %esi
jmp 0x118be
leaq 0x2(%rdx), %rsi
cmpl %r11d, %esi
jge 0x118c1
subl %edx, %r11d
addl $-0x2, %r11d
leaq (%rbx,%rsi,4), %rcx
addq %rcx, 0x8(%rsp)
xorl %edx, %edx
xorl %esi, %esi
movq 0x8(%rsp), %rcx
movl (%rcx,%rdx,4), %ebx
movl %ebx, %ecx
andl $0xf, %ecx
cmpl $0x1, %ecx
jne 0x1189e
shrl $0x4, %ebx
addl %ebx, %esi
jmp 0x118b2
cmpl $0x8, %ecx
je 0x118ba
movl %ebx, %ecx
andl $0xd, %ecx
je 0x118ba
andl $0xb, %ebx
cmpl $0x3, %ebx
je 0x118ba
incq %rdx
cmpl %edx, %r11d
jne 0x11885
testl %esi, %esi
jle 0x118c1
movl %esi, 0xc(%rdi)
movl %r9d, %ecx
andl $0xf, %ecx
cmpl $0x7, %ecx
setne %dl
testb $0x7, %r9b
setne %sil
testb %dl, %sil
jne 0x118e8
movl %eax, %ecx
subl %r10d, %ecx
addl 0x48(%r15), %ecx
movl %ecx, 0x8(%rdi)
jmp 0x11913
andl $0xe, %r9d
cmpl $0x2, %r9d
jne 0x11913
xorl %edx, %edx
cmpl $0x3, %ecx
sete %dl
movl %r8d, %ecx
orl $0x1, %ecx
movl %ecx, 0x14(%rdi)
movl 0x48(%r15), %ecx
movl %ecx, 0x8(%rdi)
leal (%r8,%rdx,8), %ecx
incl %ecx
movl %ecx, 0x14(%rdi)
xorl %ecx, %ecx
cmpl %eax, 0x4(%r15)
sete %cl
movl 0x14(%rdi), %edx
andl $-0x3, %edx
leal (%rdx,%rcx,2), %ecx
movl %ecx, 0x14(%rdi)
xorl %edx, %edx
cmpl %eax, 0x4c(%r15)
sete %dl
andl $-0x5, %ecx
leal (%rcx,%rdx,4), %eax
movl %eax, 0x14(%rdi)
incl %r13d
movq %r15, %r14
movq 0x50(%r15), %r15
leaq 0x50(%r15), %rcx
movq 0x50(%r15), %rax
testq %rax, %rax
jne 0x11536
jmp 0x1195a
xorl %r13d, %r13d
movq 0x18(%r12), %rax
movq 0x50(%rax), %rcx
movq %rcx, 0x8(%r12)
movq 0x20(%rsp), %rbx
movl %r13d, (%rbx)
movl 0x20(%r12), %eax
movq 0x10(%rsp), %r15
movl %eax, (%r15)
movl 0x24(%r12), %eax
movq 0x18(%rsp), %r14
movl %eax, (%r14)
movq 0x50(%rcx), %rax
testq %rax, %rax
je 0x1199c
movl 0x20(%r12), %edx
cmpl (%rcx), %edx
jg 0x119fc
movl (%rcx), %edx
cmpl %edx, 0x20(%r12)
jge 0x119af
movl %edx, 0x20(%r12)
movl 0x38(%rcx), %ecx
jmp 0x119bf
movl 0x24(%r12), %edx
movl 0x38(%rcx), %esi
leal 0x1(%rdx), %ecx
cmpl %esi, %edx
cmovbl %esi, %ecx
movl %ecx, 0x24(%r12)
testl %r13d, %r13d
je 0x119d9
movq 0x48(%r12), %rax
movq %rax, (%rsp)
movl $0x1, %eax
jmp 0x119f2
xorl %ecx, %ecx
cmpl $0x0, 0x30(%r12)
setne %cl
testq %rax, %rax
leal (%rcx,%rcx,2), %eax
movl $0x0, %ecx
cmovnel %ecx, %eax
testl %eax, %eax
je 0x114f2
jmp 0x11a39
movq 0x105f5(%rip), %rax     # 0x21ff8
movq (%rax), %rdi
leaq 0x9c08(%rip), %rsi      # 0x1b615
leaq 0x9c26(%rip), %rdx      # 0x1b63a
xorl %eax, %eax
callq 0x3320
movl $0x1, 0x3c(%r12)
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
movl $0x1, %eax
movq $0x0, (%rsp)
jmp 0x119f2
cmpl $0x3, %eax
je 0x114ac
movq (%rsp), %rax
jmp 0x114ae
leaq 0x9cc2(%rip), %rdi      # 0x1b714
leaq 0x9c74(%rip), %rsi      # 0x1b6cd
leaq 0x9c7a(%rip), %rcx      # 0x1b6da
movl $0x60, %edx
callq 0x3230
leaq 0x9ca3(%rip), %rdi      # 0x1b714
leaq 0x9c55(%rip), %rsi      # 0x1b6cd
leaq 0x9c5b(%rip), %rcx      # 0x1b6da
movl $0x70, %edx
callq 0x3230
leaq 0x9c87(%rip), %rdi      # 0x1b717
leaq 0x9c36(%rip), %rsi      # 0x1b6cd
leaq 0x9c3c(%rip), %rcx      # 0x1b6da
movl $0x5a, %edx
callq 0x3230