// File: /workspace/github_c_makefile_star2_O1/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, %r15
testq %rdx, %rdx
je 0x100fe
cmpl $0x1, %ebx
leaq 0x3e62d(%rip), %rax     # 0x4e64f
leaq 0x3d08f(%rip), %rsi     # 0x4d0b8
cmoveq %rax, %rsi
movq %rdx, %rdi
callq 0x270a0
movq %rax, %r14
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %r14, %r14
je 0x103c2
movq %r15, 0x8(%rsp)
cmpl $0x2, %ebx
movl %ebx, 0x14(%rsp)
je 0x10116
testl %ebx, %ebx
jne 0x1011f
leaq 0x3e27c(%rip), %rsi     # 0x4e2e3
movl $0x4, %edx
movq %r14, %rdi
callq 0x28994
testq %rax, %rax
js 0x103b5
movq 0x8(%rsp), %rax
movl 0x4(%rax), %eax
movq %rsp, %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x28994
testq %rax, %rax
js 0x103b5
movq 0x8(%rsp), %rax
movl 0x8(%rax), %eax
movq %rsp, %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x28994
testq %rax, %rax
js 0x103b5
movq 0x8(%rsp), %rax
movl 0x10(%rax), %eax
movq %rsp, %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x28994
testq %rax, %rax
js 0x103b5
movq 0x8(%rsp), %rax
movl 0x10(%rax), %edx
testq %rdx, %rdx
je 0x10145
movq 0x8(%rsp), %rax
movq 0x38(%rax), %rsi
jmp 0x10134
movq %r15, %rdi
movl %ebx, %edx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xff3d
leaq 0x3e1cb(%rip), %rsi     # 0x4e2e8
jmp 0x1012f
cmpl $0x1, %ebx
jne 0x103d1
leaq 0x3e1af(%rip), %rsi     # 0x4e2de
movl $0x4, %edx
movq %r14, %rdi
callq 0x28994
testq %rax, %rax
js 0x103b5
movq 0x8(%rsp), %rax
movl 0x14(%rax), %eax
movq %rsp, %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x28994
testq %rax, %rax
js 0x103b5
cmpl $0x2, 0x14(%rsp)
jne 0x10196
movq 0x8(%rsp), %rax
movl 0x10(%rax), %edx
testq %rdx, %rdx
je 0x10196
movq 0x8(%rsp), %rax
movq 0x38(%rax), %rsi
movq %r14, %rdi
callq 0x28994
testq %rax, %rax
js 0x103b5
movq 0x8(%rsp), %rcx
cmpl $0x0, 0x14(%rcx)
jle 0x1038f
xorl %r13d, %r13d
movq 0x28(%rcx), %rax
movq (%rax,%r13,8), %rdx
movl $0x0, %eax
testq %rdx, %rdx
je 0x101bd
movl 0x4(%rdx), %eax
movq %rdx, 0x18(%rsp)
movq %r13, 0x20(%rsp)
shlq $0x4, %r13
addq 0x30(%rcx), %r13
movl %eax, (%rsp)
movl $0x4, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x28994
testq %rax, %rax
js 0x103b5
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0x1031c
cmpl $0x0, (%rax)
je 0x1031c
xorl %r12d, %r12d
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 0x1022e
incl %r12d
movq 0x18(%rsp), %rax
cmpl (%rax), %r12d
jne 0x10205
jmp 0x1031c
movl %r12d, %eax
leaq (%rax,%rax,2), %r15
shlq $0x3, %r15
movq 0x18(%rsp), %rcx
addq 0x20(%rcx), %r15
movq 0x18(%rcx), %rcx
movl (%rcx,%rax,4), %eax
movl %eax, (%rsp)
movl $0x4, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x28994
testq %rax, %rax
js 0x103b5
cmpl $0x0, 0x14(%rsp)
jne 0x1028d
movq 0x8(%r15), %rax
movq %rax, (%rsp)
movl $0x8, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x28994
testq %rax, %rax
js 0x103b5
movl 0x4(%r15), %eax
movl %eax, (%rsp)
movl $0x4, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x28994
testq %rax, %rax
js 0x103b5
cmpl $0x0, 0x4(%r15)
jle 0x1021c
xorl %ebx, %ebx
xorl %ebp, %ebp
movq 0x10(%r15), %rax
movq (%rax,%rbx), %rax
movq %rax, (%rsp)
movl $0x8, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x28994
testq %rax, %rax
js 0x103b5
movq 0x10(%r15), %rax
movq 0x8(%rax,%rbx), %rax
movq %rax, (%rsp)
movl $0x8, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x28994
testq %rax, %rax
js 0x103b5
incq %rbp
movslq 0x4(%r15), %rax
addq $0x10, %rbx
cmpq %rax, %rbp
jl 0x102bc
jmp 0x1021c
cmpl $0x0, 0x14(%rsp)
je 0x10375
movl (%r13), %eax
movl %eax, (%rsp)
movl $0x4, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x28994
testq %rax, %rax
js 0x103b5
cmpl $0x0, (%r13)
jle 0x10375
xorl %ebx, %ebx
movq 0x8(%r13), %rax
movq (%rax,%rbx,8), %rax
movq %rax, (%rsp)
movl $0x8, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x28994
testq %rax, %rax
js 0x103b5
incq %rbx
movslq (%r13), %rax
cmpq %rax, %rbx
jl 0x10348
movq 0x20(%rsp), %r13
incq %r13
movq 0x8(%rsp), %rcx
movslq 0x14(%rcx), %rax
cmpq %rax, %r13
jl 0x101a8
movq 0x20(%rcx), %rax
movq %rsp, %rsi
movq %rax, (%rsi)
movl $0x8, %edx
movq %r14, %rdi
callq 0x28994
testq %rax, %rax
js 0x103b5
movq %r14, %rdi
callq 0x28afa
jmp 0x103c2
movq %r14, %rdi
callq 0x28afa
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3100