// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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, "r");
	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, "r");
		}
	}
	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 0xf5b6(%rip), %rsi      # 0x25a56
movl $0x6, %edx
callq 0x31c0
testl %eax, %eax
je 0x164c6
leaq 0xf5a8(%rip), %rsi      # 0x25a5d
movl $0x7, %edx
movq %rbx, %rdi
callq 0x31c0
testl %eax, %eax
jne 0x164ee
movq %rbx, %rdi
callq 0x32d0
cltq
leaq (%rax,%rbx), %rcx
decq %rcx
movq %rcx, %rax
cmpq %rbx, %rcx
jb 0x164e8
leaq -0x1(%rax), %rcx
cmpb $0x2f, (%rax)
jne 0x164d7
incq %rax
movq %rax, %rbx
movq %rbx, %rdi
callq 0x34b0
movq %rax, %r14
movq %rax, %rdi
callq 0x32d0
leaq 0x5(%rax), %rdi
movl $0x1, %esi
callq 0x3530
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
callq 0x3510
movq %r15, %rdi
callq 0x32d0
movl $0x6961622e, (%r15,%rax) # imm = 0x6961622E
movb $0x0, 0x4(%r15,%rax)
leaq 0x10b8d(%rip), %rsi     # 0x270c7
movq %r15, %rdi
callq 0x35f0
movq %rax, %rbx
testq %rax, %rax
jne 0x1659a
leaq 0x10764(%rip), %rsi     # 0x26cb5
movq %r14, %rdi
callq 0x33c0
movq %rax, %r12
movq %r14, %rdi
callq 0x32d0
movq %rax, %rbx
addq %r14, %rax
addq $-0x3, %rax
cmpq %rax, %r12
je 0x16577
xorl %ebx, %ebx
jmp 0x1659a
movq %r15, %rdi
movq %r14, %rsi
callq 0x3510
movb $0x69, -0x1(%r15,%rbx)
leaq 0x10b38(%rip), %rsi     # 0x270c7
movq %r15, %rdi
callq 0x35f0
movq %rax, %rbx
movq %r15, %rdi
callq 0x32c0
movq %r14, %rdi
callq 0x32c0
testq %rbx, %rbx
je 0x16613
leaq 0x44(%rsp), %r14
movl $0x1, %esi
movl $0x4, %edx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x3470
cmpl $0x1494142, (%r14)      # imm = 0x1494142
jne 0x1687f
movl $0x1, %edi
movl $0x18, %esi
callq 0x3530
movq %rax, %r15
movl $0x4, %esi
movl $0x1, %edx
movq %rax, %rdi
movq %rbx, %rcx
callq 0x3470
leaq 0x18d1c(%rip), %rax     # 0x2f320
cmpl $0x0, (%rax)
je 0x1661a
movl (%r15), %ebp
bswapl %ebp
movl %ebp, (%r15)
jmp 0x1661d
xorl %eax, %eax
jmp 0x16870
movl (%r15), %ebp
movslq %ebp, %r14
movl $0x8, %esi
movq %r14, %rdi
callq 0x3530
movq %rax, 0x28(%rsp)
movq %rax, 0x8(%r15)
movl $0x10, %esi
movq %r14, %rdi
callq 0x3530
movq %r15, 0x10(%rsp)
movq %rax, 0x20(%rsp)
movq %rax, 0x10(%r15)
testl %r14d, %r14d
jle 0x16863
movl %ebp, %eax
movq %rax, 0x18(%rsp)
xorl %r14d, %r14d
movl $0x1, %edi
movl $0x28, %esi
callq 0x3530
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %r14, 0x30(%rsp)
movq %rcx, 0x38(%rsp)
movq %rcx, (%rax,%r14,8)
movl $0x4, %esi
movl $0x1, %edx
leaq 0xc(%rsp), %rdi
movq %rbx, %rcx
callq 0x3470
leaq 0x18c79(%rip), %rax     # 0x2f320
cmpl $0x0, (%rax)
movl 0xc(%rsp), %eax
movl %eax, %ecx
bswapl %ecx
cmovel %eax, %ecx
movl %ecx, 0x8(%rsp)
testl %ecx, %ecx
jle 0x167ba
xorl %r14d, %r14d
movl $0x4, %esi
movl $0x1, %edx
leaq 0x4(%rsp), %rdi
movq %rbx, %rcx
callq 0x3470
leaq 0x18c3e(%rip), %rax     # 0x2f320
cmpl $0x0, (%rax)
movl 0x4(%rsp), %esi
je 0x166f1
bswapl %esi
movl %esi, 0x4(%rsp)
movq 0x38(%rsp), %r15
movq %r15, %rdi
leaq 0x40(%rsp), %rdx
callq 0x17327
movq 0x20(%r15), %r12
movl %eax, %ebp
shlq $0x4, %rbp
leaq (%r12,%rbp), %r15
addq $0x4, %r15
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %rbx, %r13
movq %rbx, %rcx
callq 0x3470
leaq 0x18bec(%rip), %rax     # 0x2f320
cmpl $0x0, (%rax)
movl (%r15), %ebx
je 0x16741
bswapl %ebx
movl %ebx, (%r15)
addq %rbp, %r12
movl %ebx, (%r12)
movl %ebx, %edi
shll $0x4, %edi
callq 0x31d0
movq %rax, 0x8(%r12)
movl %ebx, %edx
movl $0x10, %esi
movq %rax, %rdi
movq %r13, %rbx
movq %r13, %rcx
callq 0x3470
leaq 0x18bad(%rip), %rax     # 0x2f320
cmpl $0x0, (%rax)
je 0x167ac
movl (%r15), %eax
testq %rax, %rax
je 0x167ac
movq 0x8(%r12), %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 0x1678b
incl %r14d
cmpl 0x8(%rsp), %r14d
jne 0x166c4
movq 0x30(%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 0x3470
leaq 0x18b39(%rip), %rax     # 0x2f320
cmpl $0x0, (%rax)
je 0x167f8
movl (%r13), %eax
bswapl %eax
movl %eax, (%r13)
jmp 0x167fc
movl (%r13), %eax
movl %eax, 0x4(%r13)
movslq %eax, %r15
movl $0x8, %esi
movq %r15, %rdi
callq 0x3530
movq %rax, 0x8(%r13)
movl $0x8, %edx
movq %rax, %rdi
movq %r15, %rsi
movq %rbx, %rcx
callq 0x3470
leaq 0x18af2(%rip), %rax     # 0x2f320
cmpl $0x0, (%rax)
je 0x16855
movslq (%r13), %rax
testq %rax, %rax
jle 0x16855
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 0x16842
incq %r14
cmpq 0x18(%rsp), %r14
jne 0x16664
movq %rbx, %rdi
callq 0x3560
movq 0x10(%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x46f9
movq $0x0, 0x10(%rsp)
jmp 0x16863