// File: /workspace/github_c_makefile_star2_O0/zhou-lab[P]tbmate/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 ) {
        if (hts_verbose > 1)
        {
            fprintf(stderr, "[E::%s] Error opening %s%s : %s\n",
                    __func__, bname, suffix ? suffix : "", strerror(errno));
        }
        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 (fwrite_uint64(fp->idx->noffs - 1, idx) < 0) goto fail;
    for (i=1; i<fp->idx->noffs; i++)
    {
        if (fwrite_uint64(fp->idx->offs[i].caddr, idx) < 0) goto fail;
        if (fwrite_uint64(fp->idx->offs[i].uaddr, idx) < 0) goto fail;
    }

    if (fclose(idx) < 0)
    {
        if (hts_verbose > 1)
        {
            fprintf(stderr, "[E::%s] Error on closing %s%s : %s\n",
                    __func__, bname, suffix ? suffix : "", strerror(errno));
        }
        return -1;
    }
    return 0;

 fail:
    if (hts_verbose > 1)
    {
        fprintf(stderr, "[E::%s] Error writing to %s%s : %s\n",
                __func__, bname, suffix ? suffix : "", strerror(errno));
    }
    fclose(idx);
    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3b870
cmpl $0x0, %eax
je 0x3cc41
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3cfa6
movq -0x10(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0x3cc4e
jmp 0x3cc6d
leaq 0x3b763(%rip), %rdi     # 0x783b8
leaq 0x3b4c9(%rip), %rsi     # 0x78125
movl $0x47d, %edx            # imm = 0x47D
leaq 0x3b758(%rip), %rcx     # 0x783c0
callq 0x3190
movq $0x0, -0x28(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x3ccea
movq -0x18(%rbp), %rdi
callq 0x3380
movl %eax, -0x2c(%rbp)
movq -0x20(%rbp), %rdi
callq 0x3380
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %eax
addl -0x30(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
callq 0x3250
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x3ccbc
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3cfa6
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
movslq -0x2c(%rbp), %rdx
callq 0x3860
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 0x3860
cmpq $0x0, -0x28(%rbp)
je 0x3ccfb
movq -0x28(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x3cd03
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
leaq 0x391c9(%rip), %rsi     # 0x75ed7
callq 0x3260
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x3cd27
movq -0x28(%rbp), %rdi
callq 0x3370
cmpq $0x0, -0x38(%rbp)
jne 0x3cdb6
leaq 0x48757(%rip), %rax     # 0x85490
cmpl $0x1, (%rax)
jle 0x3cdaa
movq 0x482a3(%rip), %rax     # 0x84fe8
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x3cd65
movq -0x20(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0x3cd72
leaq 0x3d150(%rip), %rax     # 0x79ebc
movq %rax, -0x60(%rbp)
jmp 0x3cd72
movq -0x60(%rbp), %rax
movq %rax, -0x68(%rbp)
callq 0x35d0
movl (%rax), %edi
callq 0x34e0
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rcx
movq -0x68(%rbp), %r8
movq %rax, %r9
leaq 0x3b65c(%rip), %rsi     # 0x783f8
leaq 0x3b676(%rip), %rdx     # 0x78419
movb $0x0, %al
callq 0x37f0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3cfa6
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl (%rax), %eax
subl $0x1, %eax
movslq %eax, %rdi
movq -0x38(%rbp), %rsi
callq 0x3cfc0
cmpl $0x0, %eax
jge 0x3cdd9
jmp 0x3ceff
movl $0x1, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x48(%rcx), %rcx
cmpl (%rcx), %eax
jge 0x3ce57
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), %rdi
movq -0x38(%rbp), %rsi
callq 0x3cfc0
cmpl $0x0, %eax
jge 0x3ce1d
jmp 0x3ceff
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x8(%rax), %rax
movslq -0x3c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdi
movq -0x38(%rbp), %rsi
callq 0x3cfc0
cmpl $0x0, %eax
jge 0x3ce4a
jmp 0x3ceff
jmp 0x3ce4c
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x3cde0
movq -0x38(%rbp), %rdi
callq 0x36d0
cmpl $0x0, %eax
jge 0x3cef3
leaq 0x48620(%rip), %rax     # 0x85490
cmpl $0x1, (%rax)
jle 0x3cee7
movq 0x4816c(%rip), %rax     # 0x84fe8
movq (%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x3ce9c
movq -0x20(%rbp), %rax
movq %rax, -0x80(%rbp)
jmp 0x3cea9
leaq 0x3d019(%rip), %rax     # 0x79ebc
movq %rax, -0x80(%rbp)
jmp 0x3cea9
movq -0x80(%rbp), %rax
movq %rax, -0x88(%rbp)
callq 0x35d0
movl (%rax), %edi
callq 0x34e0
movq -0x78(%rbp), %rdi
movq -0x70(%rbp), %rcx
movq -0x88(%rbp), %r8
movq %rax, %r9
leaq 0x3b550(%rip), %rsi     # 0x78429
leaq 0x3b539(%rip), %rdx     # 0x78419
movb $0x0, %al
callq 0x37f0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3cfa6
movl $0x0, -0x4(%rbp)
jmp 0x3cfa6
leaq 0x4858a(%rip), %rax     # 0x85490
cmpl $0x1, (%rax)
jle 0x3cf96
movq 0x480d2(%rip), %rax     # 0x84fe8
movq (%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x3cf3f
movq -0x20(%rbp), %rax
movq %rax, -0xa0(%rbp)
jmp 0x3cf4f
leaq 0x3cf76(%rip), %rax     # 0x79ebc
movq %rax, -0xa0(%rbp)
jmp 0x3cf4f
movq -0xa0(%rbp), %rax
movq %rax, -0xa8(%rbp)
callq 0x35d0
movl (%rax), %edi
callq 0x34e0
movq -0x98(%rbp), %rdi
movq -0x90(%rbp), %rcx
movq -0xa8(%rbp), %r8
movq %rax, %r9
leaq 0x3b4c5(%rip), %rsi     # 0x7844d
leaq 0x3b48a(%rip), %rdx     # 0x78419
movb $0x0, %al
callq 0x37f0
movq -0x38(%rbp), %rdi
callq 0x36d0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)