// File: /workspace/github_c_makefile_star2_O0/DReichLab[P]adna/hts.c
// Function: hts_idx_save_core
static void hts_idx_save_core(const hts_idx_t *idx, void *fp, int fmt)
{
	int32_t i, size, is_be;
	int is_bgzf = (fmt != HTS_FMT_BAI);
	is_be = ed_is_big();
	if (is_be) {
		uint32_t x = idx->n;
		idx_write(is_bgzf, fp, ed_swap_4p(&x), 4);
	} else idx_write(is_bgzf, fp, &idx->n, 4);
	if (fmt == HTS_FMT_TBI && idx->l_meta) idx_write(is_bgzf, fp, idx->meta, idx->l_meta);
	for (i = 0; i < idx->n; ++i) {
		khint_t k;
		bidx_t *bidx = idx->bidx[i];
		lidx_t *lidx = &idx->lidx[i];
		// write binning index
		size = bidx? kh_size(bidx) : 0;
		if (is_be) { // big endian
			uint32_t x = size;
			idx_write(is_bgzf, fp, ed_swap_4p(&x), 4);
		} else idx_write(is_bgzf, fp, &size, 4);
		if (bidx == 0) goto write_lidx;
		for (k = kh_begin(bidx); k != kh_end(bidx); ++k) {
			hts_bin_t *p;
			if (!kh_exist(bidx, k)) continue;
			p = &kh_value(bidx, k);
			if (is_be) { // big endian
				uint32_t x;
				x = kh_key(bidx, k); idx_write(is_bgzf, fp, ed_swap_4p(&x), 4);
				if (fmt == HTS_FMT_CSI) {
					uint64_t y = kh_val(bidx, k).loff;
					idx_write(is_bgzf, fp, ed_swap_4p(&y), 8);
				}
				x = p->n; idx_write(is_bgzf, fp, ed_swap_4p(&x), 4);
				swap_bins(p);
				idx_write(is_bgzf, fp, p->list, 16 * p->n);
				swap_bins(p);
			} else {
				idx_write(is_bgzf, fp, &kh_key(bidx, k), 4);
				if (fmt == HTS_FMT_CSI) idx_write(is_bgzf, fp, &kh_val(bidx, k).loff, 8);
				//int j;for(j=0;j<p->n;++j)fprintf(stderr,"%d,%llx,%d,%llx:%llx\n",kh_key(bidx,k),kh_val(bidx, k).loff,j,p->list[j].u,p->list[j].v);
				idx_write(is_bgzf, fp, &p->n, 4);
				idx_write(is_bgzf, fp, p->list, p->n << 4);
			}
		}
write_lidx:
		if (fmt != HTS_FMT_CSI) {
			if (is_be) {
				int32_t x = lidx->n;
				idx_write(is_bgzf, fp, ed_swap_4p(&x), 4);
				for (x = 0; x < lidx->n; ++x) ed_swap_8p(&lidx->offset[x]);
				idx_write(is_bgzf, fp, lidx->offset, lidx->n << 3);
				for (x = 0; x < lidx->n; ++x) ed_swap_8p(&lidx->offset[x]);
			} else {
				idx_write(is_bgzf, fp, &lidx->n, 4);
				idx_write(is_bgzf, fp, lidx->offset, lidx->n << 3);
			}
		}
	}
	if (is_be) { // write the number of reads without coordinates
		uint64_t x = idx->n_no_coor;
		idx_write(is_bgzf, fp, &x, 8);
	} else idx_write(is_bgzf, fp, &idx->n_no_coor, 8);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
cmpl $0x1, -0x14(%rbp)
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x24(%rbp)
callq 0xbc50
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0x9e1a
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x7c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x9d80
movl -0x7c(%rbp), %edi
movq -0x78(%rbp), %rsi
movq %rax, %rdx
movl $0x4, %ecx
callq 0xc580
jmp 0x9e33
movl -0x24(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x8(%rbp), %rdx
addq $0x14, %rdx
movl $0x4, %ecx
callq 0xc580
cmpl $0x2, -0x14(%rbp)
jne 0x9e60
movq -0x8(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x9e60
movl -0x24(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdx
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %ecx
callq 0xc580
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0xa263
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x9eb5
movq -0x38(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x80(%rbp)
jmp 0x9ebc
xorl %eax, %eax
movl %eax, -0x80(%rbp)
jmp 0x9ebc
movl -0x80(%rbp), %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0x9f07
movl -0x1c(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x8c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq -0x44(%rbp), %rdi
callq 0x9d80
movl -0x8c(%rbp), %edi
movq -0x88(%rbp), %rsi
movq %rax, %rdx
movl $0x4, %ecx
callq 0xc580
jmp 0x9f1c
movl -0x24(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq -0x1c(%rbp), %rdx
movl $0x4, %ecx
callq 0xc580
cmpq $0x0, -0x38(%rbp)
jne 0x9f28
jmp 0xa13c
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl (%rcx), %eax
je 0xa13a
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
shrl $0x4, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl -0x2c(%rbp), %ecx
andl $0xf, %ecx
shll %ecx
shrl %cl, %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0x9f68
jmp 0xa12c
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0xa0a0
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x2c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x54(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x9c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x98(%rbp)
leaq -0x54(%rbp), %rdi
callq 0x9d80
movl -0x9c(%rbp), %edi
movq -0x98(%rbp), %rsi
movq %rax, %rdx
movl $0x4, %ecx
callq 0xc580
cmpl $0x0, -0x14(%rbp)
jne 0xa027
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0xac(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x9d80
movl -0xac(%rbp), %edi
movq -0xa8(%rbp), %rsi
movq %rax, %rdx
movl $0x8, %ecx
callq 0xc580
movq -0x50(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x54(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0xbc(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0x54(%rbp), %rdi
callq 0x9d80
movl -0xbc(%rbp), %edi
movq -0xb8(%rbp), %rsi
movq %rax, %rdx
movl $0x4, %ecx
callq 0xc580
movq -0x50(%rbp), %rdi
callq 0xc5e0
movl -0x24(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x50(%rbp), %rax
movl 0x4(%rax), %eax
shll $0x4, %eax
movslq %eax, %rcx
callq 0xc580
movq -0x50(%rbp), %rdi
callq 0xc5e0
jmp 0xa12a
movl -0x24(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdx
movl -0x2c(%rbp), %eax
shlq $0x2, %rax
addq %rax, %rdx
movl $0x4, %ecx
callq 0xc580
cmpl $0x0, -0x14(%rbp)
jne 0xa0f0
movl -0x24(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rdx
movl -0x2c(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rdx
addq $0x8, %rdx
movl $0x8, %ecx
callq 0xc580
movl -0x24(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq $0x4, %rdx
movl $0x4, %ecx
callq 0xc580
movl -0x24(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x50(%rbp), %rax
movl 0x4(%rax), %eax
shll $0x4, %eax
movslq %eax, %rcx
callq 0xc580
jmp 0xa12c
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x9f2f
jmp 0xa13c
cmpl $0x0, -0x14(%rbp)
je 0xa253
cmpl $0x0, -0x20(%rbp)
je 0xa21c
movq -0x40(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x64(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0xcc(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xc8(%rbp)
leaq -0x64(%rbp), %rdi
callq 0x9d80
movl -0xcc(%rbp), %edi
movq -0xc8(%rbp), %rsi
movq %rax, %rdx
movl $0x4, %ecx
callq 0xc580
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl (%rcx), %eax
jge 0xa1c5
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
movslq -0x64(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
callq 0xc650
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0xa197
movl -0x24(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x40(%rbp), %rax
movl (%rax), %eax
shll $0x3, %eax
movslq %eax, %rcx
callq 0xc580
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl (%rcx), %eax
jge 0xa21a
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
movslq -0x64(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
callq 0xc650
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0xa1ec
jmp 0xa251
movl -0x24(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x40(%rbp), %rdx
movl $0x4, %ecx
callq 0xc580
movl -0x24(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x40(%rbp), %rax
movl (%rax), %eax
shll $0x3, %eax
movslq %eax, %rcx
callq 0xc580
jmp 0xa253
jmp 0xa255
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x9e67
cmpl $0x0, -0x20(%rbp)
je 0xa28c
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x70(%rbp)
movl -0x24(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq -0x70(%rbp), %rdx
movl $0x8, %ecx
callq 0xc580
jmp 0xa2a5
movl -0x24(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x8(%rbp), %rdx
addq $0x20, %rdx
movl $0x8, %ecx
callq 0xc580
addq $0xd0, %rsp
popq %rbp
retq
nop