// File: /workspace/github_c_makefile_star2_O2/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)
movq 0x58(%r15), %r12
testq %r12, %r12
jne 0x1b1fd
movq 0x40(%r15), %rbx
movq 0x50(%r15), %r12
cmpq %rbx, %r12
jae 0x1b297
movq 0x38(%r15), %r14
movq %r12, %r13
shlq $0x4, %r13
incq %r12
movq (%r14,%r13), %rbp
movq %rbp, %rdi
callq 0x41d0
cmpq $0x79, %rax
leaq 0x5cbfa(%rip), %rax     # 0x77d56
leaq 0x5dd3a(%rip), %rcx     # 0x78e9d
cmovaeq %rcx, %rax
movq %rax, (%rsp)
pushq $0x5
popq %rdi
leaq 0x5dcf4(%rip), %rsi     # 0x78e69
leaq 0x5dcfc(%rip), %rdx     # 0x78e78
movq %r12, %rcx
movq %rbx, %r8
movq %rbp, %r9
xorl %eax, %eax
callq 0x110c6
movq (%r14,%r13), %rdi
movq 0x8(%r14,%r13), %rcx
testq %rcx, %rcx
je 0x1b1c4
andq $0x0, (%rsp)
leaq 0x5dcfb(%rip), %rsi     # 0x78ea1
leaq 0x5dcf7(%rip), %rdx     # 0x78ea4
leaq 0x5dcfa(%rip), %r8      # 0x78eae
leaq 0x5dd06(%rip), %r9      # 0x78ec1
xorl %eax, %eax
callq 0xe19b
jmp 0x1b1e3
leaq 0x5dcd6(%rip), %rsi     # 0x78ea1
leaq 0x5dcdc(%rip), %rdx     # 0x78eae
leaq 0x5dce8(%rip), %rcx     # 0x78ec1
xorl %r8d, %r8d
xorl %eax, %eax
callq 0xe19b
movq %rax, %r12
movq 0x10(%rsp), %r13
movq 0x8(%rsp), %rbp
movq %rax, 0x58(%r15)
testq %rax, %rax
je 0x1b292
testb $0x2, 0x30(%r12)
jne 0x1b24c
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 0x1b25f
testb $0x2, 0x30(%r12)
je 0x1b25f
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0xd55e
jmp 0x1b25c
movq 0x20(%r12), %rax
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq *(%rax)
movq %rax, %rbx
testq %rbx, %rbx
jne 0x1b299
movq 0x50(%r15), %rdi
movq 0x58(%r15), %rbx
shlq $0x4, %rdi
addq 0x38(%r15), %rdi
callq 0x1b0b6
incq 0x50(%r15)
andq $0x0, 0x58(%r15)
movq %rbx, %rdi
callq 0xd8ee
testl %eax, %eax
jns 0x1b119
pushq $-0x1
popq %rbx
jmp 0x1b299
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq