// File: /workspace/github_cpp_makefile_star2_O2/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, %ebx
movq %rdi, %r14
testq %rdx, %rdx
je 0xef19
cmpl $0x1, %ebx
leaq 0x35151(%rip), %rax     # 0x43fb3
leaq 0x3514d(%rip), %rsi     # 0x43fb6
cmoveq %rax, %rsi
movq %rdx, %rdi
callq 0x35ed4
testq %rax, %rax
je 0xf143
movq %rax, %r15
movq %r14, 0x8(%rsp)
cmpl $0x2, %ebx
movl %ebx, 0x14(%rsp)
je 0xef31
testl %ebx, %ebx
jne 0xef3a
leaq 0x34d4b(%rip), %rsi     # 0x43bed
pushq $0x4
popq %rdx
movq %r15, %rdi
callq 0x376df
testq %rax, %rax
js 0xf13b
movq 0x8(%rsp), %rax
movl 0x4(%rax), %esi
movq %r15, %rdi
callq 0xf15a
testq %rax, %rax
js 0xf13b
movq 0x8(%rsp), %rax
movl 0x8(%rax), %esi
movq %r15, %rdi
callq 0xf15a
testq %rax, %rax
js 0xf13b
movq 0x8(%rsp), %rax
movl 0x10(%rax), %esi
movq %r15, %rdi
callq 0xf16f
testq %rax, %rax
js 0xf13b
movq 0x8(%rsp), %rax
movl 0x10(%rax), %edx
testq %rdx, %rdx
je 0xef5e
movq 0x8(%rsp), %rax
movq 0x38(%rax), %rsi
jmp 0xef4d
movq %r14, %rdi
movl %ebx, %edx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xed81
leaq 0x34cba(%rip), %rsi     # 0x43bf2
jmp 0xef4a
cmpl $0x1, %ebx
jne 0xf155
leaq 0x34c9e(%rip), %rsi     # 0x43be8
pushq $0x4
popq %rdx
movq %r15, %rdi
callq 0x376df
testq %rax, %rax
js 0xf13b
movq 0x8(%rsp), %rax
movl 0x14(%rax), %esi
movq %r15, %rdi
callq 0xf15a
testq %rax, %rax
js 0xf13b
cmpl $0x2, 0x14(%rsp)
jne 0xefa5
movq 0x8(%rsp), %rax
movl 0x10(%rax), %edx
testq %rdx, %rdx
je 0xefa5
movq 0x8(%rsp), %rax
movq 0x38(%rax), %rsi
movq %r15, %rdi
callq 0x376df
testq %rax, %rax
js 0xf13b
xorl %ebp, %ebp
movq 0x8(%rsp), %rcx
movslq 0x14(%rcx), %rax
cmpq %rax, %rbp
jge 0xf114
movq 0x28(%rcx), %rax
movq (%rax,%rbp,8), %rax
testq %rax, %rax
movq %rax, 0x18(%rsp)
je 0xefd0
movl 0x4(%rax), %esi
jmp 0xefd2
xorl %esi, %esi
movq %rbp, 0x20(%rsp)
shlq $0x4, %rbp
addq 0x30(%rcx), %rbp
movq %r15, %rdi
callq 0xf15a
testq %rax, %rax
js 0xf13b
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0xf0cb
xorl %r12d, %r12d
cmpl (%rax), %r12d
je 0xf0cb
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 0xf02b
incl %r12d
movq 0x18(%rsp), %rax
jmp 0xf001
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 0xf16f
testq %rax, %rax
js 0xf13b
cmpl $0x0, 0x14(%rsp)
jne 0xf06f
movq 0x8(%r14), %rsi
movq %r15, %rdi
callq 0x108a5
testq %rax, %rax
js 0xf13b
movl 0x4(%r14), %esi
movq %r15, %rdi
callq 0xf15a
testq %rax, %rax
js 0xf13b
pushq $-0x1
popq %r13
xorl %ebx, %ebx
movslq 0x4(%r14), %rax
incq %r13
cmpq %rax, %r13
jge 0xf021
movq 0x10(%r14), %rax
movq (%rax,%rbx), %rsi
movq %r15, %rdi
callq 0x108a5
testq %rax, %rax
js 0xf13b
movq 0x10(%r14), %rax
movq 0x8(%rax,%rbx), %rsi
addq $0x10, %rbx
movq %r15, %rdi
callq 0x108a5
testq %rax, %rax
jns 0xf08a
jmp 0xf13b
cmpl $0x0, 0x14(%rsp)
je 0xf107
movl (%rbp), %esi
movq %r15, %rdi
callq 0xf15a
testq %rax, %rax
js 0xf13b
xorl %ebx, %ebx
movslq (%rbp), %rax
cmpq %rax, %rbx
jge 0xf107
movq 0x8(%rbp), %rax
movq (%rax,%rbx,8), %rsi
movq %r15, %rdi
callq 0x108a5
incq %rbx
testq %rax, %rax
jns 0xf0e4
jmp 0xf13b
movq 0x20(%rsp), %rbp
incq %rbp
jmp 0xefa7
movq 0x20(%rcx), %rsi
movq %r15, %rdi
callq 0x108a5
testq %rax, %rax
js 0xf13b
movq %r15, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x377bc
movq %r15, %rdi
callq 0x377bc
pushq $-0x1
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x42f0