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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1193 <main+0x33>
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0x0,%rax
jge    11f9 <main+0x99>
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rdx
mov    %rax,%rcx
lea    0xe30(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe33(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dd4(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
cmp    $0x0,%rax
jge    126b <main+0x10b>
mov    0x2dac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xde7(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xde8(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11ba <main+0x5a>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
test   %rax,%rax
js     11cd <main+0x6d>
lea    0xea7(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rbx),%rdi
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
test   %rax,%rax
js     11f1 <main+0x91>
lea    0xe93(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe92(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rbx),%rbx
mov    0x2def(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe11(%rip),%rsi
jmp    1213 <main+0xb3>
mov    0x2de0(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rbx),%rbx
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe06(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"Usage: access <pathname>\0A\00"
@R_OK = global i32 0
@stderr = global i32 0
@.str.1 = [25 x i8] c"access error for %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [16 x i8] c"read access OK\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [23 x i8] c"open error for %s: %s\0A\00"
@.str.4 = [21 x i8] c"open for reading OK\0A\00"
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 %11
8: ; preds = %2
%9 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 0)
unreachable
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @R_OK
%16 = call i64 @access(i8* %14, i32 %15)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %11
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %22, i8* %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %11
%28 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = load i32, i32* @O_RDONLY
%34 = call i64 @open(i8* %32, i32 %33)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %45
36: ; preds = %29
%37 = load i32, i32* @stderr
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = load i32, i32* @errno
%42 = call i8* @strerror(i32 %41)
%43 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %40, i8* %42)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %29
%46 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %47
47: ; preds = %45
ret i32 0
}

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