// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/samtools-0.1.18/bam_index.c
// Function: bam_index_load_core
static bam_index_t *bam_index_load_core(FILE *fp)
{
	int i;
	char magic[4];
	bam_index_t *idx;
	if (fp == 0) {
		fprintf(stderr, "[bam_index_load_core] fail to load index.\n");
		return 0;
	}
	fread(magic, 1, 4, fp);
	if (strncmp(magic, "BAI\1", 4)) {
		fprintf(stderr, "[bam_index_load] wrong magic number.\n");
		fclose(fp);
		return 0;
	}
	idx = (bam_index_t*)calloc(1, sizeof(bam_index_t));	
	fread(&idx->n, 4, 1, fp);
	if (bam_is_be) bam_swap_endian_4p(&idx->n);
	idx->index = (khash_t(i)**)calloc(idx->n, sizeof(void*));
	idx->index2 = (bam_lidx_t*)calloc(idx->n, sizeof(bam_lidx_t));
	for (i = 0; i < idx->n; ++i) {
		khash_t(i) *index;
		bam_lidx_t *index2 = idx->index2 + i;
		uint32_t key, size;
		khint_t k;
		int j, ret;
		bam_binlist_t *p;
		index = idx->index[i] = kh_init(i);
		// load binning index
		fread(&size, 4, 1, fp);
		if (bam_is_be) bam_swap_endian_4p(&size);
		for (j = 0; j < (int)size; ++j) {
			fread(&key, 4, 1, fp);
			if (bam_is_be) bam_swap_endian_4p(&key);
			k = kh_put(i, index, key, &ret);
			p = &kh_value(index, k);
			fread(&p->n, 4, 1, fp);
			if (bam_is_be) bam_swap_endian_4p(&p->n);
			p->m = p->n;
			p->list = (pair64_t*)malloc(p->m * 16);
			fread(p->list, 16, p->n, fp);
			if (bam_is_be) {
				int x;
				for (x = 0; x < p->n; ++x) {
					bam_swap_endian_8p(&p->list[x].u);
					bam_swap_endian_8p(&p->list[x].v);
				}
			}
		}
		// load linear index
		fread(&index2->n, 4, 1, fp);
		if (bam_is_be) bam_swap_endian_4p(&index2->n);
		index2->m = index2->n;
		index2->offset = (uint64_t*)calloc(index2->m, 8);
		fread(index2->offset, index2->n, 8, fp);
		if (bam_is_be)
			for (j = 0; j < index2->n; ++j) bam_swap_endian_8p(&index2->offset[j]);
	}
	if (fread(&idx->n_no_coor, 8, 1, fp) == 0) idx->n_no_coor = 0;
	if (bam_is_be) bam_swap_endian_8p(&idx->n_no_coor);
	return idx;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
cmpq $0x0, 0x48(%rsp)
jne 0x4728c7
movq 0x189720(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0x107bdd(%rip), %rsi    # 0x57a48f
movb $0x0, %al
callq 0x33960
movq $0x0, 0x50(%rsp)
jmp 0x472ccc
leaq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rcx
movl $0x1, %esi
movl $0x4, %edx
callq 0x32390
leaq 0x40(%rsp), %rdi
leaq 0x107959(%rip), %rsi    # 0x57a245
movl $0x4, %edx
callq 0x301c0
cmpl $0x0, %eax
je 0x47292b
movq 0x1896c6(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0x107bae(%rip), %rsi    # 0x57a4ba
movb $0x0, %al
callq 0x33960
movq 0x48(%rsp), %rdi
callq 0x330b0
movq $0x0, 0x50(%rsp)
jmp 0x472ccc
movl $0x1, %edi
movl $0x20, %esi
callq 0x32f50
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rdi
movq 0x48(%rsp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x32390
leaq 0x1953a1(%rip), %rax    # 0x607d00
cmpl $0x0, (%rax)
je 0x47296e
movq 0x38(%rsp), %rdi
callq 0x472640
movq 0x38(%rsp), %rax
movslq (%rax), %rdi
movl $0x8, %esi
callq 0x32f50
movq %rax, %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x38(%rsp), %rax
movslq (%rax), %rdi
movl $0x10, %esi
callq 0x32f50
movq %rax, %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x18(%rax)
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
movq 0x38(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x472c78
movq 0x38(%rsp), %rax
movq 0x18(%rax), %rax
movslq 0x44(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
callq 0x474130
movq 0x38(%rsp), %rcx
movq 0x10(%rcx), %rcx
movslq 0x44(%rsp), %rdx
movq %rax, (%rcx,%rdx,8)
movq %rax, 0x30(%rsp)
movq 0x48(%rsp), %rcx
leaq 0x20(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x32390
leaq 0x1952e7(%rip), %rax    # 0x607d00
cmpl $0x0, (%rax)
je 0x472a28
leaq 0x20(%rsp), %rdi
callq 0x472640
movl $0x0, 0x18(%rsp)
movl 0x18(%rsp), %eax
cmpl 0x20(%rsp), %eax
jge 0x472b9f
movq 0x48(%rsp), %rcx
leaq 0x24(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x32390
leaq 0x1952a2(%rip), %rax    # 0x607d00
cmpl $0x0, (%rax)
je 0x472a6d
leaq 0x24(%rsp), %rdi
callq 0x472640
movq 0x30(%rsp), %rdi
movl 0x24(%rsp), %esi
leaq 0x14(%rsp), %rdx
callq 0x474150
movl %eax, 0x1c(%rsp)
movq 0x30(%rsp), %rax
movq 0x20(%rax), %rax
movl 0x1c(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
addq $0x4, %rdi
movq 0x48(%rsp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x32390
leaq 0x19523f(%rip), %rax    # 0x607d00
cmpl $0x0, (%rax)
je 0x472ad4
movq 0x8(%rsp), %rdi
addq $0x4, %rdi
callq 0x472640
movq 0x8(%rsp), %rax
movl 0x4(%rax), %ecx
movq 0x8(%rsp), %rax
movl %ecx, (%rax)
movq 0x8(%rsp), %rax
movl (%rax), %eax
shll $0x4, %eax
movl %eax, %eax
movl %eax, %edi
callq 0x34068
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x8(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, %edx
movq 0x48(%rsp), %rcx
movl $0x10, %esi
callq 0x32390
leaq 0x1951d5(%rip), %rax    # 0x607d00
cmpl $0x0, (%rax)
je 0x472b8d
movl $0x0, 0x4(%rsp)
movl 0x4(%rsp), %eax
movq 0x8(%rsp), %rcx
cmpl 0x4(%rcx), %eax
jae 0x472b8b
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
movslq 0x4(%rsp), %rax
shlq $0x4, %rax
addq %rax, %rdi
callq 0x472660
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
movslq 0x4(%rsp), %rax
shlq $0x4, %rax
addq %rax, %rdi
addq $0x8, %rdi
callq 0x472660
movl 0x4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4(%rsp)
jmp 0x472b38
jmp 0x472b8d
jmp 0x472b8f
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x472a30
movq 0x28(%rsp), %rdi
movq 0x48(%rsp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x32390
leaq 0x195141(%rip), %rax    # 0x607d00
cmpl $0x0, (%rax)
je 0x472bce
movq 0x28(%rsp), %rdi
callq 0x472640
movq 0x28(%rsp), %rax
movl (%rax), %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x4(%rax)
movq 0x28(%rsp), %rax
movslq 0x4(%rax), %rdi
movl $0x8, %esi
callq 0x32f50
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x28(%rsp), %rax
movslq (%rax), %rsi
movq 0x48(%rsp), %rcx
movl $0x8, %edx
callq 0x32390
leaq 0x1950dd(%rip), %rax    # 0x607d00
cmpl $0x0, (%rax)
je 0x472c66
movl $0x0, 0x18(%rsp)
movl 0x18(%rsp), %eax
movq 0x28(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x472c64
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdi
movslq 0x18(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
callq 0x472660
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x472c30
jmp 0x472c66
jmp 0x472c68
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x4729b2
movq 0x38(%rsp), %rdi
addq $0x8, %rdi
movq 0x48(%rsp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x32390
cmpq $0x0, %rax
jne 0x472ca8
movq 0x38(%rsp), %rax
movq $0x0, 0x8(%rax)
leaq 0x195051(%rip), %rax    # 0x607d00
cmpl $0x0, (%rax)
je 0x472cc2
movq 0x38(%rsp), %rdi
addq $0x8, %rdi
callq 0x472660
movq 0x38(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)