// File: /workspace/github_c_makefile_star2_O0/zhou-lab[P]tbmate/htslib/knetfile.c
// Function: knet_seek
off_t knet_seek(knetFile *fp, off_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) 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 0x6c414
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x6c414
movq $0x0, -0x8(%rbp)
jmp 0x6c5bd
movq -0x10(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x6c465
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x3530
movq %rax, -0x28(%rbp)
cmpq $-0x1, -0x28(%rbp)
jne 0x6c448
movq $-0x1, -0x8(%rbp)
jmp 0x6c5bd
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 0x6c5bd
movq -0x10(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x6c4e3
cmpl $0x1, -0x1c(%rbp)
jne 0x6c486
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
jmp 0x6c4c7
cmpl $0x0, -0x1c(%rbp)
jne 0x6c49a
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x6c4c5
cmpl $0x2, -0x1c(%rbp)
jne 0x6c4b6
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rcx
addq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x6c4c3
movq $-0x1, -0x8(%rbp)
jmp 0x6c5bd
jmp 0x6c4c5
jmp 0x6c4c7
movq -0x10(%rbp), %rax
movl $0x0, 0x40(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0x6c5bd
movq -0x10(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x6c577
cmpl $0x2, -0x1c(%rbp)
jne 0x6c526
movq 0x18aeb(%rip), %rax     # 0x84fe8
movq (%rax), %rdi
leaq 0xdf20(%rip), %rsi      # 0x7a427
movb $0x0, %al
callq 0x37f0
callq 0x35d0
movl $0x1d, (%rax)
movq $-0x1, -0x8(%rbp)
jmp 0x6c5bd
cmpl $0x1, -0x1c(%rbp)
jne 0x6c53e
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
jmp 0x6c55e
cmpl $0x0, -0x1c(%rbp)
jne 0x6c552
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x6c55c
movq $-0x1, -0x8(%rbp)
jmp 0x6c5bd
jmp 0x6c55e
movq -0x10(%rbp), %rax
movl $0x0, 0x40(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0x6c5bd
jmp 0x6c579
jmp 0x6c57b
callq 0x35d0
movl $0x16, (%rax)
movq 0x18a5b(%rip), %rax     # 0x84fe8
movq (%rax), %rax
movq %rax, -0x30(%rbp)
callq 0x35d0
movl (%rax), %edi
callq 0x34e0
movq -0x30(%rbp), %rdi
movq %rax, %rdx
leaq 0xdebf(%rip), %rsi      # 0x7a46d
movb $0x0, %al
callq 0x37f0
movq $-0x1, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)