// File: /workspace/github_c_makefile_star2_O3/Genymobile[P]hiredis/net.c
// Function: redisContextWaitReady
static int redisContextWaitReady(redisContext *c, const struct timeval *timeout) {
    long msec          = -1;
    /* Only use timeout when not NULL. */
    if (timeout != NULL) {
        if (timeout->tv_usec > 1000000 || timeout->tv_sec > __MAX_MSEC) {
            __redisSetErrorFromErrno(c, REDIS_ERR_IO, NULL);
            redisContextCloseFd(c);
            return REDIS_ERR;
        }

        msec = (timeout->tv_sec * 1000) + ((timeout->tv_usec + 999) / 1000);

        if (msec < 0 || msec > INT_MAX) {
            msec = INT_MAX;
        }
    }
#ifdef _WIN32
    fd_set wfd;
    struct timeval toptr = {5, 0};
    if (timeout != NULL) {
        toptr.tv_sec = timeout->tv_sec;
        toptr.tv_usec = timeout->tv_usec;
    }
    if (errno == EINPROGRESS || errno == WSAEWOULDBLOCK) {
        FD_ZERO(&wfd);
        FD_SET(c->fd, &wfd);
        if (select(FD_SETSIZE, NULL, &wfd, NULL, &toptr) == -1) {
            SETERRNO;
            __redisSetErrorFromErrno(c,REDIS_ERR_IO,"select(2)");
            redisContextCloseFd(c);
            return REDIS_ERR;
        }
        if (!FD_ISSET(c->fd, &wfd)) {
            errno = WSAETIMEDOUT;
            __redisSetErrorFromErrno(c,REDIS_ERR_IO,NULL);
            closesocket(c->fd);
            return REDIS_ERR;
        }
        if (redisCheckSocketError(c) != REDIS_OK)
            return REDIS_ERR;

        return REDIS_OK;
    }
#else
    struct pollfd   wfd[1];
    wfd[0].fd     = c->fd;
    wfd[0].events = POLLOUT;

    if (errno == EINPROGRESS) {
        int res;

        if ((res = poll(wfd, 1, msec)) == -1) {
            __redisSetErrorFromErrno(c, REDIS_ERR_IO, "poll(2)");
            redisContextCloseFd(c);
            return REDIS_ERR;
        } else if (res == 0) {
            errno = ETIMEDOUT;
            __redisSetErrorFromErrno(c,REDIS_ERR_IO,NULL);
            redisContextCloseFd(c);
            return REDIS_ERR;
        }

        if (redisCheckSocketError(c) != REDIS_OK)
            return REDIS_ERR;

        return REDIS_OK;
    }
#endif
    __redisSetErrorFromErrno(c,REDIS_ERR_IO,NULL);
    redisContextCloseFd(c);
    return REDIS_ERR;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
testq %rsi, %rsi
je 0x92c2
movq 0x8(%rsi), %rax
cmpq $0xf4240, %rax          # imm = 0xF4240
jg 0x929f
movq (%rsi), %rcx
movabsq $0x20c49ba5e353f7, %rdx # imm = 0x20C49BA5E353F7
cmpq %rdx, %rcx
jl 0x92ca
movq %rbx, %rdi
xorl %esi, %esi
callq 0x8b0c
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rbx, %rbx
je 0x9375
movl 0x84(%rbx), %edi
jmp 0x9362
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x9304
imulq $0x3e8, %rcx, %rcx      # imm = 0x3E8
addq $0x3e7, %rax            # imm = 0x3E7
movabsq $0x20c49ba5e353f7cf, %rdx # imm = 0x20C49BA5E353F7CF
imulq %rdx
movq %rdx, %r14
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %r14
addq %rax, %r14
addq %rcx, %r14
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %r14
cmovaeq %rax, %r14
movl 0x84(%rbx), %eax
movl %eax, (%rsp)
movw $0x4, 0x4(%rsp)
callq 0x2060
cmpl $0x73, (%rax)
jne 0x934d
movq %rax, %r15
movq %rsp, %rdi
movl $0x1, %esi
movl %r14d, %edx
callq 0x2240
testl %eax, %eax
je 0x9346
cmpl $-0x1, %eax
jne 0x9382
leaq 0x26dc(%rip), %rsi      # 0xba1d
movq %rbx, %rdi
jmp 0x9352
movl $0x6e, (%r15)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x8b0c
movl 0x84(%rbx), %edi
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %edi, %edi
js 0x9375
callq 0x2160
movl $0xffffffff, 0x84(%rbx) # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x8aa3
xorl %ebp, %ebp
negl %eax
sbbl %ebp, %ebp
jmp 0x9375