#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*/ R_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
scalar_t__ open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc != 2) {
    fprintf(stderr, "%s: Usage: %s filename\n", argv[0], argv[0]);
    exit(EXIT_FAILURE);
  }
  if (access(argv[1], R_OK) < 0)
    printf("access error for %s\n", argv[1]);
  else
    printf("access OK for %s\n", argv[1]);
  if (open(argv[1], O_RDONLY) < 0)
    printf("open error for %s\n", argv[1]);
  else
    printf("open for reading OK: %s\n", argv[1]);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a1 <main+0x51>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xe72(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0x0,%rax
jge    11da <main+0x8a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
jmp    11ee <main+0x9e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
cmp    $0x0,%rax
jge    1227 <main+0xd7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe22(%rip),%rdi
call   1030 <printf@plt>
jmp    123b <main+0xeb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe1c(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11c7 <main+0x77>
mov    0x8(%rbx),%rdi
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
test   %rax,%rax
mov    0x8(%rbx),%rsi
lea    0xe9f(%rip),%rax
lea    0xead(%rip),%rdi
cmovs  %rax,%rdi
call   1030 <printf@plt>
mov    0x8(%rbx),%rdi
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
test   %rax,%rax
lea    0xe9a(%rip),%rax
lea    0xea6(%rip),%rdi
cmovs  %rax,%rdi
mov    0x8(%rbx),%rsi
call   1030 <printf@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rcx
lea    0xe26(%rip),%rsi
mov    %rcx,%rdx
call   1040 <fprintf@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"%s: Usage: %s filename\0A\00"
@EXIT_FAILURE = global i32 0
@R_OK = global i32 0
@.str.1 = [21 x i8] c"access error for %s\0A\00"
@.str.2 = [18 x i8] c"access OK for %s\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [19 x i8] c"open error for %s\0A\00"
@.str.4 = [25 x i8] c"open for reading OK: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 2
br i1 %7, label %8, label %19
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @R_OK
%24 = call i64 @access(i8* %22, i32 %23)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %19
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %29)
br label %36
31: ; preds = %19
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %31, %26
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = load i32, i32* @O_RDONLY
%41 = call i64 @open(i8* %39, i32 %40)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %36
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %46)
br label %53
48: ; preds = %36
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 1
%51 = load i8*, i8** %50
%52 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %48, %43
%54 = load i32, i32* @EXIT_SUCCESS
%55 = call i32 @exit(i32 %54)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"%s: Usage: %s filename\0A\00"
@EXIT_FAILURE = global i32 0
@R_OK = global i32 0
@.str.1 = [21 x i8] c"access error for %s\0A\00"
@.str.2 = [18 x i8] c"access OK for %s\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [19 x i8] c"open error for %s\0A\00"
@.str.4 = [25 x i8] c"open for reading OK: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %6, i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @R_OK
%14 = tail call i64 @access(i8* %12, i32 %13)
%15 = icmp slt i64 %14, 0
%16 = load i8*, i8** %11
%17 = select i1 %15, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0)
%18 = tail call i32 @printf(i8* %17, i8* %16)
%19 = load i8*, i8** %11
%20 = load i32, i32* @O_RDONLY
%21 = tail call i64 @open(i8* %19, i32 %20)
%22 = icmp slt i64 %21, 0
%23 = select i1 %22, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0)
%24 = load i8*, i8** %11
%25 = tail call i32 @printf(i8* %23, i8* %24)
%26 = load i32, i32* @EXIT_SUCCESS
%27 = tail call i32 @exit(i32 %26)
unreachable
}