// File: /workspace/github_c_makefile_star2_O3/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 0x138bc
cmpl $0x77, %eax
jne 0x138ca
movl 0x84(%rbx), %edx
testl %edx, %edx
je 0x1377d
movq 0x60(%rbx), %rsi
movq %rbx, %rdi
callq 0x13978
movq $0x0, 0x80(%rbx)
movq 0x10(%rbx), %rdi
movl 0x20(%rdi), %r14d
movl $0x4, %esi
callq 0x3250
movq 0x10(%rbx), %rdi
movl 0x20(%rdi), %eax
subl %eax, %r14d
addq %r14, 0x28(%rbx)
cmpl $0xfff, %eax            # imm = 0xFFF
ja 0x137ea
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), %rdi
movl 0x20(%rdi), %eax
movl %eax, %ecx
subl %ebp, %ecx
negl %ecx
addq %rcx, 0x28(%rbx)
cmpl %ebp, %eax
jb 0x137a9
callq 0x3420
movl 0x8(%rbx), %ebp
movq 0x18(%rbx), %rax
movl 0x10(%rax), %eax
bswapl %eax
leaq 0x4(%rsp), %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movl %ebp, %edi
callq 0x3190
movq 0x18(%rbx), %rax
movl 0x10(%rax), %edx
movl %edx, %edi
sarl $0x11, %edi
leal 0x1(%rdi), %ecx
movq 0x8(%rax), %rsi
testl %edi, %edi
js 0x1385d
movl %ecx, %edi
xorl %r8d, %r8d
movq (%rsi,%r8,8), %r9
bswapq %r9
movq %r9, (%rsi,%r8,8)
incq %r8
cmpq %r8, %rdi
jne 0x1382a
testl %edx, %edx
jle 0x1385d
movq (%rax), %rdx
xorl %edi, %edi
movl (%rdx,%rdi,4), %r8d
bswapl %r8d
movl %r8d, (%rdx,%rdi,4)
incq %rdi
movslq 0x10(%rax), %r8
cmpq %r8, %rdi
jl 0x13846
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 0x138ca
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0x138ca
callq 0x3380
movq 0x60(%rbx), %rdi
testq %rdi, %rdi
je 0x138d8
callq 0x3060
movq 0x68(%rbx), %rdi
testq %rdi, %rdi
je 0x138e6
callq 0x3060
movq 0x78(%rbx), %rax
testq %rax, %rax
je 0x1391b
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 0x13942
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
movb (%rbx), %al
cmpb $0x72, %al
jne 0x1395c
movq 0x8(%rbx), %rdi
callq 0x15d92
movb (%rbx), %al
cmpb $0x77, %al
jne 0x13968
movl 0x8(%rbx), %edi
callq 0x3270
movq %rbx, %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x3060