// File: /workspace/github_cpp_makefile_star2_O3/karel-brinda[P]ococo/ext/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 0x12097
cmpl $0x1, %ebp
leaq 0x3efb6(%rip), %rax     # 0x50f75
leaq 0x3efb2(%rip), %rsi     # 0x50f78
cmoveq %rax, %rsi
movq %rdx, %rdi
callq 0x42768
movq %rax, %r14
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %r14, %r14
je 0x1237d
movq %rbx, 0x8(%rsp)
cmpl $0x2, %ebp
je 0x120af
testl %ebp, %ebp
jne 0x120b8
leaq 0x3ebb4(%rip), %rsi     # 0x50bb4
movl $0x4, %edx
movq %r14, %rdi
callq 0x44082
testq %rax, %rax
js 0x12370
movq 0x8(%rsp), %rax
movl 0x4(%rax), %eax
movq %rsp, %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x44082
testq %rax, %rax
js 0x12370
movq 0x8(%rsp), %rax
movl 0x8(%rax), %eax
movq %rsp, %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x44082
testq %rax, %rax
js 0x12370
movq 0x8(%rsp), %rax
movl 0x10(%rax), %eax
movq %rsp, %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x44082
testq %rax, %rax
js 0x12370
movq 0x8(%rsp), %rax
movl 0x10(%rax), %edx
testq %rdx, %rdx
je 0x120de
movq 0x8(%rsp), %rax
movq 0x38(%rax), %rsi
jmp 0x120cd
movq %rbx, %rdi
movl %ebp, %edx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x11eda
leaq 0x3eb03(%rip), %rsi     # 0x50bb9
jmp 0x120c8
cmpl $0x1, %ebp
jne 0x1238c
leaq 0x3eae7(%rip), %rsi     # 0x50baf
movl $0x4, %edx
movq %r14, %rdi
callq 0x44082
testq %rax, %rax
js 0x12370
movq 0x8(%rsp), %rax
movl 0x14(%rax), %eax
movq %rsp, %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x44082
testq %rax, %rax
js 0x12370
cmpl $0x2, %ebp
jne 0x1212d
movq 0x8(%rsp), %rax
movl 0x10(%rax), %edx
testq %rdx, %rdx
je 0x1212d
movq 0x8(%rsp), %rax
movq 0x38(%rax), %rsi
movq %r14, %rdi
callq 0x44082
testq %rax, %rax
js 0x12370
movq 0x8(%rsp), %rcx
cmpl $0x0, 0x14(%rcx)
jle 0x1234a
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 0x122b0
movq %rax, 0x10(%rsp)
movl 0x4(%rax), %eax
movl %eax, (%rsp)
movl $0x4, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x44082
testq %rax, %rax
js 0x12370
movq 0x10(%rsp), %rax
cmpl $0x0, (%rax)
je 0x122d0
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 0x121c4
incl %r12d
movq 0x10(%rsp), %rax
cmpl (%rax), %r12d
jne 0x12196
jmp 0x122d0
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 0x44082
testq %rax, %rax
js 0x12370
testl %ebp, %ebp
jne 0x12220
movq 0x8(%r15), %rax
movq %rax, (%rsp)
movl $0x8, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x44082
testq %rax, %rax
js 0x12370
movl 0x4(%r15), %eax
movl %eax, (%rsp)
movl $0x4, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x44082
testq %rax, %rax
js 0x12370
cmpl $0x0, 0x4(%r15)
jle 0x121b2
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 0x44082
testq %rax, %rax
js 0x12370
movq 0x10(%r15), %rax
movq 0x8(%rax,%rbx), %rax
movq %rax, (%rsp)
movl $0x8, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x44082
testq %rax, %rax
js 0x12370
incq %r13
movslq 0x4(%r15), %rax
addq $0x10, %rbx
cmpq %rax, %r13
jl 0x12250
jmp 0x121b2
movl $0x0, (%rsp)
movl $0x4, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x44082
testq %rax, %rax
js 0x12370
testl %ebp, %ebp
movq 0x18(%rsp), %rax
je 0x12330
movl (%rax), %eax
movl %eax, (%rsp)
movl $0x4, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x44082
testq %rax, %rax
js 0x12370
movq 0x18(%rsp), %rcx
cmpl $0x0, (%rcx)
jle 0x12330
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 0x44082
testq %rax, %rax
js 0x12370
incq %rbx
movq 0x18(%rsp), %rcx
movslq (%rcx), %rax
cmpq %rax, %rbx
jl 0x122ff
movq 0x20(%rsp), %rdx
incq %rdx
movq 0x8(%rsp), %rcx
movslq 0x14(%rcx), %rax
cmpq %rax, %rdx
jl 0x1213e
movq 0x20(%rcx), %rax
movq %rsp, %rsi
movq %rax, (%rsi)
movl $0x8, %edx
movq %r14, %rdi
callq 0x44082
testq %rax, %rax
js 0x12370
movq %r14, %rdi
callq 0x441e8
jmp 0x1237d
movq %r14, %rdi
callq 0x441e8
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x42e0