// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/samtools-0.1.18/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 %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movzbl (%rdi), %eax
cmpl $0x72, %eax
je 0x2d90b0
cmpl $0x77, %eax
jne 0x2d90be
movl 0x84(%rbx), %edx
testl %edx, %edx
je 0x2d8f84
movq 0x60(%rbx), %rsi
movq %rbx, %rdi
callq 0x2d914f
andq $0x0, 0x80(%rbx)
movq 0x10(%rbx), %rdi
movl 0x20(%rdi), %r14d
pushq $0x4
popq %rbp
movl %ebp, %esi
callq 0x21822a
movq 0x10(%rbx), %rdi
movl 0x20(%rdi), %eax
subl %eax, %r14d
addq %r14, 0x28(%rbx)
cmpq $0xfff, %rax            # imm = 0xFFF
ja 0x2d8fdb
movl 0x8(%rbx), %edi
movq 0x68(%rbx), %rsi
movl $0x1000, %edx           # imm = 0x1000
subq %rax, %rdx
callq 0x17250
movq 0x10(%rbx), %rdi
movl $0x1000, 0x20(%rdi)     # imm = 0x1000
movq 0x68(%rbx), %rax
movq %rax, 0x18(%rdi)
movl $0x1000, %r14d          # imm = 0x1000
jmp 0x2d8f8f
callq 0x21791e
movl 0x8(%rbx), %ebp
movq 0x18(%rbx), %rax
movl 0x10(%rax), %eax
bswapl %eax
leaq 0xc(%rsp), %rsi
movl %eax, (%rsi)
pushq $0x4
popq %rdx
movl %ebp, %edi
callq 0x17250
movq 0x18(%rbx), %rax
movl 0x10(%rax), %edx
movl %edx, %ecx
sarl $0x11, %ecx
incl %ecx
xorl %esi, %esi
testl %ecx, %ecx
movl $0x0, %edi
cmovgl %ecx, %edi
cmpq %rsi, %rdi
je 0x2d9030
movq 0x8(%rax), %r8
movq (%r8,%rsi,8), %r9
bswapq %r9
movq %r9, (%r8,%rsi,8)
incq %rsi
jmp 0x2d9017
xorl %esi, %esi
movslq %edx, %rdx
cmpq %rdx, %rsi
jge 0x2d904d
movq (%rax), %rdx
movl (%rdx,%rsi,4), %edi
bswapl %edi
movl %edi, (%rdx,%rsi,4)
incq %rsi
movl 0x10(%rax), %edx
jmp 0x2d9032
movq 0x8(%rax), %rsi
movslq %ecx, %rdx
shlq $0x3, %rdx
movl %ebp, %edi
callq 0x17250
movq 0x18(%rbx), %rax
movq (%rax), %rsi
movslq 0x10(%rax), %rdx
shlq $0x2, %rdx
movl %ebp, %edi
callq 0x17250
movq 0x20(%rbx), %rax
bswapq %rax
leaq 0x10(%rsp), %r14
movq %rax, (%r14)
movl 0x8(%rbx), %edi
pushq $0x8
popq %r15
movq %r14, %rsi
movq %r15, %rdx
callq 0x17250
movq 0x28(%rbx), %rax
bswapq %rax
movq %rax, (%r14)
movl 0x8(%rbx), %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0x17250
jmp 0x2d90be
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0x2d90be
callq 0x21ddfd
movq 0x60(%rbx), %rdi
callq 0x17f48
movq 0x68(%rbx), %rdi
callq 0x17f48
movq 0x78(%rbx), %rax
testq %rax, %rax
je 0x2d9105
movq 0x18(%rax), %rdi
callq 0x17f48
movq 0x78(%rbx), %rax
movq 0x28(%rax), %rdi
callq 0x17f48
movq 0x78(%rbx), %rax
movq 0x38(%rax), %rdi
callq 0x17f48
movq 0x78(%rbx), %rdi
callq 0x17f48
movq 0x18(%rbx), %rax
testq %rax, %rax
je 0x2d912c
movq 0x8(%rax), %rdi
callq 0x17f48
movq 0x18(%rbx), %rax
movq (%rax), %rdi
callq 0x17f48
movq 0x18(%rbx), %rdi
callq 0x17f48
movq 0x10(%rbx), %rdi
callq 0x17f48
movl 0x8(%rbx), %edi
callq 0x17f20
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x17f48