#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 open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char **argv) {
  int revl = 0;
  int i = 0;
  int fd = 0;
  char filename[64];
  char buffer[128];
  if (argc > 1) {
    strcpy(filename, argv[1]);
  } else {
    strcpy(filename, "/tmp/test.tmp");
  }
  printf("file: %s\n", filename);
  fd = open(filename, O_RDONLY);
  if (fd < 0) {
    perror("open");
    return 1;
  }
  for (i = 0; i < 600; i++) {
    revl = read(fd, buffer, 127);
    if (revl < 0) {
      perror("write");
      break;
    }
    buffer[revl] = 0;
    printf("%s", buffer);
    sleep(1);
  }
  close(fd);
  return revl;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11be <main+0x4e>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
jmp    11ce <main+0x5e>
lea    -0x60(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x60(%rbp),%rsi
lea    0xe35(%rip),%rdi
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1215 <main+0xa5>
lea    0xe14(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a0 <main+0x130>
movl   $0x0,-0x18(%rbp)
cmpl   $0x258,-0x18(%rbp)
jge    1292 <main+0x122>
mov    -0x1c(%rbp),%edi
lea    -0xe0(%rbp),%rsi
mov    $0x7f,%edx
call   1060 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    125b <main+0xeb>
lea    0xdcc(%rip),%rdi
call   1080 <perror@plt>
jmp    1292 <main+0x122>
movslq -0x14(%rbp),%rax
movb   $0x0,-0xe0(%rbp,%rax,1)
lea    -0xe0(%rbp),%rsi
lea    0xdae(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    121c <main+0xac>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xc0,%rsp
cmp    $0x2,%edi
jl     118a <main+0x1a>
mov    0x8(%rsi),%rsi
jmp    1191 <main+0x21>
lea    0xe6f(%rip),%rsi
lea    0x80(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe66(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <open@plt>
test   %eax,%eax
js     1230 <main+0xc0>
mov    %eax,%r14d
mov    $0x258,%ebx
mov    %rsp,%r12
lea    0xe4c(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x7f,%edx
call   1060 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1243 <main+0xd3>
mov    %ebp,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
add    $0xffffffff,%ebx
jne    11e0 <main+0x70>
mov    %r14d,%edi
call   1050 <close@plt>
mov    %ebp,%eax
add    $0xc0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde1(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%ebp
jmp    121e <main+0xae>
lea    0xdd3(%rip),%rdi
call   1080 <perror@plt>
jmp    1216 <main+0xa6>

LLVM IR (-O0):
@.str = [14 x i8] c"/tmp/test.tmp\00"
@.str.1 = [10 x i8] c"file: %s\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [6 x i8] c"write\00"
@.str.4 = [3 x i8] c"%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 i32
%9 = alloca [64 x i8]
%10 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @strcpy(i8* %14, i8* %17)
br label %22
19: ; preds = %2
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%21 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %19, %13
%23 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%24 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%26 = load i32, i32* @O_RDONLY
%27 = call i32 @open(i8* %25, i32 %26)
store i32 %27, i32* %8
%28 = load i32, i32* %8
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %22
%31 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %58
32: ; preds = %22
store i32 0, i32* %7
br label %33
33: ; preds = %51, %32
%34 = load i32, i32* %7
%35 = icmp slt i32 %34, 600
br i1 %35, label %36, label %54
36: ; preds = %33
%37 = load i32, i32* %8
%38 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%39 = call i32 @read(i32 %37, i8* %38, i32 127)
store i32 %39, i32* %6
%40 = load i32, i32* %6
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %36
%43 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %54
44: ; preds = %36
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 %46
store i8 0, i8* %47
%48 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%49 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %48)
%50 = call i32 @sleep(i32 1)
br label %51
51: ; preds = %44
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
br label %33
54: ; preds = %42, %33
%55 = load i32, i32* %8
%56 = call i32 @close(i32 %55)
%57 = load i32, i32* %6
store i32 %57, i32* %3
br label %58
58: ; preds = %54, %30
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@.str = [14 x i8] c"/tmp/test.tmp\00"
@.str.1 = [10 x i8] c"file: %s\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [6 x i8] c"write\00"
@.str.4 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [64 x i8]
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
br label %11
11: ; preds = %2, %8
%12 = phi i8* [ %10, %8 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), %2 ]
%13 = call i32 @strcpy(i8* %5, i8* %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* %5, i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %35
20: ; preds = %11, %26
%21 = phi i32 [ %31, %26 ], [ 0, %11 ]
%22 = call i32 @read(i32 %16, i8* %6, i32 127)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %33
26: ; preds = %20
%27 = zext i32 %22 to i64
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 %27
store i8 0, i8* %28
%29 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%30 = call i32 @sleep(i32 1)
%31 = add nuw nsw i32 %21, 1
%32 = icmp eq i32 %31, 600
br i1 %32, label %33, label %20
33: ; preds = %26, %24
%34 = call i32 @close(i32 %16)
br label %35
35: ; preds = %33, %18
%36 = phi i32 [ 1, %18 ], [ %22, %33 ]
ret i32 %36
}