#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 open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd, ret;
  char buf[256];
  if (argc < 2)
    return -1;
  fd = open(argv[1], O_RDONLY);
  if (fd < 0) {
    perror("open");
    return -1;
  }
  while ((ret = read(fd, buf, 256)) > 0) {
    write(1, buf, ret);
  }
  printf("\n");
  if (ret < 0) {
    perror("read");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    117f <main+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1221 <main+0xd1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11ba <main+0x6a>
lea    0xe57(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1221 <main+0xd1>
jmp    11bf <main+0x6f>
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jle    11f8 <main+0xa8>
lea    -0x120(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    11bf <main+0x6f>
lea    0xe06(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
jge    121a <main+0xca>
lea    0xdf2(%rip),%rdi
call   1070 <perror@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    $0xffffffff,%ebx
cmp    $0x2,%edi
jl     11d5 <main+0x85>
mov    0x8(%rsi),%rdi
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     11e3 <main+0x93>
mov    %eax,%r14d
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x100,%edx
call   1050 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    11c5 <main+0x75>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1050 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     11a0 <main+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %ebx,%ebx
test   %ebp,%ebp
js     11f1 <main+0xa1>
mov    %ebx,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0xffffffff,%ebx
lea    0xe11(%rip),%rdi
jmp    11f8 <main+0xa8>
lea    0xe0d(%rip),%rdi
call   1070 <perror@plt>
jmp    11d5 <main+0x85>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [5 x i8] c"open\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [5 x i8] c"read\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 [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %39
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_RDONLY
%17 = call i32 @open(i8* %15, i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %39
22: ; preds = %12
br label %23
23: ; preds = %28, %22
%24 = load i32, i32* %6
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%26 = call i32 @read(i32 %24, i8* %25, i32 256)
store i32 %26, i32* %7
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%30 = load i32, i32* %7
%31 = call i32 @write(i32 1, i8* %29, i32 %30)
br label %23
32: ; preds = %23
%33 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* %7
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %36, %32
store i32 0, i32* %3
br label %39
39: ; preds = %38, %20, %11
%40 = load i32, i32* %3
ret i32 %40
}

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