// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/htslib/knetfile.c
// Function: knet_seek
off_t knet_seek(knetFile *fp, off_t off, int whence)
{
#ifdef KNETFILE_HOOKS
       if (alt_seek)
               return alt_seek(fp, off, whence);
#endif

	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) return -1;
		fp->offset = offset;
		return fp->offset;
	} 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;
		else return -1;
		fp->is_ready = 0;
		return fp->offset;
	} 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;
		else return -1;
		fp->is_ready = 0;
		return fp->offset;
	}
	errno = EINVAL;
	fprintf(stderr,"[knet_seek] %s\n", strerror(errno));
	return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0xcce14
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0xcce14
movq $0x0, -0x8(%rbp)
jmp 0xccfbd
movq -0x10(%rbp), %rax
cmpl $0x1, (%rax)
jne 0xcce65
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x6e00
movq %rax, -0x28(%rbp)
cmpq $-0x1, -0x28(%rbp)
jne 0xcce48
movq $-0x1, -0x8(%rbp)
jmp 0xccfbd
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0xccfbd
movq -0x10(%rbp), %rax
cmpl $0x2, (%rax)
jne 0xccee3
cmpl $0x1, -0x1c(%rbp)
jne 0xcce86
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
jmp 0xccec7
cmpl $0x0, -0x1c(%rbp)
jne 0xcce9a
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0xccec5
cmpl $0x2, -0x1c(%rbp)
jne 0xcceb6
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rcx
addq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0xccec3
movq $-0x1, -0x8(%rbp)
jmp 0xccfbd
jmp 0xccec5
jmp 0xccec7
movq -0x10(%rbp), %rax
movl $0x0, 0x40(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0xccfbd
movq -0x10(%rbp), %rax
cmpl $0x3, (%rax)
jne 0xccf77
cmpl $0x2, -0x1c(%rbp)
jne 0xccf26
movq 0x380d3(%rip), %rax     # 0x104fd0
movq (%rax), %rdi
leaq 0x18a0c(%rip), %rsi     # 0xe5913
movb $0x0, %al
callq 0x6a80
callq 0x6060
movl $0x1d, (%rax)
movq $-0x1, -0x8(%rbp)
jmp 0xccfbd
cmpl $0x1, -0x1c(%rbp)
jne 0xccf3e
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
jmp 0xccf5e
cmpl $0x0, -0x1c(%rbp)
jne 0xccf52
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0xccf5c
movq $-0x1, -0x8(%rbp)
jmp 0xccfbd
jmp 0xccf5e
movq -0x10(%rbp), %rax
movl $0x0, 0x40(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0xccfbd
jmp 0xccf79
jmp 0xccf7b
callq 0x6060
movl $0x16, (%rax)
movq 0x38043(%rip), %rax     # 0x104fd0
movq (%rax), %rax
movq %rax, -0x30(%rbp)
callq 0x6060
movl (%rax), %edi
callq 0x6220
movq -0x30(%rbp), %rdi
movq %rax, %rdx
leaq 0x189ab(%rip), %rsi     # 0xe5959
movb $0x0, %al
callq 0x6a80
movq $-0x1, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)