// File: /workspace/github_c_makefile_star2_O2/DReichLab[P]adna/hts.c
// Function: hts_idx_load_direct
hts_idx_t *hts_idx_load_direct(const char *fn, int fmt)
{
	uint8_t magic[4];
	int i, is_be;
	hts_idx_t *idx;
	is_be = ed_is_big();
	if (fmt == HTS_FMT_CSI) {
		BGZF *fp;
		uint32_t x[3], n;
		uint8_t *meta = 0;
		if ((fp = bgzf_open(fn, "r")) == 0) return 0;
		bgzf_read(fp, magic, 4);
		bgzf_read(fp, x, 12);
		if (is_be) for (i = 0; i < 3; ++i) ed_swap_4p(&x[i]);
		if (x[2]) {
			meta = (uint8_t*)malloc(x[2]);
			bgzf_read(fp, meta, x[2]);
		}
		bgzf_read(fp, &n, 4);
		if (is_be) ed_swap_4p(&n);
		idx = hts_idx_init(n, fmt, 0, x[0], x[1]);
		idx->l_meta = x[2];
		idx->meta = meta;
		hts_idx_load_core(idx, fp, HTS_FMT_CSI);
		bgzf_close(fp);
	} else if (fmt == HTS_FMT_TBI) {
		BGZF *fp;
		uint32_t x[8];
		if ((fp = bgzf_open(fn, "r")) == 0) return 0;
		bgzf_read(fp, magic, 4);
		bgzf_read(fp, x, 32);
		if (is_be) for (i = 0; i < 8; ++i) ed_swap_4p(&x[i]);
		idx = hts_idx_init(x[0], fmt, 0, 14, 5);
		idx->l_meta = 28 + x[7];
		idx->meta = (uint8_t*)malloc(idx->l_meta);
		memcpy(idx->meta, &x[1], 28);
		bgzf_read(fp, idx->meta + 28, x[7]);
		hts_idx_load_core(idx, fp, HTS_FMT_TBI);
		bgzf_close(fp);
	} else if (fmt == HTS_FMT_BAI) {
		uint32_t n;
#ifdef _USE_KURL
		kurl_t *fp;
		if ((fp = kurl_open(fn, 0)) == 0) return 0;
		kurl_read(fp, magic, 4);
		kurl_read(fp, &n, 4);
#else
		FILE *fp;
		if ((fp = fopen(fn, "rb")) == 0) return 0;
		fread(magic, 1, 4, fp);
		fread(&n, 4, 1, fp);
#endif
		if (is_be) ed_swap_4p(&n);
		idx = hts_idx_init(n, fmt, 0, 14, 5);
		hts_idx_load_core(idx, fp, HTS_FMT_BAI);
#ifdef _USE_KURL
		kurl_close(fp);
#else
		fclose(fp);
#endif
	} else abort();
	return idx;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x30, %rsp
cmpl $0x2, %esi
je 0x68a9
cmpl $0x1, %esi
je 0x682d
testl %esi, %esi
jne 0x6999
leaq 0x613f(%rip), %rsi      # 0xc90e
callq 0x36d8
testq %rax, %rax
je 0x6938
movq %rax, %r14
leaq 0x8(%rsp), %rsi
pushq $0x4
popq %rdx
movq %rax, %rdi
callq 0x3a53
leaq 0x10(%rsp), %rbx
pushq $0xc
popq %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3a53
movl 0x8(%rbx), %ebx
testq %rbx, %rbx
je 0x693c
movq %rbx, %rdi
callq 0x22a0
movq %rax, %r15
movq %r14, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x3a53
jmp 0x693f
leaq 0x5b0c(%rip), %rsi      # 0xc340
callq 0x2360
testq %rax, %rax
je 0x6938
movq %rax, %r14
leaq 0x8(%rsp), %rdi
pushq $0x1
popq %rbx
pushq $0x4
popq %r15
movq %rbx, %rsi
movq %r15, %rdx
movq %rax, %rcx
callq 0x20e0
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x20e0
movl (%r12), %edi
pushq $0x1
popq %rbp
pushq $0xe
popq %rcx
pushq $0x5
popq %r8
movl %ebp, %esi
xorl %edx, %edx
callq 0x589f
movq %rax, %rbx
movq %rax, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x699e
movq %r14, %rdi
callq 0x2140
jmp 0x6989
leaq 0x605e(%rip), %rsi      # 0xc90e
callq 0x36d8
testq %rax, %rax
je 0x6938
movq %rax, %r14
leaq 0x8(%rsp), %rsi
pushq $0x4
popq %rdx
movq %rax, %rdi
callq 0x3a53
leaq 0x10(%rsp), %r15
pushq $0x20
popq %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x3a53
movl (%r15), %edi
pushq $0x2
popq %rbp
pushq $0xe
popq %rcx
pushq $0x5
popq %r8
movl %ebp, %esi
xorl %edx, %edx
callq 0x589f
movq %rax, %rbx
movl 0x1c(%r15), %r12d
leal 0x1c(%r12), %edi
movl %edi, 0x10(%rax)
callq 0x22a0
movq %rax, 0x38(%rbx)
movups 0x4(%r15), %xmm0
movups 0x10(%r15), %xmm1
movups %xmm0, (%rax)
movups %xmm1, 0xc(%rax)
leaq 0x1c(%rax), %rsi
movq %r14, %rdi
movq %r12, %rdx
callq 0x3a53
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %edx
jmp 0x697c
xorl %ebx, %ebx
jmp 0x6989
xorl %r15d, %r15d
leaq 0xc(%rsp), %rbx
pushq $0x4
popq %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3a53
movl (%rbx), %edi
movl 0x10(%rsp), %ecx
movl 0x14(%rsp), %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x589f
movq %rax, %rbx
movl 0x18(%rsp), %eax
movl %eax, 0x10(%rbx)
movq %r15, 0x38(%rbx)
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x699e
movq %r14, %rdi
callq 0x3fbb
movq %rbx, %rax
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x2060