#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*/ F_OK;
int /*<<< orphan*/ R_OK;
int /*<<< orphan*/ W_OK;
int /*<<< orphan*/ X_OK;
int access(char *, int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ printf(char *, ...);
int main() {
  char *files[] = {"/readable", "/writeable", "/allaccess", "/forbidden",
                   "/nonexistent"};
  for (int i = 0; i < sizeof files / sizeof files[0]; i++) {
    printf("F_OK(%s): %d\n", files[i], access(files[i], F_OK));
    printf("errno: %d\n", errno);
    errno = 0;
    printf("R_OK(%s): %d\n", files[i], access(files[i], R_OK));
    printf("errno: %d\n", errno);
    errno = 0;
    printf("X_OK(%s): %d\n", files[i], access(files[i], X_OK));
    printf("errno: %d\n", errno);
    errno = 0;
    printf("W_OK(%s): %d\n", files[i], access(files[i], W_OK));
    printf("errno: %d\n", errno);
    errno = 0;
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
lea    0xeaa(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xea9(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xea9(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xea9(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xea9(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmp    $0x5,%rax
jae    1327 <main+0x1f7>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rax
mov    %rax,-0x58(%rbp)
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdi
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2ddf(%rip),%rax
movl   $0x0,(%rax)
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rax
mov    %rax,-0x50(%rbp)
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdi
mov    0x2db4(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d83(%rip),%rax
movl   $0x0,(%rax)
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rax
mov    %rax,-0x48(%rbp)
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdi
mov    0x2d70(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d3e(%rip),%rax
mov    (%rax),%esi
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d27(%rip),%rax
movl   $0x0,(%rax)
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rax
mov    %rax,-0x40(%rbp)
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdi
mov    0x2d1c(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
lea    0xd8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2ce2(%rip),%rax
mov    (%rax),%esi
lea    0xd4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2ccb(%rip),%rax
movl   $0x0,(%rax)
lea    0xd32(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    118d <main+0x5d>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xebb(%rip),%rbp
mov    %rbp,(%rsp)
lea    0xeba(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xeb9(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xeb8(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xeb7(%rip),%rax
mov    %rax,0x20(%rsp)
mov    0x2e50(%rip),%r14
lea    0xebf(%rip),%rbx
lea    0xed1(%rip),%r12
lea    0xed8(%rip),%r13
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1050 <access@plt>
lea    0xe80(%rip),%rdi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r14),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x0,(%r14)
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1050 <access@plt>
lea    0xe61(%rip),%rdi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r14),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x0,(%r14)
mov    0x2dc9(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1050 <access@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r14),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x0,(%r14)
mov    0x2d9d(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1050 <access@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r14),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x0,(%r14)
mov    $0xa,%edi
call   1030 <putchar@plt>
cmp    $0x4,%r15
je     1296 <main+0x166>
mov    0x8(%rsp,%r15,8),%rbp
add    $0x1,%r15
jmp    11a0 <main+0x70>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/readable\00"
@.str.1 = [11 x i8] c"/writeable\00"
@.str.2 = [11 x i8] c"/allaccess\00"
@.str.3 = [11 x i8] c"/forbidden\00"
@.str.4 = [13 x i8] c"/nonexistent\00"
@.str.5 = [14 x i8] c"F_OK(%s): %d\0A\00"
@F_OK = global i32 0
@.str.6 = [11 x i8] c"errno: %d\0A\00"
@errno = global i32 0
@.str.7 = [14 x i8] c"R_OK(%s): %d\0A\00"
@R_OK = global i32 0
@.str.8 = [14 x i8] c"X_OK(%s): %d\0A\00"
@X_OK = global i32 0
@.str.9 = [14 x i8] c"W_OK(%s): %d\0A\00"
@W_OK = global i32 0
@.str.10 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [5 x i8*]
%3 = alloca i32
store i32 0, i32* %1
%4 = bitcast [5 x i8*]* %2 to i8*
%5 = bitcast i8* %4 to [5 x i8*]*
%6 = getelementptr inbounds [5 x i8*], [5 x i8*]* %5, i32 0, i32 0
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i8** %6
%7 = getelementptr inbounds [5 x i8*], [5 x i8*]* %5, i32 0, i32 1
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i32 0, i32 0), i8** %7
%8 = getelementptr inbounds [5 x i8*], [5 x i8*]* %5, i32 0, i32 2
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i32 0, i32 0), i8** %8
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %5, i32 0, i32 3
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i32 0, i32 0), i8** %9
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* %5, i32 0, i32 4
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i32 0, i32 0), i8** %10
store i32 0, i32* %3
br label %11
11: ; preds = %69, %0
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = icmp ult i64 %13, 5
br i1 %14, label %15, label %72
15: ; preds = %11
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 %17
%19 = load i8*, i8** %18
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 %21
%23 = load i8*, i8** %22
%24 = load i32, i32* @F_OK
%25 = call i32 @access(i8* %23, i32 %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %19, i32 %25)
%27 = load i32, i32* @errno
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %27)
store i32 0, i32* @errno
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 %30
%32 = load i8*, i8** %31
%33 = load i32, i32* %3
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 %34
%36 = load i8*, i8** %35
%37 = load i32, i32* @R_OK
%38 = call i32 @access(i8* %36, i32 %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %32, i32 %38)
%40 = load i32, i32* @errno
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %40)
store i32 0, i32* @errno
%42 = load i32, i32* %3
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 %43
%45 = load i8*, i8** %44
%46 = load i32, i32* %3
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 %47
%49 = load i8*, i8** %48
%50 = load i32, i32* @X_OK
%51 = call i32 @access(i8* %49, i32 %50)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8* %45, i32 %51)
%53 = load i32, i32* @errno
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %53)
store i32 0, i32* @errno
%55 = load i32, i32* %3
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 %56
%58 = load i8*, i8** %57
%59 = load i32, i32* %3
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 %60
%62 = load i8*, i8** %61
%63 = load i32, i32* @W_OK
%64 = call i32 @access(i8* %62, i32 %63)
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), i8* %58, i32 %64)
%66 = load i32, i32* @errno
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %66)
store i32 0, i32* @errno
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
br label %69
69: ; preds = %15
%70 = load i32, i32* %3
%71 = add nsw i32 %70, 1
store i32 %71, i32* %3
br label %11
72: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"/readable\00"
@.str.1 = [11 x i8] c"/writeable\00"
@.str.2 = [11 x i8] c"/allaccess\00"
@.str.3 = [11 x i8] c"/forbidden\00"
@.str.4 = [13 x i8] c"/nonexistent\00"
@.str.5 = [14 x i8] c"F_OK(%s): %d\0A\00"
@F_OK = global i32 0
@.str.6 = [11 x i8] c"errno: %d\0A\00"
@errno = global i32 0
@.str.7 = [14 x i8] c"R_OK(%s): %d\0A\00"
@R_OK = global i32 0
@.str.8 = [14 x i8] c"X_OK(%s): %d\0A\00"
@X_OK = global i32 0
@.str.9 = [14 x i8] c"W_OK(%s): %d\0A\00"
@W_OK = global i32 0
define i32 @main() {
%1 = alloca [5 x i8*]
%2 = bitcast [5 x i8*]* %1 to i8*
%3 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 0
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %3
%4 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 1
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %4
%5 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 2
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8** %5
%6 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 3
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 4
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8** %7
br label %9
8: ; preds = %9
ret i32 0
9: ; preds = %35, %0
%10 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %0 ], [ %37, %35 ]
%11 = phi i64 [ 0, %0 ], [ %33, %35 ]
%12 = load i32, i32* @F_OK
%13 = tail call i32 @access(i8* %10, i32 %12)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %10, i32 %13)
%15 = load i32, i32* @errno
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %15)
store i32 0, i32* @errno
%17 = load i32, i32* @R_OK
%18 = tail call i32 @access(i8* %10, i32 %17)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %10, i32 %18)
%20 = load i32, i32* @errno
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %20)
store i32 0, i32* @errno
%22 = load i32, i32* @X_OK
%23 = tail call i32 @access(i8* %10, i32 %22)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8* %10, i32 %23)
%25 = load i32, i32* @errno
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %25)
store i32 0, i32* @errno
%27 = load i32, i32* @W_OK
%28 = tail call i32 @access(i8* %10, i32 %27)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), i8* %10, i32 %28)
%30 = load i32, i32* @errno
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %30)
store i32 0, i32* @errno
%32 = tail call i32 @putchar(i32 10)
%33 = add nuw nsw i64 %11, 1
%34 = icmp eq i64 %33, 5
br i1 %34, label %8, label %35
35: ; preds = %9
%36 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 %33
%37 = load i8*, i8** %36
br label %9
}