// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/samtools-0.1.18/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 0xc1988(%rip), %rsi     # 0x35b19a
pushq $0x6
popq %rdx
callq 0x2f1b0
testl %eax, %eax
je 0x299834
leaq 0xc197c(%rip), %rsi     # 0x35b1a1
pushq $0x7
popq %rdx
movq %rbx, %rdi
callq 0x2f1b0
testl %eax, %eax
jne 0x29985c
movq %rbx, %rdi
callq 0x2fe60
cltq
leaq (%rax,%rbx), %rcx
decq %rcx
movq %rcx, %rax
cmpq %rbx, %rcx
jb 0x299856
leaq -0x1(%rax), %rcx
cmpb $0x2f, (%rax)
jne 0x299845
incq %rax
movq %rax, %rbx
movq %rbx, %rdi
callq 0x316c0
movq %rax, %r14
movq %rax, %rdi
callq 0x2fe60
leaq 0x5(%rax), %rdi
pushq $0x1
popq %rsi
callq 0x31f40
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
callq 0x31b50
movq %r15, %rdi
callq 0x2fe60
movl $0x6961622e, (%r15,%rax) # imm = 0x6961622E
movb $0x0, 0x4(%r15,%rax)
leaq 0x95a74(%rip), %rsi     # 0x32f31a
movq %r15, %rdi
callq 0x32660
movq %rax, %r12
testq %rax, %rax
jne 0x299907
leaq 0xc2c76(%rip), %rsi     # 0x35c533
movq %r14, %rdi
callq 0x30a10
movq %rax, %r12
movq %r14, %rdi
callq 0x2fe60
movq %rax, %rbx
addq %r14, %rax
addq $-0x3, %rax
cmpq %rax, %r12
je 0x2998e4
xorl %r12d, %r12d
jmp 0x299907
movq %r15, %rdi
movq %r14, %rsi
callq 0x31b50
movb $0x69, -0x1(%r15,%rbx)
leaq 0x95a1e(%rip), %rsi     # 0x32f31a
movq %r15, %rdi
callq 0x32660
movq %rax, %r12
movq %r15, %rdi
callq 0x33058
movq %r14, %rdi
callq 0x33058
testq %r12, %r12
je 0x299976
leaq 0x44(%rsp), %r14
pushq $0x1
popq %rsi
pushq $0x4
popq %rdx
movq %r14, %rdi
movq %r12, %rcx
callq 0x31380
cmpl $0x1494142, (%r14)      # imm = 0x1494142
jne 0x299bfd
pushq $0x1
popq %r14
pushq $0x20
popq %rsi
movq %r14, %rdi
callq 0x31f40
movq %rax, %rbx
pushq $0x4
popq %rsi
movq %rax, %rdi
movq %r14, %rdx
movq %r12, %rcx
callq 0x31380
leaq 0x17ba17(%rip), %rax    # 0x415380
cmpl $0x0, (%rax)
je 0x29997d
movl (%rbx), %eax
bswapl %eax
movl %eax, (%rbx)
jmp 0x29997f
xorl %eax, %eax
jmp 0x299bee
movl (%rbx), %eax
movslq %eax, %r14
pushq $0x8
popq %rsi
movq %r14, %rdi
callq 0x31f40
movq %rax, 0x20(%rsp)
movq %rax, 0x10(%rbx)
pushq $0x10
popq %rsi
movq %r14, %rdi
callq 0x31f40
movq %rbx, 0x8(%rsp)
movq %rax, 0x18(%rsp)
movq %rax, 0x18(%rbx)
xorl %eax, %eax
testl %r14d, %r14d
cmovlel %eax, %r14d
movq %r14, 0x28(%rsp)
xorl %r15d, %r15d
cmpq 0x28(%rsp), %r15
je 0x299ba9
callq 0x29a69c
movq %rax, %rcx
movq 0x20(%rsp), %rax
movq %r15, 0x30(%rsp)
movq %rcx, 0x38(%rsp)
movq %rcx, (%rax,%r15,8)
leaq 0x14(%rsp), %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %r12, %rcx
callq 0x31380
leaq 0x17b980(%rip), %rax    # 0x415380
cmpl $0x0, (%rax)
movl 0x14(%rsp), %eax
movl %eax, %ecx
bswapl %ecx
cmovel %eax, %ecx
xorl %r13d, %r13d
testl %ecx, %ecx
cmovlel %r13d, %ecx
movl %ecx, 0x10(%rsp)
cmpl 0x10(%rsp), %r13d
je 0x299b09
leaq 0x4(%rsp), %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %r12, %rcx
callq 0x31380
leaq 0x17b940(%rip), %rax    # 0x415380
cmpl $0x0, (%rax)
movl 0x4(%rsp), %esi
je 0x299a4f
bswapl %esi
movl %esi, 0x4(%rsp)
movq 0x38(%rsp), %rbx
movq %rbx, %rdi
leaq 0x40(%rsp), %rdx
callq 0x29a6a7
movq 0x20(%rbx), %r15
movl %eax, %ebx
shlq $0x4, %rbx
leaq (%r15,%rbx), %r14
addq $0x4, %r14
movq %r14, %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %r12, %rbp
movq %r12, %rcx
callq 0x31380
leaq 0x17b8f2(%rip), %rax    # 0x415380
cmpl $0x0, (%rax)
movl (%r14), %r12d
je 0x299a9c
bswapl %r12d
movl %r12d, (%r14)
addq %rbx, %r15
movl %r12d, (%r15)
movl %r12d, %edi
shll $0x4, %edi
callq 0x33048
movq %rax, 0x8(%r15)
movl %r12d, %edx
movq %rax, %rdi
pushq $0x10
popq %rsi
movq %rbp, %r12
movq %rbp, %rcx
callq 0x31380
leaq 0x17b8b4(%rip), %rax    # 0x415380
cmpl $0x0, (%rax)
je 0x299b01
movl (%r14), %eax
shlq $0x4, %rax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x299b01
movq 0x8(%r15), %rdx
movq (%rdx,%rcx), %rsi
movq 0x8(%rdx,%rcx), %rdi
bswapq %rsi
movq %rsi, (%rdx,%rcx)
bswapq %rdi
movq %rdi, 0x8(%rdx,%rcx)
addq $0x10, %rcx
jmp 0x299ada
incl %r13d
jmp 0x299a1b
movq 0x30(%rsp), %r15
movq %r15, %rbp
shlq $0x4, %rbp
addq 0x18(%rsp), %rbp
movq %rbp, %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %r12, %rcx
callq 0x31380
leaq 0x17b84e(%rip), %rax    # 0x415380
cmpl $0x0, (%rax)
je 0x299b41
movl (%rbp), %eax
bswapl %eax
movl %eax, (%rbp)
jmp 0x299b44
movl (%rbp), %eax
movl %eax, 0x4(%rbp)
movslq %eax, %r14
movq %r14, %rdi
pushq $0x8
popq %rbx
movq %rbx, %rsi
callq 0x31f40
movq %rax, 0x8(%rbp)
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movq %r12, %rcx
callq 0x31380
leaq 0x17b80c(%rip), %rax    # 0x415380
cmpl $0x0, (%rax)
je 0x299ba1
movl (%rbp), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x299ba1
movq 0x8(%rbp), %rdx
movq (%rdx,%rcx,8), %rsi
bswapq %rsi
movq %rsi, (%rdx,%rcx,8)
incq %rcx
jmp 0x299b88
incq %r15
jmp 0x2999c0
movq 0x8(%rsp), %r14
addq $0x8, %r14
pushq $0x8
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
movq %r12, %rcx
callq 0x31380
testq %rax, %rax
jne 0x299bcc
andq $0x0, (%r14)
leaq 0x17b7ad(%rip), %rax    # 0x415380
cmpl $0x0, (%rax)
je 0x299be1
movq (%r14), %rax
bswapq %rax
movq %rax, (%r14)
movq %r12, %rdi
callq 0x320a0
movq 0x8(%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1713ac(%rip), %rax    # 0x40afb0
movq (%rax), %rcx
leaq 0xc17d1(%rip), %rdi     # 0x35b3df
pushq $0x25
popq %rsi
pushq $0x1
popq %rdx
callq 0x32760
movq %r12, %rdi
callq 0x320a0
movq $0x0, 0x8(%rsp)
jmp 0x299be1