// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/bam_tview.c
// Function: tv_draw_aln
int tv_draw_aln(tview_t *tv, int tid, int pos)
{
	// reset
	clear();
	tv->curr_tid = tid; tv->left_pos = pos;
	tv->last_pos = tv->left_pos - 1;
	tv->ccol = 0;
	// print ref and consensus
	if (tv->fai) {
		char *str;
		if (tv->ref) free(tv->ref);
		str = (char*)calloc(strlen(tv->header->target_name[tv->curr_tid]) + 30, 1);
		sprintf(str, "%s:%d-%d", tv->header->target_name[tv->curr_tid], tv->left_pos + 1, tv->left_pos + tv->mcol);
		tv->ref = fai_fetch(tv->fai, str, &tv->l_ref);
		free(str);
	}
	// draw aln
	bam_lplbuf_reset(tv->lplbuf);
	bam_fetch(tv->fp, tv->idx, tv->curr_tid, tv->left_pos, tv->left_pos + tv->mcol, tv, tv_fetch_func);
	bam_lplbuf_push(0, tv->lplbuf);

	while (tv->ccol < tv->mcol) {
		int pos = tv->last_pos + 1;
		if (pos%10 == 0 && tv->mcol - tv->ccol >= 10) mvprintw(0, tv->ccol, "%-d", pos+1);
		mvaddch(1, tv->ccol++, (tv->ref && pos < tv->l_ref)? tv->ref[pos - tv->left_pos] : 'N');
		++tv->last_pos;
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %r14d
movl %esi, %ebp
movq %rdi, %rbx
movq 0x282bf(%rip), %r13     # 0x2dfd8
movq (%r13), %rdi
callq 0x3070
movl %ebp, 0x38(%rbx)
movl %r14d, 0x3c(%rbx)
leal -0x1(%r14), %eax
movl %eax, 0x54(%rbx)
movl $0x0, 0x50(%rbx)
cmpq $0x0, 0x40(%rbx)
je 0x5db6
movq 0x78(%rbx), %rdi
testq %rdi, %rdi
je 0x5d53
callq 0x32c0
movl 0x38(%rbx), %ebp
movl 0x3c(%rbx), %r14d
movq 0x28(%rbx), %rax
movq 0x8(%rax), %rax
movslq %ebp, %rcx
movq (%rax,%rcx,8), %r15
movq %r15, %rdi
callq 0x32d0
leaq 0x1e(%rax), %rdi
movl $0x1, %esi
callq 0x3530
movq %rax, %r12
leal 0x1(%r14), %ecx
addl 0x4(%rbx), %r14d
leaq 0x1d38b(%rip), %rsi     # 0x23115
movq %rax, %rdi
movq %r15, %rdx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x3350
movq 0x40(%rbx), %rdi
leaq 0x68(%rbx), %rdx
movq %r12, %rsi
callq 0x1b912
movq %rax, 0x78(%rbx)
movq %r12, %rdi
callq 0x32c0
movq 0x20(%rbx), %rdi
callq 0x18970
movq 0x18(%rbx), %rsi
movq 0x30(%rbx), %rdi
movl 0x38(%rbx), %edx
movl 0x3c(%rbx), %ecx
movl 0x4(%rbx), %r8d
addl %ecx, %r8d
leaq -0x134(%rip), %rax      # 0x5ca7
movq %rax, (%rsp)
movq %rbx, %r9
callq 0x1717f
movq 0x20(%rbx), %rsi
xorl %edi, %edi
callq 0x19097
movl 0x4(%rbx), %eax
movl 0x50(%rbx), %edx
cmpl %eax, %edx
jge 0x5e97
movl 0x54(%rbx), %ecx
movl $0x19999998, %ebp       # imm = 0x19999998
leaq 0x1d2b1(%rip), %r14     # 0x230c0
movslq %ecx, %r15
incq %r15
imull $0xcccccccd, %r15d, %esi # imm = 0xCCCCCCCD
addl %ebp, %esi
rorl %esi
cmpl %ebp, %esi
ja 0x5e3f
subl %edx, %eax
cmpl $0xa, %eax
jl 0x5e3f
addl $0x2, %ecx
xorl %edi, %edi
movl %edx, %esi
movq %r14, %rdx
xorl %eax, %eax
callq 0x3260
movl 0x50(%rbx), %edx
movq (%r13), %rdi
leal 0x1(%rdx), %eax
movl %eax, 0x50(%rbx)
movl $0x1, %esi
callq 0x3490
cmpl $-0x1, %eax
je 0x5e81
movq 0x78(%rbx), %rax
movl $0x4e, %esi
testq %rax, %rax
je 0x5e78
cmpl 0x68(%rbx), %r15d
jge 0x5e78
movslq 0x3c(%rbx), %rcx
subq %rcx, %r15
movsbl (%rax,%r15), %esi
movq (%r13), %rdi
callq 0x3300
movl 0x54(%rbx), %ecx
incl %ecx
movl %ecx, 0x54(%rbx)
movl 0x4(%rbx), %eax
movl 0x50(%rbx), %edx
cmpl %eax, %edx
jl 0x5e0f
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq