#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 {
  int 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*/ *);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ sperror(char *);
int checkDataAvailableToReadOnSocket(int clientSocket) {
  fd_set readfd;
  struct timeval timeout;
  timeout.tv_sec = 0;
  timeout.tv_usec = 25000;
  FD_ZERO(&readfd);
  FD_SET(clientSocket, &readfd);
  int result = select(clientSocket + 1, &readfd, NULL, NULL, &timeout);
  if (result == -1) {
    sperror("select");
  }
  return (result == 1);
}


x86 assembly (clang, -O0):
<checkDataAvailableToReadOnSocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x61a8,-0x18(%rbp)
lea    -0x8(%rbp),%rdi
call   1040 <FD_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1060 <FD_SET@plt>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x18(%rbp),%r8
mov    %rcx,%rdx
call   1050 <select@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11a2 <checkDataAvailableToReadOnSocket+0x62>
lea    0xe63(%rip),%rdi
call   1030 <sperror@plt>
cmpl   $0x1,-0x1c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkDataAvailableToReadOnSocket>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
movq   $0x0,0x10(%rsp)
movl   $0x61a8,0x8(%rsp)
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1040 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <FD_SET@plt>
add    $0x1,%ebx
lea    0x8(%rsp),%r8
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <select@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    119a <checkDataAvailableToReadOnSocket+0x5a>
lea    0xe6b(%rip),%rdi
call   1030 <sperror@plt>
xor    %eax,%eax
cmp    $0x1,%ebx
sete   %al
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [7 x i8] c"select\00"
define i32 @checkDataAvailableToReadOnSocket(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.timeval
%5 = alloca i32
store i32 %0, i32* %2
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
store i64 0, i64* %6
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
store i32 25000, i32* %7
%8 = call i32 @FD_ZERO(i32* %3)
%9 = load i32, i32* %2
%10 = call i32 @FD_SET(i32 %9, i32* %3)
%11 = load i32, i32* %2
%12 = add nsw i32 %11, 1
%13 = call i32 @select(i32 %12, i32* %3, i32* null, i32* null, %struct.timeval* %4)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = call i32 @sperror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %1
%19 = load i32, i32* %5
%20 = icmp eq i32 %19, 1
%21 = zext i1 %20 to i32
ret i32 %21
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@.str = [7 x i8] c"select\00"
define i32 @checkDataAvailableToReadOnSocket(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = bitcast i32* %2 to i8*
%5 = bitcast %struct.timeval* %3 to i8*
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
store i64 0, i64* %6
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
store i32 25000, i32* %7
%8 = call i32 @FD_ZERO(i32* %2)
%9 = call i32 @FD_SET(i32 %0, i32* %2)
%10 = add nsw i32 %0, 1
%11 = call i32 @select(i32 %10, i32* %2, i32* null, i32* null, %struct.timeval* %3)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @sperror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %1
%16 = icmp eq i32 %11, 1
%17 = zext i1 %16 to i32
ret i32 %17
}