// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x3c08f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c2cd
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x10, %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0x3c1d8
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x1d, %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0x3c1d8
movq -0x10(%rbp), %rdi
callq 0x3b870
cmpl $0x0, %eax
je 0x3c0d3
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c2cd
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 0x3bc70
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jge 0x3c135
leaq 0x4938e(%rip), %rax     # 0x85490
cmpl $0x3, (%rax)
jl 0x3c129
movq 0x48eda(%rip), %rax     # 0x84fe8
movq (%rax), %rdi
movl -0x18(%rbp), %ecx
leaq 0x3c1c2(%rip), %rsi     # 0x782dd
leaq 0x3c247(%rip), %rdx     # 0x78369
movb $0x0, %al
callq 0x37f0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c2cd
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rsi
movslq -0x18(%rbp), %rdx
callq 0x3bd80
cmpq $0x0, %rax
jl 0x3c166
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x41120
cmpl $0x0, %eax
je 0x3c1be
leaq 0x49323(%rip), %rax     # 0x85490
cmpl $0x1, (%rax)
jl 0x3c191
movq 0x48e6f(%rip), %rax     # 0x84fe8
movq (%rax), %rdi
leaq 0x3c1f1(%rip), %rsi     # 0x78374
leaq 0x3c1df(%rip), %rdx     # 0x78369
movb $0x0, %al
callq 0x37f0
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 0x3c2cd
movq -0x10(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0x3c1d6
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x3c2e0
jmp 0x3c1d8
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x3c272
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x10, %eax
andl $0x3, %eax
cmpl $0x0, %eax
jne 0x3c20d
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
callq 0x30e0
movl %eax, -0x14(%rbp)
jmp 0x3c21d
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
callq 0x33d0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x3c265
leaq 0x49266(%rip), %rax     # 0x85490
cmpl $0x1, (%rax)
jl 0x3c265
movq 0x48db2(%rip), %rax     # 0x84fe8
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movl -0x14(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
callq 0x3a130
movq -0x20(%rbp), %rdi
movq %rax, %rcx
leaq 0x3c137(%rip), %rsi     # 0x7838e
leaq 0x3c10b(%rip), %rdx     # 0x78369
movb $0x0, %al
callq 0x37f0
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
callq 0x3370
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x415a0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x3c291
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c2cd
movq -0x10(%rbp), %rdi
callq 0x3c430
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x3370
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x3370
movq -0x10(%rbp), %rdi
callq 0x3c490
movq -0x10(%rbp), %rdi
callq 0x3370
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)