// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/deps/hiredis/net.c
// Function: redisContextWaitReady
static int redisContextWaitReady(redisContext *c, int fd, const struct timeval *timeout) {
    struct pollfd   wfd[1];
    long msec;

    msec          = -1;
    wfd[0].fd     = fd;
    wfd[0].events = POLLOUT;

    /* Only use timeout when not NULL. */
    if (timeout != NULL) {
        if (timeout->tv_usec > 1000000 || timeout->tv_sec > __MAX_MSEC) {
            close(fd);
            return REDIS_ERR;
        }

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

        if (msec < 0 || msec > INT_MAX) {
            msec = INT_MAX;
        }
    }

    if (errno == EINPROGRESS) {
        int res;

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

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

        return REDIS_OK;
    }

    __redisSetErrorFromErrno(c,REDIS_ERR_IO,NULL);
    close(fd);
    return REDIS_ERR;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq $-0x1, -0x30(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x28(%rbp)
movw $0x4, -0x24(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x87bf7
movq -0x20(%rbp), %rax
cmpq $0xf4240, 0x8(%rax)     # imm = 0xF4240
jg 0x87b93
movq -0x20(%rbp), %rax
movabsq $0x20c49ba5e353f6, %rcx # imm = 0x20C49BA5E353F6
cmpq %rcx, (%rax)
jle 0x87ba7
movl -0x14(%rbp), %edi
callq 0x1f170
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x87cc1
movq -0x20(%rbp), %rax
imulq $0x3e8, (%rax), %rax    # imm = 0x3E8
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
addq $0x3e7, %rax            # imm = 0x3E7
movl $0x3e8, %ecx            # imm = 0x3E8
cqto
idivq %rcx
movq %rax, %rcx
movq -0x40(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jl 0x87bed
cmpq $0x7fffffff, -0x30(%rbp) # imm = 0x7FFFFFFF
jle 0x87bf5
movq $0x7fffffff, -0x30(%rbp) # imm = 0x7FFFFFFF
jmp 0x87bf7
callq 0x1f820
cmpl $0x73, (%rax)
jne 0x87ca0
leaq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %edx
movl $0x1, %esi
callq 0x1f600
movl %eax, -0x34(%rbp)
cmpl $-0x1, %eax
jne 0x87c47
movq -0x10(%rbp), %rdi
movl $0x1, %esi
leaq 0x62b5c(%rip), %rdx     # 0xea78d
callq 0x876b0
movl -0x14(%rbp), %edi
callq 0x1f170
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x87cc1
cmpl $0x0, -0x34(%rbp)
jne 0x87c7b
callq 0x1f820
movl $0x6e, (%rax)
movq -0x10(%rbp), %rdi
movl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x876b0
movl -0x14(%rbp), %edi
callq 0x1f170
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x87cc1
jmp 0x87c7d
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x87600
cmpl $0x0, %eax
je 0x87c97
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x87cc1
movl $0x0, -0x4(%rbp)
jmp 0x87cc1
movq -0x10(%rbp), %rdi
movl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x876b0
movl -0x14(%rbp), %edi
callq 0x1f170
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)