// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/samtools-0.1.18/bam_lpileup.c
// Function: tview_func
static int tview_func(uint32_t tid, uint32_t pos, int n, const bam_pileup1_t *pl, void *data)
{
	bam_lplbuf_t *tv = (bam_lplbuf_t*)data;
	freenode_t *p;
	int i, l, max_level;
	// allocate memory if necessary
	if (tv->max < n) { // enlarge
		tv->max = n;
		kroundup32(tv->max);
		tv->cur_level = (int*)realloc(tv->cur_level, sizeof(int) * tv->max);
		tv->pre_level = (int*)realloc(tv->pre_level, sizeof(int) * tv->max);
	}
	tv->n_cur = n;
	// update cnt
	for (p = tv->head; p->next; p = p->next)
		if (p->cnt > 0) --p->cnt;
	// calculate cur_level[]
	max_level = 0;
	for (i = l = 0; i < n; ++i) {
		const bam_pileup1_t *p = pl + i;
		if (p->is_head) {
			if (tv->head->next && tv->head->cnt == 0) { // then take a free slot
				freenode_t *p = tv->head->next;
				tv->cur_level[i] = tv->head->level;
				mp_free(tv->mp, tv->head);
				tv->head = p;
				--tv->n_nodes;
			} else tv->cur_level[i] = ++tv->max_level;
		} else {
			tv->cur_level[i] = tv->pre_level[l++];
			if (p->is_tail) { // then return a free slot
				tv->tail->level = tv->cur_level[i];
				tv->tail->next = mp_alloc(tv->mp);
				tv->tail = tv->tail->next;
				++tv->n_nodes;
			}
		}
		if (tv->cur_level[i] > max_level) max_level = tv->cur_level[i];
		((bam_pileup1_t*)p)->level = tv->cur_level[i];
	}
	assert(l == tv->n_pre);
	tv->func(tid, pos, n, pl, tv->user_data);
	// sort the linked list
	if (tv->n_nodes) {
		freenode_t *q;
		if (tv->n_nodes + 1 > tv->m_aux) { // enlarge
			tv->m_aux = tv->n_nodes + 1;
			kroundup32(tv->m_aux);
			tv->aux = (freenode_t**)realloc(tv->aux, sizeof(void*) * tv->m_aux);
		}
		for (p = tv->head, i = l = 0; p->next;) {
			if (p->level > max_level) { // then discard this entry
				q = p->next;
				mp_free(tv->mp, p);
				p = q;
			} else {
				tv->aux[i++] = p;
				p = p->next;
			}
		}
		tv->aux[i] = tv->tail; // add a proper tail for the loop below
		tv->n_nodes = i;
		if (tv->n_nodes) {
			ks_introsort(node, tv->n_nodes, tv->aux);
			for (i = 0; i < tv->n_nodes; ++i) tv->aux[i]->next = tv->aux[i+1];
			tv->head = tv->aux[0];
		} else tv->head = tv->tail;
	}
	// clean up
	tv->max_level = max_level;
	memcpy(tv->pre_level, tv->cur_level, tv->n_cur * 4);
	// squeeze out terminated levels
	for (i = l = 0; i < n; ++i) {
		const bam_pileup1_t *p = pl + i;
		if (!p->is_tail)
			tv->pre_level[l++] = tv->pre_level[i];
	}
	tv->n_pre = l;
/*
	fprintf(stderr, "%d\t", pos+1);
	for (i = 0; i < n; ++i) {
		const bam_pileup1_t *p = pl + i;
		if (p->is_head) fprintf(stderr, "^");
		if (p->is_tail) fprintf(stderr, "$");
		fprintf(stderr, "%d,", p->level);
	}
	fprintf(stderr, "\n");
*/
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %rbx
movq %rcx, %r14
movl %edx, %r12d
movl %esi, 0x14(%rsp)
movl %edi, 0x10(%rsp)
cmpl %edx, (%r8)
jge 0x29c32a
leal -0x1(%r12), %eax
movl %eax, %ecx
sarl %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
sarl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x8, %eax
orl %ecx, %eax
movl %eax, %ecx
sarl $0x10, %ecx
orl %eax, %ecx
leal 0x1(%rcx), %eax
movl %eax, (%rbx)
movq 0x10(%rbx), %rdi
movslq %ecx, %rax
leaq 0x4(,%rax,4), %rsi
callq 0x330a8
movq %rax, 0x10(%rbx)
movq 0x18(%rbx), %rdi
movslq (%rbx), %rsi
shlq $0x2, %rsi
callq 0x330a8
movq %rax, 0x18(%rbx)
movl %r12d, 0x4(%rbx)
leaq 0x30(%rbx), %rax
movq %rax, 0x8(%rsp)
movq 0x30(%rbx), %rax
movq %rax, %rcx
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x29c35b
movl (%rcx), %edx
cmpl $0x10000000, %edx       # imm = 0x10000000
jb 0x29c33b
addl $0xf0000000, %edx       # imm = 0xF0000000
movl %edx, (%rcx)
jmp 0x29c33b
xorl %r15d, %r15d
testl %r12d, %r12d
movl $0x0, %edi
movq %r12, 0x20(%rsp)
cmovgl %r12d, %edi
movq %r14, 0x18(%rsp)
leaq 0x14(%r14), %rbp
xorl %r12d, %r12d
xorl %r13d, %r13d
movq %rdi, (%rsp)
cmpq %r15, %rdi
je 0x29c447
testb $0x2, (%rbp)
jne 0x29c3e0
movq 0x10(%rbx), %rcx
movq 0x18(%rbx), %rax
movslq %r13d, %rdx
incl %r13d
movl (%rax,%rdx,4), %eax
movl %eax, (%rcx,%r15,4)
testb $0x4, (%rbp)
je 0x29c429
movq 0x38(%rbx), %rcx
andl $0xfffffff, %eax        # imm = 0xFFFFFFF
movl (%rcx), %edx
movl $0xf0000000, %esi       # imm = 0xF0000000
andl %esi, %edx
orl %eax, %edx
movl %edx, (%rcx)
movq 0x20(%rbx), %rdi
callq 0x29c287
movq (%rsp), %rdi
movq 0x38(%rbx), %rcx
movq %rax, 0x8(%rcx)
movq %rax, 0x38(%rbx)
incl 0x40(%rbx)
jmp 0x29c429
movq 0x8(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rsi), %r14
testq %r14, %r14
je 0x29c419
movl (%rsi), %ecx
movq 0x10(%rbx), %rax
cmpl $0xfffffff, %ecx        # imm = 0xFFFFFFF
ja 0x29c41d
movl %ecx, (%rax,%r15,4)
movq 0x20(%rbx), %rdi
callq 0x29c1af
movq (%rsp), %rdi
movq %r14, 0x30(%rbx)
decl 0x40(%rbx)
jmp 0x29c429
movq 0x10(%rbx), %rax
movl 0xc(%rbx), %ecx
incl %ecx
movl %ecx, 0xc(%rbx)
movl %ecx, (%rax,%r15,4)
movq 0x10(%rbx), %rax
movl (%rax,%r15,4), %eax
cmpl %r12d, %eax
cmovgl %eax, %r12d
movl %eax, -0x4(%rbp)
incq %r15
addq $0x18, %rbp
jmp 0x29c382
cmpl 0x8(%rbx), %r13d
jne 0x29c5ad
movq 0x50(%rbx), %r8
movl 0x10(%rsp), %edi
movl 0x14(%rsp), %esi
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %r14
movq %r14, %rcx
callq *0x48(%rbx)
movl 0x40(%rbx), %eax
testl %eax, %eax
je 0x29c551
cmpl 0x44(%rbx), %eax
jl 0x29c4bd
movl %eax, %ecx
sarl %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
sarl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x8, %eax
orl %ecx, %eax
movl %eax, %ecx
sarl $0x10, %ecx
orl %eax, %ecx
leal 0x1(%rcx), %eax
movl %eax, 0x44(%rbx)
movq 0x28(%rbx), %rdi
movslq %ecx, %rax
leaq 0x8(,%rax,8), %rsi
callq 0x330a8
movq %rax, 0x28(%rbx)
xorl %ebp, %ebp
movl $0xfffffff, %r15d       # imm = 0xFFFFFFF
movq 0x8(%rsp), %rsi
movq (%rsi), %rsi
movq 0x8(%rsi), %r13
movl %ebp, %edi
testq %r13, %r13
je 0x29c500
movl (%rsi), %eax
andl %r15d, %eax
cmpl %r12d, %eax
jle 0x29c4f0
movq 0x20(%rbx), %rdi
callq 0x29c1af
movq %r13, %rsi
jmp 0x29c4cd
movq 0x28(%rbx), %rax
incl %ebp
movq %rsi, (%rax,%rdi,8)
addq $0x8, %rsi
jmp 0x29c4ca
movq 0x28(%rbx), %rcx
movq 0x38(%rbx), %rax
movq %rax, (%rcx,%rdi,8)
movl %ebp, 0x40(%rbx)
testl %ebp, %ebp
movq 0x18(%rsp), %r14
je 0x29c549
movq 0x28(%rbx), %rsi
callq 0x29bc6a
movl 0x40(%rbx), %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
movq 0x28(%rbx), %rdx
cmpq %rcx, %rax
je 0x29c546
movq (%rdx,%rcx,8), %rsi
movq 0x8(%rdx,%rcx,8), %rdi
incq %rcx
movq %rdi, 0x8(%rsi)
jmp 0x29c52f
movq (%rdx), %rax
movq 0x8(%rsp), %rcx
movq %rax, (%rcx)
movl %r12d, 0xc(%rbx)
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rdi
movslq 0x4(%rbx), %rdx
shlq $0x2, %rdx
callq 0x32ca0
addq $0x14, %r14
xorl %eax, %eax
xorl %ecx, %ecx
movq (%rsp), %r8
cmpq %rax, %r8
je 0x29c599
testb $0x4, (%r14)
jne 0x29c590
movq 0x18(%rbx), %rdx
movl (%rdx,%rax,4), %esi
movslq %ecx, %rdi
incl %ecx
movl %esi, (%rdx,%rdi,4)
incq %rax
addq $0x18, %r14
jmp 0x29c576
movl %ecx, 0x8(%rbx)
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xbf0e6(%rip), %rdi     # 0x35b69a
leaq 0xbf08c(%rip), %rsi     # 0x35b647
leaq 0xbf0e7(%rip), %rcx     # 0x35b6a9
pushq $0x74
popq %rdx
callq 0x2edc0