// File: /workspace/github_c_makefile_star2_O1/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, %r13
movq %rsi, %rbp
movq %rdi, %r15
movq %rdx, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
cmpq $0x0, 0x58(%r15)
jne 0x200a5
movq 0x40(%r15), %rbx
movq 0x50(%r15), %r12
cmpq %rbx, %r12
jae 0x2014a
movq 0x38(%r15), %r14
movq %r12, %rbp
shlq $0x4, %rbp
incq %r12
movq (%r14,%rbp), %r13
movq %r13, %rdi
callq 0x41d0
cmpq $0x79, %rax
leaq 0x78ccb(%rip), %rax     # 0x98ccd
leaq 0x79e14(%rip), %rcx     # 0x99e1d
cmovaeq %rcx, %rax
movq %rax, (%rsp)
movl $0x5, %edi
leaq 0x79dcc(%rip), %rsi     # 0x99de9
leaq 0x79dd4(%rip), %rdx     # 0x99df8
movq %r12, %rcx
movq %rbx, %r8
movq %r13, %r9
xorl %eax, %eax
callq 0x14378
movq (%r14,%rbp), %rdi
movq 0x8(%r14,%rbp), %rcx
testq %rcx, %rcx
je 0x2006f
movq $0x0, (%rsp)
leaq 0x79dd0(%rip), %rsi     # 0x99e21
leaq 0x79dcc(%rip), %rdx     # 0x99e24
leaq 0x79dcf(%rip), %r8      # 0x99e2e
leaq 0x79ddb(%rip), %r9      # 0x99e41
xorl %eax, %eax
callq 0x10014
jmp 0x2008e
leaq 0x79dab(%rip), %rsi     # 0x99e21
leaq 0x79db1(%rip), %rdx     # 0x99e2e
leaq 0x79dbd(%rip), %rcx     # 0x99e41
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x10014
movq 0x10(%rsp), %r13
movq 0x8(%rsp), %rbp
movq %rax, 0x58(%r15)
testq %rax, %rax
je 0x20141
movq 0x58(%r15), %r12
testb $0x2, 0x30(%r12)
jne 0x200f8
movq 0x8(%r12), %rsi
movq 0x10(%r12), %r14
subq %rsi, %r14
cmpq %r13, %r14
movq %r13, %rbx
cmovbq %r14, %rbx
movq %rbp, %rdi
movq %rbx, %rdx
callq 0x43c0
addq %rbx, 0x8(%r12)
cmpq %r13, %r14
jae 0x2010b
testb $0x2, 0x30(%r12)
je 0x2010b
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0xf2cd
jmp 0x20108
movq 0x20(%r12), %rax
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq *(%rax)
movq %rax, %rbx
testq %rbx, %rbx
jne 0x2014c
movq 0x50(%r15), %rdi
movq 0x58(%r15), %rbx
shlq $0x4, %rdi
addq 0x38(%r15), %rdi
callq 0x1ff54
incq 0x50(%r15)
movq $0x0, 0x58(%r15)
movq %rbx, %rdi
callq 0xf6d0
testl %eax, %eax
jns 0x1ffc1
movq $-0x1, %rbx
jmp 0x2014c
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq