#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 member_0;
  int member_1;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int O_NONBLOCK;
int O_RDONLY;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int main(void) {
  fd_set fd_rset;
  struct timeval timeout = {8, 5000};
  int rc, fd;
  fd = open("./afifo", O_RDONLY | O_NONBLOCK);
  FD_ZERO(&fd_rset);
  FD_SET(fd, &fd_rset);
  if ((rc = select(fd + 1, &fd_rset, NULL, NULL, &timeout)) < 0) {
    printf("error in select()\n");
    exit(EXIT_FAILURE);
  }
  printf(" select returned with rc=%d\n", rc);
  if (rc > 0 && FD_ISSET(fd, &fd_rset))
    printf("Data ready for reading on fd=%d\n", fd);
  if (rc == 0)
    printf("No data found\n");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe7a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
mov    0x2e4e(%rip),%rax
or     (%rax),%esi
lea    0xe65(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
lea    -0x8(%rbp),%rdi
call   1050 <FD_ZERO@plt>
mov    -0x18(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1090 <FD_SET@plt>
mov    -0x18(%rbp),%edi
add    $0x1,%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x10(%rbp),%r8
mov    %rcx,%rdx
call   1060 <select@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1202 <main+0x92>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%esi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jle    1244 <main+0xd4>
mov    -0x18(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1244 <main+0xd4>
mov    -0x18(%rbp),%esi
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jne    125c <main+0xec>
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movabs $0x138800000008,%rax
mov    %rax,0x10(%rsp)
mov    0x2e44(%rip),%rax
mov    0x2e45(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe52(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
lea    0xc(%rsp),%rbp
mov    %rbp,%rdi
call   1060 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   10a0 <FD_SET@plt>
lea    0x1(%rbx),%edi
lea    0x10(%rsp),%r8
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1070 <select@plt>
test   %eax,%eax
jns    11fe <main+0x7e>
lea    0xe69(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    %eax,%ebp
lea    0xe01(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebp,%ebp
jne    1222 <main+0xa2>
lea    0xe2b(%rip),%rdi
call   1030 <puts@plt>
jmp    1243 <main+0xc3>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     1243 <main+0xc3>
lea    0xdeb(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@__const.main.timeout = %struct.timeval { i32 8, i32 5000 }
@.str = [8 x i8] c"./afifo\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [19 x i8] c"error in select()\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [29 x i8] c" select returned with rc=%d\0A\00"
@.str.3 = [33 x i8] c"Data ready for reading on fd=%d\0A\00"
@.str.4 = [15 x i8] c"No data found\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast %struct.timeval* %3 to i8*
%7 = load i32, i32* @O_RDONLY
%8 = load i32, i32* @O_NONBLOCK
%9 = or i32 %7, %8
%10 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %5
%11 = call i32 @FD_ZERO(i32* %2)
%12 = load i32, i32* %5
%13 = call i32 @FD_SET(i32 %12, i32* %2)
%14 = load i32, i32* %5
%15 = add nsw i32 %14, 1
%16 = call i32 @select(i32 %15, i32* %2, i32* null, i32* null, %struct.timeval* %3)
store i32 %16, i32* %4
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %0
%23 = load i32, i32* %4
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %4
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %22
%28 = load i32, i32* %5
%29 = call i64 @FD_ISSET(i32 %28, i32* %2)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i32, i32* %5
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %31, %27, %22
%35 = load i32, i32* %4
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %39
39: ; preds = %37, %34
%40 = load i32, i32* @EXIT_SUCCESS
%41 = call i32 @exit(i32 %40)
unreachable
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [8 x i8] c"./afifo\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [29 x i8] c" select returned with rc=%d\0A\00"
@.str.3 = [33 x i8] c"Data ready for reading on fd=%d\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [14 x i8] c"No data found\00"
@str.5 = [18 x i8] c"error in select()\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = bitcast i64* %2 to %struct.timeval*
%4 = bitcast i32* %1 to i8*
%5 = bitcast i64* %2 to i8*
store i64 21474836480008, i64* %2
%6 = load i32, i32* @O_RDONLY
%7 = load i32, i32* @O_NONBLOCK
%8 = or i32 %7, %6
%9 = tail call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 @FD_ZERO(i32* %1)
%11 = call i32 @FD_SET(i32 %9, i32* %1)
%12 = add nsw i32 %9, 1
%13 = call i32 @select(i32 %12, i32* %1, i32* null, i32* null, %struct.timeval* %3)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %0
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.5, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %0
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%21 = icmp eq i32 %13, 0
br i1 %21, label %27, label %22
22: ; preds = %19
%23 = call i64 @FD_ISSET(i32 %9, i32* %1)
%24 = icmp eq i64 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %22
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %9)
br label %29
27: ; preds = %19
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %29
29: ; preds = %22, %25, %27
%30 = load i32, i32* @EXIT_SUCCESS
%31 = call i32 @exit(i32 %30)
unreachable
}