// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/hts.c
// Function: hts_idx_write_out
static int hts_idx_write_out(const hts_idx_t *idx, BGZF *fp, int fmt)
{
    #define check(ret) if ((ret) < 0) 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(idx_save_core(idx, fp, fmt));

    #undef check
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r15
pushq $-0x1
popq %rbx
cmpl $0x2, %edx
je 0x14007
cmpl $0x1, %ebp
je 0x13ffe
testl %ebp, %ebp
jne 0x1426e
leaq 0x63dbb(%rip), %rsi     # 0x77d57
pushq $0x4
popq %rdx
movq %r14, %rdi
callq 0xba64
testq %rax, %rax
js 0x1425d
movl 0x4(%r15), %esi
movq %r14, %rdi
callq 0x18878
testq %rax, %rax
js 0x1425d
movl 0x8(%r15), %esi
movq %r14, %rdi
callq 0x18878
testq %rax, %rax
js 0x1425d
movl 0x10(%r15), %esi
movq %r14, %rdi
callq 0x1888d
testq %rax, %rax
js 0x1425d
movl 0x10(%r15), %edx
testq %rdx, %rdx
je 0x14022
movq 0x38(%r15), %rsi
jmp 0x14011
leaq 0x63d4d(%rip), %rsi     # 0x77d52
jmp 0x1400e
leaq 0x63d4e(%rip), %rsi     # 0x77d5c
pushq $0x4
popq %rdx
movq %r14, %rdi
callq 0xba64
testq %rax, %rax
js 0x1425d
movl %ebp, 0x4(%rsp)
movl 0x14(%r15), %r12d
movq 0x38(%r15), %rax
testq %rax, %rax
movq %r15, 0x10(%rsp)
je 0x14069
cmpl $0x4, 0x10(%r15)
jb 0x14069
cmpl $0x2, (%rax)
jne 0x14069
xorl %eax, %eax
testl %r12d, %r12d
movl %r12d, %ecx
cmovlel %eax, %ecx
xorl %r12d, %r12d
cmpq %rax, %rcx
je 0x14069
movq 0x28(%r15), %rdx
cmpq $0x1, (%rdx,%rax,8)
sbbl $-0x1, %r12d
incq %rax
jmp 0x14052
movq %r14, %rdi
movl %r12d, %esi
callq 0x18878
testq %rax, %rax
js 0x1425a
cmpl $0x2, 0x4(%rsp)
jne 0x140ab
movq 0x10(%rsp), %rax
movl 0x10(%rax), %edx
testq %rdx, %rdx
je 0x140ab
movq 0x10(%rsp), %rax
movq 0x38(%rax), %rsi
movq %r14, %rdi
callq 0xba64
testq %rax, %rax
js 0x1425a
xorl %esi, %esi
movq 0x10(%rsp), %rdx
movslq 0x14(%rdx), %rax
cmpq %rax, %rsi
jge 0x14233
movq 0x28(%rdx), %rcx
movq (%rcx,%rsi,8), %rdi
movq %rsi, 0x20(%rsp)
imulq $0x18, %rsi, %rbx
addq 0x30(%rdx), %rbx
cmpl %eax, %r12d
sete %al
testq %rdi, %rdi
setne %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x141ee
testq %rdi, %rdi
movq %rdi, 0x8(%rsp)
je 0x140fa
movl 0x4(%rdi), %esi
jmp 0x140fc
xorl %esi, %esi
movq %r14, %rdi
callq 0x18878
testq %rax, %rax
js 0x1425a
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x141ee
xorl %edx, %edx
cmpl (%rax), %edx
je 0x141ee
movq 0x10(%rax), %rax
movl %edx, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %eax
movq %rdx, 0x18(%rsp)
leal (%rdx,%rdx), %ecx
shrl %cl, %eax
testb $0x3, %al
je 0x1414d
movq 0x18(%rsp), %rdx
incl %edx
movq 0x8(%rsp), %rax
jmp 0x1411d
movl 0x18(%rsp), %eax
imulq $0x18, %rax, %r15
movq 0x8(%rsp), %rcx
addq 0x20(%rcx), %r15
movq 0x18(%rcx), %rcx
movl (%rcx,%rax,4), %esi
movq %r14, %rdi
callq 0x1888d
testq %rax, %rax
js 0x1425a
cmpl $0x0, 0x4(%rsp)
jne 0x14192
movq 0x8(%r15), %rsi
movq %r14, %rdi
callq 0x188a2
testq %rax, %rax
js 0x1425a
movl 0x4(%r15), %esi
movq %r14, %rdi
callq 0x18878
testq %rax, %rax
js 0x1425a
pushq $-0x1
popq %r13
xorl %ebp, %ebp
movslq 0x4(%r15), %rax
incq %r13
cmpq %rax, %r13
jge 0x1413f
movq 0x10(%r15), %rax
movq (%rax,%rbp), %rsi
movq %r14, %rdi
callq 0x188a2
testq %rax, %rax
js 0x1425a
movq 0x10(%r15), %rax
movq 0x8(%rax,%rbp), %rsi
addq $0x10, %rbp
movq %r14, %rdi
callq 0x188a2
testq %rax, %rax
jns 0x141ad
jmp 0x1425a
cmpl $0x0, 0x4(%rsp)
je 0x14226
movl (%rbx), %esi
movq %r14, %rdi
callq 0x18878
testq %rax, %rax
js 0x1425a
xorl %r15d, %r15d
cmpq %r15, (%rbx)
jle 0x14226
movq 0x10(%rbx), %rax
movq (%rax,%r15,8), %rsi
movq %r14, %rdi
callq 0x188a2
incq %r15
testq %rax, %rax
jns 0x14207
jmp 0x1425a
movq 0x20(%rsp), %rsi
incq %rsi
jmp 0x140ad
movq 0x98(%rdx), %rax
testq %rax, %rax
je 0x14245
testb $0x40, 0x3(%rax)
je 0x14256
movq 0x20(%rdx), %rsi
movq %r14, %rdi
callq 0x188a2
testq %rax, %rax
js 0x1425a
xorl %ebx, %ebx
jmp 0x1425d
pushq $-0x1
popq %rbx
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4270