// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/razf.c
// Function: razf_close
void razf_close(RAZF *rz){
	if(rz->mode == 'w'){
#ifndef _RZ_READONLY
		razf_end_flush(rz);
		deflateEnd(rz->stream);
#ifdef _USE_KNETFILE
		save_zindex(rz, rz->x.fpw);
		if(is_big_endian()){
			write(rz->x.fpw, &rz->in, sizeof(int64_t));
			write(rz->x.fpw, &rz->out, sizeof(int64_t));
		} else {
			uint64_t v64 = byte_swap_8((uint64_t)rz->in);
			write(rz->x.fpw, &v64, sizeof(int64_t));
			v64 = byte_swap_8((uint64_t)rz->out);
			write(rz->x.fpw, &v64, sizeof(int64_t));
		}
#else
		save_zindex(rz, rz->filedes);
		if(is_big_endian()){
			write(rz->filedes, &rz->in, sizeof(int64_t));
			write(rz->filedes, &rz->out, sizeof(int64_t));
		} else {
			uint64_t v64 = byte_swap_8((uint64_t)rz->in);
			write(rz->filedes, &v64, sizeof(int64_t));
			v64 = byte_swap_8((uint64_t)rz->out);
			write(rz->filedes, &v64, sizeof(int64_t));
		}
#endif
#endif
	} else if(rz->mode == 'r'){
		if(rz->stream) inflateEnd(rz->stream);
	}
	if(rz->inbuf) free(rz->inbuf);
	if(rz->outbuf) free(rz->outbuf);
	if(rz->header){
		free(rz->header->extra);
		free(rz->header->name);
		free(rz->header->comment);
		free(rz->header);
	}
	if(rz->index){
		free(rz->index->bin_offsets);
		free(rz->index->cell_offsets);
		free(rz->index);
	}
	free(rz->stream);
#ifdef _USE_KNETFILE
    if (rz->mode == 'r')
        knet_close(rz->x.fpr);
    if (rz->mode == 'w')
        close(rz->x.fpw);
#else
	close(rz->filedes);
#endif
	free(rz);
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movzbl (%rdi), %eax
cmpl $0x72, %eax
je 0x13246
cmpl $0x77, %eax
jne 0x13254
movl 0x84(%rbx), %edx
testl %edx, %edx
je 0x130fb
movq 0x60(%rbx), %rsi
movq %rbx, %rdi
callq 0x13300
movq $0x0, 0x80(%rbx)
movq 0x10(%rbx), %rdi
movl 0x20(%rdi), %r14d
movl $0x4, %esi
callq 0x3250
movq 0x10(%rbx), %rax
movl 0x20(%rax), %eax
subl %eax, %r14d
addq %r14, 0x28(%rbx)
cmpl $0xfff, %eax            # imm = 0xFFF
ja 0x13168
movl $0x1000, %ebp           # imm = 0x1000
movl 0x8(%rbx), %edi
movq 0x68(%rbx), %rsi
movl $0x1000, %edx           # imm = 0x1000
subl %eax, %edx
callq 0x3190
movq 0x10(%rbx), %rdi
movl %ebp, 0x20(%rdi)
movq 0x68(%rbx), %rax
movq %rax, 0x18(%rdi)
movl $0x4, %esi
callq 0x3250
movq 0x10(%rbx), %rax
movl 0x20(%rax), %eax
movl %eax, %ecx
subl %ebp, %ecx
negl %ecx
addq %rcx, 0x28(%rbx)
cmpl %ebp, %eax
jb 0x13127
movq 0x10(%rbx), %rdi
callq 0x3420
movl 0x8(%rbx), %ebp
movq 0x18(%rbx), %rax
movl 0x10(%rax), %eax
bswapl %eax
leaq 0x4(%rsp), %r14
movl %eax, (%r14)
movl $0x4, %edx
movl %ebp, %edi
movq %r14, %rsi
callq 0x3190
movq 0x18(%rbx), %rax
movl 0x10(%rax), %edx
movl %edx, %esi
sarl $0x11, %esi
leal 0x1(%rsi), %ecx
movl %ecx, (%r14)
testl %esi, %esi
js 0x131c6
movq 0x8(%rax), %rsi
movl %ecx, %edi
xorl %r8d, %r8d
movq (%rsi,%r8,8), %r9
bswapq %r9
movq %r9, (%rsi,%r8,8)
incq %r8
cmpq %r8, %rdi
jne 0x131b3
testl %edx, %edx
jle 0x131e3
movq (%rax), %rdx
xorl %esi, %esi
movl (%rdx,%rsi,4), %edi
bswapl %edi
movl %edi, (%rdx,%rsi,4)
incq %rsi
movslq 0x10(%rax), %rdi
cmpq %rdi, %rsi
jl 0x131cf
movq 0x8(%rax), %rsi
movslq %ecx, %rdx
shlq $0x3, %rdx
movl %ebp, %edi
callq 0x3190
movq 0x18(%rbx), %rax
movq (%rax), %rsi
movslq 0x10(%rax), %rdx
shlq $0x2, %rdx
movl %ebp, %edi
callq 0x3190
movq 0x20(%rbx), %rax
bswapq %rax
leaq 0x8(%rsp), %r14
movq %rax, (%r14)
movl 0x8(%rbx), %edi
movl $0x8, %edx
movq %r14, %rsi
callq 0x3190
movq 0x28(%rbx), %rax
bswapq %rax
movq %rax, (%r14)
movl 0x8(%rbx), %edi
movl $0x8, %edx
movq %r14, %rsi
callq 0x3190
jmp 0x13254
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0x13254
callq 0x3380
movq 0x60(%rbx), %rdi
testq %rdi, %rdi
je 0x13262
callq 0x3060
movq 0x68(%rbx), %rdi
testq %rdi, %rdi
je 0x13270
callq 0x3060
movq 0x78(%rbx), %rax
testq %rax, %rax
je 0x132a5
movq 0x18(%rax), %rdi
callq 0x3060
movq 0x78(%rbx), %rax
movq 0x28(%rax), %rdi
callq 0x3060
movq 0x78(%rbx), %rax
movq 0x38(%rax), %rdi
callq 0x3060
movq 0x78(%rbx), %rdi
callq 0x3060
movq 0x18(%rbx), %rax
testq %rax, %rax
je 0x132cc
movq 0x8(%rax), %rdi
callq 0x3060
movq 0x18(%rbx), %rax
movq (%rax), %rdi
callq 0x3060
movq 0x18(%rbx), %rdi
callq 0x3060
movq 0x10(%rbx), %rdi
callq 0x3060
cmpb $0x72, (%rbx)
jne 0x132e3
movq 0x8(%rbx), %rdi
callq 0x157a8
cmpb $0x77, (%rbx)
jne 0x132f0
movl 0x8(%rbx), %edi
callq 0x3270
movq %rbx, %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x3060