// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/bam_index.c
// Function: bam_index_load_local
bam_index_t *bam_index_load_local(const char *_fn)
{
	FILE *fp;
	char *fnidx, *fn;

	if (strstr(_fn, "ftp://") == _fn || strstr(_fn, "http://") == _fn) {
		const char *p;
		int l = strlen(_fn);
		for (p = _fn + l - 1; p >= _fn; --p)
			if (*p == '/') break;
		fn = strdup(p + 1);
	} else fn = strdup(_fn);
	fnidx = (char*)calloc(strlen(fn) + 5, 1);
	strcpy(fnidx, fn); strcat(fnidx, ".bai");
	fp = fopen(fnidx, "rb");
	if (fp == 0) { // try "{base}.bai"
		char *s = strstr(fn, "bam");
		if (s == fn + strlen(fn) - 3) {
			strcpy(fnidx, fn);
			fnidx[strlen(fn)-1] = 'i';
			fp = fopen(fnidx, "rb");
		}
	}
	free(fnidx); free(fn);
	if (fp) {
		bam_index_t *idx = bam_index_load_core(fp);
		fclose(fp);
		return idx;
	} else return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
leaq 0xc0ad(%rip), %rsi      # 0x1c3a7
movl $0x6, %edx
callq 0x30c0
testl %eax, %eax
je 0x10320
leaq 0xc09f(%rip), %rsi      # 0x1c3ae
movl $0x7, %edx
movq %rbx, %rdi
callq 0x30c0
testl %eax, %eax
jne 0x10348
movq %rbx, %rdi
callq 0x31e0
cltq
leaq (%rax,%rbx), %rcx
decq %rcx
movq %rcx, %rax
cmpq %rbx, %rcx
jb 0x10342
leaq -0x1(%rax), %rcx
cmpb $0x2f, (%rax)
jne 0x10331
incq %rax
movq %rax, %rbx
movq %rbx, %rdi
callq 0x3590
movq %rax, %r14
movq %rax, %rdi
callq 0x31e0
leaq 0x5(%rax), %rdi
movl $0x1, %esi
callq 0x32e0
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
callq 0x30d0
movq %r15, %rdi
callq 0x31e0
movl $0x6961622e, (%r15,%rax) # imm = 0x6961622E
movb $0x0, 0x4(%r15,%rax)
leaq 0xaa6f(%rip), %rsi      # 0x1ae03
movq %r15, %rdi
callq 0x3340
movq %rax, %rbx
testq %rax, %rax
jne 0x103f4
leaq 0xac4e(%rip), %rsi      # 0x1aff9
movq %r14, %rdi
callq 0x35d0
movq %rax, %r12
movq %r14, %rdi
callq 0x31e0
movq %rax, %rbx
addq %r14, %rax
addq $-0x3, %rax
cmpq %rax, %r12
je 0x103d1
xorl %ebx, %ebx
jmp 0x103f4
movq %r15, %rdi
movq %r14, %rsi
callq 0x30d0
movb $0x69, -0x1(%r15,%rbx)
leaq 0xaa1a(%rip), %rsi      # 0x1ae03
movq %r15, %rdi
callq 0x3340
movq %rax, %rbx
movq %r15, %rdi
callq 0x3060
movq %r14, %rdi
callq 0x3060
testq %rbx, %rbx
je 0x10477
leaq 0x54(%rsp), %r14
movl $0x1, %esi
movl $0x4, %edx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x3130
cmpl $0x1494142, (%r14)      # imm = 0x1494142
jne 0x1071e
movl $0x1, %edi
movl $0x20, %esi
callq 0x32e0
movq %rax, %r14
movl $0x4, %esi
movl $0x1, %edx
movq %rax, 0x28(%rsp)
movq %rax, %rdi
movq %rbx, %rcx
callq 0x3130
leaq 0x135ed(%rip), %rax     # 0x23a50
cmpl $0x0, (%rax)
movq %rbx, 0x20(%rsp)
je 0x1047e
movl (%r14), %ebp
bswapl %ebp
movl %ebp, (%r14)
jmp 0x10481
xorl %eax, %eax
jmp 0x1070f
movl (%r14), %ebp
movq %r14, %rbx
movslq %ebp, %r14
movl $0x8, %esi
movq %r14, %rdi
callq 0x32e0
movq %rax, 0x40(%rsp)
movq %rax, 0x10(%rbx)
movl $0x10, %esi
movq %r14, %rdi
callq 0x32e0
movq %rbx, 0x18(%rsp)
movq %rax, 0x38(%rsp)
movq %rax, 0x18(%rbx)
testl %r14d, %r14d
movq 0x20(%rsp), %r14
jle 0x106c3
movl %ebp, %eax
movq %rax, 0x30(%rsp)
xorl %ebx, %ebx
movl $0x1, %edi
movl $0x28, %esi
callq 0x32e0
movq %rax, %rbp
movq 0x40(%rsp), %rax
movq %rbx, 0x48(%rsp)
movq %rbp, (%rax,%rbx,8)
movl $0x4, %esi
movl $0x1, %edx
leaq 0x14(%rsp), %rdi
movq %r14, %rcx
callq 0x3130
leaq 0x13543(%rip), %rax     # 0x23a50
cmpl $0x0, (%rax)
movl 0x14(%rsp), %eax
movl %eax, %ecx
bswapl %ecx
cmovel %eax, %ecx
movl %ecx, 0x10(%rsp)
testl %ecx, %ecx
jle 0x1061e
xorl %r15d, %r15d
movl $0x4, %esi
movl $0x1, %edx
leaq 0xc(%rsp), %rdi
movq %r14, %rcx
callq 0x3130
leaq 0x13508(%rip), %rax     # 0x23a50
cmpl $0x0, (%rax)
movl 0xc(%rsp), %esi
je 0x10557
bswapl %esi
movl %esi, 0xc(%rsp)
movq %rbp, %rdi
leaq 0x50(%rsp), %rdx
callq 0x11529
movq 0x20(%rbp), %r13
movl %eax, %ebx
shlq $0x4, %rbx
leaq (%rbx,%r13), %r12
addq $0x4, %r12
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r14, %rcx
callq 0x3130
leaq 0x134be(%rip), %rax     # 0x23a50
cmpl $0x0, (%rax)
movl (%r12), %r14d
je 0x105a2
bswapl %r14d
movl %r14d, (%r12)
addq %rbx, %r13
movl %r14d, (%r13)
movl %r14d, %edi
shll $0x4, %edi
callq 0x33e0
movq %rax, 0x8(%r13)
movl %r14d, %edx
movl $0x10, %esi
movq %rax, %rdi
movq 0x20(%rsp), %r14
movq %r14, %rcx
callq 0x3130
leaq 0x13479(%rip), %rax     # 0x23a50
cmpl $0x0, (%rax)
je 0x10610
movl (%r12), %eax
testq %rax, %rax
je 0x10610
movq 0x8(%r13), %rcx
shlq $0x4, %rax
xorl %edx, %edx
movq (%rcx,%rdx), %rsi
movq 0x8(%rcx,%rdx), %rdi
bswapq %rsi
bswapq %rdi
movq %rsi, (%rcx,%rdx)
movq %rdi, 0x8(%rcx,%rdx)
addq $0x10, %rdx
cmpq %rdx, %rax
jne 0x105ef
incl %r15d
cmpl 0x10(%rsp), %r15d
jne 0x1052a
movq 0x48(%rsp), %rbx
movq %rbx, %rbp
shlq $0x4, %rbp
addq 0x38(%rsp), %rbp
movl $0x4, %esi
movl $0x1, %edx
movq %rbp, %rdi
movq %r14, %rcx
callq 0x3130
leaq 0x13405(%rip), %rax     # 0x23a50
cmpl $0x0, (%rax)
je 0x1065a
movl (%rbp), %eax
bswapl %eax
movl %eax, (%rbp)
jmp 0x1065d
movl (%rbp), %eax
movl %eax, 0x4(%rbp)
movslq %eax, %r12
movl $0x8, %esi
movq %r12, %rdi
callq 0x32e0
movq %rax, 0x8(%rbp)
movl $0x8, %edx
movq %rax, %rdi
movq %r12, %rsi
movq %r14, %rcx
callq 0x3130
leaq 0x133c2(%rip), %rax     # 0x23a50
cmpl $0x0, (%rax)
je 0x106b5
movslq (%rbp), %rax
testq %rax, %rax
jle 0x106b5
movq 0x8(%rbp), %rcx
xorl %edx, %edx
movq (%rcx,%rdx,8), %rsi
bswapq %rsi
movq %rsi, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x106a2
incq %rbx
cmpq 0x30(%rsp), %rbx
jne 0x104cf
movq 0x28(%rsp), %rbx
addq $0x8, %rbx
movl $0x8, %esi
movl $0x1, %edx
movq %rbx, %rdi
movq %r14, %rcx
callq 0x3130
testq %rax, %rax
jne 0x106ed
movq $0x0, (%rbx)
leaq 0x1335c(%rip), %rax     # 0x23a50
cmpl $0x0, (%rax)
je 0x10702
movq (%rbx), %rax
bswapq %rax
movq %rax, (%rbx)
movq %r14, %rdi
callq 0x31c0
movq 0x18(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x3f2b
movq $0x0, 0x18(%rsp)
movq %rbx, %r14
jmp 0x10702