// File: /workspace/github_c_makefile_star2_O0/samtools[P]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) {
            bgzf_close_mt(fp);
            return -1;
        }
        fp->compress_level = -1;
        block_length = deflate_block(fp, 0); // write an empty block
        if (block_length < 0) {
            hts_log_debug("Deflate block operation failed: %s", bgzf_zerr(block_length, NULL));
            bgzf_close_mt(fp);
            return -1;
        }
        if (hwrite(fp->fp, fp->compressed_block, block_length) < 0
            || hflush(fp->fp) != 0) {
            hts_log_error("File write failed");
            fp->errcode |= BGZF_ERR_IO;
            return -1;
        }
    }

    bgzf_close_mt(fp);

    if ( fp->is_gzip )
    {
        if (fp->gz_stream == NULL) ret = Z_OK;
        else if (!fp->is_write) ret = inflateEnd(fp->gz_stream);
        else ret = deflateEnd(fp->gz_stream);
        if (ret != Z_OK) {
            hts_log_error("Call to inflateEnd/deflateEnd failed: %s", 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_cache(fp);
    ret = fp->errcode ? -1 : 0;
    free(fp);
    return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x103ef
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x10625
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x11, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1051c
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1051c
movq -0x10(%rbp), %rdi
callq 0xf820
cmpl $0x0, %eax
je 0x1043c
movq -0x10(%rbp), %rdi
callq 0x10630
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x10625
movq -0x10(%rbp), %rax
movl (%rax), %ecx
andl $0xe00fffff, %ecx       # imm = 0xE00FFFFF
orl $0x1ff00000, %ecx       # imm = 0x1FF00000
movl %ecx, (%rax)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0xfcc0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jge 0x104a2
movl -0x18(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
callq 0xcd40
movq %rax, %rcx
movl $0x5, %edi
leaq 0xdeb06(%rip), %rsi     # 0xeef85
leaq 0xdea48(%rip), %rdx     # 0xeeece
movb $0x0, %al
callq 0x1b030
movq -0x10(%rbp), %rdi
callq 0x10630
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x10625
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
movslq -0x18(%rbp), %rdx
callq 0xfdc0
cmpq $0x0, %rax
jl 0x104d3
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x143b0
cmpl $0x0, %eax
je 0x1051a
movl $0x1, %edi
leaq 0xdeaa6(%rip), %rsi     # 0xeef85
leaq 0xdeaaa(%rip), %rdx     # 0xeef90
movb $0x0, %al
callq 0x1b030
movq -0x10(%rbp), %rax
movl (%rax), %edx
andl $0xffff, %edx           # imm = 0xFFFF
orl $0x4, %edx
movl (%rax), %ecx
andl $0xffff, %edx           # imm = 0xFFFF
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
orl %edx, %ecx
movl %ecx, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x10625
jmp 0x1051c
movq -0x10(%rbp), %rdi
callq 0x10630
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x105bc
movq -0x10(%rbp), %rax
cmpq $0x0, 0x60(%rax)
jne 0x1054b
movl $0x0, -0x14(%rbp)
jmp 0x10580
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x11, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x1056e
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x44c0
movl %eax, -0x14(%rbp)
jmp 0x1057e
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x4290
movl %eax, -0x14(%rbp)
jmp 0x10580
cmpl $0x0, -0x14(%rbp)
je 0x105af
movl -0x14(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
callq 0xcd40
movq %rax, %rcx
movl $0x1, %edi
leaq 0xde9e4(%rip), %rsi     # 0xeef85
leaq 0xde9fa(%rip), %rdx     # 0xeefa2
movb $0x0, %al
callq 0x1b030
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x45a0
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x14920
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x105db
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x10625
movq -0x10(%rbp), %rdi
callq 0x10690
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x45a0
movq -0x10(%rbp), %rdi
callq 0x106f0
movq -0x10(%rbp), %rax
movl (%rax), %edx
andl $0xffff, %edx           # imm = 0xFFFF
xorl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rdi
callq 0x45a0
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nop