// File: /workspace/github_c_makefile_star2_O2/zhou-lab[P]tbmate/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)
{
    BGZF *fp;

    #define check(ret) if ((ret) < 0) goto fail

    if (fnidx == NULL) return hts_idx_save(idx, fn, fmt);

    fp = bgzf_open(fnidx, (fmt == HTS_FMT_BAI)? "wu" : "w");
    if (fp == NULL) return -1;

    if (fmt == HTS_FMT_CSI) {
        check(bgzf_write(fp, "CSI\1", 4));
        check(idx_write_int32(fp, idx->min_shift));
        check(idx_write_int32(fp, idx->n_lvls));
        check(idx_write_uint32(fp, idx->l_meta));
        if (idx->l_meta) check(bgzf_write(fp, idx->meta, idx->l_meta));
    } else if (fmt == HTS_FMT_TBI) {
        check(bgzf_write(fp, "TBI\1", 4));
    } else if (fmt == HTS_FMT_BAI) {
        check(bgzf_write(fp, "BAI\1", 4));
    } else abort();

    check(hts_idx_save_core(idx, fp, fmt));

    return bgzf_close(fp);
    #undef check

fail:
    bgzf_close(fp);
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, %ebx
movq %rdi, %r14
testq %rdx, %rdx
je 0xcc85
cmpl $0x1, %ebx
leaq 0x33ae3(%rip), %rax     # 0x406b1
leaq 0x324e3(%rip), %rsi     # 0x3f0b8
cmoveq %rax, %rsi
movq %rdx, %rdi
callq 0x1fde4
testq %rax, %rax
je 0xceaf
movq %rax, %r15
movq %r14, 0x8(%rsp)
cmpl $0x2, %ebx
movl %ebx, 0x14(%rsp)
je 0xcc9d
testl %ebx, %ebx
jne 0xcca6
leaq 0x33732(%rip), %rsi     # 0x40340
pushq $0x4
popq %rdx
movq %r15, %rdi
callq 0x215ef
testq %rax, %rax
js 0xcea7
movq 0x8(%rsp), %rax
movl 0x4(%rax), %esi
movq %r15, %rdi
callq 0xcec6
testq %rax, %rax
js 0xcea7
movq 0x8(%rsp), %rax
movl 0x8(%rax), %esi
movq %r15, %rdi
callq 0xcec6
testq %rax, %rax
js 0xcea7
movq 0x8(%rsp), %rax
movl 0x10(%rax), %esi
movq %r15, %rdi
callq 0xcedb
testq %rax, %rax
js 0xcea7
movq 0x8(%rsp), %rax
movl 0x10(%rax), %edx
testq %rdx, %rdx
je 0xccca
movq 0x8(%rsp), %rax
movq 0x38(%rax), %rsi
jmp 0xccb9
movq %r14, %rdi
movl %ebx, %edx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xcaed
leaq 0x336a1(%rip), %rsi     # 0x40345
jmp 0xccb6
cmpl $0x1, %ebx
jne 0xcec1
leaq 0x33685(%rip), %rsi     # 0x4033b
pushq $0x4
popq %rdx
movq %r15, %rdi
callq 0x215ef
testq %rax, %rax
js 0xcea7
movq 0x8(%rsp), %rax
movl 0x14(%rax), %esi
movq %r15, %rdi
callq 0xcec6
testq %rax, %rax
js 0xcea7
cmpl $0x2, 0x14(%rsp)
jne 0xcd11
movq 0x8(%rsp), %rax
movl 0x10(%rax), %edx
testq %rdx, %rdx
je 0xcd11
movq 0x8(%rsp), %rax
movq 0x38(%rax), %rsi
movq %r15, %rdi
callq 0x215ef
testq %rax, %rax
js 0xcea7
xorl %ebp, %ebp
movq 0x8(%rsp), %rcx
movslq 0x14(%rcx), %rax
cmpq %rax, %rbp
jge 0xce80
movq 0x28(%rcx), %rax
movq (%rax,%rbp,8), %rax
testq %rax, %rax
movq %rax, 0x18(%rsp)
je 0xcd3c
movl 0x4(%rax), %esi
jmp 0xcd3e
xorl %esi, %esi
movq %rbp, 0x20(%rsp)
shlq $0x4, %rbp
addq 0x30(%rcx), %rbp
movq %r15, %rdi
callq 0xcec6
testq %rax, %rax
js 0xcea7
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0xce37
xorl %r12d, %r12d
cmpl (%rax), %r12d
je 0xce37
movq 0x10(%rax), %rax
movl %r12d, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %eax
leal (%r12,%r12), %ecx
shrl %cl, %eax
testb $0x3, %al
je 0xcd97
incl %r12d
movq 0x18(%rsp), %rax
jmp 0xcd6d
movl %r12d, %eax
imulq $0x18, %rax, %r14
movq 0x18(%rsp), %rcx
addq 0x20(%rcx), %r14
movq 0x18(%rcx), %rcx
movl (%rcx,%rax,4), %esi
movq %r15, %rdi
callq 0xcedb
testq %rax, %rax
js 0xcea7
cmpl $0x0, 0x14(%rsp)
jne 0xcddb
movq 0x8(%r14), %rsi
movq %r15, %rdi
callq 0xe572
testq %rax, %rax
js 0xcea7
movl 0x4(%r14), %esi
movq %r15, %rdi
callq 0xcec6
testq %rax, %rax
js 0xcea7
pushq $-0x1
popq %r13
xorl %ebx, %ebx
movslq 0x4(%r14), %rax
incq %r13
cmpq %rax, %r13
jge 0xcd8d
movq 0x10(%r14), %rax
movq (%rax,%rbx), %rsi
movq %r15, %rdi
callq 0xe572
testq %rax, %rax
js 0xcea7
movq 0x10(%r14), %rax
movq 0x8(%rax,%rbx), %rsi
addq $0x10, %rbx
movq %r15, %rdi
callq 0xe572
testq %rax, %rax
jns 0xcdf6
jmp 0xcea7
cmpl $0x0, 0x14(%rsp)
je 0xce73
movl (%rbp), %esi
movq %r15, %rdi
callq 0xcec6
testq %rax, %rax
js 0xcea7
xorl %ebx, %ebx
movslq (%rbp), %rax
cmpq %rax, %rbx
jge 0xce73
movq 0x8(%rbp), %rax
movq (%rax,%rbx,8), %rsi
movq %r15, %rdi
callq 0xe572
incq %rbx
testq %rax, %rax
jns 0xce50
jmp 0xcea7
movq 0x20(%rsp), %rbp
incq %rbp
jmp 0xcd13
movq 0x20(%rcx), %rsi
movq %r15, %rdi
callq 0xe572
testq %rax, %rax
js 0xcea7
movq %r15, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x216cc
movq %r15, %rdi
callq 0x216cc
pushq $-0x1
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3100