#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*/ STDOUT_FILENO;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int my_open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int main(int argc, char *argv[]) {
  int fd, n;
  char buf[1024];
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <pathname>\n", argv[0]);
    exit(-1);
  }
  if ((fd = my_open(argv[1], O_RDONLY)) < 0) {
    fprintf(stderr, "cannot open %s\n", argv[1]);
    exit(-1);
  }
  while ((n = read(fd, buf, 1024)) > 0)
    write(STDOUT_FILENO, buf, n);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1199 <main+0x49>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe76(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
call   1050 <my_open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11e2 <main+0x92>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe43(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
jmp    11e7 <main+0x97>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1040 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jle    1224 <main+0xd4>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <write@plt>
jmp    11e7 <main+0x97>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11ce <main+0x7e>
mov    0x8(%rbx),%rdi
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
call   1050 <my_open@plt>
test   %eax,%eax
js     11e3 <main+0x93>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x400,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    11c0 <main+0x70>
mov    0x2e5b(%rip),%r14
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
mov    (%r14),%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
test   %eax,%eax
jg     11a0 <main+0x50>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe1f(%rip),%rsi
jmp    11f7 <main+0xa7>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xe1f(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"Usage: %s <pathname>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [16 x i8] c"cannot open %s\0A\00"
@STDOUT_FILENO = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1024 x i8]
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 %18
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = load i32, i32* @O_RDONLY
%23 = call i32 @my_open(i8* %21, i32 %22)
store i32 %23, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 -1)
unreachable
32: ; preds = %18
br label %33
33: ; preds = %38, %32
%34 = load i32, i32* %6
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%36 = call i32 @read(i32 %34, i8* %35, i32 1024)
store i32 %36, i32* %7
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %33
%39 = load i32, i32* @STDOUT_FILENO
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%41 = load i32, i32* %7
%42 = call i32 @write(i32 %39, i8* %40, i32 %41)
br label %33
43: ; preds = %33
ret i32 0
}

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