#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ poll(int /*<<< orphan*/, int /*<<< orphan*/, int);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
int main(int argc, char **argv) {
  char buf[10];
  int fd, r;
  if (argc != 2) {
    fprintf(stderr, "What, no files?\n");
    return 1;
  }
  fd = open(argv[1], O_RDONLY);
  if (fd < 0)
    return 1;
  while (1) {
    r = read(fd, buf, 1);
    if (r != 1)
      break;
    r = write(1, buf, 1);
    if (r != 1)
      break;
    poll(0, 0, 10);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a1 <main+0x41>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    123c <main+0xdc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11d0 <main+0x70>
movl   $0x1,-0x4(%rbp)
jmp    123c <main+0xdc>
jmp    11d5 <main+0x75>
mov    -0x20(%rbp),%edi
lea    -0x1a(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
je     11f8 <main+0x98>
jmp    122d <main+0xcd>
lea    -0x1a(%rbp),%rsi
mov    $0x1,%edx
mov    %edx,%edi
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
je     121a <main+0xba>
jmp    122d <main+0xcd>
xor    %esi,%esi
mov    $0xa,%edx
mov    %esi,%edi
call   1070 <poll@plt>
jmp    11d5 <main+0x75>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    11e4 <main+0x84>
mov    0x8(%rsi),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     11f9 <main+0x99>
mov    %eax,%ebx
lea    0xe(%rsp),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x1,%eax
jne    11d9 <main+0x79>
lea    0xe(%rsp),%r14
nop
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jne    11d9 <main+0x79>
xor    %edi,%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <poll@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x1,%eax
je     11a0 <main+0x40>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
jmp    11fe <main+0x9e>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [17 x i8] c"What, no files?\0A\00"
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [10 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %42
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = load i32, i32* @O_RDONLY
%19 = call i32 @open(i8* %17, i32 %18)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %14
store i32 1, i32* %3
br label %42
23: ; preds = %14
br label %24
24: ; preds = %23, %37
%25 = load i32, i32* %7
%26 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%27 = call i32 @read(i32 %25, i8* %26, i32 1)
store i32 %27, i32* %8
%28 = load i32, i32* %8
%29 = icmp ne i32 %28, 1
br i1 %29, label %30, label %31
30: ; preds = %24
br label %39
31: ; preds = %24
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%33 = call i32 @write(i32 1, i8* %32, i32 1)
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = icmp ne i32 %34, 1
br i1 %35, label %36, label %37
36: ; preds = %31
br label %39
37: ; preds = %31
%38 = call i32 @poll(i32 0, i32 0, i32 10)
br label %24
39: ; preds = %36, %30
%40 = load i32, i32* %7
%41 = call i32 @close(i32 %40)
store i32 0, i32* %3
br label %42
42: ; preds = %39, %22, %11
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [17 x i8] c"What, no files?\0A\00"
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %27
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 @open(i8* %11, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %27, label %15
15: ; preds = %9
%16 = call i32 @read(i32 %13, i8* %4, i32 1)
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %25
18: ; preds = %15, %21
%19 = call i32 @write(i32 1, i8* %4, i32 1)
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = tail call i32 @poll(i32 0, i32 0, i32 10)
%23 = call i32 @read(i32 %13, i8* %4, i32 1)
%24 = icmp eq i32 %23, 1
br i1 %24, label %18, label %25
25: ; preds = %21, %18, %15
%26 = tail call i32 @close(i32 %13)
br label %27
27: ; preds = %9, %25, %6
%28 = phi i32 [ 1, %6 ], [ 0, %25 ], [ 1, %9 ]
ret i32 %28
}