// File: ctSkennerton[P]fxtract/util/sock.c
// Function: sock_status
int
sock_status(int nsocks, int const sockv[], int statusv[], int waitsecs)
{
    dyninit();

    if (nsocks <= 0) return nsocks;
    int i, ret, maxfd = -1;

    fd_set fds;
    FD_ZERO(&fds);
    for (i = 0; i < nsocks; ++i) {
        FD_SET(sockv[i], &fds);
        if (maxfd < sockv[i])  maxfd = sockv[i];
    }

    fd_set rfds, wfds, efds = fds;
    do {
        struct timeval to = { waitsecs, 0 }, *top = waitsecs == WAIT_FOREVER ? NULL : &to;
        rfds = wfds = efds = fds;
        errno = 0;
        ret = select(maxfd + 1, &rfds, &wfds, &efds, top);
    } while (ret < 0 && errno == EINTR);

    if (ret > 0)
        for (i = ret = 0; i <= maxfd; ++i)
            ret += !!(statusv[i] = (FD_ISSET(i, &rfds) ? SOCK_CAN_RECV : 0)
                                 | (FD_ISSET(i, &wfds) ? SOCK_CAN_SEND : 0)
                                 | (FD_ISSET(i, &efds) ? SOCK_IN_ERROR : 0));

    return ret;   
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
callq 0x8020
cmpl $0x0, -0x8(%rbp)
jg 0x8cff
movl -0x8(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x9019
movl $0xffffffff, -0x28(%rbp) # imm = 0xFFFFFFFF
leaq -0xa8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movl $0x0, -0xac(%rbp)
movl -0xac(%rbp), %eax
cmpq $0x10, %rax
jae 0x8d50
movq -0xb8(%rbp), %rax
movl -0xac(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
movl -0xac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xac(%rbp)
jmp 0x8d1e
jmp 0x8d52
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x8dd3
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rdx
movl (%rax,%rdx,4), %eax
movl $0x40, %esi
cltd
idivl %esi
cltq
orq -0xa8(%rbp,%rax,8), %rcx
movq %rcx, -0xa8(%rbp,%rax,8)
movl -0x28(%rbp), %eax
movq -0x10(%rbp), %rcx
movslq -0x20(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x8dc6
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x28(%rbp)
jmp 0x8dc8
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x8d59
leaq -0x238(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
movl $0x80, %edx
callq 0x3270
movslq -0x1c(%rbp), %rax
movq %rax, -0x248(%rbp)
movq $0x0, -0x240(%rbp)
cmpl $-0x1, -0x1c(%rbp)
jne 0x8e12
xorl %eax, %eax
movq %rax, -0x258(%rbp)
jmp 0x8e22
leaq -0x248(%rbp), %rax
movq %rax, -0x258(%rbp)
jmp 0x8e22
movq -0x258(%rbp), %rax
movq %rax, -0x250(%rbp)
leaq -0x238(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
movl $0x80, %edx
callq 0x3270
leaq -0x1b8(%rbp), %rdi
leaq -0x238(%rbp), %rsi
movl $0x80, %edx
callq 0x3270
leaq -0x138(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
movl $0x80, %edx
callq 0x3270
callq 0x3040
movl $0x0, (%rax)
movl -0x28(%rbp), %edi
addl $0x1, %edi
movq -0x250(%rbp), %r8
leaq -0x138(%rbp), %rsi
leaq -0x1b8(%rbp), %rdx
leaq -0x238(%rbp), %rcx
callq 0x3300
movl %eax, -0x24(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x24(%rbp)
movb %al, -0x259(%rbp)
jge 0x8ecc
callq 0x3040
cmpl $0x4, (%rax)
sete %al
movb %al, -0x259(%rbp)
movb -0x259(%rbp), %al
testb $0x1, %al
jne 0x8deb
cmpl $0x0, -0x24(%rbp)
jle 0x9013
movl $0x0, -0x24(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x28(%rbp), %eax
jg 0x9011
movl -0x20(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
cltq
movq -0x138(%rbp,%rax,8), %rax
movq %rax, -0x270(%rbp)
movl -0x20(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movq -0x270(%rbp), %rdx
movl %eax, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
andq %rax, %rdx
xorl %eax, %eax
movl $0x1, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
movl %eax, -0x264(%rbp)
movl -0x20(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
cltq
movq -0x1b8(%rbp,%rax,8), %rsi
movl -0x20(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl -0x264(%rbp), %eax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rsi
xorl %ecx, %ecx
movl $0x2, %edx
cmpq $0x0, %rsi
cmovnel %edx, %ecx
orl %ecx, %eax
movl %eax, -0x260(%rbp)
movl -0x20(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
cltq
movq -0x238(%rbp,%rax,8), %rsi
movl -0x20(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl -0x260(%rbp), %eax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rsi
xorl %ecx, %ecx
movl $0x4, %edx
cmpq $0x0, %rsi
cmovnel %edx, %ecx
orl %ecx, %eax
movq -0x18(%rbp), %rcx
movslq -0x20(%rbp), %rdx
movl %eax, (%rcx,%rdx,4)
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x8ef2
jmp 0x9013
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
nopw %cs:(%rax,%rax)