// File: /workspace/github_c_makefile_star2_O1/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, %r15
movq %rsi, %r14
movq %rdi, %rbx
callq 0x67c85
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x68ae0
cmpq $0x0, 0x48(%rbx)
je 0x68af1
testq %r15, %r15
je 0x68969
movq %r14, %rdi
callq 0x62d0
movq %rax, %r12
movq %r15, %rdi
callq 0x62d0
movq %rax, %r13
movq %r12, 0x10(%rsp)
addl %r12d, %eax
incl %eax
movslq %eax, %rdi
callq 0x69d0
testq %rax, %rax
je 0x68ae0
movq %rax, %r12
movslq 0x10(%rsp), %rdx
movq %rdx, 0x10(%rsp)
movq %rax, %rdi
movq %r14, %rsi
callq 0x6570
movq %r12, %rdi
addq 0x10(%rsp), %rdi
shlq $0x20, %r13
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r13
sarq $0x20, %r13
movq %r15, %rsi
movq %r13, %rdx
callq 0x6570
jmp 0x6896c
xorl %r12d, %r12d
testq %r12, %r12
cmovneq %r12, %r14
leaq 0x2a1fb(%rip), %rsi     # 0x92b75
movq %r14, %rdi
callq 0x6880
movq %rax, %r14
testq %r12, %r12
je 0x68992
movq %r12, %rdi
callq 0x68a0
testq %r14, %r14
je 0x68ae0
testb $0xc, 0x2(%rbx)
je 0x68a4f
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 0x68ad6
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 0x689e7
jmp 0x68ad6
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 0x68ad6
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 0x68a88
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 0x31076(%rip), %rdi     # 0x99b6e
leaq 0x30f76(%rip), %rsi     # 0x99a75
leaq 0x31070(%rip), %rcx     # 0x99b76
movl $0x3cf, %edx            # imm = 0x3CF
callq 0x6460