// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %rdi, %rbx
leaq 0xb342(%rip), %rsi      # 0x1b297
movl $0x6, %edx
callq 0x30c0
testl %eax, %eax
je 0xff7b
leaq 0xb334(%rip), %rsi      # 0x1b29e
movl $0x7, %edx
movq %rbx, %rdi
callq 0x30c0
testl %eax, %eax
jne 0xffa3
movq %rbx, %rdi
callq 0x31e0
cltq
leaq (%rax,%rbx), %rcx
decq %rcx
movq %rcx, %rax
cmpq %rbx, %rcx
jb 0xff9d
leaq -0x1(%rax), %rcx
cmpb $0x2f, (%rax)
jne 0xff8c
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 0x9d64(%rip), %rsi      # 0x19d53
movq %r15, %rdi
callq 0x3340
movq %rax, %rbx
testq %rax, %rax
jne 0x10054
leaq 0x9f43(%rip), %rsi      # 0x19f49
movq %r14, %rdi
callq 0x35d0
movq %rax, %rbx
movq %r14, %rdi
callq 0x31e0
addq %r14, %rax
addq $-0x3, %rax
cmpq %rax, %rbx
je 0x10029
xorl %ebx, %ebx
jmp 0x10054
movq %r15, %rdi
movq %r14, %rsi
callq 0x30d0
movq %r14, %rdi
callq 0x31e0
movb $0x69, -0x1(%r15,%rax)
leaq 0x9d0a(%rip), %rsi      # 0x19d53
movq %r15, %rdi
callq 0x3340
movq %rax, %rbx
movq %r15, %rdi
callq 0x3060
movq %r14, %rdi
callq 0x3060
testq %rbx, %rbx
je 0x1035e
leaq 0x44(%rsp), %r14
movl $0x1, %esi
movl $0x4, %edx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x3130
cmpl $0x1494142, (%r14)      # imm = 0x1494142
jne 0x10373
movl $0x1, %edi
movl $0x20, %esi
callq 0x32e0
movq %rax, %r14
movl $0x4, %esi
movl $0x1, %edx
movq %rax, 0x10(%rsp)
movq %rax, %rdi
movq %rbx, %rcx
callq 0x3130
leaq 0x12989(%rip), %rax     # 0x22a50
cmpl $0x0, (%rax)
je 0x100d4
movl (%r14), %eax
bswapl %eax
movl %eax, (%r14)
movslq (%r14), %r15
movl $0x8, %esi
movq %r15, %rdi
callq 0x32e0
movq %rax, 0x28(%rsp)
movq %rax, 0x10(%r14)
movl $0x10, %esi
movq %r15, %rdi
callq 0x32e0
movq %r14, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movq %rax, 0x18(%r14)
movq %r15, 0x30(%rsp)
testq %r15, %r15
jle 0x10310
xorl %r14d, %r14d
movl $0x1, %edi
movl $0x28, %esi
callq 0x32e0
movq %rax, %r13
movq 0x28(%rsp), %rax
movq %r14, 0x38(%rsp)
movq %r13, (%rax,%r14,8)
movl $0x4, %esi
movl $0x1, %edx
leaq 0x4(%rsp), %rdi
movq %rbx, %rcx
callq 0x3130
leaq 0x128f9(%rip), %rax     # 0x22a50
cmpl $0x0, (%rax)
je 0x10166
movl 0x4(%rsp), %eax
bswapl %eax
movl %eax, 0x4(%rsp)
movl 0x4(%rsp), %eax
movl %eax, 0xc(%rsp)
testl %eax, %eax
jle 0x1026c
xorl %r15d, %r15d
movl $0x4, %esi
movl $0x1, %edx
leaq 0x8(%rsp), %rdi
movq %rbx, %rcx
callq 0x3130
leaq 0x128b9(%rip), %rax     # 0x22a50
cmpl $0x0, (%rax)
je 0x101a6
movl 0x8(%rsp), %eax
bswapl %eax
movl %eax, 0x8(%rsp)
movl 0x8(%rsp), %esi
movq %r13, %rdi
leaq 0x40(%rsp), %rdx
callq 0x10e9c
movq 0x20(%r13), %r14
movl %eax, %r12d
shlq $0x4, %r12
leaq (%r14,%r12), %rbp
addq $0x4, %rbp
movl $0x4, %esi
movl $0x1, %edx
movq %rbp, %rdi
movq %rbx, %rcx
callq 0x3130
leaq 0x1286a(%rip), %rax     # 0x22a50
cmpl $0x0, (%rax)
je 0x101f3
movl (%rbp), %eax
bswapl %eax
movl %eax, (%rbp)
addq %r12, %r14
movl 0x4(%r14), %r12d
movl %r12d, (%r14)
movl %r12d, %edi
shll $0x4, %edi
callq 0x33e0
movq %rax, 0x8(%r14)
movl $0x10, %esi
movq %rax, %rdi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x3130
leaq 0x1282a(%rip), %rax     # 0x22a50
cmpl $0x0, (%rax)
je 0x1025e
movl (%rbp), %eax
testq %rax, %rax
je 0x1025e
movq 0x8(%r14), %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 0x1023d
incl %r15d
cmpl 0xc(%rsp), %r15d
jne 0x10179
movq 0x38(%rsp), %r14
movq %r14, %r13
shlq $0x4, %r13
addq 0x20(%rsp), %r13
movl $0x4, %esi
movl $0x1, %edx
movq %r13, %rdi
movq %rbx, %rcx
callq 0x3130
leaq 0x127b7(%rip), %rax     # 0x22a50
cmpl $0x0, (%rax)
je 0x102a8
movl (%r13), %eax
bswapl %eax
movl %eax, (%r13)
movslq (%r13), %r12
movl %r12d, 0x4(%r13)
movl $0x8, %esi
movq %r12, %rdi
callq 0x32e0
movq %rax, 0x8(%r13)
movl $0x8, %edx
movq %rax, %rdi
movq %r12, %rsi
movq %rbx, %rcx
callq 0x3130
leaq 0x12775(%rip), %rax     # 0x22a50
cmpl $0x0, (%rax)
je 0x10302
movslq (%r13), %rax
testq %rax, %rax
jle 0x10302
movq 0x8(%r13), %rcx
xorl %edx, %edx
movq (%rcx,%rdx,8), %rsi
bswapq %rsi
movq %rsi, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x102ef
incq %r14
cmpq 0x30(%rsp), %r14
jne 0x10119
movq 0x10(%rsp), %r15
addq $0x8, %r15
movl $0x8, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %rbx, %rcx
callq 0x3130
testq %rax, %rax
jne 0x1033a
movq $0x0, (%r15)
leaq 0x1270f(%rip), %rax     # 0x22a50
cmpl $0x0, (%rax)
movq 0x18(%rsp), %r14
je 0x10354
movq (%r15), %rax
bswapq %rax
movq %rax, (%r15)
movq %rbx, %rdi
callq 0x31c0
jmp 0x10361
xorl %r14d, %r14d
movq %r14, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x3c5b
xorl %r14d, %r14d
jmp 0x10354