// File: /workspace/github_c_makefile_star2_O0/DReichLab[P]adna/hts.c
// Function: hts_idx_save
void hts_idx_save(const hts_idx_t *idx, const char *fn, int fmt)
{
	char *fnidx;
	fnidx = (char*)calloc(1, strlen(fn) + 5);
	strcpy(fnidx, fn);
	if (fmt == HTS_FMT_CSI) {
		BGZF *fp;
		uint32_t x[3];
		int is_be, i;
		is_be = ed_is_big();
		fp = bgzf_open(strcat(fnidx, ".csi"), "w");
		bgzf_write(fp, "CSI\1", 4);
		x[0] = idx->min_shift; x[1] = idx->n_lvls; x[2] = idx->l_meta;
		if (is_be) {
			for (i = 0; i < 3; ++i)
				bgzf_write(fp, ed_swap_4p(&x[i]), 4);
		} else bgzf_write(fp, &x, 12);
		if (idx->l_meta) bgzf_write(fp, idx->meta, idx->l_meta);
		hts_idx_save_core(idx, fp, HTS_FMT_CSI);
		bgzf_close(fp);
	} else if (fmt == HTS_FMT_TBI) {
		BGZF *fp;
		fp = bgzf_open(strcat(fnidx, ".tbi"), "w");
		bgzf_write(fp, "TBI\1", 4);
		hts_idx_save_core(idx, fp, HTS_FMT_TBI);
		bgzf_close(fp);
	} else if (fmt == HTS_FMT_BAI) {
		FILE *fp;
		fp = fopen(strcat(fnidx, ".bai"), "w");
		fwrite("BAI\1", 1, 4, fp);
		hts_idx_save_core(idx, fp, HTS_FMT_BAI);
		fclose(fp);
	} else abort();
	free(fnidx);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2150
movq %rax, %rsi
addq $0x5, %rsi
movl $0x1, %edi
callq 0x2200
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2090
cmpl $0x0, -0x14(%rbp)
jne 0x9ca6
callq 0xbc50
movl %eax, -0x38(%rbp)
movq -0x20(%rbp), %rdi
leaq 0x97d8(%rip), %rsi      # 0x13393
callq 0x23b0
movq %rax, %rdi
leaq 0x9547(%rip), %rsi      # 0x13111
callq 0x4790
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
leaq 0x97ba(%rip), %rsi      # 0x13398
movl $0x4, %edx
callq 0x57d0
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x9c53
movl $0x0, -0x3c(%rbp)
cmpl $0x3, -0x3c(%rbp)
jge 0x9c51
movq -0x28(%rbp), %rax
movq %rax, -0x58(%rbp)
movslq -0x3c(%rbp), %rax
leaq -0x34(%rbp), %rdi
shlq $0x2, %rax
addq %rax, %rdi
callq 0x9d80
movq -0x58(%rbp), %rdi
movq %rax, %rsi
movl $0x4, %edx
callq 0x57d0
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x9c13
jmp 0x9c65
movq -0x28(%rbp), %rdi
leaq -0x34(%rbp), %rsi
movl $0xc, %edx
callq 0x57d0
movq -0x8(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x9c89
movq -0x28(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rsi
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %edx
callq 0x57d0
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
xorl %edx, %edx
callq 0x9db0
movq -0x28(%rbp), %rdi
callq 0x5a10
jmp 0x9d6a
cmpl $0x2, -0x14(%rbp)
jne 0x9d01
movq -0x20(%rbp), %rdi
leaq 0x96e6(%rip), %rsi      # 0x1339d
callq 0x23b0
movq %rax, %rdi
leaq 0x944b(%rip), %rsi      # 0x13111
callq 0x4790
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
leaq 0x96c8(%rip), %rsi      # 0x133a2
movl $0x4, %edx
callq 0x57d0
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl $0x2, %edx
callq 0x9db0
movq -0x48(%rbp), %rdi
callq 0x5a10
jmp 0x9d68
cmpl $0x1, -0x14(%rbp)
jne 0x9d61
movq -0x20(%rbp), %rdi
leaq 0x9695(%rip), %rsi      # 0x133a7
callq 0x23b0
movq %rax, %rdi
leaq 0x93f0(%rip), %rsi      # 0x13111
callq 0x2360
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rcx
leaq 0x9677(%rip), %rdi      # 0x133ac
movl $0x1, %esi
movl $0x4, %edx
callq 0x23d0
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
movl $0x1, %edx
callq 0x9db0
movq -0x50(%rbp), %rdi
callq 0x2140
jmp 0x9d66
callq 0x2050
jmp 0x9d68
jmp 0x9d6a
movq -0x20(%rbp), %rdi
callq 0x2040
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)