// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/hfile_libcurl.c
// Function: libcurl_read
static ssize_t libcurl_read(hFILE *fpv, void *bufferv, size_t nbytes)
{
    hFILE_libcurl *fp = (hFILE_libcurl *) fpv;
    char *buffer = (char *) bufferv;
    off_t to_skip = -1;
    ssize_t got = 0;
    CURLcode err;

    if (fp->delayed_seek >= 0) {
        assert(fp->base.offset == fp->delayed_seek);

        if (fp->preserved
            && fp->last_offset > fp->delayed_seek
            && fp->last_offset - fp->preserved_bytes <= fp->delayed_seek) {
            // Can use buffer contents copied when seeking started, to
            // avoid having to re-read data discarded by hseek().
            // Note fp->last_offset is the offset of the *end* of the
            // preserved buffer.
            size_t n = fp->last_offset - fp->delayed_seek;
            char *start = fp->preserved + (fp->preserved_bytes - n);
            size_t bytes = n <= nbytes ? n : nbytes;
            memcpy(buffer, start, bytes);
            if (bytes < n) { // Part of the preserved buffer still left
                fp->delayed_seek += bytes;
            } else {
                fp->last_offset = fp->delayed_seek = -1;
            }
            return bytes;
        }

        if (fp->last_offset >= 0
            && fp->delayed_seek > fp->last_offset
            && fp->delayed_seek - fp->last_offset < MIN_SEEK_FORWARD) {
            // If not seeking far, just read the data and throw it away.  This
            // is likely to be quicker than opening a new stream
            to_skip = fp->delayed_seek - fp->last_offset;
        } else {
            if (restart_from_position(fp, fp->delayed_seek) < 0) {
                return -1;
            }
        }
        fp->delayed_seek = -1;
        fp->last_offset = -1;
        fp->preserved_bytes = 0;
    }

    do {
        fp->buffer.ptr.rd = buffer;
        fp->buffer.len = nbytes;
        fp->paused = 0;
        if (!fp->finished) {
            err = curl_easy_pause(fp->easy, CURLPAUSE_CONT);
            if (err != CURLE_OK) {
                errno = easy_errno(fp->easy, err);
                return -1;
            }
        }

        while (! fp->paused && ! fp->finished) {
            if (wait_perform(fp) < 0) return -1;
        }

        got = fp->buffer.ptr.rd - buffer;

        if (to_skip >= 0) { // Skipping over a small seek
            if (got <= to_skip) { // Need to skip more data
                to_skip -= got;
            } else {
                got -= to_skip;
                if (got > 0) {  // If enough was skipped, return the rest
                    memmove(buffer, buffer + to_skip, got);
                    to_skip = -1;
                }
            }
        }
    } while (to_skip >= 0 && ! fp->finished);
    fp->buffer.ptr.rd = NULL;
    fp->buffer.len = 0;

    if (fp->finished && fp->final_result != CURLE_OK) {
        errno = easy_errno(fp->easy, fp->final_result);
        return -1;
    }

    return got;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq 0xd0(%rdi), %rsi
pushq $-0x1
popq %rbp
movq %rbp, %r12
testq %rsi, %rsi
js 0x666b5
cmpq %rsi, 0x28(%rbx)
jne 0x6679b
movq 0xd8(%rbx), %rcx
movq 0xe0(%rbx), %rax
testq %rax, %rax
setne %dl
movq %rcx, %r13
subq %rsi, %r13
setg %dil
andb %dl, %dil
cmpb $0x1, %dil
jne 0x6666d
movq 0xe8(%rbx), %rdx
movq %rcx, %rdi
subq %rdx, %rdi
cmpq %rsi, %rdi
ja 0x66672
addq $0xd0, %rbx
subq %r13, %rdx
addq %rdx, %rax
cmpq %r14, %r13
movq %r14, %r12
cmovbq %r13, %r12
movq %r15, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x43c0
cmpq %r14, %r13
jbe 0x66733
addq %r12, (%rbx)
jmp 0x66789
testq %rcx, %rcx
js 0x66689
movq %rsi, %r12
subq %rcx, %r12
seta %al
cmpq $0xf4240, %r12          # imm = 0xF4240
setl %cl
testb %cl, %al
jne 0x6669d
movq %rbx, %rdi
callq 0x657ce
pushq $-0x1
popq %r12
testl %eax, %eax
js 0x66789
orq $-0x1, 0xd0(%rbx)
orq $-0x1, 0xd8(%rbx)
andq $0x0, 0xe8(%rbx)
leaq 0x50(%rbx), %rax
movq %rax, (%rsp)
movb 0x64(%rbx), %al
movq %r12, %r13
movq %r15, 0x50(%rbx)
movq %r14, 0x58(%rbx)
movl %eax, %ecx
andb $-0x2, %cl
movb %cl, 0x64(%rbx)
testb $0x4, %al
jne 0x666e6
movq 0x38(%rbx), %rdi
xorl %esi, %esi
callq 0x4970
testl %eax, %eax
jne 0x6673d
movb 0x64(%rbx), %al
testb $0x5, %al
jne 0x666fe
movq %rbx, %rdi
callq 0x6561b
testl %eax, %eax
jns 0x666e6
jmp 0x66786
movq (%rsp), %rcx
movq (%rcx), %r12
subq %r15, %r12
testq %r13, %r13
js 0x6675f
movq %r14, %rcx
movq %rbp, %r14
movq %r12, %rbp
subq %r13, %rbp
jle 0x66722
jg 0x66745
movq %rbp, %r12
jmp 0x66727
subq %r12, %r13
js 0x6675c
testb $0x4, %al
movq %r14, %rbp
movq %rcx, %r14
je 0x666c3
jmp 0x6675f
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, (%rbx)
jmp 0x66789
movq 0x38(%rbx), %rdi
movl %eax, %esi
jmp 0x66778
addq %r15, %r13
movq %r15, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x4830
movb 0x64(%rbx), %al
movq %rbp, %r12
movq %r14, %rbp
xorps %xmm0, %xmm0
movq (%rsp), %rcx
movups %xmm0, (%rcx)
testb $0x4, %al
je 0x66789
movl 0x60(%rbx), %esi
testl %esi, %esi
je 0x66789
movq 0x38(%rbx), %rdi
callq 0x645af
movl %eax, %ebx
callq 0x4050
movl %ebx, (%rax)
movq %rbp, %r12
movq %r12, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1c4c7(%rip), %rdi     # 0x82c69
leaq 0x1c4e4(%rip), %rsi     # 0x82c8d
leaq 0x1c4ed(%rip), %rcx     # 0x82c9d
movl $0x310, %edx            # imm = 0x310
callq 0x42f0