#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int my_open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int main(int argc, char *argv[]) {
  int fd, n;
  char buff[256];
  if (2 != argc) {
    printf("USAGE : %s <pathname>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if ((fd = my_open(argv[1], O_RDONLY)) < 0) {
    perror("my_open");
    exit(EXIT_FAILURE);
  }
  while ((n = read(fd, buff, 256)) > 0) {
    write(STDOUT_FILENO, buff, n);
  }
  exit(EXIT_SUCCESS);
}


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)
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
je     11a8 <main+0x48>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
call   1060 <my_open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11e4 <main+0x84>
lea    0xe46(%rip),%rdi
call   1070 <perror@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    11e9 <main+0x89>
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jle    1226 <main+0xc6>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
lea    -0x120(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <write@plt>
jmp    11e9 <main+0x89>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
cmp    $0x2,%edi
jne    1194 <main+0x34>
mov    0x8(%rsi),%rdi
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
call   1060 <my_open@plt>
test   %eax,%eax
jns    11b1 <main+0x51>
lea    0xe8a(%rip),%rdi
call   1070 <perror@plt>
jmp    11a3 <main+0x43>
mov    (%rsi),%rsi
lea    0xe62(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x100,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11f0 <main+0x90>
mov    0x2e23(%rip),%r14
mov    %rsp,%rbx
mov    (%r14),%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1050 <read@plt>
test   %eax,%eax
jg     11d0 <main+0x70>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"USAGE : %s <pathname>\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [8 x i8] c"my_open\00"
@STDOUT_FILENO = global i32 0
@EXIT_SUCCESS = 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 [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 ne i32 2, %9
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
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 %29
25: ; preds = %18
%26 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %18
br label %30
30: ; preds = %35, %29
%31 = load i32, i32* %6
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%33 = call i32 @read(i32 %31, i8* %32, i32 256)
store i32 %33, i32* %7
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %30
%36 = load i32, i32* @STDOUT_FILENO
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%38 = load i32, i32* %7
%39 = call i32 @write(i32 %36, i8* %37, i32 %38)
br label %30
40: ; preds = %30
%41 = load i32, i32* @EXIT_SUCCESS
%42 = call i32 @exit(i32 %41)
unreachable
}

LLVM IR (-O2):
@.str = [23 x i8] c"USAGE : %s <pathname>\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [8 x i8] c"my_open\00"
@STDOUT_FILENO = global i32 0
@EXIT_SUCCESS = global i32 0
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 eq i32 %0, 2
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
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 256)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %24, label %30
20: ; preds = %11
%21 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %17, %24
%25 = phi i32 [ %28, %24 ], [ %18, %17 ]
%26 = load i32, i32* @STDOUT_FILENO
%27 = call i32 @write(i32 %26, i8* %4, i32 %25)
%28 = call i32 @read(i32 %15, i8* %4, i32 256)
%29 = icmp sgt i32 %28, 0
br i1 %29, label %24, label %30
30: ; preds = %24, %17
%31 = load i32, i32* @EXIT_SUCCESS
%32 = tail call i32 @exit(i32 %31)
unreachable
}