// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/multipart.c
// Function: multipart_read
static ssize_t multipart_read(hFILE *fpv, void *buffer, size_t nbytes)
{
    hFILE_multipart *fp = (hFILE_multipart *) fpv;
    size_t n;

open_next:
    if (fp->currentfp == NULL) {
        if (fp->current < fp->nparts) {
            const hfile_part *p = &fp->parts[fp->current];
            hts_log_debug("Opening part #%zu of %zu: \"%.120s%s\"",
                fp->current+1, fp->nparts, p->url,
                (strlen(p->url) > 120)? "..." : "");

            fp->currentfp = p->headers?
                  hopen(p->url, "r:",
                        "httphdr:v", p->headers,
                        "auth_token_enabled", "false", NULL)
                : hopen(p->url, "r:", "auth_token_enabled", "false", NULL);

            if (fp->currentfp == NULL) return -1;
        }
        else return 0;  // No more parts, so we're truly at EOF
    }

    n = fp->currentfp->mobile?
          fp->currentfp->backend->read(fp->currentfp, buffer, nbytes)
        : hread(fp->currentfp, buffer, nbytes);

    if (n == 0) {
        // We're at EOF on this part, so set up the next part
        hFILE *prevfp = fp->currentfp;
        free_part(&fp->parts[fp->current]);
        fp->current++;
        fp->currentfp = NULL;
        if (hclose(prevfp) < 0) return -1;
        goto open_next;
    }

    return n;  // Number of bytes read by (or an error from) fp->currentfp
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %r15
movq %rdx, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
movq 0x58(%r15), %rbp
testq %rbp, %rbp
jne 0x1f822
movq 0x40(%r15), %rbx
movq 0x50(%r15), %rbp
cmpq %rbx, %rbp
jae 0x1f8bb
movq 0x38(%r15), %r14
movq %rbp, %r12
shlq $0x4, %r12
incq %rbp
movq (%r14,%r12), %r13
movq %r13, %rdi
callq 0x41d0
cmpq $0x79, %rax
leaq 0x765f1(%rip), %rax     # 0x95d6d
leaq 0x77748(%rip), %rcx     # 0x96ecb
cmovaeq %rcx, %rax
movq %rax, (%rsp)
movl $0x5, %edi
leaq 0x77700(%rip), %rsi     # 0x96e97
leaq 0x77708(%rip), %rdx     # 0x96ea6
movq %rbp, %rcx
movq %rbx, %r8
movq %r13, %r9
xorl %eax, %eax
callq 0x13de5
movq (%r14,%r12), %rdi
movq 0x8(%r14,%r12), %rcx
testq %rcx, %rcx
je 0x1f7e9
movq $0x0, (%rsp)
leaq 0x77704(%rip), %rsi     # 0x96ecf
leaq 0x77700(%rip), %rdx     # 0x96ed2
leaq 0x77703(%rip), %r8      # 0x96edc
leaq 0x7770f(%rip), %r9      # 0x96eef
xorl %eax, %eax
callq 0xfe44
jmp 0x1f808
leaq 0x776df(%rip), %rsi     # 0x96ecf
leaq 0x776e5(%rip), %rdx     # 0x96edc
leaq 0x776f1(%rip), %rcx     # 0x96eef
xorl %r8d, %r8d
xorl %eax, %eax
callq 0xfe44
movq %rax, %rbp
movq 0x10(%rsp), %r12
movq 0x8(%rsp), %r13
movq %rax, 0x58(%r15)
testq %rax, %rax
je 0x1f8b2
testb $0x2, 0x30(%rbp)
jne 0x1f86a
movq 0x8(%rbp), %rsi
movq 0x10(%rbp), %r14
subq %rsi, %r14
cmpq %r12, %r14
movq %r12, %rbx
cmovbq %r14, %rbx
movq %r13, %rdi
movq %rbx, %rdx
callq 0x43c0
addq %rbx, 0x8(%rbp)
cmpq %r12, %r14
jae 0x1f87c
testb $0x2, 0x30(%rbp)
je 0x1f87c
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0xf129
jmp 0x1f879
movq 0x20(%rbp), %rax
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq *(%rax)
movq %rax, %rbx
testq %rbx, %rbx
jne 0x1f8bd
movq 0x50(%r15), %rdi
movq 0x58(%r15), %rbx
shlq $0x4, %rdi
addq 0x38(%r15), %rdi
callq 0x1f6c9
incq 0x50(%r15)
movq $0x0, 0x58(%r15)
movq %rbx, %rdi
callq 0xf4df
testl %eax, %eax
jns 0x1f739
movq $-0x1, %rbx
jmp 0x1f8bd
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq