// File: /workspace/github_c_makefile_star2_O3/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 $0x38, %rsp
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
cmpl $0x2, %edx
je 0x17105
cmpl $0x1, %ebp
je 0x170fc
testl %ebp, %ebp
jne 0x17477
leaq 0x7ed10(%rip), %rsi     # 0x95d6e
movl $0x4, %edx
movq %rbx, %rdi
callq 0xd005
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testq %rax, %rax
js 0x1745d
movl 0x4(%r14), %eax
leaq 0x8(%rsp), %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %rbx, %rdi
callq 0xd005
testq %rax, %rax
js 0x1745d
movl 0x8(%r14), %eax
leaq 0x8(%rsp), %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %rbx, %rdi
callq 0xd005
testq %rax, %rax
js 0x1745d
movl 0x10(%r14), %eax
leaq 0x8(%rsp), %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %rbx, %rdi
callq 0xd005
testq %rax, %rax
js 0x1745d
movl 0x10(%r14), %edx
testq %rdx, %rdx
je 0x17122
movq 0x38(%r14), %rsi
movq %rbx, %rdi
callq 0xd005
testq %rax, %rax
jns 0x17122
jmp 0x1745d
leaq 0x7ec66(%rip), %rsi     # 0x95d69
jmp 0x1710c
leaq 0x7ec67(%rip), %rsi     # 0x95d73
movl $0x4, %edx
movq %rbx, %rdi
callq 0xd005
testq %rax, %rax
js 0x17457
movl 0x14(%r14), %eax
movq 0x38(%r14), %rcx
testq %rcx, %rcx
movq %r14, 0x28(%rsp)
movl %ebp, 0x1c(%rsp)
je 0x17168
cmpl $0x4, 0x10(%r14)
jb 0x17168
cmpl $0x2, (%rcx)
jne 0x17168
testl %eax, %eax
jle 0x1746f
movq 0x28(%r14), %rcx
xorl %edx, %edx
xorl %r12d, %r12d
cmpq $0x1, (%rcx,%rdx,8)
sbbl $-0x1, %r12d
incq %rdx
cmpq %rdx, %rax
jne 0x17155
jmp 0x1716b
movl %eax, %r12d
leaq 0x8(%rsp), %rsi
movl %r12d, (%rsi)
movl $0x4, %edx
movq %rbx, 0x10(%rsp)
movq %rbx, %rdi
callq 0xd005
testq %rax, %rax
js 0x17457
cmpl $0x2, 0x1c(%rsp)
jne 0x171be
movq 0x28(%rsp), %rax
movl 0x10(%rax), %edx
testq %rdx, %rdx
je 0x171be
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rsi
movq 0x10(%rsp), %rdi
callq 0xd005
testq %rax, %rax
js 0x17457
movq 0x28(%rsp), %rdx
movl 0x14(%rdx), %eax
testl %eax, %eax
jle 0x17420
xorl %esi, %esi
movq 0x28(%rdx), %rcx
movq (%rcx,%rsi,8), %rcx
movq %rsi, 0x30(%rsp)
leaq (%rsi,%rsi,2), %rbp
shlq $0x3, %rbp
addq 0x30(%rdx), %rbp
cmpl %eax, %r12d
sete %al
movq %rcx, 0x20(%rsp)
testq %rcx, %rcx
setne %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x173a3
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0x1737e
movl 0x4(%rax), %eax
movl %eax, 0x8(%rsp)
movl $0x4, %edx
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0xd005
testq %rax, %rax
js 0x17457
movq 0x20(%rsp), %rax
cmpl $0x0, (%rax)
je 0x173a3
xorl %r14d, %r14d
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movl %r14d, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %eax
leal (%r14,%r14), %ecx
shrl %cl, %eax
testb $0x3, %al
je 0x17276
incl %r14d
movq 0x20(%rsp), %rax
cmpl (%rax), %r14d
jne 0x17248
jmp 0x173a3
movl %r14d, %eax
leaq (%rax,%rax,2), %r13
shlq $0x3, %r13
movq 0x20(%rsp), %rcx
addq 0x20(%rcx), %r13
movq 0x18(%rcx), %rcx
movl (%rcx,%rax,4), %eax
movl %eax, 0x8(%rsp)
movl $0x4, %edx
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0xd005
testq %rax, %rax
js 0x17457
cmpl $0x0, 0x1c(%rsp)
jne 0x172df
movq 0x8(%r13), %rax
movq %rax, 0x8(%rsp)
movl $0x8, %edx
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0xd005
testq %rax, %rax
js 0x17457
movl 0x4(%r13), %eax
movl %eax, 0x8(%rsp)
movl $0x4, %edx
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0xd005
testq %rax, %rax
js 0x17457
cmpl $0x0, 0x4(%r13)
jle 0x17264
xorl %r15d, %r15d
xorl %ebx, %ebx
movq 0x10(%r13), %rax
movq (%rax,%r15), %rax
movq %rax, 0x8(%rsp)
movl $0x8, %edx
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0xd005
testq %rax, %rax
js 0x17457
movq 0x10(%r13), %rax
movq 0x8(%rax,%r15), %rax
movq %rax, 0x8(%rsp)
movl $0x8, %edx
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0xd005
testq %rax, %rax
js 0x17457
incq %rbx
movslq 0x4(%r13), %rax
addq $0x10, %r15
cmpq %rax, %rbx
jl 0x17314
jmp 0x17264
movl $0x0, 0x8(%rsp)
movl $0x4, %edx
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0xd005
testq %rax, %rax
js 0x17457
cmpl $0x0, 0x1c(%rsp)
je 0x17406
movl (%rbp), %eax
movl %eax, 0x8(%rsp)
movl $0x4, %edx
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0xd005
testq %rax, %rax
js 0x17457
cmpq $0x0, (%rbp)
jle 0x17406
xorl %ebx, %ebx
movq 0x10(%rbp), %rax
movq (%rax,%rbx,8), %rax
movq %rax, 0x8(%rsp)
movl $0x8, %edx
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0xd005
testq %rax, %rax
js 0x17457
incq %rbx
cmpq %rbx, (%rbp)
jg 0x173d7
movq 0x30(%rsp), %rsi
incq %rsi
movq 0x28(%rsp), %rdx
movslq 0x14(%rdx), %rax
cmpq %rax, %rsi
jl 0x171d0
movq 0x98(%rdx), %rax
testq %rax, %rax
je 0x17432
testb $0x40, 0x3(%rax)
je 0x17452
movq 0x20(%rdx), %rax
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
movl $0x8, %edx
movq 0x10(%rsp), %rdi
callq 0xd005
testq %rax, %rax
js 0x17457
xorl %r15d, %r15d
jmp 0x1745d
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r12d, %r12d
jmp 0x1716b
callq 0x4270