// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
cmpl $0x2, %edx
je 0x17632
cmpl $0x1, %ebp
je 0x17629
testl %ebp, %ebp
jne 0x17989
leaq 0x8173f(%rip), %rsi     # 0x98cce
movl $0x4, %edx
movq %r14, %rdi
callq 0xd0bb
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testq %rax, %rax
js 0x1796f
movl 0x4(%rbx), %eax
leaq 0x8(%rsp), %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0xd0bb
testq %rax, %rax
js 0x1796f
movl 0x8(%rbx), %eax
leaq 0x8(%rsp), %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0xd0bb
testq %rax, %rax
js 0x1796f
movl 0x10(%rbx), %eax
leaq 0x8(%rsp), %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0xd0bb
testq %rax, %rax
js 0x1796f
movl 0x10(%rbx), %edx
testq %rdx, %rdx
je 0x1764f
movq 0x38(%rbx), %rsi
movq %r14, %rdi
callq 0xd0bb
testq %rax, %rax
jns 0x1764f
jmp 0x1796f
leaq 0x81699(%rip), %rsi     # 0x98cc9
jmp 0x17639
leaq 0x8169a(%rip), %rsi     # 0x98cd3
movl $0x4, %edx
movq %r14, %rdi
callq 0xd0bb
testq %rax, %rax
js 0x17969
movl 0x14(%rbx), %eax
movq 0x38(%rbx), %rcx
testq %rcx, %rcx
je 0x1768a
cmpl $0x4, 0x10(%rbx)
jb 0x1768a
cmpl $0x2, (%rcx)
jne 0x1768a
testl %eax, %eax
jle 0x17981
movq 0x28(%rbx), %rcx
xorl %edx, %edx
xorl %r13d, %r13d
cmpq $0x1, (%rcx,%rdx,8)
sbbl $-0x1, %r13d
incq %rdx
cmpq %rdx, %rax
jne 0x17677
jmp 0x1768d
movl %eax, %r13d
leaq 0x8(%rsp), %rsi
movl %r13d, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0xd0bb
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testq %rax, %rax
js 0x1796f
cmpl $0x2, %ebp
jne 0x176d3
movl 0x10(%rbx), %edx
testq %rdx, %rdx
je 0x176d3
movq 0x38(%rbx), %rsi
movq %r14, %rdi
callq 0xd0bb
testq %rax, %rax
js 0x1796f
movl 0x14(%rbx), %eax
testl %eax, %eax
jle 0x17934
xorl %r12d, %r12d
movq %r14, 0x20(%rsp)
movq %rbx, 0x30(%rsp)
movl %ebp, 0x14(%rsp)
movl %r13d, 0x2c(%rsp)
movq 0x28(%rbx), %rcx
movq (%rcx,%r12,8), %rdx
leaq (%r12,%r12,2), %rcx
shlq $0x3, %rcx
addq 0x30(%rbx), %rcx
movq %rcx, 0x40(%rsp)
cmpl %eax, %r13d
sete %al
testq %rdx, %rdx
setne %cl
orb %al, %cl
cmpb $0x1, %cl
movq %rdx, 0x18(%rsp)
jne 0x17755
testq %rdx, %rdx
je 0x1772f
movl 0x4(%rdx), %eax
jmp 0x17731
xorl %eax, %eax
movl %eax, 0x8(%rsp)
movl $0x4, %edx
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0xd0bb
testq %rax, %rax
movq 0x18(%rsp), %rdx
js 0x1796f
movq %r12, 0x38(%rsp)
testq %rdx, %rdx
je 0x178a5
cmpl $0x0, (%rdx)
je 0x178a5
xorl %r14d, %r14d
movq 0x10(%rdx), %rax
movl %r14d, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %eax
leal (%r14,%r14), %ecx
shrl %cl, %eax
testb $0x3, %al
je 0x17798
incl %r14d
movq 0x18(%rsp), %rdx
cmpl (%rdx), %r14d
jne 0x1776f
jmp 0x178a5
movl %r14d, %eax
leaq (%rax,%rax,2), %r12
shlq $0x3, %r12
movq 0x18(%rsp), %rcx
addq 0x20(%rcx), %r12
movq 0x18(%rcx), %rcx
movl (%rcx,%rax,4), %eax
movl %eax, 0x8(%rsp)
movl $0x4, %edx
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
leaq 0x8(%rsp), %r15
movq %r15, %rsi
callq 0xd0bb
testq %rax, %rax
js 0x17969
cmpl $0x0, 0x14(%rsp)
jne 0x17804
movq 0x8(%r12), %rax
movq %rax, 0x8(%rsp)
movl $0x8, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xd0bb
testq %rax, %rax
js 0x17969
movl 0x4(%r12), %eax
movl %eax, 0x8(%rsp)
movl $0x4, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xd0bb
testq %rax, %rax
js 0x17969
cmpl $0x0, 0x4(%r12)
jle 0x17786
xorl %ebp, %ebp
xorl %ebx, %ebx
movq 0x10(%r12), %rax
movq (%rax,%rbp), %rax
movq %rax, 0x8(%rsp)
movl $0x8, %edx
movq 0x20(%rsp), %r15
movq %r15, %rdi
leaq 0x8(%rsp), %r13
movq %r13, %rsi
callq 0xd0bb
testq %rax, %rax
js 0x17969
movq 0x10(%r12), %rax
movq 0x8(%rax,%rbp), %rax
movq %rax, 0x8(%rsp)
movl $0x8, %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0xd0bb
testq %rax, %rax
js 0x17969
incq %rbx
movslq 0x4(%r12), %rax
addq $0x10, %rbp
cmpq %rax, %rbx
jl 0x17836
jmp 0x17786
movl 0x14(%rsp), %ebp
testl %ebp, %ebp
movq 0x20(%rsp), %r14
movq 0x38(%rsp), %r12
movl 0x2c(%rsp), %r13d
movq 0x40(%rsp), %rbx
je 0x17919
movl (%rbx), %eax
movl %eax, 0x8(%rsp)
movl $0x4, %edx
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0xd0bb
testq %rax, %rax
js 0x17969
cmpq $0x0, (%rbx)
jle 0x17919
movq %rbx, %r15
xorl %ebx, %ebx
movq 0x10(%r15), %rax
movq (%rax,%rbx,8), %rax
movq %rax, 0x8(%rsp)
movl $0x8, %edx
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0xd0bb
testq %rax, %rax
js 0x17969
incq %rbx
cmpq %rbx, (%r15)
jg 0x178ed
incq %r12
movq 0x30(%rsp), %rbx
movslq 0x14(%rbx), %rax
cmpq %rax, %r12
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jl 0x176f4
movq 0x98(%rbx), %rax
testq %rax, %rax
je 0x17946
testb $0x40, 0x3(%rax)
je 0x17964
movq 0x20(%rbx), %rax
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
movl $0x8, %edx
movq %r14, %rdi
callq 0xd0bb
testq %rax, %rax
js 0x1796f
xorl %r15d, %r15d
jmp 0x1796f
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl %r15d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r13d, %r13d
jmp 0x1768d
callq 0x4270