#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct timeval {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, struct timeval *);
int sock_has_data(int socket) {
  fd_set readfds;
  fd_set writefds;
  fd_set exceptfds;
  struct timeval tv;
  tv.tv_sec = 0;
  tv.tv_usec = 0;
  FD_ZERO(&readfds);
  FD_ZERO(&writefds);
  FD_ZERO(&exceptfds);
  FD_SET(socket, &readfds);
  return (select(socket + 1, &readfds, &writefds, &exceptfds, &tv) > 0);
}


x86 assembly (clang, -O0):
<sock_has_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x8(%rbp),%rdi
call   1030 <FD_ZERO@plt>
lea    -0xc(%rbp),%rdi
call   1030 <FD_ZERO@plt>
lea    -0x10(%rbp),%rdi
call   1030 <FD_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1050 <FD_SET@plt>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
lea    -0x20(%rbp),%r8
call   1040 <select@plt>
cmp    $0x0,%rax
setg   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_has_data>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebx
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xc(%rsp),%r14
mov    %r14,%rdi
call   1030 <FD_ZERO@plt>
lea    0x8(%rsp),%r15
mov    %r15,%rdi
call   1030 <FD_ZERO@plt>
lea    0x4(%rsp),%r12
mov    %r12,%rdi
call   1030 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <FD_SET@plt>
add    $0x1,%ebx
lea    0x10(%rsp),%r8
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
call   1040 <select@plt>
xor    %ecx,%ecx
test   %rax,%rax
setg   %cl
mov    %ecx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define i32 @sock_has_data(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.timeval
store i32 %0, i32* %2
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
store i64 0, i64* %7
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
store i64 0, i64* %8
%9 = call i32 @FD_ZERO(i32* %3)
%10 = call i32 @FD_ZERO(i32* %4)
%11 = call i32 @FD_ZERO(i32* %5)
%12 = load i32, i32* %2
%13 = call i32 @FD_SET(i32 %12, i32* %3)
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 1
%16 = call i64 @select(i32 %15, i32* %3, i32* %4, i32* %5, %struct.timeval* %6)
%17 = icmp sgt i64 %16, 0
%18 = zext i1 %17 to i32
ret i32 %18
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define i32 @sock_has_data(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast %struct.timeval* %5 to i8*
%10 = bitcast %struct.timeval* %5 to i8*
%11 = call i32 @FD_ZERO(i32* %2)
%12 = call i32 @FD_ZERO(i32* %3)
%13 = call i32 @FD_ZERO(i32* %4)
%14 = call i32 @FD_SET(i32 %0, i32* %2)
%15 = add nsw i32 %0, 1
%16 = call i64 @select(i32 %15, i32* %2, i32* %3, i32* %4, %struct.timeval* %5)
%17 = icmp sgt i64 %16, 0
%18 = zext i1 %17 to i32
ret i32 %18
}