#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*/ EXIT_SUCCESS;
int /*<<< orphan*/ FD_SET(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int main(void) {
  fd_set rfds;
  struct timeval tv;
  int retval;
  FD_ZERO(&rfds);
  FD_SET(0, &rfds);
  tv.tv_sec = 5;
  tv.tv_usec = 0;
  retval = select(1, &rfds, NULL, NULL, &tv);
  if (retval == -1)
    perror("select()");
  else if (retval)
    printf("Data is available now.\n");
  else
    printf("No data within five seconds.\n");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1040 <FD_ZERO@plt>
xor    %edi,%edi
lea    -0x8(%rbp),%rsi
call   1080 <FD_SET@plt>
movl   $0x5,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $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    11c9 <main+0x69>
lea    0xe41(%rip),%rdi
call   1060 <perror@plt>
jmp    11f5 <main+0x95>
cmpl   $0x0,-0x1c(%rbp)
je     11e4 <main+0x84>
lea    0xe2f(%rip),%rdi
call   1030 <printf@plt>
jmp    11f0 <main+0x90>
lea    0xe36(%rip),%rdi
call   1030 <printf@plt>
jmp    11f5 <main+0x95>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <FD_ZERO@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1080 <FD_SET@plt>
movl   $0x5,0x10(%rsp)
movq   $0x0,0x18(%rsp)
lea    0x10(%rsp),%r8
mov    $0x1,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <select@plt>
cmp    $0xffffffff,%eax
jne    11c2 <main+0x62>
lea    0xe51(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
test   %eax,%eax
jne    11cf <main+0x6f>
lea    0xe3c(%rip),%rdi
jmp    11d6 <main+0x76>
lea    0xe50(%rip),%rdi
call   1030 <puts@plt>
jmp    11b4 <main+0x54>

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [9 x i8] c"select()\00"
@.str.1 = [24 x i8] c"Data is available now.\0A\00"
@.str.2 = [30 x i8] c"No data within five seconds.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @FD_ZERO(i32* %2)
%6 = call i32 @FD_SET(i32 0, i32* %2)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
store i32 5, i32* %7
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
store i64 0, i64* %8
%9 = call i32 @select(i32 1, i32* %2, i32* null, i32* null, %struct.timeval* %3)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %22
14: ; preds = %0
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %21
19: ; preds = %14
%20 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19, %17
br label %22
22: ; preds = %21, %12
%23 = load i32, i32* @EXIT_SUCCESS
%24 = call i32 @exit(i32 %23)
unreachable
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@.str = [9 x i8] c"select()\00"
@EXIT_SUCCESS = global i32 0
@str = [29 x i8] c"No data within five seconds.\00"
@str.3 = [23 x i8] c"Data is available now.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = bitcast i32* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = call i32 @FD_ZERO(i32* %1)
%6 = call i32 @FD_SET(i32 0, i32* %1)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
store i32 5, i32* %7
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
store i64 0, i64* %8
%9 = call i32 @select(i32 1, i32* %1, i32* null, i32* null, %struct.timeval* %2)
switch i32 %9, label %12 [
i32 -1, label %10
i32 0, label %14
]
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %16
12: ; preds = %0
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.3, i64 0, i64 0))
br label %16
14: ; preds = %0
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %16
16: ; preds = %12, %14, %10
%17 = load i32, i32* @EXIT_SUCCESS
%18 = call i32 @exit(i32 %17)
unreachable
}