// File: /workspace/github_c_makefile_star2_O3/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, %ebp
movq %rdi, %rbx
testq %rdx, %rdx
je 0x1041d
cmpl $0x1, %ebp
leaq 0x3e37e(%rip), %rax     # 0x4e6c3
leaq 0x3cd6c(%rip), %rsi     # 0x4d0b8
cmoveq %rax, %rsi
movq %rdx, %rdi
callq 0x26f1c
movq %rax, %r14
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %r14, %r14
je 0x10703
movq %rbx, 0x8(%rsp)
cmpl $0x2, %ebp
je 0x10435
testl %ebp, %ebp
jne 0x1043e
leaq 0x3dfd1(%rip), %rsi     # 0x4e357
movl $0x4, %edx
movq %r14, %rdi
callq 0x28836
testq %rax, %rax
js 0x106f6
movq 0x8(%rsp), %rax
movl 0x4(%rax), %eax
movq %rsp, %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x28836
testq %rax, %rax
js 0x106f6
movq 0x8(%rsp), %rax
movl 0x8(%rax), %eax
movq %rsp, %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x28836
testq %rax, %rax
js 0x106f6
movq 0x8(%rsp), %rax
movl 0x10(%rax), %eax
movq %rsp, %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x28836
testq %rax, %rax
js 0x106f6
movq 0x8(%rsp), %rax
movl 0x10(%rax), %edx
testq %rdx, %rdx
je 0x10464
movq 0x8(%rsp), %rax
movq 0x38(%rax), %rsi
jmp 0x10453
movq %rbx, %rdi
movl %ebp, %edx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10260
leaq 0x3df20(%rip), %rsi     # 0x4e35c
jmp 0x1044e
cmpl $0x1, %ebp
jne 0x10712
leaq 0x3df04(%rip), %rsi     # 0x4e352
movl $0x4, %edx
movq %r14, %rdi
callq 0x28836
testq %rax, %rax
js 0x106f6
movq 0x8(%rsp), %rax
movl 0x14(%rax), %eax
movq %rsp, %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x28836
testq %rax, %rax
js 0x106f6
cmpl $0x2, %ebp
jne 0x104b3
movq 0x8(%rsp), %rax
movl 0x10(%rax), %edx
testq %rdx, %rdx
je 0x104b3
movq 0x8(%rsp), %rax
movq 0x38(%rax), %rsi
movq %r14, %rdi
callq 0x28836
testq %rax, %rax
js 0x106f6
movq 0x8(%rsp), %rcx
cmpl $0x0, 0x14(%rcx)
jle 0x106d0
xorl %edx, %edx
movq 0x28(%rcx), %rax
movq (%rax,%rdx,8), %rax
movq %rdx, 0x20(%rsp)
shlq $0x4, %rdx
addq 0x30(%rcx), %rdx
movq %rdx, 0x18(%rsp)
testq %rax, %rax
je 0x10636
movq %rax, 0x10(%rsp)
movl 0x4(%rax), %eax
movl %eax, (%rsp)
movl $0x4, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x28836
testq %rax, %rax
js 0x106f6
movq 0x10(%rsp), %rax
cmpl $0x0, (%rax)
je 0x10656
xorl %r12d, %r12d
movq 0x10(%rsp), %rax
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 0x1054a
incl %r12d
movq 0x10(%rsp), %rax
cmpl (%rax), %r12d
jne 0x1051c
jmp 0x10656
movl %r12d, %eax
leaq (%rax,%rax,2), %r15
shlq $0x3, %r15
movq 0x10(%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 0x28836
testq %rax, %rax
js 0x106f6
testl %ebp, %ebp
jne 0x105a6
movq 0x8(%r15), %rax
movq %rax, (%rsp)
movl $0x8, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x28836
testq %rax, %rax
js 0x106f6
movl 0x4(%r15), %eax
movl %eax, (%rsp)
movl $0x4, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x28836
testq %rax, %rax
js 0x106f6
cmpl $0x0, 0x4(%r15)
jle 0x10538
xorl %ebx, %ebx
xorl %r13d, %r13d
movq 0x10(%r15), %rax
movq (%rax,%rbx), %rax
movq %rax, (%rsp)
movl $0x8, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x28836
testq %rax, %rax
js 0x106f6
movq 0x10(%r15), %rax
movq 0x8(%rax,%rbx), %rax
movq %rax, (%rsp)
movl $0x8, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x28836
testq %rax, %rax
js 0x106f6
incq %r13
movslq 0x4(%r15), %rax
addq $0x10, %rbx
cmpq %rax, %r13
jl 0x105d6
jmp 0x10538
movl $0x0, (%rsp)
movl $0x4, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x28836
testq %rax, %rax
js 0x106f6
testl %ebp, %ebp
movq 0x18(%rsp), %rax
je 0x106b6
movl (%rax), %eax
movl %eax, (%rsp)
movl $0x4, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x28836
testq %rax, %rax
js 0x106f6
movq 0x18(%rsp), %rcx
cmpl $0x0, (%rcx)
jle 0x106b6
xorl %ebx, %ebx
movq 0x8(%rcx), %rax
movq (%rax,%rbx,8), %rax
movq %rax, (%rsp)
movl $0x8, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x28836
testq %rax, %rax
js 0x106f6
incq %rbx
movq 0x18(%rsp), %rcx
movslq (%rcx), %rax
cmpq %rax, %rbx
jl 0x10685
movq 0x20(%rsp), %rdx
incq %rdx
movq 0x8(%rsp), %rcx
movslq 0x14(%rcx), %rax
cmpq %rax, %rdx
jl 0x104c4
movq 0x20(%rcx), %rax
movq %rsp, %rsi
movq %rax, (%rsi)
movl $0x8, %edx
movq %r14, %rdi
callq 0x28836
testq %rax, %rax
js 0x106f6
movq %r14, %rdi
callq 0x2899c
jmp 0x10703
movq %r14, %rdi
callq 0x2899c
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3100