// File: /workspace/github_cpp_makefile_star2_O1/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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 0x2301e
cmpl $0x77, %eax
jne 0x2302c
movl 0x84(%rbx), %edx
testl %edx, %edx
je 0x22ed3
movq 0x60(%rbx), %rsi
movq %rbx, %rdi
callq 0x230d8
movq $0x0, 0x80(%rbx)
movq 0x10(%rbx), %rdi
movl 0x20(%rdi), %r14d
movl $0x4, %esi
callq 0x3180
movq 0x10(%rbx), %rax
movl 0x20(%rax), %eax
subl %eax, %r14d
addq %r14, 0x28(%rbx)
cmpl $0xfff, %eax            # imm = 0xFFF
ja 0x22f40
movl $0x1000, %ebp           # imm = 0x1000
movl 0x8(%rbx), %edi
movq 0x68(%rbx), %rsi
movl $0x1000, %edx           # imm = 0x1000
subl %eax, %edx
callq 0x3640
movq 0x10(%rbx), %rdi
movl %ebp, 0x20(%rdi)
movq 0x68(%rbx), %rax
movq %rax, 0x18(%rdi)
movl $0x4, %esi
callq 0x3180
movq 0x10(%rbx), %rax
movl 0x20(%rax), %eax
movl %eax, %ecx
subl %ebp, %ecx
negl %ecx
addq %rcx, 0x28(%rbx)
cmpl %ebp, %eax
jb 0x22eff
movq 0x10(%rbx), %rdi
callq 0x32f0
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 0x3640
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 0x22f9e
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 0x22f8b
testl %edx, %edx
jle 0x22fbb
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 0x22fa7
movq 0x8(%rax), %rsi
movslq %ecx, %rdx
shlq $0x3, %rdx
movl %ebp, %edi
callq 0x3640
movq 0x18(%rbx), %rax
movq (%rax), %rsi
movslq 0x10(%rax), %rdx
shlq $0x2, %rdx
movl %ebp, %edi
callq 0x3640
movq 0x20(%rbx), %rax
bswapq %rax
leaq 0x8(%rsp), %r14
movq %rax, (%r14)
movl 0x8(%rbx), %edi
movl $0x8, %edx
movq %r14, %rsi
callq 0x3640
movq 0x28(%rbx), %rax
bswapq %rax
movq %rax, (%r14)
movl 0x8(%rbx), %edi
movl $0x8, %edx
movq %r14, %rsi
callq 0x3640
jmp 0x2302c
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0x2302c
callq 0x30a0
movq 0x60(%rbx), %rdi
testq %rdi, %rdi
je 0x2303a
callq 0x32c0
movq 0x68(%rbx), %rdi
testq %rdi, %rdi
je 0x23048
callq 0x32c0
movq 0x78(%rbx), %rax
testq %rax, %rax
je 0x2307d
movq 0x18(%rax), %rdi
callq 0x32c0
movq 0x78(%rbx), %rax
movq 0x28(%rax), %rdi
callq 0x32c0
movq 0x78(%rbx), %rax
movq 0x38(%rax), %rdi
callq 0x32c0
movq 0x78(%rbx), %rdi
callq 0x32c0
movq 0x18(%rbx), %rax
testq %rax, %rax
je 0x230a4
movq 0x8(%rax), %rdi
callq 0x32c0
movq 0x18(%rbx), %rax
movq (%rax), %rdi
callq 0x32c0
movq 0x18(%rbx), %rdi
callq 0x32c0
movq 0x10(%rbx), %rdi
callq 0x32c0
cmpb $0x72, (%rbx)
jne 0x230bb
movq 0x8(%rbx), %rdi
callq 0x1c43b
cmpb $0x77, (%rbx)
jne 0x230c8
movl 0x8(%rbx), %edi
callq 0x3090
movq %rbx, %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x32c0