// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/hfile_libcurl.c
// Function: restart_from_position
static int restart_from_position(hFILE_libcurl *fp, off_t pos) {
    hFILE_libcurl temp_fp;
    CURLcode err;
    CURLMcode errm;
    int update_headers = 0;
    int save_errno = 0;

    // TODO If we seem to be doing random access, use CURLOPT_RANGE to do
    // limited reads (e.g. about a BAM block!) so seeking can reuse the
    // existing connection more often.

    // Get new headers from the callback (if defined).  This changes the
    // headers in fp before it gets duplicated, but they should be have been
    // sent by now.

    if (fp->headers.callback) {
        if (add_callback_headers(fp) != 0)
            return -1;
        update_headers = 1;
    }
    if (fp->headers.auth_hdr_num > 0 && fp->headers.auth) {
        if (add_auth_header(fp) != 0)
            return -1;
        update_headers = 1;
    }
    if (update_headers) {
        struct curl_slist *list = get_header_list(fp);
        if (list) {
            err = curl_easy_setopt(fp->easy, CURLOPT_HTTPHEADER, list);
            if (err != CURLE_OK) {
                errno = easy_errno(fp->easy,err);
                return -1;
            }
        }
    }

    /*
      Duplicate the easy handle, and use CURLOPT_RESUME_FROM_LARGE to open
      a new request to the server, reading from the location that we want
      to seek to.  If the new request works and returns the correct data,
      the original easy handle in *fp is closed and replaced with the new
      one.  If not, we close the new handle and leave *fp unchanged.
     */

    memcpy(&temp_fp, fp, sizeof(temp_fp));
    temp_fp.buffer.len = 0;
    temp_fp.buffer.ptr.rd = NULL;
    temp_fp.easy = curl_easy_duphandle(fp->easy);
    if (!temp_fp.easy)
        goto early_error;

    err = curl_easy_setopt(temp_fp.easy, CURLOPT_RESUME_FROM_LARGE,(curl_off_t)pos);
    err |= curl_easy_setopt(temp_fp.easy, CURLOPT_PRIVATE, &temp_fp);
    err |= curl_easy_setopt(temp_fp.easy, CURLOPT_WRITEDATA, &temp_fp);
    if (err != CURLE_OK) {
        save_errno = easy_errno(temp_fp.easy, err);
        goto error;
    }

    temp_fp.buffer.len = 0;  // Ensures we only read the response headers
    temp_fp.paused = temp_fp.finished = 0;

    // fp->multi and temp_fp.multi are the same.
    errm = curl_multi_add_handle(fp->multi, temp_fp.easy);
    if (errm != CURLM_OK) {
        save_errno = multi_errno(errm);
        goto error;
    }
    temp_fp.nrunning = ++fp->nrunning;

    while (! temp_fp.paused && ! temp_fp.finished)
        if (wait_perform(&temp_fp) < 0) {
            save_errno = errno;
            goto error_remove;
        }

    if (temp_fp.finished && temp_fp.final_result != CURLE_OK) {
        save_errno = easy_errno(temp_fp.easy, temp_fp.final_result);
        goto error_remove;
    }

    // We've got a good response, close the original connection and
    // replace it with the new one.

    errm = curl_multi_remove_handle(fp->multi, fp->easy);
    if (errm != CURLM_OK) {
        // Clean up as much as possible
        curl_easy_reset(temp_fp.easy);
        if (curl_multi_remove_handle(fp->multi, temp_fp.easy) == CURLM_OK) {
            fp->nrunning--;
            curl_easy_cleanup(temp_fp.easy);
        }
        save_errno = multi_errno(errm);
        goto early_error;
    }
    fp->nrunning--;

    curl_easy_cleanup(fp->easy);
    fp->easy = temp_fp.easy;
    err = curl_easy_setopt(fp->easy, CURLOPT_WRITEDATA, fp);
    err |= curl_easy_setopt(fp->easy, CURLOPT_PRIVATE, fp);
    if (err != CURLE_OK) {
        save_errno = easy_errno(fp->easy, err);
        curl_easy_reset(fp->easy);
        errno = save_errno;
        return -1;
    }
    fp->buffer.len = 0;
    fp->paused = temp_fp.paused;
    fp->finished = temp_fp.finished;
    fp->perform_again = temp_fp.perform_again;
    fp->final_result = temp_fp.final_result;

    return 0;

 error_remove:
    curl_easy_reset(temp_fp.easy); // Ensure no pointers to on-stack temp_fp
    errm = curl_multi_remove_handle(fp->multi, temp_fp.easy);
    if (errm != CURLM_OK) {
        errno = multi_errno(errm);
        return -1;
    }
    fp->nrunning--;
 error:
    curl_easy_cleanup(temp_fp.easy);
 early_error:
    fp->can_seek = 0;  // Don't try to seek again
    if (save_errno)
        errno = save_errno;
    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x11c(%rbp)
movl $0x0, -0x120(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x90(%rax)
je 0xd07e9
movq -0x10(%rbp), %rdi
callq 0xcfe20
cmpl $0x0, %eax
je 0xd07df
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd0d0a
movl $0x1, -0x11c(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0xa8(%rax)
jle 0xd0828
movq -0x10(%rbp), %rax
cmpq $0x0, 0xa0(%rax)
je 0xd0828
movq -0x10(%rbp), %rdi
callq 0xd1440
cmpl $0x0, %eax
je 0xd081e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd0d0a
movl $0x1, -0x11c(%rbp)
cmpl $0x0, -0x11c(%rbp)
je 0xd08ab
movq -0x10(%rbp), %rdi
callq 0xd0320
movq %rax, -0x128(%rbp)
cmpq $0x0, -0x128(%rbp)
je 0xd08a9
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x128(%rbp), %rdx
movl $0x2727, %esi           # imm = 0x2727
movb $0x0, %al
callq 0x4560
movl %eax, -0x114(%rbp)
cmpl $0x0, -0x114(%rbp)
je 0xd08a7
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movl -0x114(%rbp), %esi
callq 0xced50
movl %eax, -0x12c(%rbp)
callq 0x4050
movl -0x12c(%rbp), %ecx
movl %ecx, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd0d0a
jmp 0xd08a9
jmp 0xd08ab
movq -0x10(%rbp), %rsi
leaq -0x110(%rbp), %rdi
movl $0xf8, %edx
callq 0x43b0
movq $0x0, -0xb8(%rbp)
movq $0x0, -0xc0(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x41a0
movq %rax, -0xd8(%rbp)
cmpq $0x0, -0xd8(%rbp)
jne 0xd08f9
jmp 0xd0cd1
movq -0xd8(%rbp), %rdi
movq -0x18(%rbp), %rdx
movl $0x75a4, %esi           # imm = 0x75A4
movb $0x0, %al
callq 0x4560
movl %eax, -0x114(%rbp)
movq -0xd8(%rbp), %rdi
movl $0x2777, %esi           # imm = 0x2777
leaq -0x110(%rbp), %rdx
movb $0x0, %al
callq 0x4560
orl -0x114(%rbp), %eax
movl %eax, -0x114(%rbp)
movq -0xd8(%rbp), %rdi
movl $0x2711, %esi           # imm = 0x2711
leaq -0x110(%rbp), %rdx
movb $0x0, %al
callq 0x4560
orl -0x114(%rbp), %eax
movl %eax, -0x114(%rbp)
cmpl $0x0, -0x114(%rbp)
je 0xd0988
movq -0xd8(%rbp), %rdi
movl -0x114(%rbp), %esi
callq 0xced50
movl %eax, -0x120(%rbp)
jmp 0xd0cc5
movq $0x0, -0xb8(%rbp)
movb -0xac(%rbp), %al
andb $-0x5, %al
orb $0x0, %al
movb %al, -0xac(%rbp)
movb -0xac(%rbp), %al
andb $-0x2, %al
orb $0x0, %al
movb %al, -0xac(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0xd8(%rbp), %rsi
callq 0x4930
movl %eax, -0x118(%rbp)
cmpl $0x0, -0x118(%rbp)
je 0xd09ec
movl -0x118(%rbp), %edi
callq 0xd03d0
movl %eax, -0x120(%rbp)
jmp 0xd0cc5
movq -0x10(%rbp), %rcx
movl 0x68(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x68(%rcx)
movl %eax, -0xa8(%rbp)
movb -0xac(%rbp), %al
andb $0x1, %al
movzbl %al, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x12d(%rbp)
jne 0xd0a33
movb -0xac(%rbp), %al
shrb $0x2, %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, -0x12d(%rbp)
movb -0x12d(%rbp), %al
testb $0x1, %al
jne 0xd0a3f
jmp 0xd0a64
leaq -0x110(%rbp), %rdi
callq 0xd0470
cmpl $0x0, %eax
jge 0xd0a62
callq 0x4050
movl (%rax), %eax
movl %eax, -0x120(%rbp)
jmp 0xd0c62
jmp 0xd09ff
movb -0xac(%rbp), %al
shrb $0x2, %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0xd0a9d
cmpl $0x0, -0xb0(%rbp)
je 0xd0a9d
movq -0xd8(%rbp), %rdi
movl -0xb0(%rbp), %esi
callq 0xced50
movl %eax, -0x120(%rbp)
jmp 0xd0c62
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rsi
callq 0x4140
movl %eax, -0x118(%rbp)
cmpl $0x0, -0x118(%rbp)
je 0xd0b15
movq -0xd8(%rbp), %rdi
callq 0x43a0
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0xd8(%rbp), %rsi
callq 0x4140
cmpl $0x0, %eax
jne 0xd0aff
movq -0x10(%rbp), %rax
movl 0x68(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x68(%rax)
movq -0xd8(%rbp), %rdi
callq 0x4600
movl -0x118(%rbp), %edi
callq 0xd03d0
movl %eax, -0x120(%rbp)
jmp 0xd0cd1
movq -0x10(%rbp), %rax
movl 0x68(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x68(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x4600
movq -0xd8(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x10(%rbp), %rdx
movl $0x2711, %esi           # imm = 0x2711
movb $0x0, %al
callq 0x4560
movl %eax, -0x114(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x10(%rbp), %rdx
movl $0x2777, %esi           # imm = 0x2777
movb $0x0, %al
callq 0x4560
orl -0x114(%rbp), %eax
movl %eax, -0x114(%rbp)
cmpl $0x0, -0x114(%rbp)
je 0xd0bd4
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movl -0x114(%rbp), %esi
callq 0xced50
movl %eax, -0x120(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x43a0
movl -0x120(%rbp), %eax
movl %eax, -0x134(%rbp)
callq 0x4050
movl -0x134(%rbp), %ecx
movl %ecx, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd0d0a
movq -0x10(%rbp), %rax
movq $0x0, 0x58(%rax)
movb -0xac(%rbp), %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x10(%rbp), %rax
movb %cl, %dl
movb 0x64(%rax), %cl
andb $0x1, %dl
andb $-0x2, %cl
orb %dl, %cl
movb %cl, 0x64(%rax)
movb -0xac(%rbp), %al
shrb $0x2, %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x10(%rbp), %rax
movb %cl, %dl
movb 0x64(%rax), %cl
andb $0x1, %dl
shlb $0x2, %dl
andb $-0x5, %cl
orb %dl, %cl
movb %cl, 0x64(%rax)
movb -0xac(%rbp), %al
shrb $0x3, %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x10(%rbp), %rax
movb %cl, %dl
movb 0x64(%rax), %cl
andb $0x1, %dl
shlb $0x3, %dl
andb $-0x9, %cl
orb %dl, %cl
movb %cl, 0x64(%rax)
movl -0xb0(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x60(%rax)
movl $0x0, -0x4(%rbp)
jmp 0xd0d0a
movq -0xd8(%rbp), %rdi
callq 0x43a0
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0xd8(%rbp), %rsi
callq 0x4140
movl %eax, -0x118(%rbp)
cmpl $0x0, -0x118(%rbp)
je 0xd0cb8
movl -0x118(%rbp), %edi
callq 0xd03d0
movl %eax, -0x138(%rbp)
callq 0x4050
movl -0x138(%rbp), %ecx
movl %ecx, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd0d0a
movq -0x10(%rbp), %rax
movl 0x68(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x68(%rax)
movq -0xd8(%rbp), %rdi
callq 0x4600
movq -0x10(%rbp), %rax
movb 0x64(%rax), %cl
andb $-0x21, %cl
orb $0x0, %cl
movb %cl, 0x64(%rax)
cmpl $0x0, -0x120(%rbp)
je 0xd0d03
movl -0x120(%rbp), %eax
movl %eax, -0x13c(%rbp)
callq 0x4050
movl -0x13c(%rbp), %ecx
movl %ecx, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nopw %cs:(%rax,%rax)