// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movb 0x64(%rax), %al
shrb $0x4, %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0xd2b33
movq -0x28(%rbp), %rax
movb 0x64(%rax), %al
shrb $0x5, %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0xd2b4b
callq 0x4050
movl $0x1d, (%rax)
movq $-0x1, -0x8(%rbp)
jmp 0xd2cda
movl -0x1c(%rbp), %eax
movl %eax, -0x3c(%rbp)
testl %eax, %eax
je 0xd2b6b
jmp 0xd2b57
movl -0x3c(%rbp), %eax
subl $0x1, %eax
je 0xd2b75
jmp 0xd2b61
movl -0x3c(%rbp), %eax
subl $0x2, %eax
je 0xd2b8d
jmp 0xd2bbe
movq $0x0, -0x30(%rbp)
jmp 0xd2bd6
callq 0x4050
movl $0x26, (%rax)
movq $-0x1, -0x8(%rbp)
jmp 0xd2cda
movq -0x28(%rbp), %rax
cmpq $0x0, 0x48(%rax)
jge 0xd2bb0
callq 0x4050
movl $0x1d, (%rax)
movq $-0x1, -0x8(%rbp)
jmp 0xd2cda
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0xd2bd6
callq 0x4050
movl $0x16, (%rax)
movq $-0x1, -0x8(%rbp)
jmp 0xd2cda
cmpq $0x0, -0x18(%rbp)
jge 0xd2bed
movq -0x30(%rbp), %rax
addq -0x18(%rbp), %rax
cmpq $0x0, %rax
jl 0xd2c0d
jmp 0xd2c25
movq -0x28(%rbp), %rax
cmpq $0x0, 0x48(%rax)
jl 0xd2c25
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movq 0x48(%rcx), %rcx
subq -0x30(%rbp), %rcx
cmpq %rcx, %rax
jle 0xd2c25
callq 0x4050
movl $0x16, (%rax)
movq $-0x1, -0x8(%rbp)
jmp 0xd2cda
movq -0x30(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movb 0x64(%rax), %al
shrb $0x7, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0xd2c9b
movq -0x28(%rbp), %rax
cmpq $0x0, 0xd0(%rax)
jge 0xd2c82
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rdx
movq (%rdx), %rdx
subq %rdx, %rax
addq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0xd8(%rax)
movq -0x28(%rbp), %rdi
callq 0xd2f00
movq -0x38(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0xd0(%rax)
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xd2cda
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xd0790
cmpl $0x0, %eax
jge 0xd2cc2
callq 0x4050
movl $0x1d, (%rax)
movq $-0x1, -0x8(%rbp)
jmp 0xd2cda
movq -0x28(%rbp), %rax
movb 0x64(%rax), %cl
andb $0x7f, %cl
orb $-0x80, %cl
movb %cl, 0x64(%rax)
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)