#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;
scalar_t__ ENOENT;
scalar_t__ EROFS;
int /*<<< orphan*/ F_OK;
int /*<<< orphan*/ R_OK;
int /*<<< orphan*/ W_OK;
int access(char *, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  char *path = argv[1];
  int retval;
  retval = access(path, F_OK);
  if (retval == 0) {
    printf("%s exists.\n", path);
  } else {
    if (errno == ENOENT) {
      printf("%s does not exist.\n", path);
    } else if (errno == EACCES) {
      printf("%s is not accessible.\n", path);
    }
    return 0;
  }
  retval = access(path, R_OK);
  if (retval == 0) {
    printf("%s is readable.\n", path);
  } else {
    printf("%s is not readable, permission denied!\n", path);
  }
  retval = access(path, W_OK);
  if (retval == 0) {
    printf("%s is writable.\n", path);
  } else {
    if (errno == EACCES) {
      printf("%s is not writable, permission denied!\n", path);
    } else if (errno == EROFS) {
      printf("%s is not writable, read-only system!\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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1176 <main+0x56>
mov    -0x18(%rbp),%rsi
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
jmp    11e0 <main+0xc0>
mov    0x2e4b(%rip),%rax
mov    (%rax),%rax
mov    0x2e29(%rip),%rcx
cmp    (%rcx),%rax
jne    11a5 <main+0x85>
mov    -0x18(%rbp),%rsi
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
jmp    11d4 <main+0xb4>
mov    0x2e1c(%rip),%rax
mov    (%rax),%rax
mov    0x2e22(%rip),%rcx
cmp    (%rcx),%rax
jne    11cf <main+0xaf>
mov    -0x18(%rbp),%rsi
lea    0xe56(%rip),%rdi
call   1030 <printf@plt>
jmp    11d4 <main+0xb4>
movl   $0x0,-0x4(%rbp)
jmp    12c2 <main+0x1a2>
mov    -0x18(%rbp),%rdi
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1214 <main+0xf4>
mov    -0x18(%rbp),%rsi
lea    0xe2d(%rip),%rdi
call   1030 <printf@plt>
jmp    1224 <main+0x104>
mov    -0x18(%rbp),%rsi
lea    0xe29(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1258 <main+0x138>
mov    -0x18(%rbp),%rsi
lea    0xe22(%rip),%rdi
call   1030 <printf@plt>
jmp    12bb <main+0x19b>
mov    0x2d69(%rip),%rax
mov    (%rax),%rax
mov    0x2d6f(%rip),%rcx
cmp    (%rcx),%rax
jne    1287 <main+0x167>
mov    -0x18(%rbp),%rsi
lea    0xe04(%rip),%rdi
call   1030 <printf@plt>
jmp    12b6 <main+0x196>
mov    0x2d3a(%rip),%rax
mov    (%rax),%rax
mov    0x2d50(%rip),%rcx
cmp    (%rcx),%rax
jne    12b1 <main+0x191>
mov    -0x18(%rbp),%rsi
lea    0xdfd(%rip),%rdi
call   1030 <printf@plt>
jmp    12b6 <main+0x196>
jmp    12bb <main+0x19b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x8(%rsi),%rbx
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <access@plt>
test   %eax,%eax
je     115c <main+0x3c>
mov    0x2e87(%rip),%rax
mov    (%rax),%rax
mov    0x2e65(%rip),%rcx
cmp    (%rcx),%rax
jne    11cc <main+0xac>
lea    0xeb5(%rip),%rdi
jmp    11fd <main+0xdd>
lea    0xe9d(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <access@plt>
test   %eax,%eax
lea    0xeb2(%rip),%rax
lea    0xebc(%rip),%rdi
cmove  %rax,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <access@plt>
test   %eax,%eax
je     11e1 <main+0xc1>
mov    0x2e14(%rip),%rax
mov    (%rax),%rax
mov    0x2e1a(%rip),%rcx
cmp    (%rcx),%rax
jne    11ea <main+0xca>
lea    0xeb7(%rip),%rdi
jmp    11fd <main+0xdd>
mov    0x2e05(%rip),%rcx
cmp    (%rcx),%rax
jne    1205 <main+0xe5>
lea    0xe41(%rip),%rdi
jmp    11fd <main+0xdd>
lea    0xe88(%rip),%rdi
jmp    11fd <main+0xdd>
mov    0x2df7(%rip),%rcx
cmp    (%rcx),%rax
jne    1205 <main+0xe5>
lea    0xeac(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@F_OK = global i32 0
@.str = [12 x i8] c"%s exists.\0A\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.1 = [20 x i8] c"%s does not exist.\0A\00"
@EACCES = global i64 0
@.str.2 = [23 x i8] c"%s is not accessible.\0A\00"
@R_OK = global i32 0
@.str.3 = [17 x i8] c"%s is readable.\0A\00"
@.str.4 = [40 x i8] c"%s is not readable, permission denied!\0A\00"
@W_OK = global i32 0
@.str.5 = [17 x i8] c"%s is writable.\0A\00"
@.str.6 = [40 x i8] c"%s is not writable, permission denied!\0A\00"
@EROFS = global i64 0
@.str.7 = [39 x i8] c"%s is not writable, read-only system!\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 i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = load i32, i32* @F_OK
%13 = call i32 @access(i8* %11, i32 %12)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i8*, i8** %6
%18 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %35
19: ; preds = %2
%20 = load i64, i64* @errno
%21 = load i64, i64* @ENOENT
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i8*, i8** %6
%25 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %34
26: ; preds = %19
%27 = load i64, i64* @errno
%28 = load i64, i64* @EACCES
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i8*, i8** %6
%32 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %30, %26
br label %34
34: ; preds = %33, %23
store i32 0, i32* %3
br label %73
35: ; preds = %16
%36 = load i8*, i8** %6
%37 = load i32, i32* @R_OK
%38 = call i32 @access(i8* %36, i32 %37)
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %35
%42 = load i8*, i8** %6
%43 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %42)
br label %47
44: ; preds = %35
%45 = load i8*, i8** %6
%46 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %44, %41
%48 = load i8*, i8** %6
%49 = load i32, i32* @W_OK
%50 = call i32 @access(i8* %48, i32 %49)
store i32 %50, i32* %7
%51 = load i32, i32* %7
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %47
%54 = load i8*, i8** %6
%55 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %54)
br label %72
56: ; preds = %47
%57 = load i64, i64* @errno
%58 = load i64, i64* @EACCES
%59 = icmp eq i64 %57, %58
br i1 %59, label %60, label %63
60: ; preds = %56
%61 = load i8*, i8** %6
%62 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i8* %61)
br label %71
63: ; preds = %56
%64 = load i64, i64* @errno
%65 = load i64, i64* @EROFS
%66 = icmp eq i64 %64, %65
br i1 %66, label %67, label %70
67: ; preds = %63
%68 = load i8*, i8** %6
%69 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i8* %68)
br label %70
70: ; preds = %67, %63
br label %71
71: ; preds = %70, %60
br label %72
72: ; preds = %71, %53
store i32 0, i32* %3
br label %73
73: ; preds = %72, %34
%74 = load i32, i32* %3
ret i32 %74
}

LLVM IR (-O2):
@F_OK = global i32 0
@.str = [12 x i8] c"%s exists.\0A\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.1 = [20 x i8] c"%s does not exist.\0A\00"
@EACCES = global i64 0
@.str.2 = [23 x i8] c"%s is not accessible.\0A\00"
@R_OK = global i32 0
@.str.3 = [17 x i8] c"%s is readable.\0A\00"
@.str.4 = [40 x i8] c"%s is not readable, permission denied!\0A\00"
@W_OK = global i32 0
@.str.5 = [17 x i8] c"%s is writable.\0A\00"
@.str.6 = [40 x i8] c"%s is not writable, permission denied!\0A\00"
@EROFS = global i64 0
@.str.7 = [39 x i8] c"%s is not writable, read-only system!\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = load i32, i32* @F_OK
%6 = tail call i32 @access(i8* %4, i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %2
%9 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %4)
%10 = load i32, i32* @R_OK
%11 = tail call i32 @access(i8* %4, i32 %10)
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0)
%14 = tail call i32 @printf(i8* %13, i8* %4)
%15 = load i32, i32* @W_OK
%16 = tail call i32 @access(i8* %4, i32 %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %32, label %25
18: ; preds = %2
%19 = load i64, i64* @errno
%20 = load i64, i64* @ENOENT
%21 = icmp eq i64 %19, %20
br i1 %21, label %32, label %22
22: ; preds = %18
%23 = load i64, i64* @EACCES
%24 = icmp eq i64 %19, %23
br i1 %24, label %32, label %35
25: ; preds = %8
%26 = load i64, i64* @errno
%27 = load i64, i64* @EACCES
%28 = icmp eq i64 %26, %27
br i1 %28, label %32, label %29
29: ; preds = %25
%30 = load i64, i64* @EROFS
%31 = icmp eq i64 %26, %30
br i1 %31, label %32, label %35
32: ; preds = %29, %25, %8, %22, %18
%33 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), %18 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), %22 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), %8 ], [ getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), %25 ], [ getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), %29 ]
%34 = tail call i32 @printf(i8* %33, i8* %4)
br label %35
35: ; preds = %32, %29, %22
ret i32 0
}