// File: /workspace/github_c_makefile_star2_O3/icebert[P]pblat/htslib/bgzf.c
// Function: bgzf_index_dump
int bgzf_index_dump(BGZF *fp, const char *bname, const char *suffix)
{
    if (bgzf_flush(fp) != 0) return -1;

    assert(fp->idx);
    char *tmp = NULL;
    if ( suffix )
    {
        int blen = strlen(bname);
        int slen = strlen(suffix);
        tmp = (char*) malloc(blen + slen + 1);
        if ( !tmp ) return -1;
        memcpy(tmp,bname,blen);
        memcpy(tmp+blen,suffix,slen+1);
    }

    FILE *idx = fopen(tmp?tmp:bname,"wb");
    if ( tmp ) free(tmp);
    if ( !idx ) return -1;

    // 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->is_be )
    {
        uint64_t x = fp->idx->noffs - 1;
        fwrite(ed_swap_8p(&x), 1, sizeof(x), idx);
        for (i=1; i<fp->idx->noffs; i++)
        {
            x = fp->idx->offs[i].caddr; fwrite(ed_swap_8p(&x), 1, sizeof(x), idx);
            x = fp->idx->offs[i].uaddr; fwrite(ed_swap_8p(&x), 1, sizeof(x), idx);
        }
    }
    else
    {
        uint64_t x = fp->idx->noffs - 1;
        fwrite(&x, 1, sizeof(x), idx);
        for (i=1; i<fp->idx->noffs; i++)
        {
            fwrite(&fp->idx->offs[i].caddr, 1, sizeof(fp->idx->offs[i].caddr), idx);
            fwrite(&fp->idx->offs[i].uaddr, 1, sizeof(fp->idx->offs[i].uaddr), idx);
        }
    }
    fclose(idx);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
callq 0x67c54
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x68bd1
cmpq $0x0, 0x48(%rbx)
je 0x68be2
testq %r14, %r14
je 0x68a71
movq %r15, %rdi
callq 0x62d0
movq %rax, %r12
movq %r14, %rdi
callq 0x62d0
movq %rax, %r13
movq %r12, 0x10(%rsp)
addl %r12d, %eax
incl %eax
movslq %eax, %rdi
callq 0x69d0
testq %rax, %rax
je 0x68bd1
movq %rax, %r12
movslq 0x10(%rsp), %rax
movq %r12, %rdi
movq %r15, %rsi
movq %rax, %r15
movq %rax, %rdx
callq 0x6570
movq %r12, %rdi
addq %r15, %rdi
shlq $0x20, %r13
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r13
sarq $0x20, %r13
movq %r14, %rsi
movq %r13, %rdx
callq 0x6570
leaq 0x2a1ea(%rip), %rsi     # 0x92c46
movq %r12, %rdi
callq 0x6880
movq %rax, %r14
movq %r12, %rdi
callq 0x68a0
jmp 0x68a83
leaq 0x2a1ce(%rip), %rsi     # 0x92c46
movq %r15, %rdi
callq 0x6880
movq %rax, %r14
testq %r14, %r14
je 0x68bd1
testb $0xc, 0x2(%rbx)
je 0x68b40
movq 0x48(%rbx), %rax
movslq (%rax), %rax
decq %rax
bswapq %rax
leaq 0x8(%rsp), %rdi
movq %rax, (%rdi)
movl $0x1, %r12d
movl $0x1, %esi
movl $0x8, %edx
movq %r14, %rcx
callq 0x6e70
movq 0x48(%rbx), %rax
cmpl $0x2, (%rax)
jl 0x68bc7
xorl %r13d, %r13d
leaq 0x8(%rsp), %r15
movq 0x8(%rax), %rax
movq 0x18(%rax,%r13), %rax
bswapq %rax
movq %rax, 0x8(%rsp)
movl $0x1, %esi
movl $0x8, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x6e70
movq 0x48(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x10(%rax,%r13), %rax
bswapq %rax
movq %rax, 0x8(%rsp)
movl $0x1, %esi
movl $0x8, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x6e70
incq %r12
movq 0x48(%rbx), %rax
movslq (%rax), %rcx
addq $0x10, %r13
cmpq %rcx, %r12
jl 0x68ad8
jmp 0x68bc7
movq 0x48(%rbx), %rax
movslq (%rax), %rax
decq %rax
leaq 0x8(%rsp), %rdi
movq %rax, (%rdi)
movl $0x1, %r15d
movl $0x1, %esi
movl $0x8, %edx
movq %r14, %rcx
callq 0x6e70
movq 0x48(%rbx), %rax
cmpl $0x2, (%rax)
jl 0x68bc7
movl $0x10, %r12d
movq 0x8(%rax), %rax
leaq (%rax,%r12), %rdi
addq $0x8, %rdi
movl $0x1, %esi
movl $0x8, %edx
movq %r14, %rcx
callq 0x6e70
movq 0x48(%rbx), %rax
movq 0x8(%rax), %rdi
addq %r12, %rdi
movl $0x1, %esi
movl $0x8, %edx
movq %r14, %rcx
callq 0x6e70
incq %r15
movq 0x48(%rbx), %rax
movslq (%rax), %rcx
addq $0x10, %r12
cmpq %rcx, %r15
jl 0x68b79
movq %r14, %rdi
callq 0x66e0
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x311b5(%rip), %rdi     # 0x99d9e
leaq 0x310b5(%rip), %rsi     # 0x99ca5
leaq 0x311af(%rip), %rcx     # 0x99da6
movl $0x3cf, %edx            # imm = 0x3CF
callq 0x6460