#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_sec;
  scalar_t__ tv_usec;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, struct timeval *);
int easy_select_w(int fd, int seconds) {
  fd_set rfds;
  FD_ZERO(&rfds);
  FD_SET(fd, &rfds);
  if (seconds <= 0) {
    if (select(fd + 1, NULL, &rfds, NULL, NULL) < 0) {
      perror("select");
      return -1;
    } else
      return 1;
  } else {
    struct timeval tv;
    tv.tv_sec = seconds;
    tv.tv_usec = 0;
    int retval;
    if ((retval = select(fd + 1, NULL, &rfds, NULL, &tv)) < 0) {
      perror("select");
      return -1;
    } else
      return retval;
  }
}


x86 assembly (clang, -O0):
<easy_select_w>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
call   1030 <FD_ZERO@plt>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1060 <FD_SET@plt>
cmpl   $0x0,-0xc(%rbp)
jg     11b5 <easy_select_w+0x75>
mov    -0x8(%rbp),%edi
add    $0x1,%edi
xor    %eax,%eax
mov    %eax,%r8d
lea    -0x10(%rbp),%rdx
mov    %r8,%rsi
mov    %r8,%rcx
call   1040 <select@plt>
cmp    $0x0,%rax
jge    11a9 <easy_select_w+0x69>
lea    0xe68(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1207 <easy_select_w+0xc7>
movl   $0x1,-0x4(%rbp)
jmp    1207 <easy_select_w+0xc7>
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
add    $0x1,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x10(%rbp),%rdx
lea    -0x20(%rbp),%r8
mov    %rcx,%rsi
call   1040 <select@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    1201 <easy_select_w+0xc1>
lea    0xe10(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1207 <easy_select_w+0xc7>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<easy_select_w>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
lea    0xc(%rsp),%r14
mov    %r14,%rdi
call   1030 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <FD_SET@plt>
test   %ebp,%ebp
jle    1199 <easy_select_w+0x59>
mov    %ebp,0x10(%rsp)
movq   $0x0,0x18(%rsp)
add    $0x1,%ebx
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%r8
mov    %ebx,%edi
xor    %esi,%esi
xor    %ecx,%ecx
call   1040 <select@plt>
test   %eax,%eax
js     11bc <easy_select_w+0x7c>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
add    $0x1,%ebx
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
xor    %esi,%esi
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <select@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jns    1190 <easy_select_w+0x50>
lea    0xe3d(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
jmp    1190 <easy_select_w+0x50>

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [7 x i8] c"select\00"
define i32 @easy_select_w(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.timeval
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%9 = call i32 @FD_ZERO(i32* %6)
%10 = load i32, i32* %4
%11 = call i32 @FD_SET(i32 %10, i32* %6)
%12 = load i32, i32* %5
%13 = icmp sle i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %2
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
%17 = call i64 @select(i32 %16, i32* null, i32* %6, i32* null, %struct.timeval* null)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %35
21: ; preds = %14
store i32 1, i32* %3
br label %35
22: ; preds = %2
%23 = load i32, i32* %5
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
store i64 0, i64* %25
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
%28 = call i64 @select(i32 %27, i32* null, i32* %6, i32* null, %struct.timeval* %7)
%29 = trunc i64 %28 to i32
store i32 %29, i32* %8
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %22
%32 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %35
33: ; preds = %22
%34 = load i32, i32* %8
store i32 %34, i32* %3
br label %35
35: ; preds = %33, %31, %21, %19
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@.str = [7 x i8] c"select\00"
define i32 @easy_select_w(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.timeval
%5 = bitcast i32* %3 to i8*
%6 = call i32 @FD_ZERO(i32* %3)
%7 = call i32 @FD_SET(i32 %0, i32* %3)
%8 = icmp slt i32 %1, 1
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = add nsw i32 %0, 1
%11 = call i64 @select(i32 %10, i32* null, i32* %3, i32* null, %struct.timeval* null)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %27
13: ; preds = %9
%14 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %27
15: ; preds = %2
%16 = bitcast %struct.timeval* %4 to i8*
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
store i32 %1, i32* %17
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
store i64 0, i64* %18
%19 = add nsw i32 %0, 1
%20 = call i64 @select(i32 %19, i32* null, i32* %3, i32* null, %struct.timeval* %4)
%21 = trunc i64 %20 to i32
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %15, %23
%26 = phi i32 [ -1, %23 ], [ %21, %15 ]
br label %27
27: ; preds = %9, %25, %13
%28 = phi i32 [ -1, %13 ], [ %26, %25 ], [ 1, %9 ]
ret i32 %28
}