// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/bgzf.c
// Function: bgzf_close
int bgzf_close(BGZF* fp)
{
	int ret, count, block_length;
	if (fp == 0) return -1;
	if (fp->is_write) {
		if (bgzf_flush(fp) != 0) return -1;
		fp->compress_level = -1;
		block_length = deflate_block(fp, 0); // write an empty block
		count = fwrite(fp->compressed_block, 1, block_length, fp->fp);
		if (fflush(fp->fp) != 0) {
			fp->errcode |= BGZF_ERR_IO;
			return -1;
		}
		if (fp->mt) mt_destroy(fp->mt);
	}
	ret = fp->is_write? fclose(fp->fp) : _bgzf_close(fp->fp);
	if (ret != 0) return -1;
	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 0x18932
movq %rdi, %rbx
testb $0x3, 0x2(%rdi)
je 0x1887b
movq %rbx, %rdi
callq 0x1831c
testl %eax, %eax
jne 0x18932
orl $0xfffc0000, (%rbx)     # imm = 0xFFFC0000
movq %rbx, %rdi
xorl %esi, %esi
callq 0x18569
movslq %eax, %rdx
movq 0x20(%rbx), %rdi
movq 0x30(%rbx), %rcx
movl $0x1, %esi
callq 0x3540
movq 0x30(%rbx), %rdi
callq 0x33f0
testl %eax, %eax
je 0x18789
orb $0x4, (%rbx)
jmp 0x18932
movq 0x38(%rbx), %r14
testq %r14, %r14
je 0x1887b
leaq 0x38(%r14), %r15
movq %r15, %rdi
callq 0x35e0
movl $0x1, 0xc(%r14)
movl $0x0, 0x10(%r14)
leaq 0x60(%r14), %rdi
movq %rdi, (%rsp)
callq 0x30f0
movq %r15, %rdi
callq 0x33d0
movl (%r14), %eax
cmpl $0x2, %eax
jl 0x187ef
movl $0x1, %r12d
movq 0x30(%r14), %rax
movq (%rax,%r12,8), %rdi
xorl %esi, %esi
callq 0x3580
incq %r12
movslq (%r14), %rax
cmpq %rax, %r12
jl 0x187d5
cmpl $0x0, 0x4(%r14)
jle 0x18815
xorl %r12d, %r12d
movq 0x18(%r14), %rax
movq (%rax,%r12,8), %rdi
callq 0x3060
incq %r12
movslq 0x4(%r14), %rax
cmpq %rax, %r12
jl 0x187f9
movl (%r14), %eax
testl %eax, %eax
jle 0x1883e
movl $0x10, %r13d
xorl %r12d, %r12d
movq 0x28(%r14), %rax
movq (%rax,%r13), %rdi
callq 0x3060
incq %r12
movslq (%r14), %rax
addq $0x28, %r13
cmpq %rax, %r12
jl 0x18822
movq 0x18(%r14), %rdi
callq 0x3060
movq 0x20(%r14), %rdi
callq 0x3060
movq 0x28(%r14), %rdi
callq 0x3060
movq 0x30(%r14), %rdi
callq 0x3060
movq (%rsp), %rdi
callq 0x3480
movq %r15, %rdi
callq 0x3220
movq %r14, %rdi
callq 0x3060
testb $0x3, 0x2(%rbx)
movq 0x30(%rbx), %rdi
je 0x1888c
callq 0x31c0
jmp 0x18891
callq 0x15d92
testl %eax, %eax
jne 0x18932
movq 0x18(%rbx), %rdi
callq 0x3060
movq 0x20(%rbx), %rdi
callq 0x3060
testb $0x3, 0x2(%rbx)
jne 0x18928
movq 0x28(%rbx), %r14
movl (%r14), %eax
testl %eax, %eax
je 0x18905
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 0x188f3
movq 0x20(%r14), %rax
movq (%rax,%r15,2), %rdi
callq 0x3060
movl (%r14), %eax
incq %r13
movl %eax, %ecx
addq $0xc, %r15
addl $0x2, %r12d
cmpq %rcx, %r13
jb 0x188c8
movq 0x18(%r14), %rdi
callq 0x3060
movq 0x10(%r14), %rdi
callq 0x3060
movq 0x20(%r14), %rdi
callq 0x3060
movq %r14, %rdi
callq 0x3060
movq %rbx, %rdi
callq 0x3060
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq