// File: /workspace/github_c_makefile_star2_O3/zhou-lab[P]tbmate/htslib/bgzf.c
// Function: bgzf_close
int bgzf_close(BGZF* fp)
{
    int ret, block_length;
    if (fp == 0) return -1;
    if (fp->is_write && fp->is_compressed) {
        if (bgzf_flush(fp) != 0) return -1;
        fp->compress_level = -1;
        block_length = deflate_block(fp, 0); // write an empty block
        if (block_length < 0) {
            if (hts_verbose >= 3) fprintf(stderr, "[E::%s] deflate_block error %d\n", __func__, block_length);
            return -1;
        }
        if (hwrite(fp->fp, fp->compressed_block, block_length) < 0
            || hflush(fp->fp) != 0) {
            if (hts_verbose >= 1) fprintf(stderr, "[E::%s] file write error\n", __func__);
            fp->errcode |= BGZF_ERR_IO;
            return -1;
        }
#ifdef BGZF_MT
        if (fp->mt) mt_destroy(fp->mt);
#endif
    }
    if ( fp->is_gzip )
    {
        if (!fp->is_write) ret = inflateEnd(fp->gz_stream);
        else ret = deflateEnd(fp->gz_stream);
        if (ret != Z_OK && hts_verbose >= 1)
            fprintf(stderr, "[E::%s] inflateEnd/deflateEnd failed: %s\n",
                    __func__, bgzf_zerr(ret, NULL));
        free(fp->gz_stream);
    }
    ret = hclose(fp->fp);
    if (ret != 0) return -1;
    bgzf_index_destroy(fp);
    free(fp->uncompressed_block);
    free(fp->compressed_block);
    free_cache(fp);
    free(fp);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rdi, %rdi
je 0x28b73
movq %rdi, %rbx
movl (%rdi), %eax
testl $0x30000, %eax          # imm = 0x30000
sete %cl
testl $0x60000000, %eax       # imm = 0x60000000
sete %al
orb %cl, %al
je 0x289f1
movl (%rbx), %eax
testl %eax, %eax
jns 0x28ab3
movq 0x58(%rbx), %rdi
testl $0x30000, %eax          # imm = 0x30000
je 0x28a91
callq 0x33d0
jmp 0x28a96
movq %rbx, %rdi
callq 0x2835e
testl %eax, %eax
jne 0x28b73
orl $0x1ff00000, (%rbx)     # imm = 0x1FF00000
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2872d
testl %eax, %eax
js 0x28b67
movq 0x28(%rbx), %rsi
movq 0x38(%rbx), %r12
movl %eax, %r15d
movq 0x8(%r12), %rdi
movq 0x18(%r12), %r14
subq %rdi, %r14
cmpq %r15, %r14
movq %r15, %r13
cmovbq %r14, %r13
movq %rsi, (%rsp)
movq %r13, %rdx
callq 0x3850
addq %r13, 0x8(%r12)
cmpq %r15, %r14
jae 0x28a68
movq %r12, %rdi
movq (%rsp), %rsi
movq %r15, %rdx
movq %r13, %rcx
callq 0x2ba7d
testq %rax, %rax
js 0x28a79
movq 0x38(%rbx), %rdi
callq 0x2b9a8
testl %eax, %eax
je 0x28b84
leaq 0x36a08(%rip), %rax     # 0x5f488
cmpl $0x0, (%rax)
jg 0x28ba7
orb $0x4, (%rbx)
jmp 0x28b73
callq 0x30e0
testl %eax, %eax
je 0x28aaa
leaq 0x369e7(%rip), %rcx     # 0x5f488
cmpl $0x0, (%rcx)
jg 0x28b9b
movq 0x58(%rbx), %rdi
callq 0x3370
movq 0x38(%rbx), %rdi
callq 0x2bbcf
testl %eax, %eax
jne 0x28b73
movq %rbx, %rdi
callq 0x28cc7
movq 0x20(%rbx), %rdi
callq 0x3370
movq 0x28(%rbx), %rdi
callq 0x3370
testb $0x3, 0x2(%rbx)
jne 0x28b5b
movq 0x30(%rbx), %r14
movl (%r14), %eax
testl %eax, %eax
je 0x28b38
movl $0x4, %r15d
xorl %r12d, %r12d
xorl %r13d, %r13d
movq 0x10(%r14), %rcx
movq %r13, %rdx
shrq $0x4, %rdx
movl (%rcx,%rdx,4), %edx
movl %r12d, %ecx
andb $0x1e, %cl
shrl %cl, %edx
testb $0x3, %dl
jne 0x28b26
movq 0x20(%r14), %rax
movq (%rax,%r15,2), %rdi
callq 0x3370
movl (%r14), %eax
incq %r13
movl %eax, %ecx
addq $0xc, %r15
addl $0x2, %r12d
cmpq %rcx, %r13
jb 0x28afb
movq 0x18(%r14), %rdi
callq 0x3370
movq 0x10(%r14), %rdi
callq 0x3370
movq 0x20(%r14), %rdi
callq 0x3370
movq %r14, %rdi
callq 0x3370
movq %rbx, %rdi
callq 0x3370
xorl %ebp, %ebp
jmp 0x28b73
leaq 0x3691a(%rip), %rcx     # 0x5f488
cmpl $0x3, (%rcx)
jge 0x28bb1
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x40(%rbx), %rdi
testq %rdi, %rdi
je 0x289ce
callq 0x28bd4
jmp 0x289ce
movl %eax, %edi
callq 0x48aa
jmp 0x28aaa
callq 0x488b
jmp 0x28a89
movq 0x36430(%rip), %rcx     # 0x5efe8
movq (%rcx), %rdi
leaq 0x2742b(%rip), %rsi     # 0x4ffed
leaq 0x274b0(%rip), %rdx     # 0x50079
movl %eax, %ecx
xorl %eax, %eax
callq 0x37e0
jmp 0x28b73