#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 */
scalar_t__ EACCES;
int /*<<< orphan*/ F_OK;
int /*<<< orphan*/ R_OK;
int /*<<< orphan*/ W_OK;
int /*<<< orphan*/ X_OK;
int access(char *, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  char *path;
  if (argc == 2) {
    path = argv[1];
  } else {
    path = ".";
  }
  int r = access(path, R_OK);
  if (r == 0) {
    printf("access R %s ok \n", path);
  } else {
    printf("access R %s error \n", path);
  }
  r = access(path, W_OK);
  if (r == 0) {
    printf("access W %s ok \n", path);
  } else {
    printf("access W %s error \n", path);
    if (errno == EACCES) {
      printf("Permission bits of the file mode do not permit the requested "
             "access, "
             "or search permission is denied on a component of the path "
             "prefix.\n");
    }
  }
  r = access(path, X_OK);
  if (r == 0) {
    printf("access X %s ok \n", path);
  } else {
    printf("access X %s error \n", path);
    printf("access W %s error \n", path);
    if (errno == EACCES) {
      printf("Permission bits of the file mode do not permit the requested "
             "access, "
             "or search permission is denied on a component of the path "
             "prefix.\n");
    }
  }
  if (access(path, F_OK) == 0) {
    printf("access F %s ok \n", path);
  } else {
    printf("access F %s error \n", path);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1151 <main+0x31>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    115c <main+0x3c>
lea    0xea8(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1192 <main+0x72>
mov    -0x18(%rbp),%rsi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a4 <main+0x84>
mov    -0x18(%rbp),%rsi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11da <main+0xba>
mov    -0x18(%rbp),%rsi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1219 <main+0xf9>
mov    -0x18(%rbp),%rsi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%rax
mov    0x2ddb(%rip),%rcx
cmp    (%rcx),%rax
jne    1214 <main+0xf4>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1219 <main+0xf9>
mov    -0x18(%rbp),%rdi
mov    0x2dbc(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    124f <main+0x12f>
mov    -0x18(%rbp),%rsi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12a0 <main+0x180>
mov    -0x18(%rbp),%rsi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d4e(%rip),%rax
mov    (%rax),%rax
mov    0x2d54(%rip),%rcx
cmp    (%rcx),%rax
jne    129b <main+0x17b>
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12a0 <main+0x180>
mov    -0x18(%rbp),%rdi
mov    0x2d05(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
cmp    $0x0,%eax
jne    12d2 <main+0x1b2>
mov    -0x18(%rbp),%rsi
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12e4 <main+0x1c4>
mov    -0x18(%rbp),%rsi
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jne    113c <main+0xc>
mov    0x8(%rsi),%rbx
jmp    1143 <main+0x13>
lea    0xfd6(%rip),%rbx
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <access@plt>
test   %eax,%eax
lea    0xea3(%rip),%rax
lea    0xead(%rip),%rdi
cmove  %rax,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <access@plt>
test   %eax,%eax
je     11bc <main+0x8c>
lea    0xea8(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%rax
mov    0x2e2f(%rip),%rcx
cmp    (%rcx),%rax
jne    11cd <main+0x9d>
lea    0xedf(%rip),%rdi
call   1030 <puts@plt>
jmp    11cd <main+0x9d>
lea    0xe62(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <access@plt>
test   %eax,%eax
je     1228 <main+0xf8>
lea    0xe72(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe3c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%rax
mov    0x2dc3(%rip),%rcx
cmp    (%rcx),%rax
jne    1239 <main+0x109>
lea    0xe73(%rip),%rdi
call   1030 <puts@plt>
jmp    1239 <main+0x109>
lea    0xe1b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <access@plt>
test   %eax,%eax
lea    0xe1c(%rip),%rax
lea    0xe26(%rip),%rdi
cmove  %rax,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@R_OK = global i32 0
@.str.1 = [17 x i8] c"access R %s ok \0A\00"
@.str.2 = [20 x i8] c"access R %s error \0A\00"
@W_OK = global i32 0
@.str.3 = [17 x i8] c"access W %s ok \0A\00"
@.str.4 = [20 x i8] c"access W %s error \0A\00"
@errno = global i64 0
@EACCES = global i64 0
@.str.5 = [136 x i8] c"Permission bits of the file mode do not permit the requested access, or search permission is denied on a component of the path prefix.\0A\00"
@X_OK = global i32 0
@.str.6 = [17 x i8] c"access X %s ok \0A\00"
@.str.7 = [20 x i8] c"access X %s error \0A\00"
@F_OK = global i32 0
@.str.8 = [17 x i8] c"access F %s ok \0A\00"
@.str.9 = [20 x i8] c"access F %s error \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 2
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
store i8* %13, i8** %6
br label %15
14: ; preds = %2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %6
br label %15
15: ; preds = %14, %10
%16 = load i8*, i8** %6
%17 = load i32, i32* @R_OK
%18 = call i32 @access(i8* %16, i32 %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = load i8*, i8** %6
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %27
24: ; preds = %15
%25 = load i8*, i8** %6
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %24, %21
%28 = load i8*, i8** %6
%29 = load i32, i32* @W_OK
%30 = call i32 @access(i8* %28, i32 %29)
store i32 %30, i32* %7
%31 = load i32, i32* %7
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %27
%34 = load i8*, i8** %6
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %34)
br label %45
36: ; preds = %27
%37 = load i8*, i8** %6
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %37)
%39 = load i64, i64* @errno
%40 = load i64, i64* @EACCES
%41 = icmp eq i64 %39, %40
br i1 %41, label %42, label %44
42: ; preds = %36
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.5, i64 0, i64 0))
br label %44
44: ; preds = %42, %36
br label %45
45: ; preds = %44, %33
%46 = load i8*, i8** %6
%47 = load i32, i32* @X_OK
%48 = call i32 @access(i8* %46, i32 %47)
store i32 %48, i32* %7
%49 = load i32, i32* %7
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %45
%52 = load i8*, i8** %6
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %52)
br label %65
54: ; preds = %45
%55 = load i8*, i8** %6
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i8* %55)
%57 = load i8*, i8** %6
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %57)
%59 = load i64, i64* @errno
%60 = load i64, i64* @EACCES
%61 = icmp eq i64 %59, %60
br i1 %61, label %62, label %64
62: ; preds = %54
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.5, i64 0, i64 0))
br label %64
64: ; preds = %62, %54
br label %65
65: ; preds = %64, %51
%66 = load i8*, i8** %6
%67 = load i32, i32* @F_OK
%68 = call i32 @access(i8* %66, i32 %67)
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %65
%71 = load i8*, i8** %6
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i8* %71)
br label %76
73: ; preds = %65
%74 = load i8*, i8** %6
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i8* %74)
br label %76
76: ; preds = %73, %70
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@R_OK = global i32 0
@.str.1 = [17 x i8] c"access R %s ok \0A\00"
@.str.2 = [20 x i8] c"access R %s error \0A\00"
@W_OK = global i32 0
@.str.3 = [17 x i8] c"access W %s ok \0A\00"
@.str.4 = [20 x i8] c"access W %s error \0A\00"
@errno = global i64 0
@EACCES = global i64 0
@X_OK = global i32 0
@.str.6 = [17 x i8] c"access X %s ok \0A\00"
@.str.7 = [20 x i8] c"access X %s error \0A\00"
@F_OK = global i32 0
@.str.8 = [17 x i8] c"access F %s ok \0A\00"
@.str.9 = [20 x i8] c"access F %s error \0A\00"
@str.10 = [135 x i8] c"Permission bits of the file mode do not permit the requested access, or search permission is denied on a component of the path prefix.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
br label %7
7: ; preds = %2, %4
%8 = phi i8* [ %6, %4 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %2 ]
%9 = load i32, i32* @R_OK
%10 = tail call i32 @access(i8* %8, i32 %9)
%11 = icmp eq i32 %10, 0
%12 = select i1 %11, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %12, i8* %8)
%14 = load i32, i32* @W_OK
%15 = tail call i32 @access(i8* %8, i32 %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %7
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %8)
br label %26
19: ; preds = %7
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %8)
%21 = load i64, i64* @errno
%22 = load i64, i64* @EACCES
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([135 x i8], [135 x i8]* @str.10, i64 0, i64 0))
br label %26
26: ; preds = %19, %24, %17
%27 = load i32, i32* @X_OK
%28 = tail call i32 @access(i8* %8, i32 %27)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %8)
br label %40
32: ; preds = %26
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i8* %8)
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %8)
%35 = load i64, i64* @errno
%36 = load i64, i64* @EACCES
%37 = icmp eq i64 %35, %36
br i1 %37, label %38, label %40
38: ; preds = %32
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([135 x i8], [135 x i8]* @str.10, i64 0, i64 0))
br label %40
40: ; preds = %32, %38, %30
%41 = load i32, i32* @F_OK
%42 = tail call i32 @access(i8* %8, i32 %41)
%43 = icmp eq i32 %42, 0
%44 = select i1 %43, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0)
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %44, i8* %8)
ret i32 0
}