#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 {
  long tv_sec;
  long tv_usec;
};
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 sock_read_isready(int fd, long tv_sec, long tv_usec) {
  fd_set rfds;
  struct timeval tv;
  FD_ZERO(&rfds);
  FD_SET(fd, &rfds);
  tv.tv_sec = tv_sec;
  tv.tv_usec = tv_usec;
  return select(fd + 1, &rfds, NULL, NULL, &tv);
}


x86 assembly (clang, -O0):
<sock_read_isready>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x1c(%rbp),%rdi
call   1030 <FD_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   1050 <FD_SET@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
add    $0x1,%edi
lea    -0x1c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x30(%rbp),%r8
mov    %rcx,%rdx
call   1040 <select@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_read_isready>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0x4(%rsp),%r15
mov    %r15,%rdi
call   1030 <FD_ZERO@plt>
mov    %ebp,%edi
mov    %r15,%rsi
call   1050 <FD_SET@plt>
mov    %rbx,0x8(%rsp)
mov    %r14,0x10(%rsp)
add    $0x1,%ebp
lea    0x8(%rsp),%r8
mov    %ebp,%edi
mov    %r15,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <select@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define i32 @sock_read_isready(i32 %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = bitcast i32* %4 to i8*
%7 = bitcast %struct.timeval* %5 to i8*
%8 = call i32 @FD_ZERO(i32* %4)
%9 = call i32 @FD_SET(i32 %0, i32* %4)
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
store i64 %1, i64* %10
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
store i64 %2, i64* %11
%12 = add nsw i32 %0, 1
%13 = call i32 @select(i32 %12, i32* %4, i32* null, i32* null, %struct.timeval* %5)
ret i32 %13
}