// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movl %ecx, %r14d
movq %rdx, %rbx
movq %rsi, %r15
movl %edi, %ebp
callq 0x5ce6
testl %ebp, %ebp
jle 0x661c
xorl %eax, %eax
cmpq $0x10, %rax
je 0x64bc
andq $0x0, 0x38(%rsp,%rax,8)
incq %rax
jmp 0x64ab
movl %ebp, %edi
pushq $-0x1
popq %r12
xorl %r8d, %r8d
pushq $0x40
popq %r9
pushq $0x1
popq %r10
cmpq %r8, %rdi
je 0x64fd
movl (%r15,%r8,4), %esi
movl %esi, %eax
cltd
idivl %r9d
movslq %eax, %rdx
shll $0x6, %eax
movl %esi, %ecx
subl %eax, %ecx
movq %r10, %rax
shlq %cl, %rax
orq %rax, 0x38(%rsp,%rdx,8)
cmpl %esi, %r12d
cmovlel %esi, %r12d
incq %r8
jmp 0x64cd
movq %rbx, 0x10(%rsp)
movslq %r14d, %rcx
xorl %eax, %eax
movq %rcx, 0x20(%rsp)
cmpl $-0x1, %ecx
leaq 0x28(%rsp), %rcx
cmoveq %rax, %rcx
movq %rcx, 0x18(%rsp)
callq 0x3040
movq %rax, %r15
leal 0x1(%r12), %eax
movl %eax, 0xc(%rsp)
pushq $0x10
popq %r13
leaq 0x38(%rsp), %r14
leaq 0x1b8(%rsp), %rbx
movq 0x20(%rsp), %rax
movq %rax, 0x28(%rsp)
andq $0x0, 0x30(%rsp)
movq %r13, %rcx
leaq 0xb8(%rsp), %rax
movq %rax, %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r13, %rcx
leaq 0x138(%rsp), %rdx
movq %rdx, %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r13, %rcx
movq %rbx, %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
andl $0x0, (%r15)
movl 0xc(%rsp), %edi
movq %rbx, %rsi
movq %rax, %rcx
movq 0x18(%rsp), %r8
callq 0x32f0
testl %eax, %eax
jns 0x65a9
cmpl $0x4, (%r15)
je 0x653f
movl %eax, %ebp
jmp 0x661c
je 0x661a
movslq %r12d, %rax
xorl %ecx, %ecx
xorl %ebp, %ebp
movq 0x10(%rsp), %r10
cmpq %rax, %rcx
jg 0x661c
movl %ecx, %edx
shrl $0x6, %edx
movq 0x1b8(%rsp,%rdx,8), %rsi
movl %ecx, %edi
andl $0x3f, %edi
xorl %r8d, %r8d
btq %rdi, %rsi
setb %r8b
movq 0x138(%rsp,%rdx,8), %rsi
xorl %r9d, %r9d
btq %rdi, %rsi
setb %r9b
leal (%r8,%r9,2), %esi
movq 0xb8(%rsp,%rdx,8), %rdx
xorl %r8d, %r8d
btq %rdi, %rdx
setb %r8b
shll $0x2, %r8d
xorl %edx, %edx
orl %esi, %r8d
movl %r8d, (%r10,%rcx,4)
setne %dl
addl %edx, %ebp
incq %rcx
jmp 0x65b7
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq