// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/samtools-0.1.18/knetfile.c
// Function: knet_seek
off_t knet_seek(knetFile *fp, int64_t off, int whence)
{
	if (whence == SEEK_SET && off == fp->offset) return 0;
	if (fp->type == KNF_TYPE_LOCAL) {
		/* Be aware that lseek() returns the offset after seeking,
		 * while fseek() returns zero on success. */
		off_t offset = lseek(fp->fd, off, whence);
		if (offset == -1) {
            // Be silent, it is OK for knet_seek to fail when the file is streamed
            // fprintf(stderr,"[knet_seek] %s\n", strerror(errno));
			return -1;
		}
		fp->offset = offset;
		return 0;
	}
    else if (fp->type == KNF_TYPE_FTP) 
    {
        if (whence==SEEK_CUR)
            fp->offset += off;
        else if (whence==SEEK_SET)
            fp->offset = off;
        else if ( whence==SEEK_END)
            fp->offset = fp->file_size+off;
		fp->is_ready = 0;
		return 0;
	} 
    else if (fp->type == KNF_TYPE_HTTP) 
    {
		if (whence == SEEK_END) { // FIXME: can we allow SEEK_END in future?
			fprintf(stderr, "[knet_seek] SEEK_END is not supported for HTTP. Offset is unchanged.\n");
			errno = ESPIPE;
			return -1;
		}
        if (whence==SEEK_CUR)
            fp->offset += off;
        else if (whence==SEEK_SET)
            fp->offset = off;
		fp->is_ready = 0;
		return 0;
	}
	errno = EINVAL;
    fprintf(stderr,"[knet_seek] %s\n", strerror(errno));
	return -1;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movl %edx, 0x1c(%rsp)
cmpl $0x0, 0x1c(%rsp)
jne 0x484137
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x484137
movq $0x0, 0x30(%rsp)
jmp 0x4842de
movq 0x28(%rsp), %rax
cmpl $0x1, (%rax)
jne 0x48418e
movq 0x28(%rsp), %rax
movl 0x4(%rax), %edi
movq 0x20(%rsp), %rsi
movl 0x1c(%rsp), %edx
callq 0x33270
movq %rax, 0x10(%rsp)
cmpq $-0x1, 0x10(%rsp)
jne 0x484172
movq $-0x1, 0x30(%rsp)
jmp 0x4842de
movq 0x10(%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x8(%rax)
movq $0x0, 0x30(%rsp)
jmp 0x4842de
movq 0x28(%rsp), %rax
cmpl $0x2, (%rax)
jne 0x484206
cmpl $0x1, 0x1c(%rsp)
jne 0x4841b3
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
jmp 0x4841ec
cmpl $0x0, 0x1c(%rsp)
jne 0x4841ca
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x8(%rax)
jmp 0x4841ea
cmpl $0x2, 0x1c(%rsp)
jne 0x4841e8
movq 0x28(%rsp), %rax
movq 0x68(%rax), %rcx
addq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x8(%rax)
jmp 0x4841ea
jmp 0x4841ec
movq 0x28(%rsp), %rax
movl $0x0, 0x40(%rax)
movq $0x0, 0x30(%rsp)
jmp 0x4842de
movq 0x28(%rsp), %rax
cmpl $0x3, (%rax)
jne 0x484295
cmpl $0x2, 0x1c(%rsp)
jne 0x48424c
movq 0x177da6(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0xf6dd2(%rip), %rsi     # 0x57affe
movb $0x0, %al
callq 0x33960
callq 0x32640
movl $0x1d, (%rax)
movq $-0x1, 0x30(%rsp)
jmp 0x4842de
cmpl $0x1, 0x1c(%rsp)
jne 0x484267
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
jmp 0x48427e
cmpl $0x0, 0x1c(%rsp)
jne 0x48427c
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x8(%rax)
jmp 0x48427e
movq 0x28(%rsp), %rax
movl $0x0, 0x40(%rax)
movq $0x0, 0x30(%rsp)
jmp 0x4842de
jmp 0x484297
jmp 0x484299
callq 0x32640
movl $0x16, (%rax)
movq 0x177d1d(%rip), %rax    # 0x5fbfc8
movq (%rax), %rax
movq %rax, 0x8(%rsp)
callq 0x32640
movl (%rax), %edi
callq 0x319e0
movq 0x8(%rsp), %rdi
movq %rax, %rdx
leaq 0xf6d76(%rip), %rsi     # 0x57b044
movb $0x0, %al
callq 0x33960
movq $-0x1, 0x30(%rsp)
movq 0x30(%rsp), %rax
addq $0x38, %rsp
retq
nopl (%rax,%rax)