#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 */
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_RDWR;
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
void main(int args, char *argv[]) {
  char nam_t1[] = "tuberia1";
  char nam_t2[] = "tuberia";
  char buf[80];
  int sread;
  int fd1 = open(nam_t1, O_RDWR | O_NONBLOCK);
  int fd2 = open(nam_t2, O_RDWR | O_NONBLOCK);
  fd_set rfds;
  struct timeval tv;
  int retval;
  FD_ZERO(&rfds);
  FD_SET(fd1, &rfds);
  FD_SET(fd2, &rfds);
  tv.tv_sec = 15;
  tv.tv_usec = 0;
  retval = select(fd2 + 1, &rfds, NULL, NULL, &tv);
  if (retval == 0)
    printf("15 s timeval expired");
  else {
    if (FD_ISSET(fd1, &rfds)) {
      printf("%s suffered changes\n", nam_t1);
      sread = read(fd1, buf, 80);
      buf[sread] = '\0';
      printf("%s", buf);
    } else if (FD_ISSET(fd2, &rfds)) {
      printf("%s suffered changes\n", nam_t2);
      sread = read(fd2, buf, 80);
      buf[sread] = '\0';
      printf("%s", buf);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe77(%rip),%rax
mov    %rax,-0x19(%rbp)
mov    0xe75(%rip),%al
mov    %al,-0x11(%rbp)
mov    0xe6c(%rip),%rax
mov    %rax,-0x21(%rbp)
lea    -0x19(%rbp),%rdi
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
mov    0x2e2b(%rip),%rax
or     (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x88(%rbp)
lea    -0x21(%rbp),%rdi
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
mov    0x2e0a(%rip),%rax
or     (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x8c(%rbp)
lea    -0x90(%rbp),%rdi
call   1060 <FD_ZERO@plt>
mov    -0x88(%rbp),%edi
lea    -0x90(%rbp),%rsi
call   1090 <FD_SET@plt>
mov    -0x8c(%rbp),%edi
lea    -0x90(%rbp),%rsi
call   1090 <FD_SET@plt>
movl   $0xf,-0xa0(%rbp)
movq   $0x0,-0x98(%rbp)
mov    -0x8c(%rbp),%edi
add    $0x1,%edi
lea    -0x90(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0xa0(%rbp),%r8
mov    %rcx,%rdx
call   1070 <select@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0x0,-0xa4(%rbp)
jne    1271 <main+0x101>
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    134c <main+0x1dc>
mov    -0x88(%rbp),%edi
lea    -0x90(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     12dc <main+0x16c>
lea    -0x19(%rbp),%rsi
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x88(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x50,%edx
call   1050 <read@plt>
mov    %eax,-0x84(%rbp)
movslq -0x84(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
lea    -0x80(%rbp),%rsi
lea    0xd6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1347 <main+0x1d7>
mov    -0x8c(%rbp),%edi
lea    -0x90(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1342 <main+0x1d2>
lea    -0x21(%rbp),%rsi
lea    0xd23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8c(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x50,%edx
call   1050 <read@plt>
mov    %eax,-0x84(%rbp)
movslq -0x84(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
lea    -0x80(%rbp),%rsi
lea    0xd00(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1347 <main+0x1d7>
jmp    134c <main+0x1dc>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
movabs $0x3161697265627574,%rax
69 61 31
mov    %rax,0x8(%rsp)
movb   $0x0,0x10(%rsp)
movabs $0x61697265627574,%rax
mov    %rax,0x18(%rsp)
mov    0x2e43(%rip),%rbx
mov    0x2e34(%rip),%rbp
mov    0x0(%rbp),%esi
or     (%rbx),%esi
lea    0x8(%rsp),%rdi
call   1080 <open@plt>
mov    %eax,%r14d
mov    0x0(%rbp),%esi
or     (%rbx),%esi
lea    0x18(%rsp),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
lea    0x4(%rsp),%rbp
mov    %rbp,%rdi
call   1060 <FD_ZERO@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
call   1090 <FD_SET@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1090 <FD_SET@plt>
movl   $0xf,0x20(%rsp)
movq   $0x0,0x28(%rsp)
lea    0x1(%rbx),%edi
lea    0x20(%rsp),%r8
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1070 <select@plt>
test   %eax,%eax
je     1267 <main+0xf7>
lea    0x4(%rsp),%rsi
mov    %r14d,%edi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     1277 <main+0x107>
lea    0xdeb(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x30(%rsp),%rbx
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x50,%edx
call   1050 <read@plt>
cltq
movb   $0x0,0x30(%rsp,%rax,1)
lea    0xdd1(%rip),%rdi
mov    %rbx,%rsi
jmp    12c0 <main+0x150>
lea    0xd9b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    12c7 <main+0x157>
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     12c7 <main+0x157>
lea    0xd8f(%rip),%rdi
lea    0x18(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x30(%rsp),%rbp
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x50,%edx
call   1050 <read@plt>
cltq
movb   $0x0,0x30(%rsp,%rax,1)
lea    0xd76(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@__const.main.nam_t1 = [9 x i8] c"tuberia1\00"
@__const.main.nam_t2 = [8 x i8] c"tuberia\00"
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@.str = [21 x i8] c"15 s timeval expired\00"
@.str.1 = [21 x i8] c"%s suffered changes\0A\00"
@.str.2 = [3 x i8] c"%s\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [9 x i8]
%6 = alloca [8 x i8]
%7 = alloca [80 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.timeval
%13 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%14 = bitcast [9 x i8]* %5 to i8*
%15 = bitcast [8 x i8]* %6 to i8*
%16 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%17 = load i32, i32* @O_RDWR
%18 = load i32, i32* @O_NONBLOCK
%19 = or i32 %17, %18
%20 = call i32 @open(i8* %16, i32 %19)
store i32 %20, i32* %9
%21 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%22 = load i32, i32* @O_RDWR
%23 = load i32, i32* @O_NONBLOCK
%24 = or i32 %22, %23
%25 = call i32 @open(i8* %21, i32 %24)
store i32 %25, i32* %10
%26 = call i32 @FD_ZERO(i32* %11)
%27 = load i32, i32* %9
%28 = call i32 @FD_SET(i32 %27, i32* %11)
%29 = load i32, i32* %10
%30 = call i32 @FD_SET(i32 %29, i32* %11)
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
store i32 15, i32* %31
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
store i64 0, i64* %32
%33 = load i32, i32* %10
%34 = add nsw i32 %33, 1
%35 = call i32 @select(i32 %34, i32* %11, i32* null, i32* null, %struct.timeval* %12)
store i32 %35, i32* %13
%36 = load i32, i32* %13
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %2
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %72
40: ; preds = %2
%41 = load i32, i32* %9
%42 = call i64 @FD_ISSET(i32 %41, i32* %11)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %55
44: ; preds = %40
%45 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %45)
%47 = load i32, i32* %9
%48 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%49 = call i32 @read(i32 %47, i8* %48, i32 80)
store i32 %49, i32* %8
%50 = load i32, i32* %8
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 %51
store i8 0, i8* %52
%53 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %53)
br label %71
55: ; preds = %40
%56 = load i32, i32* %10
%57 = call i64 @FD_ISSET(i32 %56, i32* %11)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %70
59: ; preds = %55
%60 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %60)
%62 = load i32, i32* %10
%63 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%64 = call i32 @read(i32 %62, i8* %63, i32 80)
store i32 %64, i32* %8
%65 = load i32, i32* %8
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 %66
store i8 0, i8* %67
%68 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %68)
br label %70
70: ; preds = %59, %55
br label %71
71: ; preds = %70, %44
br label %72
72: ; preds = %71, %38
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@__const.main.nam_t1 = [9 x i8] c"tuberia1\00"
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@.str = [21 x i8] c"15 s timeval expired\00"
@.str.1 = [21 x i8] c"%s suffered changes\0A\00"
@.str.2 = [3 x i8] c"%s\00"
define void @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [9 x i8]
%4 = alloca i64
%5 = alloca [80 x i8]
%6 = alloca i32
%7 = alloca %struct.timeval
%8 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 0
%9 = bitcast i64* %4 to i8*
store i64 27419012789073268, i64* %4
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%11 = load i32, i32* @O_RDWR
%12 = load i32, i32* @O_NONBLOCK
%13 = or i32 %12, %11
%14 = call i32 @open(i8* %8, i32 %13)
%15 = load i32, i32* @O_RDWR
%16 = load i32, i32* @O_NONBLOCK
%17 = or i32 %16, %15
%18 = call i32 @open(i8* %9, i32 %17)
%19 = bitcast i32* %6 to i8*
%20 = bitcast %struct.timeval* %7 to i8*
%21 = call i32 @FD_ZERO(i32* %6)
%22 = call i32 @FD_SET(i32 %14, i32* %6)
%23 = call i32 @FD_SET(i32 %18, i32* %6)
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
store i32 15, i32* %24
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
store i64 0, i64* %25
%26 = add nsw i32 %18, 1
%27 = call i32 @select(i32 %26, i32* %6, i32* null, i32* null, %struct.timeval* %7)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %2
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %49
31: ; preds = %2
%32 = call i64 @FD_ISSET(i32 %14, i32* %6)
%33 = icmp eq i64 %32, 0
br i1 %33, label %40, label %34
34: ; preds = %31
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%36 = call i32 @read(i32 %14, i8* %10, i32 80)
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 %37
store i8 0, i8* %38
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %10)
br label %49
40: ; preds = %31
%41 = call i64 @FD_ISSET(i32 %18, i32* %6)
%42 = icmp eq i64 %41, 0
br i1 %42, label %49, label %43
43: ; preds = %40
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i64* %4)
%45 = call i32 @read(i32 %18, i8* %10, i32 80)
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 %46
store i8 0, i8* %47
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %10)
br label %49
49: ; preds = %34, %43, %40, %29
ret void
}