#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 *, 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: %s <pathname>", argv[0]);
  }
  if (access(argv[1], R_OK) < 0) {
    err_ret("access error for %s", argv[1]);
  } else {
    printf("read access OK\n");
  }
  if (open(argv[0], 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     1193 <main+0x33>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe72(%rip),%rdi
call   1040 <err_quit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0x0,%rax
jge    11cc <main+0x6c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe53(%rip),%rdi
call   1070 <err_ret@plt>
jmp    11d8 <main+0x78>
lea    0xe56(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
cmp    $0x0,%rax
jge    1210 <main+0xb0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe33(%rip),%rdi
call   1070 <err_ret@plt>
jmp    121c <main+0xbc>
lea    0xe34(%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     1178 <main+0x18>
mov    (%rbx),%rsi
lea    0xe8d(%rip),%rdi
call   1040 <err_quit@plt>
mov    0x8(%rbx),%rdi
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
test   %rax,%rax
jns    11a1 <main+0x41>
mov    0x8(%rbx),%rsi
lea    0xe7b(%rip),%rdi
call   1070 <err_ret@plt>
jmp    11ad <main+0x4d>
lea    0xe93(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rdi
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
test   %rax,%rax
jns    11da <main+0x7a>
mov    0x8(%rbx),%rsi
lea    0xe5b(%rip),%rdi
call   1070 <err_ret@plt>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xe69(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>

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

LLVM IR (-O2):
@.str = [21 x i8] c"usage: %s <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 %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @err_quit(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %7
7: ; preds = %4, %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 %16
13: ; preds = %7
%14 = load i8*, i8** %8
%15 = tail call i32 @err_ret(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %18
16: ; preds = %7
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %18
18: ; preds = %16, %13
%19 = load i8*, i8** %1
%20 = load i32, i32* @O_RDONLY
%21 = tail call i64 @open(i8* %19, i32 %20)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i8*, i8** %8
%25 = tail call i32 @err_ret(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %24)
br label %28
26: ; preds = %18
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.5, i64 0, i64 0))
br label %28
28: ; preds = %26, %23
%29 = tail call i32 @exit(i32 0)
unreachable
}