// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/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 $0x38, %rsp
movq %r8, %rbx
movq %rcx, %r14
movl %edx, %r15d
movl %esi, 0x18(%rsp)
movl %edi, 0x14(%rsp)
cmpl %edx, (%r8)
jge 0x2cf03
leal -0x1(%r15), %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 0x3720
movq %rax, 0x10(%rbx)
movq 0x18(%rbx), %rdi
movslq (%rbx), %rsi
shlq $0x2, %rsi
callq 0x3720
movq %rax, 0x18(%rbx)
movl %r15d, 0x4(%rbx)
movq 0x30(%rbx), %rax
movq 0x8(%rax), %rcx
testq %rcx, %rcx
je 0x2cf32
movq %rcx, %rdx
movl (%rax), %ecx
cmpl $0x10000000, %ecx       # imm = 0x10000000
jb 0x2cf29
addl $0xf0000000, %ecx       # imm = 0xF0000000
movl %ecx, (%rax)
movq 0x8(%rdx), %rcx
movq %rdx, %rax
jmp 0x2cf0f
movl %r15d, %edi
movq %r15, 0x20(%rsp)
testl %r15d, %r15d
movq %rbx, 0x28(%rsp)
movq %rdi, 0x8(%rsp)
movq %r14, 0x30(%rsp)
jle 0x2d0c4
leaq 0x14(%r14), %r12
xorl %r15d, %r15d
xorl %r8d, %r8d
xorl %ebp, %ebp
testb $0x2, (%r12)
jne 0x2cfc3
movq 0x10(%rbx), %rcx
movq 0x18(%rbx), %rax
movslq %r8d, %rdx
incl %r8d
movl (%rax,%rdx,4), %eax
movl %eax, (%rcx,%r15,4)
testb $0x4, (%r12)
je 0x2d0a0
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), %rax
incl (%rax)
movslq 0x4(%rax), %rcx
testq %rcx, %rcx
je 0x2d058
movq 0x10(%rax), %rdx
leaq -0x1(%rcx), %rsi
movl %esi, 0x4(%rax)
movq -0x8(%rdx,%rcx,8), %rax
jmp 0x2d072
movq 0x30(%rbx), %r13
movq 0x8(%r13), %r14
testq %r14, %r14
je 0x2d046
movl (%r13), %ecx
movq 0x10(%rbx), %rax
cmpl $0xfffffff, %ecx        # imm = 0xFFFFFFF
ja 0x2d04a
movl %ecx, (%rax,%r15,4)
movq 0x20(%rbx), %rbx
decl (%rbx)
movq $0x0, 0x8(%r13)
movl (%r13), %eax
movl $0xfffffff, %ecx        # imm = 0xFFFFFFF
andl %ecx, %eax
orl $0x20000000, %eax       # imm = 0x20000000
movl %eax, (%r13)
movl 0x4(%rbx), %ecx
cmpl 0x8(%rbx), %ecx
jne 0x2d083
leal (%rcx,%rcx), %eax
testl %ecx, %ecx
movl $0x100, %ecx            # imm = 0x100
cmovel %ecx, %eax
movl %eax, 0x8(%rbx)
movq 0x10(%rbx), %rdi
movslq %eax, %rsi
shlq $0x3, %rsi
movl %r8d, 0x1c(%rsp)
callq 0x3720
movl 0x1c(%rsp), %r8d
movq 0x8(%rsp), %rdi
movq %rax, 0x10(%rbx)
movl 0x4(%rbx), %ecx
jmp 0x2d087
movq 0x10(%rbx), %rax
movl 0xc(%rbx), %ecx
incl %ecx
movl %ecx, 0xc(%rbx)
movl %ecx, (%rax,%r15,4)
jmp 0x2d0a0
movl $0x1, %edi
movl $0x10, %esi
movl %r8d, %r14d
callq 0x3610
movl %r14d, %r8d
movq 0x8(%rsp), %rdi
movq 0x38(%rbx), %rcx
movq %rax, 0x8(%rcx)
movq %rax, 0x38(%rbx)
incl 0x40(%rbx)
jmp 0x2d0a0
movq 0x10(%rbx), %rax
leal 0x1(%rcx), %edx
movl %edx, 0x4(%rbx)
movslq %ecx, %rcx
movq %r13, (%rax,%rcx,8)
movq 0x28(%rsp), %rbx
movq %r14, 0x30(%rbx)
decl 0x40(%rbx)
movq 0x10(%rbx), %rax
movl (%rax,%r15,4), %eax
cmpl %ebp, %eax
cmovgl %eax, %ebp
movl %eax, -0x4(%r12)
incq %r15
addq $0x18, %r12
cmpq %r15, %rdi
jne 0x2cf5e
jmp 0x2d0c9
xorl %ebp, %ebp
xorl %r8d, %r8d
cmpl 0x8(%rbx), %r8d
jne 0x2d2c2
movq 0x50(%rbx), %r8
movl 0x14(%rsp), %edi
movl 0x18(%rsp), %esi
movq 0x20(%rsp), %r15
movl %r15d, %edx
movq 0x30(%rsp), %r14
movq %r14, %rcx
callq *0x48(%rbx)
movl 0x40(%rbx), %eax
testl %eax, %eax
je 0x2d25f
cmpl 0x44(%rbx), %eax
jl 0x2d142
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 0x3720
movq %rax, 0x28(%rbx)
movq 0x30(%rbx), %r13
movq 0x8(%r13), %r12
testq %r12, %r12
je 0x2d249
leaq 0x8(%r13), %rax
xorl %r15d, %r15d
movl $0xfffffff, %esi        # imm = 0xFFFFFFF
movl (%r13), %ecx
andl %esi, %ecx
cmpl %ebp, %ecx
jle 0x2d1bb
movq 0x20(%rbx), %rbx
decl (%rbx)
movq $0x0, (%rax)
movl (%r13), %eax
andl %esi, %eax
orl $0x20000000, %eax       # imm = 0x20000000
movl %eax, (%r13)
movl 0x4(%rbx), %ecx
cmpl 0x8(%rbx), %ecx
jne 0x2d1ce
leal (%rcx,%rcx), %eax
testl %ecx, %ecx
movl $0x100, %ecx            # imm = 0x100
cmovel %ecx, %eax
movl %eax, 0x8(%rbx)
movq 0x10(%rbx), %rdi
movslq %eax, %rsi
shlq $0x3, %rsi
callq 0x3720
movl $0xfffffff, %esi        # imm = 0xFFFFFFF
movq %rax, 0x10(%rbx)
movl 0x4(%rbx), %ecx
jmp 0x2d1d2
movq 0x28(%rbx), %rcx
movslq %r15d, %rdx
incl %r15d
movq %r13, (%rcx,%rdx,8)
movq (%rax), %r12
jmp 0x2d1e4
movq 0x10(%rbx), %rax
leal 0x1(%rcx), %edx
movl %edx, 0x4(%rbx)
movslq %ecx, %rcx
movq %r13, (%rax,%rcx,8)
movq 0x28(%rsp), %rbx
movq %r12, %r13
leaq 0x8(%r12), %rax
movq 0x8(%r12), %r12
testq %r12, %r12
jne 0x2d15f
movq 0x28(%rbx), %rcx
movq 0x38(%rbx), %rax
movslq %r15d, %rdi
movq %rax, (%rcx,%rdi,8)
movl %edi, 0x40(%rbx)
testl %edi, %edi
movq 0x20(%rsp), %r15
je 0x2d25b
movq 0x28(%rbx), %rsi
callq 0x2c7f0
movslq 0x40(%rbx), %rax
movq 0x28(%rbx), %rcx
testq %rax, %rax
jle 0x2d244
movq (%rcx), %rsi
xorl %edx, %edx
movq 0x8(%rcx,%rdx,8), %rdi
incq %rdx
movq %rdi, 0x8(%rsi)
movq %rdi, %rsi
cmpq %rdx, %rax
jne 0x2d230
movq (%rcx), %rax
jmp 0x2d25b
movq 0x28(%rbx), %rcx
movq 0x38(%rbx), %rax
movq %rax, (%rcx)
movl $0x0, 0x40(%rbx)
movq %rax, 0x30(%rbx)
movl %ebp, 0xc(%rbx)
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rdi
movslq 0x4(%rbx), %rdx
shlq $0x2, %rdx
callq 0x37d0
testl %r15d, %r15d
jle 0x2d2ac
addq $0x14, %r14
xorl %ecx, %ecx
xorl %eax, %eax
movq 0x8(%rsp), %r8
testb $0x4, (%r14)
jne 0x2d29e
movq 0x18(%rbx), %rdx
movl (%rdx,%rcx,4), %esi
movslq %eax, %rdi
incl %eax
movl %esi, (%rdx,%rdi,4)
incq %rcx
addq $0x18, %r14
cmpq %rcx, %r8
jne 0x2d289
jmp 0x2d2ae
xorl %eax, %eax
movl %eax, 0x8(%rbx)
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x17404(%rip), %rdi     # 0x446cd
leaq 0x173c7(%rip), %rsi     # 0x44697
leaq 0x17405(%rip), %rcx     # 0x446dc
movl $0x74, %edx
callq 0x31b0