// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x9cc20
cmpl $0x0, %eax
je 0x9de8e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9e12b
movq -0x10(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0x9de9b
jmp 0x9deba
leaq 0x45d6c(%rip), %rdi     # 0xe3c0e
leaq 0x45c6c(%rip), %rsi     # 0xe3b15
movl $0x3cf, %edx            # imm = 0x3CF
leaq 0x45d61(%rip), %rcx     # 0xe3c16
callq 0x6450
movq $0x0, -0x28(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x9df37
movq -0x18(%rbp), %rdi
callq 0x62c0
movl %eax, -0x2c(%rbp)
movq -0x20(%rbp), %rdi
callq 0x62c0
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %eax
addl -0x30(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
callq 0x69c0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x9df09
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9e12b
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
movslq -0x2c(%rbp), %rdx
callq 0x6570
movq -0x28(%rbp), %rdi
movslq -0x2c(%rbp), %rax
addq %rax, %rdi
movq -0x20(%rbp), %rsi
movl -0x30(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdx
callq 0x6570
cmpq $0x0, -0x28(%rbp)
je 0x9df48
movq -0x28(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x9df50
movq -0x18(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
leaq 0x3eaba(%rip), %rsi     # 0xdca15
callq 0x6860
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x9df74
movq -0x28(%rbp), %rdi
callq 0x6880
cmpq $0x0, -0x38(%rbp)
jne 0x9df87
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9e12b
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x12, %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0x9e076
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl (%rax), %eax
subl $0x1, %eax
cltq
movq %rax, -0x48(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x9e140
movq %rax, %rdi
movq -0x38(%rbp), %rcx
movl $0x1, %esi
movl $0x8, %edx
callq 0x6e80
movl $0x1, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x48(%rcx), %rcx
cmpl (%rcx), %eax
jge 0x9e071
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x8(%rax), %rax
movslq -0x3c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x9e140
movq %rax, %rdi
movq -0x38(%rbp), %rcx
movl $0x1, %esi
movl $0x8, %edx
callq 0x6e80
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x8(%rax), %rax
movslq -0x3c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x9e140
movq %rax, %rdi
movq -0x38(%rbp), %rcx
movl $0x1, %esi
movl $0x8, %edx
callq 0x6e80
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x9dfd5
jmp 0x9e11b
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl (%rax), %eax
subl $0x1, %eax
cltq
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rcx
leaq -0x50(%rbp), %rdi
movl $0x1, %esi
movl $0x8, %edx
callq 0x6e80
movl $0x1, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x48(%rcx), %rcx
cmpl (%rcx), %eax
jge 0x9e119
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x8(%rax), %rdi
movslq -0x3c(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdi
addq $0x8, %rdi
movq -0x38(%rbp), %rcx
movl $0x1, %esi
movl $0x8, %edx
callq 0x6e80
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x8(%rax), %rdi
movslq -0x3c(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdi
movq -0x38(%rbp), %rcx
movl $0x1, %esi
movl $0x8, %edx
callq 0x6e80
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x9e0a7
jmp 0x9e11b
movq -0x38(%rbp), %rdi
callq 0x66e0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)