#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 *, int /*<<< orphan*/);
int /*<<< orphan*/ err_quit(char *);
int /*<<< orphan*/ err_ret(char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    err_quit("usage: a.out <pathname>");
  }
  if (access(argv[1], R_OK) < 0) {
    err_ret("access error for %s", argv[1]);
  } else {
    printf("read access OK\n");
  }
  if (open(argv[1], O_RDONLY) < 0) {
    err_ret("open error for %s", argv[1]);
  } else {
    printf("open for reading OK\n");
  }
  exit(0);
}


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     118c <main+0x2c>
lea    0xe79(%rip),%rdi
call   1040 <err_quit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0x0,%rax
jge    11c5 <main+0x65>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe5d(%rip),%rdi
call   1070 <err_ret@plt>
jmp    11d1 <main+0x71>
lea    0xe60(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
cmp    $0x0,%rax
jge    120a <main+0xaa>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe3c(%rip),%rdi
call   1070 <err_ret@plt>
jmp    1216 <main+0xb6>
lea    0xe3d(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
je     1175 <main+0x15>
lea    0xe90(%rip),%rdi
call   1040 <err_quit@plt>
mov    0x8(%rbx),%rdi
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
test   %rax,%rax
jns    119e <main+0x3e>
mov    0x8(%rbx),%rsi
lea    0xe81(%rip),%rdi
call   1070 <err_ret@plt>
jmp    11aa <main+0x4a>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rbx),%rdi
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
test   %rax,%rax
jns    11d8 <main+0x78>
mov    0x8(%rbx),%rsi
lea    0xe60(%rip),%rdi
call   1070 <err_ret@plt>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>

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

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