#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 */
typedef size_t ssize_t;
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 /*<<< orphan*/ assert(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, ...);
size_t read(int, char *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  fd_set permSet, testSet;
  int fd[100];
  int i, maxFd = -1;
  char buffer[(4 * 1024) + 1];
  ssize_t byteCount;
  FD_ZERO(&permSet);
  assert(argc < 100);
  for (i = 1; i < argc; ++i) {
    fd[i] = open(argv[i], O_RDONLY);
    if (fd[i] < 0) {
      fprintf(stderr, "Opening %s failed: %s\n", argv[i], strerror(errno));
      exit(1);
    } else {
      printf("Opened %s successfully\n", argv[i]);
    }
    FD_SET(fd[i], &permSet);
    if (fd[i] > maxFd) {
      maxFd = fd[i];
    }
  }
  for (;;) {
    testSet = permSet;
    i = select(maxFd + 1, &testSet, NULL, NULL, NULL);
    assert(i > 0);
    for (i = 1; i < argc; ++i) {
      if (FD_ISSET(fd[i], &testSet)) {
        byteCount = read(fd[i], buffer, (4 * 1024));
        assert(byteCount > 0);
        buffer[byteCount] = '\0';
        printf("Got data from %s: %s", argv[i], buffer);
      }
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x11e0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x1b8(%rbp)
ff ff ff
lea    -0x14(%rbp),%rdi
call   1080 <FD_ZERO@plt>
cmpl   $0x64,-0x8(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
movl   $0x1,-0x1b4(%rbp)
mov    -0x1b4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    131c <main+0x16c>
mov    -0x10(%rbp),%rax
movslq -0x1b4(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2dcc(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,%ecx
movslq -0x1b4(%rbp),%rax
mov    %ecx,-0x1b0(%rbp,%rax,4)
movslq -0x1b4(%rbp),%rax
cmpl   $0x0,-0x1b0(%rbp,%rax,4)
jge    12a1 <main+0xf1>
mov    0x2d89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x11d4(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1b4(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x11d0(%rbp)
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x11d4(%rbp),%edi
mov    -0x11d0(%rbp),%rdx
mov    %rax,%rcx
lea    0xd6e(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
movslq -0x1b4(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0x1b4(%rbp),%rax
mov    -0x1b0(%rbp,%rax,4),%edi
lea    -0x14(%rbp),%rsi
call   10d0 <FD_SET@plt>
movslq -0x1b4(%rbp),%rax
mov    -0x1b0(%rbp,%rax,4),%eax
cmp    -0x1b8(%rbp),%eax
jle    1303 <main+0x153>
movslq -0x1b4(%rbp),%rax
mov    -0x1b0(%rbp,%rax,4),%eax
mov    %eax,-0x1b8(%rbp)
jmp    1308 <main+0x158>
mov    -0x1b4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b4(%rbp)
jmp    11f7 <main+0x47>
jmp    1321 <main+0x171>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1b8(%rbp),%edi
add    $0x1,%edi
lea    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1090 <select@plt>
mov    %eax,-0x1b4(%rbp)
cmpl   $0x0,-0x1b4(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
movl   $0x1,-0x1b4(%rbp)
mov    -0x1b4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    141f <main+0x26f>
movslq -0x1b4(%rbp),%rax
mov    -0x1b0(%rbp,%rax,4),%edi
lea    -0x18(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1406 <main+0x256>
movslq -0x1b4(%rbp),%rax
mov    -0x1b0(%rbp,%rax,4),%edi
lea    -0x11c0(%rbp),%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %rax,-0x11c8(%rbp)
cmpq   $0x0,-0x11c8(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x11c8(%rbp),%rax
movb   $0x0,-0x11c0(%rbp,%rax,1)
mov    -0x10(%rbp),%rax
movslq -0x1b4(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    -0x11c0(%rbp),%rdx
lea    0xc30(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    140b <main+0x25b>
mov    -0x1b4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b4(%rbp)
jmp    1368 <main+0x1b8>
jmp    1321 <main+0x171>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x11a8,%rsp
mov    %rsi,%r12
mov    %edi,%ebp
lea    0x8(%rsp),%rdi
call   1080 <FD_ZERO@plt>
xor    %edi,%edi
cmp    $0x64,%ebp
setl   %dil
call   1060 <assert@plt>
movl   $0x0,(%rsp)
mov    %ebp,%r13d
mov    %ebp,0xc(%rsp)
cmp    $0x2,%ebp
jl     1260 <main+0xb0>
movl   $0xffffffff,(%rsp)
mov    $0x1,%ebp
lea    0xe13(%rip),%r14
lea    0x8(%rsp),%r15
nopl   0x0(%rax)
mov    (%r12,%rbp,8),%rdi
mov    0x2dcd(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,0x10(%rsp,%rbp,4)
test   %eax,%eax
js     1310 <main+0x160>
mov    %eax,%ebx
mov    (%r12,%rbp,8),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
mov    %r15,%rsi
call   10d0 <FD_SET@plt>
mov    (%rsp),%eax
cmp    %eax,%ebx
cmovg  %ebx,%eax
mov    %eax,(%rsp)
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1210 <main+0x60>
addl   $0x1,(%rsp)
mov    %r12,%r15
lea    0x1a0(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%eax
mov    %eax,0x4(%rsp)
mov    (%rsp),%edi
lea    0x4(%rsp),%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1090 <select@plt>
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1060 <assert@plt>
cmpl   $0x2,0xc(%rsp)
jl     1270 <main+0xc0>
mov    $0x1,%r12d
jmp    12b9 <main+0x109>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
cmp    %r12,%r13
je     1270 <main+0xc0>
mov    0x10(%rsp,%r12,4),%r14d
mov    %r14d,%edi
lea    0x4(%rsp),%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     12b0 <main+0x100>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %rax,%rbp
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1060 <assert@plt>
movb   $0x0,0x1a0(%rsp,%rbp,1)
mov    (%r15,%r12,8),%rsi
lea    0xd2b(%rip),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    12b0 <main+0x100>
mov    0x2cc1(%rip),%rax
mov    (%rax),%ebx
mov    (%r12,%rbp,8),%rbp
mov    0x2cac(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xcce(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"Opening %s failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [24 x i8] c"Opened %s successfully\0A\00"
@.str.2 = [21 x i8] c"Got data from %s: %s\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 [100 x i32]
%9 = alloca i32
%10 = alloca i32
%11 = alloca [4097 x i8]
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %10
%13 = call i32 @FD_ZERO(i32* %6)
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 100
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
store i32 1, i32* %9
br label %18
18: ; preds = %74, %2
%19 = load i32, i32* %9
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %77
22: ; preds = %18
%23 = load i8**, i8*** %5
%24 = load i32, i32* %9
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = load i32, i32* @O_RDONLY
%29 = call i32 @open(i8* %27, i32 %28)
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [100 x i32], [100 x i32]* %8, i64 0, i64 %31
store i32 %29, i32* %32
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [100 x i32], [100 x i32]* %8, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %49
38: ; preds = %22
%39 = load i32, i32* @stderr
%40 = load i8**, i8*** %5
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
%45 = load i32, i32* @errno
%46 = call i8* @strerror(i32 %45)
%47 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %44, i8* %46)
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %22
%50 = load i8**, i8*** %5
%51 = load i32, i32* %9
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %50, i64 %52
%54 = load i8*, i8** %53
%55 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %54)
br label %56
56: ; preds = %49
%57 = load i32, i32* %9
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [100 x i32], [100 x i32]* %8, i64 0, i64 %58
%60 = load i32, i32* %59
%61 = call i32 @FD_SET(i32 %60, i32* %6)
%62 = load i32, i32* %9
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [100 x i32], [100 x i32]* %8, i64 0, i64 %63
%65 = load i32, i32* %64
%66 = load i32, i32* %10
%67 = icmp sgt i32 %65, %66
br i1 %67, label %68, label %73
68: ; preds = %56
%69 = load i32, i32* %9
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [100 x i32], [100 x i32]* %8, i64 0, i64 %70
%72 = load i32, i32* %71
store i32 %72, i32* %10
br label %73
73: ; preds = %68, %56
br label %74
74: ; preds = %73
%75 = load i32, i32* %9
%76 = add nsw i32 %75, 1
store i32 %76, i32* %9
br label %18
77: ; preds = %18
br label %78
78: ; preds = %122, %77
%79 = load i32, i32* %6
store i32 %79, i32* %7
%80 = load i32, i32* %10
%81 = add nsw i32 %80, 1
%82 = call i32 @select(i32 %81, i32* %7, i32* null, i32* null, i32* null)
store i32 %82, i32* %9
%83 = load i32, i32* %9
%84 = icmp sgt i32 %83, 0
%85 = zext i1 %84 to i32
%86 = call i32 @assert(i32 %85)
store i32 1, i32* %9
br label %87
87: ; preds = %119, %78
%88 = load i32, i32* %9
%89 = load i32, i32* %4
%90 = icmp slt i32 %88, %89
br i1 %90, label %91, label %122
91: ; preds = %87
%92 = load i32, i32* %9
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds [100 x i32], [100 x i32]* %8, i64 0, i64 %93
%95 = load i32, i32* %94
%96 = call i64 @FD_ISSET(i32 %95, i32* %7)
%97 = icmp ne i64 %96, 0
br i1 %97, label %98, label %118
98: ; preds = %91
%99 = load i32, i32* %9
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds [100 x i32], [100 x i32]* %8, i64 0, i64 %100
%102 = load i32, i32* %101
%103 = getelementptr inbounds [4097 x i8], [4097 x i8]* %11, i64 0, i64 0
%104 = call i64 @read(i32 %102, i8* %103, i32 4096)
store i64 %104, i64* %12
%105 = load i64, i64* %12
%106 = icmp ugt i64 %105, 0
%107 = zext i1 %106 to i32
%108 = call i32 @assert(i32 %107)
%109 = load i64, i64* %12
%110 = getelementptr inbounds [4097 x i8], [4097 x i8]* %11, i64 0, i64 %109
store i8 0, i8* %110
%111 = load i8**, i8*** %5
%112 = load i32, i32* %9
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds i8*, i8** %111, i64 %113
%115 = load i8*, i8** %114
%116 = getelementptr inbounds [4097 x i8], [4097 x i8]* %11, i64 0, i64 0
%117 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %115, i8* %116)
br label %118
118: ; preds = %98, %91
br label %119
119: ; preds = %118
%120 = load i32, i32* %9
%121 = add nsw i32 %120, 1
store i32 %121, i32* %9
br label %87
122: ; preds = %87
br label %78
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"Opening %s failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [24 x i8] c"Opened %s successfully\0A\00"
@.str.2 = [21 x i8] c"Got data from %s: %s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [100 x i32]
%6 = alloca [4097 x i8]
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast [100 x i32]* %5 to i8*
%10 = getelementptr inbounds [4097 x i8], [4097 x i8]* %6, i64 0, i64 0
%11 = call i32 @FD_ZERO(i32* %3)
%12 = icmp slt i32 %0, 100
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = icmp sgt i32 %0, 1
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = zext i32 %0 to i64
br label %23
18: ; preds = %39
%19 = add nuw i32 %44, 1
br label %20
20: ; preds = %18, %2
%21 = phi i32 [ 0, %2 ], [ %19, %18 ]
%22 = zext i32 %0 to i64
br label %47
23: ; preds = %16, %39
%24 = phi i64 [ 1, %16 ], [ %45, %39 ]
%25 = phi i32 [ -1, %16 ], [ %44, %39 ]
%26 = getelementptr inbounds i8*, i8** %1, i64 %24
%27 = load i8*, i8** %26
%28 = load i32, i32* @O_RDONLY
%29 = call i32 @open(i8* %27, i32 %28)
%30 = getelementptr inbounds [100 x i32], [100 x i32]* %5, i64 0, i64 %24
store i32 %29, i32* %30
%31 = icmp slt i32 %29, 0
br i1 %31, label %32, label %39
32: ; preds = %23
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %26
%35 = load i32, i32* @errno
%36 = call i8* @strerror(i32 %35)
%37 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %34, i8* %36)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %23
%40 = load i8*, i8** %26
%41 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %40)
%42 = call i32 @FD_SET(i32 %29, i32* %3)
%43 = icmp sgt i32 %29, %25
%44 = select i1 %43, i32 %29, i32 %25
%45 = add nuw nsw i64 %24, 1
%46 = icmp eq i64 %45, %17
br i1 %46, label %18, label %23
47: ; preds = %53, %20
%48 = load i32, i32* %3
store i32 %48, i32* %4
%49 = call i32 @select(i32 %21, i32* %4, i32* null, i32* null, i32* null)
%50 = icmp sgt i32 %49, 0
%51 = zext i1 %50 to i32
%52 = call i32 @assert(i32 %51)
br i1 %15, label %54, label %53
53: ; preds = %69, %47
br label %47
54: ; preds = %47, %69
%55 = phi i64 [ %70, %69 ], [ 1, %47 ]
%56 = getelementptr inbounds [100 x i32], [100 x i32]* %5, i64 0, i64 %55
%57 = load i32, i32* %56
%58 = call i64 @FD_ISSET(i32 %57, i32* %4)
%59 = icmp eq i64 %58, 0
br i1 %59, label %69, label %60
60: ; preds = %54
%61 = call i64 @read(i32 %57, i8* %10, i32 4096)
%62 = icmp ne i64 %61, 0
%63 = zext i1 %62 to i32
%64 = call i32 @assert(i32 %63)
%65 = getelementptr inbounds [4097 x i8], [4097 x i8]* %6, i64 0, i64 %61
store i8 0, i8* %65
%66 = getelementptr inbounds i8*, i8** %1, i64 %55
%67 = load i8*, i8** %66
%68 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %67, i8* %10)
br label %69
69: ; preds = %54, %60
%70 = add nuw nsw i64 %55, 1
%71 = icmp eq i64 %70, %22
br i1 %71, label %53, label %54
}