// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/bgzf.c
// Function: bgzf_index_dump_hfile
int bgzf_index_dump_hfile(BGZF *fp, struct hFILE *idx, const char *name)
{
    // Note that the index contains one extra record when indexing files opened
    // for reading. The terminating record is not present when opened for writing.
    // This is not a bug.

    int i;

    if (!fp->idx) {
        hts_log_error("Called for BGZF handle with no index");
        errno = EINVAL;
        return -1;
    }

    if (bgzf_flush(fp) != 0) return -1;

    // discard the entry marking the end of the file
    if (fp->mt && fp->idx)
        fp->idx->noffs--;

    if (hwrite_uint64(fp->idx->noffs - 1, idx) < 0) goto fail;
    for (i=1; i<fp->idx->noffs; i++)
    {
        if (hwrite_uint64(fp->idx->offs[i].caddr, idx) < 0) goto fail;
        if (hwrite_uint64(fp->idx->offs[i].uaddr, idx) < 0) goto fail;
    }
    return 0;

 fail:
    hts_log_error("Error writing to %s : %s", name ? name : "index", strerror(errno));
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
cmpq $0x0, 0x50(%rdi)
je 0xdf1e
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
callq 0xcc29
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
jne 0xe14d
cmpq $0x0, 0x48(%r15)
je 0xde93
movq 0x50(%r15), %rax
testq %rax, %rax
je 0xde93
decl (%rax)
movq %rbx, 0x10(%rsp)
movq 0x50(%r15), %rax
movslq (%rax), %rax
decq %rax
movq %rax, (%rsp)
testb $0x2, 0x30(%r14)
jne 0xded5
movq 0x18(%r14), %rsi
movq %rsi, %rax
subq 0x8(%r14), %rax
cmpq $0x7, %rax
ja 0xded5
subq (%r14), %rsi
addq $0x8, %rsi
movq %r14, %rdi
callq 0xefdd
movq 0x18(%r14), %rax
movq %rax, 0x10(%r14)
movq 0x8(%r14), %rdi
movq 0x18(%r14), %rbx
subq %rdi, %rbx
cmpq $0x8, %rbx
ja 0xdeeb
cmpq (%r14), %rdi
je 0xdf48
cmpq $0x8, %rbx
movl $0x8, %r12d
cmovbq %rbx, %r12
movq %rsp, %rsi
movq %r12, %rdx
callq 0x43c0
addq %r12, 0x8(%r14)
cmpq $0x7, %rbx
ja 0xdf5d
movq %rsp, %rsi
movl $0x8, %edx
movq %r14, %rdi
movq %r12, %rcx
jmp 0xdf55
leaq 0x89ea1(%rip), %rsi     # 0x97dc6
leaq 0x89eb0(%rip), %rdx     # 0x97ddc
movl $0x1, %edi
xorl %eax, %eax
callq 0x14378
callq 0x4050
movl $0x16, (%rax)
jmp 0xe148
movq %rsp, %rsi
movl $0x8, %edx
movq %r14, %rdi
xorl %ecx, %ecx
callq 0xf4c6
movq %rax, %r12
cmpq $0x8, %r12
jne 0xe109
movq 0x50(%r15), %rcx
xorl %eax, %eax
cmpl $0x2, (%rcx)
jl 0xe14d
movl $0x1, %ebp
xorl %ebx, %ebx
movq %r15, 0x8(%rsp)
movq 0x8(%rcx), %rax
movq 0x18(%rax,%rbx), %rax
movq %rax, (%rsp)
testb $0x2, 0x30(%r14)
jne 0xdfbe
movq 0x18(%r14), %rsi
movq %rsi, %rax
subq 0x8(%r14), %rax
cmpq $0x7, %rax
ja 0xdfbe
subq (%r14), %rsi
addq $0x8, %rsi
movq %r14, %rdi
callq 0xefdd
movq 0x18(%r14), %rax
movq %rax, 0x10(%r14)
movq 0x8(%r14), %rdi
movq 0x18(%r14), %r12
subq %rdi, %r12
cmpq $0x8, %r12
movq %rsp, %rsi
ja 0xdfdb
cmpq (%r14), %rdi
je 0xe0db
cmpq $0x8, %r12
movl $0x8, %r13d
cmovbq %r12, %r13
movq %r13, %rdx
movq %rsi, %r15
callq 0x43c0
addq %r13, 0x8(%r14)
cmpq $0x7, %r12
ja 0xe014
movl $0x8, %edx
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rcx
callq 0xf4c6
movq %rax, %r13
movq 0x8(%rsp), %r15
cmpq $0x8, %r13
jne 0xe109
movq 0x50(%r15), %rax
movq 0x8(%rax), %rax
movq 0x10(%rax,%rbx), %rax
movq %rax, (%rsp)
testb $0x2, 0x30(%r14)
jne 0xe063
movq 0x18(%r14), %rsi
movq %rsi, %rax
subq 0x8(%r14), %rax
cmpq $0x7, %rax
ja 0xe063
subq (%r14), %rsi
addq $0x8, %rsi
movq %r14, %rdi
callq 0xefdd
movq 0x18(%r14), %rax
movq %rax, 0x10(%r14)
movq 0x8(%r14), %rdi
movq 0x18(%r14), %r12
subq %rdi, %r12
cmpq $0x8, %r12
ja 0xe079
cmpq (%r14), %rdi
je 0xe0f2
cmpq $0x8, %r12
movl $0x8, %r13d
cmovbq %r12, %r13
movq %rsp, %r15
movq %r15, %rsi
movq %r13, %rdx
callq 0x43c0
addq %r13, 0x8(%r14)
cmpq $0x7, %r12
ja 0xe0b5
movl $0x8, %edx
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rcx
callq 0xf4c6
movq %rax, %r13
movq 0x8(%rsp), %r15
cmpq $0x8, %r13
jne 0xe109
incq %rbp
movq 0x50(%r15), %rcx
movslq (%rcx), %rdx
addq $0x10, %rbx
xorl %eax, %eax
cmpq %rdx, %rbp
jl 0xdf82
jmp 0xe14d
movl $0x8, %edx
movq %r14, %rdi
xorl %ecx, %ecx
callq 0xf4c6
movq %rax, %r13
jmp 0xe019
movl $0x8, %edx
movq %r14, %rdi
movq %rsp, %rsi
xorl %ecx, %ecx
callq 0xf4c6
movq %rax, %r13
jmp 0xe0ba
movq 0x10(%rsp), %rax
testq %rax, %rax
leaq 0x8d2f6(%rip), %r14     # 0x9b40e
cmovneq %rax, %r14
callq 0x4050
movl (%rax), %edi
callq 0x4150
leaq 0x89c97(%rip), %rsi     # 0x97dc6
leaq 0x89ccb(%rip), %rdx     # 0x97e01
movl $0x1, %edi
movq %r14, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x14378
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq