// File: ctSkennerton[P]fxtract/util/sock.c
// Function: sock_ready
int
sock_ready(int skt, int mode, int waitsecs)
{
    dyninit();

    int ret, err;
#ifdef USE_POLL
    struct pollfd sockpoll = { skt, mode ? POLLOUT : POLLIN,  0 };

    do errno = 0, ret = poll(&sockpoll, 1, waitsecs);
    while (ret < 0 && errno == EINTR);

    err = sockpoll.revents & POLLERR;
#else//USE_POLL
    fd_set rwfds, erfds;
    FD_ZERO(&rwfds);
    FD_ZERO(&erfds);
    do {
        struct timeval to = { waitsecs, 0 }, *top = waitsecs == WAIT_FOREVER ? NULL : &to;
        FD_SET(skt, &rwfds);
        FD_SET(skt, &erfds);

        errno = 0;
        ret = mode  ? select(skt + 1, NULL, &rwfds, &erfds, top)
                    : select(skt + 1, &rwfds, NULL, &erfds, top);
    } while (ret < 0 && errno == EINTR);

    err = FD_ISSET(skt, &erfds);
#endif//USE_POLL

    return err && ret > 0 ? -2 : ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
callq 0x8020
leaq -0x98(%rbp), %rax
movq %rax, -0x128(%rbp)
movl $0x0, -0x11c(%rbp)
movl -0x11c(%rbp), %eax
cmpq $0x10, %rax
jae 0x8aa3
movq -0x128(%rbp), %rax
movl -0x11c(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
movl -0x11c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x11c(%rbp)
jmp 0x8a71
jmp 0x8aa5
jmp 0x8aa7
leaq -0x118(%rbp), %rax
movq %rax, -0x138(%rbp)
movl $0x0, -0x12c(%rbp)
movl -0x12c(%rbp), %eax
cmpq $0x10, %rax
jae 0x8af1
movq -0x138(%rbp), %rax
movl -0x12c(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
movl -0x12c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x12c(%rbp)
jmp 0x8abf
jmp 0x8af3
jmp 0x8af5
movslq -0xc(%rbp), %rax
movq %rax, -0x148(%rbp)
movq $0x0, -0x140(%rbp)
cmpl $-0x1, -0xc(%rbp)
jne 0x8b1c
xorl %eax, %eax
movq %rax, -0x158(%rbp)
jmp 0x8b2c
leaq -0x148(%rbp), %rax
movq %rax, -0x158(%rbp)
jmp 0x8b2c
movq -0x158(%rbp), %rax
movq %rax, -0x150(%rbp)
movl -0x4(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
movl -0x4(%rbp), %eax
movl $0x40, %esi
cltd
idivl %esi
cltq
orq -0x98(%rbp,%rax,8), %rcx
movq %rcx, -0x98(%rbp,%rax,8)
movl -0x4(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
movl -0x4(%rbp), %eax
movl $0x40, %esi
cltd
idivl %esi
cltq
orq -0x118(%rbp,%rax,8), %rcx
movq %rcx, -0x118(%rbp,%rax,8)
callq 0x3040
movl $0x0, (%rax)
cmpl $0x0, -0x8(%rbp)
je 0x8be5
movl -0x4(%rbp), %edi
addl $0x1, %edi
movq -0x150(%rbp), %r8
xorl %eax, %eax
movl %eax, %esi
leaq -0x98(%rbp), %rdx
leaq -0x118(%rbp), %rcx
callq 0x3300
movl %eax, -0x15c(%rbp)
jmp 0x8c0f
movl -0x4(%rbp), %edi
addl $0x1, %edi
movq -0x150(%rbp), %r8
leaq -0x98(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
leaq -0x118(%rbp), %rcx
callq 0x3300
movl %eax, -0x15c(%rbp)
movl -0x15c(%rbp), %eax
movl %eax, -0x10(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x10(%rbp)
movb %al, -0x15d(%rbp)
jge 0x8c37
callq 0x3040
cmpl $0x4, (%rax)
sete %al
movb %al, -0x15d(%rbp)
movb -0x15d(%rbp), %al
testb $0x1, %al
jne 0x8af5
movl -0x4(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
cltq
movq -0x118(%rbp,%rax,8), %rax
movq %rax, -0x168(%rbp)
movl -0x4(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0x168(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x8cab
cmpl $0x0, -0x10(%rbp)
jle 0x8cab
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
movl %eax, -0x16c(%rbp)
jmp 0x8cb4
movl -0x10(%rbp), %eax
movl %eax, -0x16c(%rbp)
movl -0x16c(%rbp), %eax
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
nopw %cs:(%rax,%rax)