// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x3c(%rax)
je 0x11659
movq -0x28(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq $0x0, -0x8(%rbp)
jmp 0x119bf
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x30(%rax)
je 0x11689
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
cmpq $0x0, 0x48(%rax)
jne 0x11689
movq $0x0, -0x8(%rbp)
jmp 0x119bf
jmp 0x1168b
movq -0x10(%rbp), %rcx
movb $0x1, %al
cmpl $0x0, 0x30(%rcx)
movb %al, -0x41(%rbp)
jne 0x116de
movq -0x10(%rbp), %rax
movl 0x28(%rax), %ecx
movq -0x10(%rbp), %rdx
movb $0x1, %al
cmpl 0x20(%rdx), %ecx
movb %al, -0x41(%rbp)
jg 0x116de
movq -0x10(%rbp), %rax
movl 0x28(%rax), %ecx
movq -0x10(%rbp), %rdx
xorl %eax, %eax
cmpl 0x20(%rdx), %ecx
movb %al, -0x42(%rbp)
jne 0x116d8
movq -0x10(%rbp), %rax
movl 0x2c(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x24(%rcx), %eax
setg %al
movb %al, -0x42(%rbp)
movb -0x42(%rbp), %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0x116ea
jmp 0x119b7
movl $0x0, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0x11878
movq -0x38(%rbp), %rax
movl (%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jl 0x1175a
movq -0x38(%rbp), %rax
movl (%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jne 0x11787
movq -0x38(%rbp), %rax
movl 0x34(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x24(%rcx), %eax
jg 0x11787
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x38(%rbp), %rsi
callq 0x114f0
movq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x1185d
movq -0x38(%rbp), %rax
movl (%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jne 0x1185b
movq -0x38(%rbp), %rax
movl 0x30(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x24(%rcx), %eax
jg 0x1185b
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x38(%rcx), %eax
jne 0x1180a
movq -0x10(%rbp), %rax
cmpl $0x0, 0x38(%rax)
je 0x117d2
movq -0x10(%rbp), %rax
movl 0x38(%rax), %eax
shll %eax
movl %eax, -0x48(%rbp)
jmp 0x117dc
movl $0x100, %eax            # imm = 0x100
movl %eax, -0x48(%rbp)
jmp 0x117dc
movl -0x48(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x10(%rbp), %rax
movslq 0x38(%rax), %rax
imulq $0x18, %rax, %rsi
callq 0x22f0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x2c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movslq -0x2c(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
movq -0x10(%rbp), %rax
movl 0x24(%rax), %esi
movq -0x38(%rbp), %rdx
addq $0x38, %rdx
callq 0x119d0
cmpl $0x0, %eax
je 0x11859
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1185b
jmp 0x1185d
jmp 0x1185f
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x1171d
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x48(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0x2c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movl 0x20(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movl 0x24(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
cmpq $0x0, 0x48(%rax)
je 0x11914
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
cmpl (%rcx), %eax
jle 0x11912
movq 0x5720(%rip), %rax      # 0x16ff8
movq (%rax), %rdi
leaq 0x1e75(%rip), %rsi      # 0x13757
leaq 0x1e93(%rip), %rdx      # 0x1377c
movb $0x0, %al
callq 0x2230
movq -0x10(%rbp), %rax
movl $0x1, 0x3c(%rax)
movq -0x28(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq $0x0, -0x8(%rbp)
jmp 0x119bf
jmp 0x11914
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
cmpl (%rcx), %eax
jge 0x1194c
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x30(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x24(%rax)
jmp 0x11983
movq -0x10(%rbp), %rax
movl 0x24(%rax), %eax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
cmpl 0x30(%rcx), %eax
jge 0x11974
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x30(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x24(%rax)
jmp 0x11981
movq -0x10(%rbp), %rax
movl 0x24(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x24(%rax)
jmp 0x11983
cmpl $0x0, -0x2c(%rbp)
je 0x11997
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0x119bf
movq -0x10(%rbp), %rax
cmpl $0x0, 0x30(%rax)
je 0x119b2
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
cmpq $0x0, 0x48(%rax)
jne 0x119b2
jmp 0x119b7
jmp 0x1168b
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)