// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/hfile_libcurl.c
// Function: libcurl_seek
static off_t libcurl_seek(hFILE *fpv, off_t offset, int whence)
{
    hFILE_libcurl *fp = (hFILE_libcurl *) fpv;
    off_t origin, pos;

    if (!fp->is_read || !fp->can_seek) {
        // Cowardly refuse to seek when writing or a previous seek failed.
        errno = ESPIPE;
        return -1;
    }

    switch (whence) {
    case SEEK_SET:
        origin = 0;
        break;
    case SEEK_CUR:
        errno = ENOSYS;
        return -1;
    case SEEK_END:
        if (fp->file_size < 0) { errno = ESPIPE; return -1; }
        origin = fp->file_size;
        break;
    default:
        errno = EINVAL;
        return -1;
    }

    // Check 0 <= origin+offset < fp->file_size carefully, avoiding overflow
    if ((offset < 0)? origin + offset < 0
                : (fp->file_size >= 0 && offset > fp->file_size - origin)) {
        errno = EINVAL;
        return -1;
    }

    pos = origin + offset;

    if (fp->tried_seek) {
        /* Seeking has worked at least once, so now we can delay doing
           the actual work until the next read.  This avoids lots of pointless
           http or ftp reconnections if the caller does lots of seeks
           without any intervening reads. */
        if (fp->delayed_seek < 0) {
            fp->last_offset = fp->base.offset + (fp->base.end - fp->base.buffer);
            // Stash the current hFILE buffer content in case it's useful later
            preserve_buffer_content(fp);
        }
        fp->delayed_seek = pos;
        return pos;
    }

    if (restart_from_position(fp, pos) < 0) {
        /* This value for errno may not be entirely true, but the caller may be
           able to carry on with the existing handle. */
        errno = ESPIPE;
        return -1;
    }

    fp->tried_seek = 1;
    return pos;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movb 0x64(%rdi), %al
movl %eax, %ecx
notb %cl
testb $0x30, %cl
jne 0x668c1
movq %rdi, %r14
testl %edx, %edx
je 0x6687f
cmpl $0x2, %edx
je 0x66874
cmpl $0x1, %edx
jne 0x668ce
callq 0x4050
movl $0x26, (%rax)
jmp 0x668d9
movq 0x48(%r14), %rbx
testq %rbx, %rbx
jns 0x66881
jmp 0x668c1
movl %edx, %ebx
testq %rsi, %rsi
js 0x668a2
movq 0x48(%r14), %rcx
testq %rcx, %rcx
setns %dl
subq %rbx, %rcx
cmpq %rsi, %rcx
setl %cl
testb %cl, %dl
jne 0x668ce
addq %rsi, %rbx
jmp 0x668a7
addq %rsi, %rbx
js 0x668ce
testb %al, %al
js 0x668e9
movq %r14, %rdi
movq %rbx, %rsi
callq 0x657ce
testl %eax, %eax
js 0x668c1
orb $-0x80, 0x64(%r14)
jmp 0x668dc
callq 0x4050
movl $0x1d, (%rax)
jmp 0x668d9
callq 0x4050
movl $0x16, (%rax)
pushq $-0x1
popq %rbx
movq %rbx, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
cmpq $0x0, 0xd0(%r14)
jns 0x66987
movq 0x10(%r14), %r15
movq (%r14), %rax
movq 0x8(%r14), %r12
movq 0x28(%r14), %rcx
addq %r15, %rcx
subq %rax, %rcx
movq %rcx, 0xd8(%r14)
cmpq %r15, %r12
je 0x66939
movq 0xe0(%r14), %rdi
testq %rdi, %rdi
je 0x6693d
movq 0x18(%r14), %r13
movq 0xf0(%r14), %rcx
subq %rax, %r13
cmpq %r13, %rcx
jb 0x66944
jmp 0x66965
xorl %eax, %eax
jmp 0x66980
movq 0x18(%r14), %r13
subq %rax, %r13
movq %r13, %rdi
callq 0x4680
movq %rax, 0xe0(%r14)
testq %rax, %rax
je 0x66987
movq %rax, %rdi
movq %r13, 0xf0(%r14)
movq %r13, %rcx
subq %r12, %r15
cmpq %rcx, %r15
ja 0x66993
movq %r12, %rsi
movq %r15, %rdx
callq 0x43c0
movq 0x10(%r14), %rax
subq 0x8(%r14), %rax
movq %rax, 0xe8(%r14)
movq %rbx, 0xd0(%r14)
jmp 0x668dc
leaq 0x1c331(%rip), %rdi     # 0x82ccb
leaq 0x1c2ec(%rip), %rsi     # 0x82c8d
leaq 0x1c357(%rip), %rcx     # 0x82cff
movl $0x398, %edx            # imm = 0x398
callq 0x42f0