// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/hfile_libcurl.c
// Function: wait_perform
static int wait_perform(hFILE_libcurl *fp)
{
    fd_set rd, wr, ex;
    int maxfd, nrunning;
    long timeout;
    CURLMcode errm;

    if (!fp->perform_again) {
        FD_ZERO(&rd);
        FD_ZERO(&wr);
        FD_ZERO(&ex);
        if (curl_multi_fdset(fp->multi, &rd, &wr, &ex, &maxfd) != CURLM_OK)
            maxfd = -1, timeout = 1000;
        else {
            if (curl_multi_timeout(fp->multi, &timeout) != CURLM_OK)
                timeout = 1000;
            else if (timeout < 0) {
                timeout = 10000;  // as recommended by curl_multi_timeout(3)
            }
        }
        if (maxfd < 0) {
            if (timeout > 100)
                timeout = 100; // as recommended by curl_multi_fdset(3)
#ifdef _WIN32
            /* Windows ignores the first argument of select, so calling select
             * with maxfd=-1 does not give the expected result of sleeping for
             * timeout milliseconds in the conditional block below.
             * So sleep here and skip the next block.
             */
            Sleep(timeout);
            timeout = 0;
#endif
        }

        if (timeout > 0) {
            struct timeval tval;
            tval.tv_sec  = (timeout / 1000);
            tval.tv_usec = (timeout % 1000) * 1000;

            if (select(maxfd + 1, &rd, &wr, &ex, &tval) < 0) return -1;
        }
    }

    errm = curl_multi_perform(fp->multi, &nrunning);
    fp->perform_again = 0;
    if (errm == CURLM_CALL_MULTI_PERFORM) fp->perform_again = 1;
    else if (errm != CURLM_OK) { errno = multi_errno(errm); return -1; }

    if (nrunning < fp->nrunning) process_messages(fp);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq %rdi, %r14
testb $0x8, 0x64(%rdi)
pushq $-0x1
popq %rbx
jne 0x6572d
xorl %eax, %eax
cmpq $0x10, %rax
je 0x6564e
andq $0x0, 0x128(%rsp,%rax,8)
incq %rax
jmp 0x6563a
xorl %eax, %eax
cmpq $0x10, %rax
je 0x65664
andq $0x0, 0xa8(%rsp,%rax,8)
incq %rax
jmp 0x65650
xorl %eax, %eax
cmpq $0x10, %rax
je 0x65677
andq $0x0, 0x28(%rsp,%rax,8)
incq %rax
jmp 0x65666
movq 0x40(%r14), %rdi
leaq 0x128(%rsp), %rsi
leaq 0xa8(%rsp), %rdx
leaq 0x28(%rsp), %rcx
leaq 0x10(%rsp), %r8
callq 0x4500
testl %eax, %eax
je 0x656a5
orl $-0x1, 0x10(%rsp)
jmp 0x656bb
movq 0x40(%r14), %rdi
leaq 0x8(%rsp), %rsi
callq 0x4120
testl %eax, %eax
je 0x657ad
movq $0x3e8, 0x8(%rsp)       # imm = 0x3E8
movl $0x3e8, %eax            # imm = 0x3E8
movl 0x10(%rsp), %edi
testl %edi, %edi
setns %cl
cmpq $0x65, %rax
setb %dl
orb %cl, %dl
jne 0x656eb
movq $0x64, 0x8(%rsp)
pushq $0x64
popq %rax
jmp 0x656f0
testq %rax, %rax
je 0x6572d
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divq %rcx
leaq 0x18(%rsp), %r8
movq %rax, (%r8)
imulq $0x3e8, %rdx, %rax      # imm = 0x3E8
movq %rax, 0x8(%r8)
incl %edi
leaq 0x128(%rsp), %rsi
leaq 0xa8(%rsp), %rdx
leaq 0x28(%rsp), %rcx
callq 0x4480
testl %eax, %eax
js 0x6579d
movq 0x40(%r14), %rdi
leaq 0x14(%rsp), %rsi
callq 0x4360
movb 0x64(%r14), %cl
movl %ecx, %edx
andb $-0x9, %dl
movb %dl, 0x64(%r14)
testl %eax, %eax
je 0x65758
cmpl $-0x1, %eax
jne 0x6578d
orb $0x8, %cl
movb %cl, 0x64(%r14)
movl 0x14(%rsp), %eax
xorl %ebx, %ebx
cmpl 0x68(%r14), %eax
jge 0x6579d
leaq 0x18(%rsp), %r15
movq 0x40(%r14), %rdi
movq %r15, %rsi
callq 0x48b0
testq %rax, %rax
je 0x6579d
cmpl $0x1, (%rax)
jne 0x65769
orb $0x4, 0x64(%r14)
movl 0x10(%rax), %eax
movl %eax, 0x60(%r14)
jmp 0x65769
movl %eax, %edi
callq 0x655d1
movl %eax, %ebp
callq 0x4050
movl %ebp, (%rax)
movl %ebx, %eax
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rax
testq %rax, %rax
jns 0x656c9
movq $0x2710, 0x8(%rsp)      # imm = 0x2710
movl $0x2710, %eax           # imm = 0x2710
jmp 0x656c9