// File: /workspace/github_cpp_makefile_star2_O1/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, %r15
testq %rdx, %rdx
je 0x11fe8
cmpl $0x1, %ebx
leaq 0x41035(%rip), %rax     # 0x52f41
leaq 0x41031(%rip), %rsi     # 0x52f44
cmoveq %rax, %rsi
movq %rdx, %rdi
callq 0x436f0
movq %rax, %r14
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %r14, %r14
je 0x122ac
movq %r15, 0x8(%rsp)
cmpl $0x2, %ebx
movl %ebx, 0x14(%rsp)
je 0x12000
testl %ebx, %ebx
jne 0x12009
leaq 0x40c2f(%rip), %rsi     # 0x52b80
movl $0x4, %edx
movq %r14, %rdi
callq 0x44fe4
testq %rax, %rax
js 0x1229f
movq 0x8(%rsp), %rax
movl 0x4(%rax), %eax
movq %rsp, %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x44fe4
testq %rax, %rax
js 0x1229f
movq 0x8(%rsp), %rax
movl 0x8(%rax), %eax
movq %rsp, %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x44fe4
testq %rax, %rax
js 0x1229f
movq 0x8(%rsp), %rax
movl 0x10(%rax), %eax
movq %rsp, %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x44fe4
testq %rax, %rax
js 0x1229f
movq 0x8(%rsp), %rax
movl 0x10(%rax), %edx
testq %rdx, %rdx
je 0x1202f
movq 0x8(%rsp), %rax
movq 0x38(%rax), %rsi
jmp 0x1201e
movq %r15, %rdi
movl %ebx, %edx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x11e27
leaq 0x40b7e(%rip), %rsi     # 0x52b85
jmp 0x12019
cmpl $0x1, %ebx
jne 0x122bb
leaq 0x40b62(%rip), %rsi     # 0x52b7b
movl $0x4, %edx
movq %r14, %rdi
callq 0x44fe4
testq %rax, %rax
js 0x1229f
movq 0x8(%rsp), %rax
movl 0x14(%rax), %eax
movq %rsp, %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x44fe4
testq %rax, %rax
js 0x1229f
cmpl $0x2, 0x14(%rsp)
jne 0x12080
movq 0x8(%rsp), %rax
movl 0x10(%rax), %edx
testq %rdx, %rdx
je 0x12080
movq 0x8(%rsp), %rax
movq 0x38(%rax), %rsi
movq %r14, %rdi
callq 0x44fe4
testq %rax, %rax
js 0x1229f
movq 0x8(%rsp), %rcx
cmpl $0x0, 0x14(%rcx)
jle 0x12279
xorl %r13d, %r13d
movq 0x28(%rcx), %rax
movq (%rax,%r13,8), %rdx
movl $0x0, %eax
testq %rdx, %rdx
je 0x120a7
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 0x44fe4
testq %rax, %rax
js 0x1229f
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0x12206
cmpl $0x0, (%rax)
je 0x12206
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 0x12118
incl %r12d
movq 0x18(%rsp), %rax
cmpl (%rax), %r12d
jne 0x120ef
jmp 0x12206
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 0x44fe4
testq %rax, %rax
js 0x1229f
cmpl $0x0, 0x14(%rsp)
jne 0x12177
movq 0x8(%r15), %rax
movq %rax, (%rsp)
movl $0x8, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x44fe4
testq %rax, %rax
js 0x1229f
movl 0x4(%r15), %eax
movl %eax, (%rsp)
movl $0x4, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x44fe4
testq %rax, %rax
js 0x1229f
cmpl $0x0, 0x4(%r15)
jle 0x12106
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 0x44fe4
testq %rax, %rax
js 0x1229f
movq 0x10(%r15), %rax
movq 0x8(%rax,%rbx), %rax
movq %rax, (%rsp)
movl $0x8, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x44fe4
testq %rax, %rax
js 0x1229f
incq %rbp
movslq 0x4(%r15), %rax
addq $0x10, %rbx
cmpq %rax, %rbp
jl 0x121a6
jmp 0x12106
cmpl $0x0, 0x14(%rsp)
je 0x1225f
movl (%r13), %eax
movl %eax, (%rsp)
movl $0x4, %edx
movq %r14, %rdi
movq %rsp, %rsi
callq 0x44fe4
testq %rax, %rax
js 0x1229f
cmpl $0x0, (%r13)
jle 0x1225f
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 0x44fe4
testq %rax, %rax
js 0x1229f
incq %rbx
movslq (%r13), %rax
cmpq %rax, %rbx
jl 0x12232
movq 0x20(%rsp), %r13
incq %r13
movq 0x8(%rsp), %rcx
movslq 0x14(%rcx), %rax
cmpq %rax, %r13
jl 0x12092
movq 0x20(%rcx), %rax
movq %rsp, %rsi
movq %rax, (%rsi)
movl $0x8, %edx
movq %r14, %rdi
callq 0x44fe4
testq %rax, %rax
js 0x1229f
movq %r14, %rdi
callq 0x4514a
jmp 0x122ac
movq %r14, %rdi
callq 0x4514a
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x42e0