// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/samtools-0.1.18/bam_index.c
// Function: bam_index_save
void bam_index_save(const bam_index_t *idx, FILE *fp)
{
	int32_t i, size;
	khint_t k;
	fwrite("BAI\1", 1, 4, fp);
	if (bam_is_be) {
		uint32_t x = idx->n;
		fwrite(bam_swap_endian_4p(&x), 4, 1, fp);
	} else fwrite(&idx->n, 4, 1, fp);
	for (i = 0; i < idx->n; ++i) {
		khash_t(i) *index = idx->index[i];
		bam_lidx_t *index2 = idx->index2 + i;
		// write binning index
		size = kh_size(index);
		if (bam_is_be) { // big endian
			uint32_t x = size;
			fwrite(bam_swap_endian_4p(&x), 4, 1, fp);
		} else fwrite(&size, 4, 1, fp);
		for (k = kh_begin(index); k != kh_end(index); ++k) {
			if (kh_exist(index, k)) {
				bam_binlist_t *p = &kh_value(index, k);
				if (bam_is_be) { // big endian
					uint32_t x;
					x = kh_key(index, k); fwrite(bam_swap_endian_4p(&x), 4, 1, fp);
					x = p->n; fwrite(bam_swap_endian_4p(&x), 4, 1, fp);
					for (x = 0; (int)x < p->n; ++x) {
						bam_swap_endian_8p(&p->list[x].u);
						bam_swap_endian_8p(&p->list[x].v);
					}
					fwrite(p->list, 16, p->n, fp);
					for (x = 0; (int)x < p->n; ++x) {
						bam_swap_endian_8p(&p->list[x].u);
						bam_swap_endian_8p(&p->list[x].v);
					}
				} else {
					fwrite(&kh_key(index, k), 4, 1, fp);
					fwrite(&p->n, 4, 1, fp);
					fwrite(p->list, 16, p->n, fp);
				}
			}
		}
		// write linear index (index2)
		if (bam_is_be) {
			int x = index2->n;
			fwrite(bam_swap_endian_4p(&x), 4, 1, fp);
		} else fwrite(&index2->n, 4, 1, fp);
		if (bam_is_be) { // big endian
			int x;
			for (x = 0; (int)x < index2->n; ++x)
				bam_swap_endian_8p(&index2->offset[x]);
			fwrite(index2->offset, 8, index2->n, fp);
			for (x = 0; (int)x < index2->n; ++x)
				bam_swap_endian_8p(&index2->offset[x]);
		} else fwrite(index2->offset, 8, index2->n, fp);
	}
	{ // write the number of reads coor-less records.
		uint64_t x = idx->n_no_coor;
		if (bam_is_be) bam_swap_endian_8p(&x);
		fwrite(&x, 8, 1, fp);
	}
	fflush(fp);
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq 0x48(%rsp), %rcx
leaq 0x1080ab(%rip), %rdi    # 0x57a245
movl $0x1, %esi
movl $0x4, %edx
callq 0x33760
leaq 0x195b50(%rip), %rax    # 0x607d00
cmpl $0x0, (%rax)
je 0x4721e3
movq 0x50(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x38(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x472640
movq %rax, %rdi
movq 0x48(%rsp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x33760
jmp 0x4721fc
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x33760
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
movq 0x50(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x4725f2
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x44(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x30(%rsp)
movq 0x50(%rsp), %rax
movq 0x18(%rax), %rax
movslq 0x44(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
movq 0x30(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, 0x40(%rsp)
leaq 0x195aa7(%rip), %rax    # 0x607d00
cmpl $0x0, (%rax)
je 0x472289
movl 0x40(%rsp), %eax
movl %eax, 0x24(%rsp)
leaq 0x24(%rsp), %rdi
callq 0x472640
movq %rax, %rdi
movq 0x48(%rsp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x33760
jmp 0x4722a2
movq 0x48(%rsp), %rcx
leaq 0x40(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x33760
movl $0x0, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
movq 0x30(%rsp), %rcx
cmpl (%rcx), %eax
je 0x4724c3
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x3c(%rsp), %ecx
shrl $0x4, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl 0x3c(%rsp), %ecx
andl $0xf, %ecx
shll %ecx
shrl %cl, %eax
andl $0x3, %eax
cmpl $0x0, %eax
jne 0x4724b1
movq 0x30(%rsp), %rax
movq 0x20(%rax), %rax
movl 0x3c(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, 0x18(%rsp)
leaq 0x1959f9(%rip), %rax    # 0x607d00
cmpl $0x0, (%rax)
je 0x472448
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x3c(%rsp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, 0x14(%rsp)
leaq 0x14(%rsp), %rdi
callq 0x472640
movq %rax, %rdi
movq 0x48(%rsp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x33760
movq 0x18(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, 0x14(%rsp)
leaq 0x14(%rsp), %rdi
callq 0x472640
movq %rax, %rdi
movq 0x48(%rsp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x33760
movl $0x0, 0x14(%rsp)
movl 0x14(%rsp), %eax
movq 0x18(%rsp), %rcx
cmpl 0x4(%rcx), %eax
jae 0x4723cb
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rdi
movl 0x14(%rsp), %eax
shlq $0x4, %rax
addq %rax, %rdi
callq 0x472660
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rdi
movl 0x14(%rsp), %eax
shlq $0x4, %rax
addq %rax, %rdi
addq $0x8, %rdi
callq 0x472660
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x47237a
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x18(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, %edx
movq 0x48(%rsp), %rcx
movl $0x10, %esi
callq 0x33760
movl $0x0, 0x14(%rsp)
movl 0x14(%rsp), %eax
movq 0x18(%rsp), %rcx
cmpl 0x4(%rcx), %eax
jae 0x472446
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rdi
movl 0x14(%rsp), %eax
shlq $0x4, %rax
addq %rax, %rdi
callq 0x472660
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rdi
movl 0x14(%rsp), %eax
shlq $0x4, %rax
addq %rax, %rdi
addq $0x8, %rdi
callq 0x472660
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x4723f5
jmp 0x4724af
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rdi
movl 0x3c(%rsp), %eax
shlq $0x2, %rax
addq %rax, %rdi
movq 0x48(%rsp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x33760
movq 0x18(%rsp), %rdi
addq $0x4, %rdi
movq 0x48(%rsp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x33760
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x18(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, %edx
movq 0x48(%rsp), %rcx
movl $0x10, %esi
callq 0x33760
jmp 0x4724b1
jmp 0x4724b3
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x4722aa
leaq 0x195836(%rip), %rax    # 0x607d00
cmpl $0x0, (%rax)
je 0x4724fd
movq 0x28(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x10(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x472640
movq %rax, %rdi
movq 0x48(%rsp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x33760
jmp 0x472516
movq 0x28(%rsp), %rdi
movq 0x48(%rsp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x33760
leaq 0x1957e3(%rip), %rax    # 0x607d00
cmpl $0x0, (%rax)
je 0x4725c0
movl $0x0, 0xc(%rsp)
movl 0xc(%rsp), %eax
movq 0x28(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x472562
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdi
movslq 0xc(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
callq 0x472660
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x47252e
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x28(%rsp), %rax
movslq (%rax), %rdx
movq 0x48(%rsp), %rcx
movl $0x8, %esi
callq 0x33760
movl $0x0, 0xc(%rsp)
movl 0xc(%rsp), %eax
movq 0x28(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x4725be
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdi
movslq 0xc(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
callq 0x472660
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x47258a
jmp 0x4725e0
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x28(%rsp), %rax
movslq (%rax), %rdx
movq 0x48(%rsp), %rcx
movl $0x8, %esi
callq 0x33760
jmp 0x4725e2
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x472204
movq 0x50(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, (%rsp)
leaq 0x1956fa(%rip), %rax    # 0x607d00
cmpl $0x0, (%rax)
je 0x472613
movq %rsp, %rdi
callq 0x472660
movq 0x48(%rsp), %rcx
movq %rsp, %rdi
movl $0x8, %esi
movl $0x1, %edx
callq 0x33760
movq 0x48(%rsp), %rdi
callq 0x33f50
addq $0x58, %rsp
retq
nopl (%rax)