// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/htslib/hts.c
// Function: hts_idx_save_as
int hts_idx_save_as(const hts_idx_t *idx, const char *fn, const char *fnidx, int fmt)
{
    if (fnidx == NULL) return hts_idx_save(idx, fn, fmt);

    if (fmt == HTS_FMT_CSI) {
        BGZF *fp;
        uint32_t x[3];
        int is_be, i;
        is_be = ed_is_big();
        fp = bgzf_open(fnidx, "w");
        if (fp == NULL) return -1;
        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 = bgzf_open(fnidx, "w");
        if (fp == NULL) return -1;
        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 = fopen(fnidx, "w");
        if (fp == NULL) return -1;
        fwrite("BAI\1", 1, 4, fp);
        hts_idx_save_core(idx, fp, HTS_FMT_BAI);
        fclose(fp);
    } else abort();

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x75706
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x24(%rbp), %edx
callq 0x755d0
movl %eax, -0x4(%rbp)
jmp 0x758e2
cmpl $0x0, -0x24(%rbp)
jne 0x75812
callq 0x72270
movl %eax, -0x40(%rbp)
movq -0x20(%rbp), %rdi
leaq 0x6342b(%rip), %rsi     # 0xd8b4e
callq 0x9afb0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x7573f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x758e2
movq -0x30(%rbp), %rdi
leaq 0x6cb37(%rip), %rsi     # 0xe2281
movl $0x4, %edx
callq 0x9d200
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x40(%rbp)
je 0x757bf
movl $0x0, -0x44(%rbp)
cmpl $0x3, -0x44(%rbp)
jge 0x757bd
movq -0x30(%rbp), %rax
movq %rax, -0x60(%rbp)
movslq -0x44(%rbp), %rax
leaq -0x3c(%rbp), %rdi
shlq $0x2, %rax
addq %rax, %rdi
callq 0x758f0
movq -0x60(%rbp), %rdi
movq %rax, %rsi
movl $0x4, %edx
callq 0x9d200
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x7577f
jmp 0x757d1
movq -0x30(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
movl $0xc, %edx
callq 0x9d200
movq -0x10(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x757f5
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rsi
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %edx
callq 0x9d200
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
xorl %edx, %edx
callq 0x75920
movq -0x30(%rbp), %rdi
callq 0x9d380
jmp 0x758db
cmpl $0x2, -0x24(%rbp)
jne 0x75871
movq -0x20(%rbp), %rdi
leaq 0x6332b(%rip), %rsi     # 0xd8b4e
callq 0x9afb0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x7583f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x758e2
movq -0x50(%rbp), %rdi
leaq 0x6ca3c(%rip), %rsi     # 0xe2286
movl $0x4, %edx
callq 0x9d200
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
movl $0x2, %edx
callq 0x75920
movq -0x50(%rbp), %rdi
callq 0x9d380
jmp 0x758d9
cmpl $0x1, -0x24(%rbp)
jne 0x758d2
movq -0x20(%rbp), %rdi
leaq 0x632cc(%rip), %rsi     # 0xd8b4e
callq 0x6860
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x7589b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x758e2
movq -0x58(%rbp), %rcx
leaq 0x6c9cc(%rip), %rdi     # 0xe2272
movl $0x1, %esi
movl $0x4, %edx
callq 0x6e80
movq -0x10(%rbp), %rdi
movq -0x58(%rbp), %rsi
movl $0x1, %edx
callq 0x75920
movq -0x58(%rbp), %rdi
callq 0x66e0
jmp 0x758d7
callq 0x63b0
jmp 0x758d9
jmp 0x758db
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)