// File: /workspace/github_cpp_makefile_star2_O1/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 0x10987(%rip), %rsi     # 0x26965
movl $0x6, %edx
callq 0x31c0
testl %eax, %eax
je 0x16004
leaq 0x10979(%rip), %rsi     # 0x2696c
movl $0x7, %edx
movq %rbx, %rdi
callq 0x31c0
testl %eax, %eax
jne 0x1602c
movq %rbx, %rdi
callq 0x32d0
cltq
leaq (%rax,%rbx), %rcx
decq %rcx
movq %rcx, %rax
cmpq %rbx, %rcx
jb 0x16026
leaq -0x1(%rax), %rcx
cmpb $0x2f, (%rax)
jne 0x16015
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 0x11f4f(%rip), %rsi     # 0x27fc7
movq %r15, %rdi
callq 0x35f0
movq %rax, %rbx
testq %rax, %rax
jne 0x160dd
leaq 0x11b26(%rip), %rsi     # 0x27bb5
movq %r14, %rdi
callq 0x33c0
movq %rax, %rbx
movq %r14, %rdi
callq 0x32d0
addq %r14, %rax
addq $-0x3, %rax
cmpq %rax, %rbx
je 0x160b2
xorl %ebx, %ebx
jmp 0x160dd
movq %r15, %rdi
movq %r14, %rsi
callq 0x3510
movq %r14, %rdi
callq 0x32d0
movb $0x69, -0x1(%r15,%rax)
leaq 0x11ef5(%rip), %rsi     # 0x27fc7
movq %r15, %rdi
callq 0x35f0
movq %rax, %rbx
movq %r15, %rdi
callq 0x32c0
movq %r14, %rdi
callq 0x32c0
testq %rbx, %rbx
je 0x163ab
leaq 0x44(%rsp), %r14
movl $0x1, %esi
movl $0x4, %edx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x3470
cmpl $0x1494142, (%r14)      # imm = 0x1494142
jne 0x163c0
movl $0x1, %edi
movl $0x18, %esi
callq 0x3530
movq %rax, %r14
movl $0x4, %esi
movl $0x1, %edx
movq %rax, %rdi
movq %rbx, %rcx
callq 0x3470
leaq 0x1a1d5(%rip), %rax     # 0x30320
cmpl $0x0, (%rax)
je 0x16158
movl (%r14), %eax
bswapl %eax
movl %eax, (%r14)
movslq (%r14), %r15
movl $0x8, %esi
movq %r15, %rdi
callq 0x3530
movq %rax, 0x28(%rsp)
movq %rax, 0x8(%r14)
movl $0x10, %esi
movq %r15, %rdi
callq 0x3530
movq %rax, 0x20(%rsp)
movq %rax, 0x10(%r14)
movq %r15, 0x30(%rsp)
testq %r15, %r15
jle 0x163a1
movq %r14, 0x18(%rsp)
xorl %r14d, %r14d
movl $0x1, %edi
movl $0x28, %esi
callq 0x3530
movq %rax, %r12
movq 0x28(%rsp), %rax
movq %r14, 0x38(%rsp)
movq %r12, (%rax,%r14,8)
movl $0x4, %esi
movl $0x1, %edx
leaq 0xc(%rsp), %rdi
movq %rbx, %rcx
callq 0x3470
leaq 0x1a145(%rip), %rax     # 0x30320
cmpl $0x0, (%rax)
je 0x161ea
movl 0xc(%rsp), %eax
bswapl %eax
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %eax
movl %eax, 0x14(%rsp)
testl %eax, %eax
jle 0x162f5
xorl %r14d, %r14d
movl $0x4, %esi
movl $0x1, %edx
leaq 0x10(%rsp), %rdi
movq %rbx, %rcx
callq 0x3470
leaq 0x1a105(%rip), %rax     # 0x30320
cmpl $0x0, (%rax)
je 0x1622a
movl 0x10(%rsp), %eax
bswapl %eax
movl %eax, 0x10(%rsp)
movl 0x10(%rsp), %esi
movq %r12, %rdi
leaq 0x40(%rsp), %rdx
callq 0x16b94
movq 0x20(%r12), %rbp
movl %eax, %r15d
shlq $0x4, %r15
leaq (%r15,%rbp), %r13
addq $0x4, %r13
movl $0x4, %esi
movl $0x1, %edx
movq %r13, %rdi
movq %rbx, %rcx
callq 0x3470
leaq 0x1a0b5(%rip), %rax     # 0x30320
cmpl $0x0, (%rax)
je 0x1627a
movl (%r13), %eax
bswapl %eax
movl %eax, (%r13)
addq %r15, %rbp
movl 0x4(%rbp), %r15d
movl %r15d, (%rbp)
movl %r15d, %edi
shll $0x4, %edi
callq 0x31d0
movq %rax, 0x8(%rbp)
movl $0x10, %esi
movq %rax, %rdi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x3470
leaq 0x1a072(%rip), %rax     # 0x30320
cmpl $0x0, (%rax)
je 0x162e7
movl (%r13), %eax
testq %rax, %rax
je 0x162e7
movq 0x8(%rbp), %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 0x162c6
incl %r14d
cmpl 0x14(%rsp), %r14d
jne 0x161fd
movq 0x38(%rsp), %r14
movq %r14, %r12
shlq $0x4, %r12
addq 0x20(%rsp), %r12
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %rbx, %rcx
callq 0x3470
leaq 0x19ffe(%rip), %rax     # 0x30320
cmpl $0x0, (%rax)
je 0x16331
movl (%r12), %eax
bswapl %eax
movl %eax, (%r12)
movslq (%r12), %r15
movl %r15d, 0x4(%r12)
movl $0x8, %esi
movq %r15, %rdi
callq 0x3530
movq %rax, 0x8(%r12)
movl $0x8, %edx
movq %rax, %rdi
movq %r15, %rsi
movq %rbx, %rcx
callq 0x3470
leaq 0x19fba(%rip), %rax     # 0x30320
cmpl $0x0, (%rax)
je 0x1638e
movslq (%r12), %rax
testq %rax, %rax
jle 0x1638e
movq 0x8(%r12), %rcx
xorl %edx, %edx
movq (%rcx,%rdx,8), %rsi
bswapq %rsi
movq %rsi, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x1637b
incq %r14
cmpq 0x30(%rsp), %r14
jne 0x1619d
movq 0x18(%rsp), %r14
movq %rbx, %rdi
callq 0x3560
jmp 0x163ae
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 0x4458
xorl %r14d, %r14d
jmp 0x163a1