// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/bam_tview.c
// Function: base_tv_init
int base_tv_init(tview_t* tv,const char *fn, const char *fn_fa, const char *samples)
	{
	assert(tv!=NULL);
	assert(fn!=NULL);
	tv->mrow = 24; tv->mcol = 80;
	tv->color_for = TV_COLOR_MAPQ;
	tv->is_dot = 1;
	
	tv->fp = bam_open(fn, "r");
	if(tv->fp==0)
		{
		fprintf(stderr,"bam_open %s. %s\n", fn,fn_fa);
            	exit(EXIT_FAILURE);
		}
	bgzf_set_cache_size(tv->fp, 8 * 1024 *1024);
	assert(tv->fp);
	
	tv->header = bam_header_read(tv->fp);
	if(tv->header==0)
		{
		fprintf(stderr,"Cannot read '%s'.\n", fn);
            	exit(EXIT_FAILURE);
		}
	tv->idx = bam_index_load(fn);
	if (tv->idx == 0)
		{
		fprintf(stderr,"Cannot read index for '%s'.\n", fn);
		exit(EXIT_FAILURE);
		}
	tv->lplbuf = bam_lplbuf_init(tv_pl_func, tv);
	if (fn_fa) tv->fai = fai_load(fn_fa);
	tv->bca = bcf_call_init(0.83, 13);
	tv->ins = 1;

    if ( samples ) 
    {
        if ( !tv->header->dict ) tv->header->dict = sam_header_parse2(tv->header->text);
        void *iter = tv->header->dict;
        const char *key, *val;
        int n = 0;
        tv->rg_hash = kh_init(kh_rg);
        while ( (iter = sam_header2key_val(iter, "RG","ID","SM", &key, &val)) )
        {
            if ( !strcmp(samples,key) || (val && !strcmp(samples,val)) )
            {
                khiter_t k = kh_get(kh_rg, tv->rg_hash, key);
                if ( k != kh_end(tv->rg_hash) ) continue;
                int ret;
                k = kh_put(kh_rg, tv->rg_hash, key, &ret);
                kh_value(tv->rg_hash, k) = val;
                n++;
            }
        }
        if ( !n )
        {
            fprintf(stderr,"The sample or read group \"%s\" not present.\n", samples);
            exit(EXIT_FAILURE);
        }
    }

	return 0;
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
testq %rdi, %rdi
je 0x60da
movq %rsi, %rbx
testq %rsi, %rsi
je 0x60f9
movq %rcx, %r14
movq %rdx, %r15
movq %rdi, %r12
movabsq $0x5000000018, %rax     # imm = 0x5000000018
movq %rax, (%rdi)
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x50(%rdi)
leaq 0x3f035(%rip), %rsi     # 0x44c6f
movq %rbx, %rdi
callq 0x1fdb8
movq %rax, 0x20(%r12)
testq %rax, %rax
je 0x6118
movq %rax, %rdi
movl $0x800000, %esi         # imm = 0x800000
callq 0x20cd0
movq 0x20(%r12), %rdi
testq %rdi, %rdi
je 0x6123
callq 0x22efa
movq %rax, 0x18(%r12)
testq %rax, %rax
je 0x6142
movq %rbx, %rdi
callq 0x29a74
movq %rax, 0x8(%r12)
testq %rax, %rax
je 0x614a
leaq 0x4b7(%rip), %rdi       # 0x6152
movq %r12, %rsi
callq 0x2c42a
movq %rax, 0x10(%r12)
testq %r15, %r15
je 0x5cba
movq %r15, %rdi
callq 0x2ee9e
movq %rax, 0x30(%r12)
movsd 0x38346(%rip), %xmm0    # 0x3e008
movl $0xd, %edi
callq 0x10978
movq %rax, 0x38(%r12)
movl $0x1, 0x5c(%r12)
testq %r14, %r14
je 0x60c1
movq 0x18(%r12), %rax
cmpq $0x0, 0x18(%rax)
jne 0x5d01
movq 0x38(%rax), %rdi
callq 0x363c3
movq 0x18(%r12), %rcx
movq %rax, 0x18(%rcx)
movq 0x18(%r12), %rax
movq 0x18(%rax), %rbx
movl $0x1, %edi
movl $0x28, %esi
callq 0x3610
movq %rax, 0x70(%r12)
leaq 0x3b024(%rip), %rsi     # 0x40d49
leaq 0x38460(%rip), %rdx     # 0x3e18c
leaq 0x3845c(%rip), %rcx     # 0x3e18f
leaq 0x48(%rsp), %r8
leaq 0x40(%rsp), %r9
movq %rbx, %rdi
callq 0x36c61
testq %rax, %rax
je 0x60d2
movq %rax, %r15
leaq 0x3aff1(%rip), %rbx     # 0x40d49
movl $0x0, 0x14(%rsp)
movq %r14, 0x18(%rsp)
movq %r12, 0x20(%rsp)
movq 0x48(%rsp), %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x35a0
testl %eax, %eax
je 0x5d9c
movq 0x40(%rsp), %rsi
testq %rsi, %rsi
je 0x608b
movq %r14, %rdi
callq 0x35a0
testl %eax, %eax
jne 0x608b
movq 0x70(%r12), %r8
movl (%r8), %r9d
testl %r9d, %r9d
movq %r8, 0x38(%rsp)
movq %r15, 0x28(%rsp)
movq %r13, 0x8(%rsp)
je 0x5de4
movsbl (%r13), %ecx
testl %ecx, %ecx
je 0x5dec
movb 0x1(%r13), %al
testb %al, %al
je 0x5dee
leaq 0x2(%r13), %rdx
movl %ecx, %esi
shll $0x5, %esi
subl %ecx, %esi
movsbl %al, %ecx
addl %esi, %ecx
movb (%rdx), %al
incq %rdx
testb %al, %al
jne 0x5dcd
jmp 0x5dee
xorl %r15d, %r15d
jmp 0x5e97
xorl %ecx, %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %r9d
movl %edx, %edi
leal -0x1(%r9), %esi
movl %ecx, %eax
xorl %edx, %edx
divl %esi
movl %edx, %ebp
incl %ebp
movq 0x10(%r8), %r12
movl %edi, %r15d
movl %edi, 0x30(%rsp)
movl %r15d, %eax
shrl $0x4, %eax
movl (%r12,%rax,4), %r13d
leal (%r15,%r15), %r14d
andl $0x1e, %r14d
movl %r13d, %eax
movl %r14d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x5e78
testb $0x1, %al
jne 0x5e5a
movq 0x18(%r8), %rax
movl %r15d, %ecx
movq (%rax,%rcx,8), %rdi
movq 0x8(%rsp), %rsi
movq %r9, %rbx
callq 0x35a0
movq %rbx, %r9
movl 0x30(%rsp), %edi
movq 0x38(%rsp), %r8
testl %eax, %eax
je 0x5e78
addl %ebp, %r15d
cmpl %r9d, %r15d
movl %r9d, %eax
movl $0x0, %ecx
cmovbl %ecx, %eax
subl %eax, %r15d
cmpl %edi, %r15d
jne 0x5e10
movl %r9d, %r15d
jmp 0x5e86
movl %r14d, %ecx
shrl %cl, %r13d
testb $0x3, %r13b
cmovnel %r9d, %r15d
movq 0x18(%rsp), %r14
leaq 0x3aeb7(%rip), %rbx     # 0x40d49
movq 0x8(%rsp), %r13
cmpl %r9d, %r15d
jne 0x5ef8
movl 0x8(%r8), %eax
cmpl 0xc(%r8), %eax
jb 0x5ec9
movl 0x4(%r8), %eax
addl %eax, %eax
cmpl %r9d, %eax
movl $0x0, %esi
sbbl %esi, %esi
orl $0x1, %esi
addl %r9d, %esi
movq %r8, %rdi
callq 0x71ac
movq 0x38(%rsp), %r8
movl (%r8), %r15d
movsbl (%r13), %esi
testl %esi, %esi
je 0x5f07
movb 0x1(%r13), %al
testb %al, %al
je 0x5f09
leaq 0x2(%r13), %rcx
movl %esi, %edx
shll $0x5, %edx
subl %esi, %edx
movsbl %al, %esi
addl %edx, %esi
movb (%rcx), %al
incq %rcx
testb %al, %al
jne 0x5ee1
jmp 0x5f09
movq 0x20(%rsp), %r12
movq 0x28(%rsp), %r15
jmp 0x608b
xorl %esi, %esi
movl %esi, %eax
xorl %edx, %edx
divl %r15d
movl %edx, %r10d
movq 0x10(%r8), %rdi
movl %edx, %eax
shrl $0x4, %eax
movl (%rdi,%rax,4), %eax
leal (%r10,%r10), %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x5ff8
leal -0x1(%r15), %ecx
movl %esi, %eax
xorl %edx, %edx
divl %ecx
movl %edx, %r12d
incl %r12d
movl %r10d, %r13d
movl %r15d, %ebp
movq %rdi, 0x30(%rsp)
movq %r10, 0x50(%rsp)
movl %r13d, %eax
shrl $0x4, %eax
movl (%rdi,%rax,4), %ebx
leal (,%r13,2), %r14d
andl $0x1e, %r14d
movl %ebx, %eax
movl %r14d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x5fbe
testb $0x1, %al
jne 0x5f99
movq 0x18(%r8), %rax
movl %r13d, %ecx
movq (%rax,%rcx,8), %rdi
movq 0x8(%rsp), %rsi
callq 0x35a0
movq 0x50(%rsp), %r10
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %r8
testl %eax, %eax
je 0x5fbe
btl %r14d, %ebx
cmovbl %r13d, %ebp
addl %r12d, %r13d
cmpl %r15d, %r13d
movl %r15d, %eax
movl $0x0, %ecx
cmovbl %ecx, %eax
subl %eax, %r13d
movl %ebp, %eax
cmpl %r10d, %r13d
jne 0x5f4d
jmp 0x5fc1
movl %r15d, %eax
movl %eax, %r10d
cmpl %r15d, %eax
movq 0x18(%rsp), %r14
leaq 0x3ad76(%rip), %rbx     # 0x40d49
jne 0x5ff8
movl %r13d, %eax
shrl $0x4, %eax
movl (%rdi,%rax,4), %eax
leal (,%r13,2), %ecx
shrl %cl, %eax
cmpl %r15d, %ebp
cmovel %r13d, %ebp
testb $0x2, %al
cmovel %r13d, %ebp
movl %ebp, %r10d
movl %r10d, %eax
shrl $0x4, %eax
movl (%rdi,%rax,4), %esi
leal (%r10,%r10), %ecx
andl $0x1e, %ecx
shrl %cl, %esi
movl %r10d, %edx
testb $0x2, %sil
jne 0x6046
testb $0x1, %sil
movq 0x20(%rsp), %r12
movq 0x28(%rsp), %r15
movq 0x8(%rsp), %rdi
je 0x6075
movq 0x18(%r8), %rsi
movq %rdi, (%rsi,%rdx,8)
movl $0x3, %esi
shll %cl, %esi
notl %esi
movq 0x10(%r8), %rcx
andl %esi, (%rcx,%rax,4)
incl 0x4(%r8)
jmp 0x6075
movq 0x18(%r8), %rsi
movq 0x8(%rsp), %rdi
movq %rdi, (%rsi,%rdx,8)
movl $0x3, %esi
shll %cl, %esi
notl %esi
movq 0x10(%r8), %rcx
andl %esi, (%rcx,%rax,4)
incl 0x4(%r8)
incl 0x8(%r8)
movq 0x20(%rsp), %r12
movq 0x28(%rsp), %r15
movq 0x40(%rsp), %rax
movq 0x70(%r12), %rcx
movq 0x20(%rcx), %rcx
movq %rax, (%rcx,%rdx,8)
incl 0x14(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
leaq 0x380f4(%rip), %rdx     # 0x3e18c
leaq 0x380f0(%rip), %rcx     # 0x3e18f
leaq 0x48(%rsp), %r8
leaq 0x40(%rsp), %r9
callq 0x36c61
movq %rax, %r15
testq %rax, %rax
jne 0x5d6a
cmpl $0x0, 0x14(%rsp)
je 0x60d2
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x3840
leaq 0x37fff(%rip), %rdi     # 0x3e0e0
leaq 0x38001(%rip), %rsi     # 0x3e0e9
leaq 0x38006(%rip), %rcx     # 0x3e0f5
movl $0x6, %edx
callq 0x31b0
leaq 0x3803b(%rip), %rdi     # 0x3e13b
leaq 0x37fe2(%rip), %rsi     # 0x3e0e9
leaq 0x37fe7(%rip), %rcx     # 0x3e0f5
movl $0x7, %edx
callq 0x31b0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x38ac
leaq 0x3802b(%rip), %rdi     # 0x3e155
leaq 0x37fb8(%rip), %rsi     # 0x3e0e9
leaq 0x37fbd(%rip), %rcx     # 0x3e0f5
movl $0x13, %edx
callq 0x31b0
movq %rbx, %rdi
callq 0x3888
movq %rbx, %rdi
callq 0x3864