// File: /workspace/github_c_makefile_star2_O3/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 $0x38, %rsp
movq %rcx, %r14
cmpl $0x0, 0x3c(%rdi)
je 0x11b01
movl $0xffffffff, (%r14)     # imm = 0xFFFFFFFF
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, %r15
movl $0x0, (%r14)
movl 0x30(%rdi), %ecx
testl %ecx, %ecx
je 0x11b1d
movq 0x8(%r15), %rax
cmpq $0x0, 0x50(%rax)
je 0x11af0
movl $0x100, %ebp            # imm = 0x100
movq %r14, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
testl %ecx, %ecx
jne 0x11b4b
movl 0x20(%r15), %eax
cmpl %eax, 0x28(%r15)
jg 0x11b4b
jne 0x11af0
movl 0x2c(%r15), %eax
cmpl 0x24(%r15), %eax
jle 0x11af0
movq 0x8(%r15), %r13
movq 0x18(%r15), %r12
movq %r13, 0x50(%r12)
movq 0x50(%r13), %rax
testq %rax, %rax
je 0x1203b
leaq 0x50(%r13), %rdx
xorl %ebx, %ebx
movl 0x20(%r15), %ecx
cmpl %ecx, (%r13)
jge 0x11bbe
movq %rax, 0x50(%r12)
movq (%r15), %r14
decl (%r14)
movq $0x0, (%rdx)
movl 0x4(%r14), %ecx
cmpl 0x8(%r14), %ecx
jne 0x11d2f
leal (%rcx,%rcx), %eax
testl %ecx, %ecx
cmovel %ebp, %eax
movl %eax, 0x8(%r14)
movq 0x10(%r14), %rdi
movslq %eax, %rsi
shlq $0x3, %rsi
callq 0x3430
movq %rax, 0x10(%r14)
movl 0x4(%r14), %ecx
jmp 0x11d33
jne 0x11d44
movl 0x24(%r15), %ecx
cmpl %ecx, 0x3c(%r13)
jbe 0x11b75
cmpl %ecx, 0x38(%r13)
ja 0x11d44
movq 0x48(%r15), %rax
cmpl 0x38(%r15), %ebx
jne 0x11c09
leal (%rbx,%rbx), %ecx
testl %ebx, %ebx
cmovel %ebp, %ecx
movl %ecx, 0x38(%r15)
movslq %ecx, %rcx
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
movq %rax, %rdi
callq 0x3430
movq %rax, 0x48(%r15)
movl 0x24(%r15), %ecx
movslq %ebx, %rdx
leaq (%rdx,%rdx,2), %r14
movq %r13, (%rax,%r14,8)
movq 0x8(%r13), %r10
movq 0x30(%r13), %r12
movl %r10d, %esi
shrl $0x18, %esi
leaq (%r12,%rsi), %rdi
movslq 0x40(%r13), %r9
cmpq $-0x1, %r9
je 0x11d61
movl (%rdi,%r9,4), %edx
movl %edx, %r11d
shrl $0x4, %r11d
movl 0x44(%r13), %ebp
movl %ecx, %r8d
subl %ebp, %r8d
cmpl %r11d, %r8d
jb 0x11e88
movq %rsi, 0x8(%rsp)
shrq $0x30, %r10
cmpl %r10d, %r9d
jge 0x120f4
movq %rbx, %rsi
movq %r12, %rbx
movq %r14, %r12
movl 0x4(%rdi,%r9,4), %r14d
movl %r14d, %r8d
andl $0xf, %r8d
andl $0xf, %edx
cmpl $0x8, %r8d
je 0x11e8f
movl %r14d, %r8d
andl $0xd, %r8d
je 0x11e8f
andl $0xb, %r14d
cmpl $0x3, %r14d
je 0x11e8f
cmpl $0x8, %edx
movq %r12, %r14
ja 0x11cb9
movl $0x181, %r8d            # imm = 0x181
btl %edx, %r8d
jae 0x11cb9
addl %r11d, 0x48(%r13)
addl %r11d, %ebp
movl %ebp, 0x44(%r13)
incq %r9
cmpl %r10d, %r9d
movl $0x100, %ebp            # imm = 0x100
movq %rbx, %r12
movq %rsi, %rbx
movq 0x8(%rsp), %rsi
jge 0x11ec1
movl (%rdi,%r9,4), %edx
movl %edx, %r11d
andl $0xf, %r11d
cmpl $0x8, %r11d
je 0x11ec1
movl %edx, %r8d
andl $0xd, %r8d
je 0x11ec1
movl %edx, %r8d
andl $0xb, %r8d
cmpl $0x3, %r8d
je 0x11ec1
cmpl $0x4, %r11d
je 0x11d1b
cmpl $0x1, %r11d
jne 0x11d22
shrl $0x4, %edx
addl %edx, 0x48(%r13)
incq %r9
cmpq %r10, %r9
jl 0x11cdc
jmp 0x11ec1
movq 0x10(%r14), %rax
leal 0x1(%rcx), %edx
movl %edx, 0x4(%r14)
movslq %ecx, %rcx
movq %r13, (%rax,%rcx,8)
movq %r12, %r13
movq %r13, %r12
movq 0x50(%r13), %r13
leaq 0x50(%r13), %rdx
movq 0x50(%r13), %rax
testq %rax, %rax
jne 0x11b6b
jmp 0x12029
movq %r10, %rdx
movabsq $-0x1000000000000, %r8  # imm = 0xFFFF000000000000
andq %r8, %rdx
movabsq $0x1000000000000, %r8   # imm = 0x1000000000000
cmpq %r8, %rdx
jne 0x11dbc
movl (%rdi), %edx
andl $0xf, %edx
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
cmpl $0x8, %edx
ja 0x11ece
movl $0x181, %r8d            # imm = 0x181
btl %edx, %r8d
jae 0x11ece
xorl %r9d, %r9d
movl %r9d, 0x40(%r13)
movl 0x4(%r13), %edx
movl %edx, 0x44(%r13)
movl %r9d, 0x48(%r13)
jmp 0x11ece
movq %r8, %rdx
movl 0x4(%r13), %r8d
movl %r8d, 0x44(%r13)
movl $0x0, 0x48(%r13)
xorl %r9d, %r9d
cmpq %rdx, %r10
jb 0x11e77
movl %r8d, 0x8(%rsp)
movl (%rdi), %ebp
movl %ebp, %edx
andl $0xf, %edx
testb $0xd, %bpl
sete %r11b
movq %r14, 0x10(%rsp)
leal -0x7(%rdx), %r14d
cmpl $0x2, %r14d
setb %r14b
orb %r11b, %r14b
movq 0x10(%rsp), %r14
jne 0x11e77
movq %r12, 0x18(%rsp)
movq %r10, %r12
shrq $0x30, %r12
xorl %r14d, %r14d
movl $0x1, %r11d
movq %r11, %r9
shrl $0x4, %ebp
cmpl $0x1, %edx
je 0x11e44
cmpl $0x4, %edx
je 0x11e44
cmpl $0x3, %edx
jne 0x11e4b
movl 0x8(%rsp), %edx
addl %ebp, %edx
movl %edx, 0x8(%rsp)
movl %edx, 0x44(%r13)
jmp 0x11e4b
addl %ebp, %r14d
movl %r14d, 0x48(%r13)
cmpq %r12, %r9
jae 0x11e6d
movl (%rdi,%r9,4), %ebp
testb $0xd, %bpl
je 0x11e6d
movl %ebp, %edx
andl $0xf, %edx
leal -0x7(%rdx), %r8d
leaq 0x1(%r9), %r11
cmpl $0x2, %r8d
jae 0x11e1f
movq 0x18(%rsp), %r12
movq 0x10(%rsp), %r14
shrq $0x30, %r10
cmpl %r10d, %r9d
jae 0x12132
movl %r9d, 0x40(%r13)
movl $0x100, %ebp            # imm = 0x100
jmp 0x11ece
cmpl $0x8, %edx
movq %r12, %r14
ja 0x11ea7
movl $0x181, %r8d            # imm = 0x181
btl %edx, %r8d
jae 0x11ea7
addl %r11d, 0x48(%r13)
addl %r11d, %ebp
movl %ebp, 0x44(%r13)
incl %r9d
movl $0x100, %ebp            # imm = 0x100
movq %rbx, %r12
movq %rsi, %rbx
movq 0x8(%rsp), %rsi
movl %r9d, 0x40(%r13)
cmpl %r10d, %r9d
jge 0x12113
leaq (%rax,%r14,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(%r13), %r10d
addl %r10d, %edx
decl %edx
cmpl %ecx, %edx
jne 0x11fa5
movslq 0x40(%r13), %rdx
leal 0x1(%rdx), %ebp
movzwl 0xe(%r13), %r11d
cmpl %r11d, %ebp
movl $0x100, %ebp            # imm = 0x100
jge 0x11fa5
movl 0x4(%rdi,%rdx,4), %edi
movl %edi, %ebp
andl $0xf, %ebp
shrl $0x4, %edi
cmpl $0x1, %ebp
je 0x11f9d
cmpl $0x6, %ebp
je 0x11f41
cmpl $0x2, %ebp
movl $0x100, %ebp            # imm = 0x100
jne 0x11fa5
negl %edi
jmp 0x11fa2
leaq 0x2(%rdx), %rdi
cmpl %r11d, %edi
movl $0x100, %ebp            # imm = 0x100
jge 0x11fa5
subl %edx, %r11d
addl $-0x2, %r11d
leaq (%rsi,%rdi,4), %rdx
addq %rdx, %r12
xorl %edx, %edx
xorl %edi, %edi
movl (%r12,%rdx,4), %esi
movl %esi, %ebp
andl $0xf, %ebp
cmpl $0x1, %ebp
jne 0x11f76
shrl $0x4, %esi
addl %esi, %edi
jmp 0x11f8a
cmpl $0x8, %ebp
je 0x11f92
movl %esi, %ebp
andl $0xd, %ebp
je 0x11f92
andl $0xb, %esi
cmpl $0x3, %esi
je 0x11f92
incq %rdx
cmpl %edx, %r11d
jne 0x11f61
testl %edi, %edi
movl $0x100, %ebp            # imm = 0x100
jg 0x11fa2
jmp 0x11fa5
movl $0x100, %ebp            # imm = 0x100
movl %edi, 0xc(%rax)
movl %r9d, %edx
andl $0xf, %edx
cmpl $0x7, %edx
setne %sil
testb $0x7, %r9b
setne %dil
testb %sil, %dil
jne 0x11fcd
movl %ecx, %edx
subl %r10d, %edx
addl 0x48(%r13), %edx
movl %edx, 0x8(%rax)
jmp 0x11ffb
andl $0xe, %r9d
cmpl $0x2, %r9d
jne 0x11ffb
xorl %esi, %esi
cmpl $0x3, %edx
sete %sil
movl %r8d, %edx
orl $0x1, %edx
movl %edx, 0x14(%rax)
movl 0x48(%r13), %edx
movl %edx, 0x8(%rax)
leal (%r8,%rsi,8), %r8d
incl %r8d
movl %r8d, 0x14(%rax)
xorl %edx, %edx
cmpl %ecx, 0x4(%r13)
sete %dl
andl $-0x3, %r8d
leal (%r8,%rdx,2), %edx
movl %edx, 0x14(%rax)
xorl %esi, %esi
cmpl %ecx, 0x4c(%r13)
sete %sil
andl $-0x5, %edx
leal (%rdx,%rsi,4), %ecx
movl %ecx, 0x14(%rax)
incl %ebx
jmp 0x11d44
movq 0x18(%r15), %rax
movq 0x50(%rax), %r13
cmpq $0x0, 0x50(%r13)
setne %al
jmp 0x1203f
xorl %eax, %eax
xorl %ebx, %ebx
movq %r13, 0x8(%r15)
movq 0x30(%rsp), %r14
movl %ebx, (%r14)
movl 0x20(%r15), %ecx
movq 0x20(%rsp), %rsi
movl %ecx, (%rsi)
movl 0x24(%r15), %ecx
movq 0x28(%rsp), %rdx
movl %ecx, (%rdx)
movl 0x20(%r15), %r9d
movl (%r13), %r8d
cmpl %r8d, %r9d
setg %dil
andb %al, %dil
cmpb $0x1, %dil
je 0x120bf
cmpl %r8d, %r9d
jge 0x12088
movl %r8d, 0x20(%r15)
movl 0x38(%r13), %edi
jmp 0x12096
movl 0x38(%r13), %r8d
leal 0x1(%rcx), %edi
cmpl %r8d, %ecx
cmovbl %r8d, %edi
movl %edi, 0x24(%r15)
testl %ebx, %ebx
jne 0x120b6
movl 0x30(%r15), %ecx
testl %ecx, %ecx
sete %dil
orb %dil, %al
jne 0x11b31
jmp 0x11af0
movq 0x48(%r15), %rax
jmp 0x11af2
movq 0x10f32(%rip), %rax     # 0x22ff8
movq (%rax), %rdi
leaq 0xa675(%rip), %rsi      # 0x1c745
leaq 0xa693(%rip), %rdx      # 0x1c76a
xorl %eax, %eax
callq 0x3320
xorl %eax, %eax
movl $0x1, 0x3c(%r15)
movl $0xffffffff, (%r14)     # imm = 0xFFFFFFFF
jmp 0x11af2
leaq 0xa749(%rip), %rdi      # 0x1c844
leaq 0xa6fb(%rip), %rsi      # 0x1c7fd
leaq 0xa701(%rip), %rcx      # 0x1c80a
movl $0x60, %edx
callq 0x3230
leaq 0xa72a(%rip), %rdi      # 0x1c844
leaq 0xa6dc(%rip), %rsi      # 0x1c7fd
leaq 0xa6e2(%rip), %rcx      # 0x1c80a
movl $0x70, %edx
callq 0x3230
leaq 0xa70e(%rip), %rdi      # 0x1c847
leaq 0xa6bd(%rip), %rsi      # 0x1c7fd
leaq 0xa6c3(%rip), %rcx      # 0x1c80a
movl $0x5a, %edx
callq 0x3230