// File: /workspace/github_c_makefile_star2_O2/icebert[P]pblat/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 (hwrite(fp->fp, fp->compressed_block, block_length) < 0
            || hflush(fp->fp) != 0) {
            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) (void)inflateEnd(fp->gz_stream);
        else (void)deflateEnd(fp->gz_stream);
        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
pushq $-0x1
popq %rbp
testq %rdi, %rdi
je 0x5d1fc
movq %rdi, %rbx
movl (%rdi), %eax
testl $0x30000, %eax          # imm = 0x30000
sete %cl
testl $0x60000000, %eax       # imm = 0x60000000
sete %al
orb %cl, %al
je 0x5d0f8
movl (%rbx), %eax
testl %eax, %eax
jns 0x5d154
movq 0x58(%rbx), %rdi
testl $0x30000, %eax          # imm = 0x30000
je 0x5d146
callq 0x6420
jmp 0x5d14b
movq %rbx, %rdi
callq 0x5ccd1
testl %eax, %eax
jne 0x5d1fc
orl $0x1ff00000, (%rbx)     # imm = 0x1FF00000
movq %rbx, %rdi
xorl %esi, %esi
callq 0x5ce99
movq 0x28(%rbx), %rsi
movq 0x38(%rbx), %rdi
movslq %eax, %rdx
callq 0x5cf25
testq %rax, %rax
js 0x5d13e
movq 0x38(%rbx), %rdi
callq 0x5f83e
testl %eax, %eax
je 0x5d20d
orb $0x4, (%rbx)
jmp 0x5d1fc
callq 0x6730
movq 0x58(%rbx), %rdi
callq 0x68a0
movq 0x38(%rbx), %rdi
callq 0x5fa52
testl %eax, %eax
jne 0x5d1fc
movq %rbx, %rdi
callq 0x5d2f0
movq 0x20(%rbx), %rdi
callq 0x68a0
movq 0x28(%rbx), %rdi
callq 0x68a0
testb $0x3, 0x2(%rbx)
jne 0x5d1f2
movq 0x30(%rbx), %r14
pushq $0x4
popq %r15
xorl %r12d, %r12d
xorl %r13d, %r13d
movl (%r14), %eax
cmpq %rax, %r13
jae 0x5d1cf
movq 0x10(%r14), %rax
movq %r13, %rcx
shrq $0x4, %rcx
movl (%rax,%rcx,4), %eax
movl %r12d, %ecx
andb $0x1e, %cl
shrl %cl, %eax
testb $0x3, %al
jne 0x5d1c2
movq 0x20(%r14), %rax
movq (%rax,%r15,2), %rdi
callq 0x68a0
incq %r13
addq $0xc, %r15
addl $0x2, %r12d
jmp 0x5d193
movq 0x18(%r14), %rdi
callq 0x68a0
movq 0x10(%r14), %rdi
callq 0x68a0
movq 0x20(%r14), %rdi
callq 0x68a0
movq %r14, %rdi
callq 0x68a0
movq %rbx, %rdi
callq 0x68a0
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x40(%rbx), %r14
testq %r14, %r14
je 0x5d0e0
leaq 0x38(%r14), %r15
movq %r15, %rdi
callq 0x6ae0
movl $0x1, 0xc(%r14)
movl $0x0, 0x10(%r14)
leaq 0x60(%r14), %rdi
movq %rdi, (%rsp)
callq 0x6250
movq %r15, %rdi
callq 0x64f0
pushq $0x1
popq %r12
movslq (%r14), %rax
cmpq %rax, %r12
jge 0x5d26b
movq 0x30(%r14), %rax
movq (%rax,%r12,8), %rdi
xorl %esi, %esi
callq 0x6610
incq %r12
jmp 0x5d24f
xorl %r12d, %r12d
movslq 0x4(%r14), %rax
cmpq %rax, %r12
jge 0x5d289
movq 0x18(%r14), %rax
movq (%rax,%r12,8), %rdi
callq 0x68a0
incq %r12
jmp 0x5d26e
pushq $0x8
popq %r13
xorl %r12d, %r12d
movslq (%r14), %rax
cmpq %rax, %r12
jge 0x5d2ae
movq 0x28(%r14), %rax
movq (%rax,%r13), %rdi
callq 0x68a0
incq %r12
addq $0x20, %r13
jmp 0x5d290
movq 0x18(%r14), %rdi
callq 0x68a0
movq 0x20(%r14), %rdi
callq 0x68a0
movq 0x28(%r14), %rdi
callq 0x68a0
movq 0x30(%r14), %rdi
callq 0x68a0
movq (%rsp), %rdi
callq 0x6e60
movq %r15, %rdi
callq 0x6860
movq %r14, %rdi
callq 0x68a0
jmp 0x5d0e0