#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*/ exit(int);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  char *path = argv[1];
  int rval;
  if (argc != 2) {
    printf("Usage: %s <file>\n", argv[0]);
    exit(1);
  }
  rval = access(path, F_OK);
  if (rval == 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;
  }
  rval = access(path, R_OK);
  if (rval == 0) {
    printf("%s is readable\n", path);
  } else {
    printf("%s is not readable (access denied)\n", path);
  }
  rval = access(path, W_OK);
  if (rval == 0) {
    printf("%s is writeable\n", path);
  } else if (errno == EACCES) {
    printf("%s is not writable (access denied)\n", path);
  } else if (errno == EROFS) {
    printf("%s is not writable (read-only filssytem)\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)
cmpl   $0x2,-0x8(%rbp)
je     1179 <main+0x49>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe96(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11ad <main+0x7d>
mov    -0x18(%rbp),%rsi
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
jmp    1217 <main+0xe7>
mov    0x2e14(%rip),%rax
mov    (%rax),%rax
mov    0x2df2(%rip),%rcx
cmp    (%rcx),%rax
jne    11dc <main+0xac>
mov    -0x18(%rbp),%rsi
lea    0xe4b(%rip),%rdi
call   1030 <printf@plt>
jmp    120b <main+0xdb>
mov    0x2de5(%rip),%rax
mov    (%rax),%rax
mov    0x2deb(%rip),%rcx
cmp    (%rcx),%rax
jne    1206 <main+0xd6>
mov    -0x18(%rbp),%rsi
lea    0xe2f(%rip),%rdi
call   1030 <printf@plt>
jmp    120b <main+0xdb>
movl   $0x0,-0x4(%rbp)
jmp    12f9 <main+0x1c9>
mov    -0x18(%rbp),%rdi
mov    0x2d9e(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    124b <main+0x11b>
mov    -0x18(%rbp),%rsi
lea    0xe05(%rip),%rdi
call   1030 <printf@plt>
jmp    125b <main+0x12b>
mov    -0x18(%rbp),%rsi
lea    0xe00(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d7a(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    128f <main+0x15f>
mov    -0x18(%rbp),%rsi
lea    0xdf5(%rip),%rdi
call   1030 <printf@plt>
jmp    12f2 <main+0x1c2>
mov    0x2d32(%rip),%rax
mov    (%rax),%rax
mov    0x2d38(%rip),%rcx
cmp    (%rcx),%rax
jne    12be <main+0x18e>
mov    -0x18(%rbp),%rsi
lea    0xdd7(%rip),%rdi
call   1030 <printf@plt>
jmp    12ed <main+0x1bd>
mov    0x2d03(%rip),%rax
mov    (%rax),%rax
mov    0x2d19(%rip),%rcx
cmp    (%rcx),%rax
jne    12e8 <main+0x1b8>
mov    -0x18(%rbp),%rsi
lea    0xdcc(%rip),%rdi
call   1030 <printf@plt>
jmp    12ed <main+0x1bd>
jmp    12f2 <main+0x1c2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jne    1222 <main+0xf2>
mov    0x8(%rsi),%rbx
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <access@plt>
test   %eax,%eax
je     1175 <main+0x45>
mov    0x2e6e(%rip),%rax
mov    (%rax),%rax
mov    0x2e4c(%rip),%rcx
cmp    (%rcx),%rax
jne    11e5 <main+0xb5>
lea    0xead(%rip),%rdi
jmp    1216 <main+0xe6>
lea    0xe96(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <access@plt>
test   %eax,%eax
lea    0xea8(%rip),%rax
lea    0xeb1(%rip),%rdi
cmove  %rax,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <access@plt>
test   %eax,%eax
je     11fa <main+0xca>
mov    0x2dfb(%rip),%rax
mov    (%rax),%rax
mov    0x2e01(%rip),%rcx
cmp    (%rcx),%rax
jne    1203 <main+0xd3>
lea    0xea8(%rip),%rdi
jmp    1216 <main+0xe6>
mov    0x2dec(%rip),%rcx
cmp    (%rcx),%rax
jne    121e <main+0xee>
lea    0xe38(%rip),%rdi
jmp    1216 <main+0xe6>
lea    0xe79(%rip),%rdi
jmp    1216 <main+0xe6>
mov    0x2dde(%rip),%rcx
cmp    (%rcx),%rax
jne    121e <main+0xee>
lea    0xe99(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    (%rsi),%rsi
lea    0xdd4(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

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

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