#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 /*<<< orphan*/ O_RDONLY;
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ showdata(char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int fd1, fd2;
  struct timeval timeout;
  fd_set readfds;
  int maxfd;
  int retval;
  if (argc != 4) {
    fprintf(stderr, "Usage: %s file file timeout\n", argv[0]);
    exit(1);
  }
  if ((fd1 = open(argv[1], O_RDONLY)) == -1) {
    perror(argv[1]);
    exit(2);
  };
  if ((fd2 = open(argv[2], O_RDONLY)) == -1) {
    perror(argv[1]);
    exit(3);
  };
  maxfd = 1 + (fd1 > fd2 ? fd1 : fd2);
  while (1) {
    FD_ZERO(&readfds);
    FD_SET(fd1, &readfds);
    FD_SET(fd2, &readfds);
    timeout.tv_sec = atoi(argv[3]);
    timeout.tv_usec = 0;
    retval = select(maxfd, &readfds, NULL, NULL, &timeout);
    if (retval == -1) {
      perror("select() failed");
      exit(4);
    };
    if (retval > 0) {
      if (FD_ISSET(fd1, &readfds))
        showdata(argv[1], fd1);
      if (FD_ISSET(fd2, &readfds))
        showdata(argv[2], fd2);
    } else
      printf("No input after %d seconds\n", atoi(argv[3]));
  }
  close(fd1);
  close(fd2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11f6 <main+0x46>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe19(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    122f <main+0x7f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <perror@plt>
mov    $0x2,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    1268 <main+0xb8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <perror@plt>
mov    $0x3,%edi
call   10c0 <exit@plt>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    127f <main+0xcf>
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    1285 <main+0xd5>
mov    -0x18(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
lea    -0x2c(%rbp),%rdi
call   1070 <FD_ZERO@plt>
mov    -0x14(%rbp),%edi
lea    -0x2c(%rbp),%rsi
call   10d0 <FD_SET@plt>
mov    -0x18(%rbp),%edi
lea    -0x2c(%rbp),%rsi
call   10d0 <FD_SET@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x30(%rbp),%edi
lea    -0x2c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x28(%rbp),%r8
mov    %rcx,%rdx
call   1080 <select@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    1301 <main+0x151>
lea    0xd2b(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x4,%edi
call   10c0 <exit@plt>
cmpl   $0x0,-0x34(%rbp)
jle    135c <main+0x1ac>
mov    -0x14(%rbp),%edi
lea    -0x2c(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1331 <main+0x181>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x14(%rbp),%esi
call   1050 <showdata@plt>
mov    -0x18(%rbp),%edi
lea    -0x2c(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1357 <main+0x1a7>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x18(%rbp),%esi
call   1050 <showdata@plt>
jmp    1377 <main+0x1c7>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,%esi
lea    0xcbb(%rip),%rdi
call   1040 <printf@plt>
jmp    128e <main+0xde>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
cmp    $0x4,%edi
jne    11f0 <main+0x40>
mov    0x8(%r14),%rdi
mov    0x2e17(%rip),%rbx
mov    (%rbx),%esi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
jne    1212 <main+0x62>
mov    0x8(%r14),%rdi
call   10a0 <perror@plt>
mov    $0x2,%edi
call   10c0 <exit@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xdfd(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    %eax,%r12d
mov    0x10(%r14),%rdi
mov    (%rbx),%esi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
jne    1238 <main+0x88>
mov    0x8(%r14),%rdi
call   10a0 <perror@plt>
mov    $0x3,%edi
call   10c0 <exit@plt>
mov    %eax,%ebx
cmp    %eax,%r12d
mov    %eax,%r15d
cmovg  %r12d,%r15d
add    $0x1,%r15d
lea    0x4(%rsp),%rbp
lea    0x8(%rsp),%r13
jmp    1277 <main+0xc7>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x18(%r14),%rdi
call   10b0 <atoi@plt>
lea    0xdbd(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbp,%rdi
call   1070 <FD_ZERO@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
call   10d0 <FD_SET@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   10d0 <FD_SET@plt>
mov    0x18(%r14),%rdi
call   10b0 <atoi@plt>
mov    %eax,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    %r15d,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r13,%r8
call   1080 <select@plt>
cmp    $0xffffffff,%eax
je     1300 <main+0x150>
test   %eax,%eax
jle    1260 <main+0xb0>
mov    %r12d,%edi
mov    %rbp,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     12e1 <main+0x131>
mov    0x8(%r14),%rdi
mov    %r12d,%esi
call   1050 <showdata@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     1277 <main+0xc7>
mov    0x10(%r14),%rdi
mov    %ebx,%esi
call   1050 <showdata@plt>
jmp    1277 <main+0xc7>
lea    0xd16(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x4,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@stderr = global i32 0
@.str = [29 x i8] c"Usage: %s file file timeout\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [16 x i8] c"select() failed\00"
@.str.2 = [27 x i8] c"No input after %d seconds\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.timeval
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 4
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_RDONLY
%26 = call i32 @open(i8* %24, i32 %25)
store i32 %26, i32* %6
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %34
28: ; preds = %21
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @perror(i8* %31)
%33 = call i32 @exit(i32 2)
unreachable
34: ; preds = %21
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = load i32, i32* @O_RDONLY
%39 = call i32 @open(i8* %37, i32 %38)
store i32 %39, i32* %7
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %47
41: ; preds = %34
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = call i32 @perror(i8* %44)
%46 = call i32 @exit(i32 3)
unreachable
47: ; preds = %34
%48 = load i32, i32* %6
%49 = load i32, i32* %7
%50 = icmp sgt i32 %48, %49
br i1 %50, label %51, label %53
51: ; preds = %47
%52 = load i32, i32* %6
br label %55
53: ; preds = %47
%54 = load i32, i32* %7
br label %55
55: ; preds = %53, %51
%56 = phi i32 [ %52, %51 ], [ %54, %53 ]
%57 = add nsw i32 1, %56
store i32 %57, i32* %10
br label %58
58: ; preds = %55, %107
%59 = call i32 @FD_ZERO(i32* %9)
%60 = load i32, i32* %6
%61 = call i32 @FD_SET(i32 %60, i32* %9)
%62 = load i32, i32* %7
%63 = call i32 @FD_SET(i32 %62, i32* %9)
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 3
%66 = load i8*, i8** %65
%67 = call i32 @atoi(i8* %66)
%68 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
store i32 %67, i32* %68
%69 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
store i64 0, i64* %69
%70 = load i32, i32* %10
%71 = call i32 @select(i32 %70, i32* %9, i32* null, i32* null, %struct.timeval* %8)
store i32 %71, i32* %11
%72 = load i32, i32* %11
%73 = icmp eq i32 %72, -1
br i1 %73, label %74, label %77
74: ; preds = %58
%75 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%76 = call i32 @exit(i32 4)
unreachable
77: ; preds = %58
%78 = load i32, i32* %11
%79 = icmp sgt i32 %78, 0
br i1 %79, label %80, label %101
80: ; preds = %77
%81 = load i32, i32* %6
%82 = call i64 @FD_ISSET(i32 %81, i32* %9)
%83 = icmp ne i64 %82, 0
br i1 %83, label %84, label %90
84: ; preds = %80
%85 = load i8**, i8*** %5
%86 = getelementptr inbounds i8*, i8** %85, i64 1
%87 = load i8*, i8** %86
%88 = load i32, i32* %6
%89 = call i32 @showdata(i8* %87, i32 %88)
br label %90
90: ; preds = %84, %80
%91 = load i32, i32* %7
%92 = call i64 @FD_ISSET(i32 %91, i32* %9)
%93 = icmp ne i64 %92, 0
br i1 %93, label %94, label %100
94: ; preds = %90
%95 = load i8**, i8*** %5
%96 = getelementptr inbounds i8*, i8** %95, i64 2
%97 = load i8*, i8** %96
%98 = load i32, i32* %7
%99 = call i32 @showdata(i8* %97, i32 %98)
br label %100
100: ; preds = %94, %90
br label %107
101: ; preds = %77
%102 = load i8**, i8*** %5
%103 = getelementptr inbounds i8*, i8** %102, i64 3
%104 = load i8*, i8** %103
%105 = call i32 @atoi(i8* %104)
%106 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %105)
br label %107
107: ; preds = %101, %100
br label %58
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@stderr = global i32 0
@.str = [29 x i8] c"Usage: %s file file timeout\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [16 x i8] c"select() failed\00"
@.str.2 = [27 x i8] c"No input after %d seconds\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeval
%4 = alloca i32
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = icmp eq i32 %0, 4
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_RDONLY
%17 = tail call i32 @open(i8* %15, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = load i8*, i8** %14
%21 = tail call i32 @perror(i8* %20)
%22 = tail call i32 @exit(i32 2)
unreachable
23: ; preds = %13
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = load i32, i32* @O_RDONLY
%27 = tail call i32 @open(i8* %25, i32 %26)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %33
29: ; preds = %23
%30 = load i8*, i8** %14
%31 = tail call i32 @perror(i8* %30)
%32 = tail call i32 @exit(i32 3)
unreachable
33: ; preds = %23
%34 = icmp sgt i32 %17, %27
%35 = select i1 %34, i32 %17, i32 %27
%36 = add nuw nsw i32 %35, 1
%37 = getelementptr inbounds i8*, i8** %1, i64 3
%38 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%39 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
br label %40
40: ; preds = %62, %33
%41 = call i32 @FD_ZERO(i32* %4)
%42 = call i32 @FD_SET(i32 %17, i32* %4)
%43 = call i32 @FD_SET(i32 %27, i32* %4)
%44 = load i8*, i8** %37
%45 = call i32 @atoi(i8* %44)
store i32 %45, i32* %38
store i64 0, i64* %39
%46 = call i32 @select(i32 %36, i32* %4, i32* null, i32* null, %struct.timeval* %3)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %51
48: ; preds = %40
%49 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%50 = call i32 @exit(i32 4)
unreachable
51: ; preds = %40
%52 = icmp sgt i32 %46, 0
br i1 %52, label %53, label %66
53: ; preds = %51
%54 = call i64 @FD_ISSET(i32 %17, i32* %4)
%55 = icmp eq i64 %54, 0
br i1 %55, label %59, label %56
56: ; preds = %53
%57 = load i8*, i8** %14
%58 = call i32 @showdata(i8* %57, i32 %17)
br label %59
59: ; preds = %56, %53
%60 = call i64 @FD_ISSET(i32 %27, i32* %4)
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %59, %63, %66
br label %40
63: ; preds = %59
%64 = load i8*, i8** %24
%65 = call i32 @showdata(i8* %64, i32 %27)
br label %62
66: ; preds = %51
%67 = load i8*, i8** %37
%68 = call i32 @atoi(i8* %67)
%69 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %68)
br label %62
}