#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__ ENAMETOOLONG;
scalar_t__ ENOENT;
int /*<<< orphan*/ F_OK;
int /*<<< orphan*/ R_OK;
int /*<<< orphan*/ W_OK;
int /*<<< orphan*/ X_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
int access_test(void) {
  printf("Test access F_OK (exists)...");
  if (access("/app/flash/posix", F_OK) < 0) {
    fflush(stdout);
    perror("failed");
    return -1;
  }
  printf("passed\n");
  printf("Test access F_OK (doesn't exist)...");
  if (access("/nomount/some/file", F_OK) == 0) {
    printf("failed (should have indicated an error)\n");
    return -1;
  }
  if (errno != ENOENT) {
    printf("failed (errno should be ENOENT not %d)\n", errno);
    return -1;
  }
  printf("passed\n");
  printf("Test access ENAMETOOLONG (name)...");
  if (access("/0123456789012345678901234567890123456789012345678901234567890123"
             "456789",
             F_OK) == 0) {
    printf("failed (should have indicated an error)\n");
    return -1;
  }
  if (errno != ENAMETOOLONG) {
    printf("failed (errno should be ENAMETOOLONG not %d)\n", errno);
    return -1;
  }
  printf("passed\n");
  printf("Test access ENAMETOOLONG (path)...");
  if (access("/0123456789/01234567890/123456789/0123/4567890/123456789012345/"
             "67890123/456/789",
             F_OK) == 0) {
    printf("failed (should have indicated an error)\n");
    return -1;
  }
  if (errno != ENAMETOOLONG) {
    printf("failed (errno should be ENAMETOOLONG not %d)\n", errno);
    return -1;
  }
  printf("passed\n");
  printf("Test access W_OK...");
  if (access("/app/flash/posix", W_OK) == 0) {
    printf("failed (should have indicated an error)\n");
    return -1;
  }
  if (errno != EACCES) {
    printf("failed (errno should be EACCES not %d)\n", errno);
    return -1;
  }
  printf("passed\n");
  printf("Test access W_OK (no write)...");
  if (access("/", W_OK) == 0) {
    printf("failed (should have indicated an error)\n");
    return -1;
  }
  if (errno != EACCES) {
    printf("failed (errno should be EACCES not %d)\n", errno);
    return -1;
  }
  printf("passed\n");
  printf("Test access R_OK...");
  if (access("/app/flash/posix", R_OK) < 0) {
    fflush(stdout);
    perror("failed");
    return -1;
  }
  printf("passed\n");
  printf("Test access R_OK (no read)...");
  if (access("/app/.install", R_OK) == 0) {
    printf("failed (should have indicated an error)\n");
    return -1;
  }
  if (errno != EACCES) {
    printf("failed (errno should be EACCES not %d)\n", errno);
    return -1;
  }
  printf("passed\n");
  printf("Test access X_OK...");
  if (access("/app/flash/posix", X_OK) < 0) {
    fflush(stdout);
    perror("failed");
    return -1;
  }
  printf("passed\n");
  printf("Test access X_OK (no exec)...");
  if (access("/app/.install", X_OK) == 0) {
    printf("failed (should have indicated an error)\n");
    return -1;
  }
  if (errno != EACCES) {
    printf("failed (errno should be EACCES not %d)\n", errno);
    return -1;
  }
  printf("passed\n");
  return 0;
}


x86 assembly (clang, -O0):
<access_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
lea    0xeb7(%rip),%rdi
call   1050 <access@plt>
cmp    $0x0,%rax
jge    119b <access_test+0x5b>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
lea    0xea4(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1677 <access_test+0x537>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
lea    0xe9a(%rip),%rdi
call   1050 <access@plt>
cmp    $0x0,%rax
jne    11f0 <access_test+0xb0>
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1677 <access_test+0x537>
mov    0x2dd1(%rip),%rax
mov    (%rax),%rax
mov    0x2d9f(%rip),%rcx
cmp    (%rcx),%rax
je     122e <access_test+0xee>
mov    0x2db7(%rip),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1677 <access_test+0x537>
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%esi
lea    0xe8e(%rip),%rdi
call   1050 <access@plt>
cmp    $0x0,%rax
jne    1283 <access_test+0x143>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1677 <access_test+0x537>
mov    0x2d3e(%rip),%rax
mov    (%rax),%rax
mov    0x2d1c(%rip),%rcx
cmp    (%rcx),%rax
je     12c1 <access_test+0x181>
mov    0x2d24(%rip),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1677 <access_test+0x537>
lea    0xd6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2cb4(%rip),%rax
mov    (%rax),%esi
lea    0xe94(%rip),%rdi
call   1050 <access@plt>
cmp    $0x0,%rax
jne    1316 <access_test+0x1d6>
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1677 <access_test+0x537>
mov    0x2cab(%rip),%rax
mov    (%rax),%rax
mov    0x2c89(%rip),%rcx
cmp    (%rcx),%rax
je     1354 <access_test+0x214>
mov    0x2c91(%rip),%rax
mov    (%rax),%rsi
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1677 <access_test+0x537>
lea    0xcda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2c71(%rip),%rax
mov    (%rax),%esi
lea    0xc9d(%rip),%rdi
call   1050 <access@plt>
cmp    $0x0,%rax
jne    13a9 <access_test+0x269>
lea    0xcde(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1677 <access_test+0x537>
mov    0x2c18(%rip),%rax
mov    (%rax),%rax
mov    0x2c1e(%rip),%rcx
cmp    (%rcx),%rax
je     13e7 <access_test+0x2a7>
mov    0x2bfe(%rip),%rax
mov    (%rax),%rsi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1677 <access_test+0x537>
lea    0xc47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2bde(%rip),%rax
mov    (%rax),%esi
lea    0xe19(%rip),%rdi
call   1050 <access@plt>
cmp    $0x0,%rax
jne    143c <access_test+0x2fc>
lea    0xc4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1677 <access_test+0x537>
mov    0x2b85(%rip),%rax
mov    (%rax),%rax
mov    0x2b8b(%rip),%rcx
cmp    (%rcx),%rax
je     147a <access_test+0x33a>
mov    0x2b6b(%rip),%rax
mov    (%rax),%rsi
lea    0xd7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1677 <access_test+0x537>
lea    0xbb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2b1b(%rip),%rax
mov    (%rax),%esi
lea    0xb77(%rip),%rdi
call   1050 <access@plt>
cmp    $0x0,%rax
jge    14db <access_test+0x39b>
mov    0x2b04(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
lea    0xb64(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1677 <access_test+0x537>
lea    0xb53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2aba(%rip),%rax
mov    (%rax),%esi
lea    0xd59(%rip),%rdi
call   1050 <access@plt>
cmp    $0x0,%rax
jne    1530 <access_test+0x3f0>
lea    0xb57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1677 <access_test+0x537>
mov    0x2a91(%rip),%rax
mov    (%rax),%rax
mov    0x2a97(%rip),%rcx
cmp    (%rcx),%rax
je     156e <access_test+0x42e>
mov    0x2a77(%rip),%rax
mov    (%rax),%rsi
lea    0xc8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1677 <access_test+0x537>
lea    0xac0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xceb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2a4f(%rip),%rax
mov    (%rax),%esi
lea    0xa83(%rip),%rdi
call   1050 <access@plt>
cmp    $0x0,%rax
jge    15cf <access_test+0x48f>
mov    0x2a10(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
lea    0xa70(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1677 <access_test+0x537>
lea    0xa5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xc9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x29ee(%rip),%rax
mov    (%rax),%esi
lea    0xc65(%rip),%rdi
call   1050 <access@plt>
cmp    $0x0,%rax
jne    1624 <access_test+0x4e4>
lea    0xa63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1677 <access_test+0x537>
mov    0x299d(%rip),%rax
mov    (%rax),%rax
mov    0x29a3(%rip),%rcx
cmp    (%rcx),%rax
je     1662 <access_test+0x522>
mov    0x2983(%rip),%rax
mov    (%rax),%rsi
lea    0xb96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1677 <access_test+0x537>
lea    0x9cc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<access_test>:
push   %r15
push   %r14
push   %rbx
lea    0xea4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e2e(%rip),%rbx
mov    (%rbx),%esi
lea    0xeaa(%rip),%rdi
call   1060 <access@plt>
test   %rax,%rax
js     13f3 <access_test+0x2a3>
lea    0x10e7(%rip),%rdi
call   1030 <puts@plt>
lea    0xea1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%esi
lea    0xeb5(%rip),%rdi
call   1060 <access@plt>
test   %rax,%rax
je     13c3 <access_test+0x273>
mov    0x2e0f(%rip),%r15
mov    (%r15),%rsi
mov    0x2ddd(%rip),%rax
cmp    (%rax),%rsi
jne    13d1 <access_test+0x281>
lea    0x109c(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%esi
lea    0xec8(%rip),%rdi
call   1060 <access@plt>
test   %rax,%rax
je     13c3 <access_test+0x273>
mov    (%r15),%rsi
mov    0x2da9(%rip),%r14
cmp    (%r14),%rsi
jne    13da <access_test+0x28a>
lea    0x1058(%rip),%rdi
call   1030 <puts@plt>
lea    0xf0a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%esi
lea    0xf1d(%rip),%rdi
call   1060 <access@plt>
test   %rax,%rax
je     13c3 <access_test+0x273>
mov    (%r15),%rsi
cmp    (%r14),%rsi
jne    13da <access_test+0x28a>
lea    0x101b(%rip),%rdi
call   1030 <puts@plt>
lea    0xf40(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2d7a(%rip),%rbx
mov    (%rbx),%esi
lea    0xda6(%rip),%rdi
call   1060 <access@plt>
test   %rax,%rax
je     13c3 <access_test+0x273>
mov    (%r15),%rsi
mov    0x2d49(%rip),%r14
cmp    (%r14),%rsi
jne    140f <access_test+0x2bf>
lea    0xfd0(%rip),%rdi
call   1030 <puts@plt>
lea    0xf31(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%esi
lea    0xf40(%rip),%rdi
call   1060 <access@plt>
test   %rax,%rax
je     13c3 <access_test+0x273>
mov    (%r15),%rsi
cmp    (%r14),%rsi
jne    140f <access_test+0x2bf>
lea    0xf93(%rip),%rdi
call   1030 <puts@plt>
lea    0xf15(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2cc2(%rip),%rbx
mov    (%rbx),%esi
lea    0xd1e(%rip),%rdi
call   1060 <access@plt>
test   %rax,%rax
js     13f3 <access_test+0x2a3>
lea    0xf5b(%rip),%rdi
call   1030 <puts@plt>
lea    0xef1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%esi
lea    0xeff(%rip),%rdi
call   1060 <access@plt>
test   %rax,%rax
je     13c3 <access_test+0x273>
mov    (%r15),%rsi
cmp    (%r14),%rsi
jne    140f <access_test+0x2bf>
lea    0xf1e(%rip),%rdi
call   1030 <puts@plt>
lea    0xee0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2c75(%rip),%rbx
mov    (%rbx),%esi
lea    0xca9(%rip),%rdi
call   1060 <access@plt>
test   %rax,%rax
js     13f3 <access_test+0x2a3>
lea    0xeea(%rip),%rdi
call   1030 <puts@plt>
lea    0xec0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%esi
lea    0xe8e(%rip),%rdi
call   1060 <access@plt>
test   %rax,%rax
je     13c3 <access_test+0x273>
mov    (%r15),%rsi
cmp    (%r14),%rsi
jne    140f <access_test+0x2bf>
lea    0xeb5(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    13ed <access_test+0x29d>
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
jmp    13e8 <access_test+0x298>
lea    0xc94(%rip),%rdi
jmp    13e1 <access_test+0x291>
lea    0xd1e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2bc6(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
lea    0xc26(%rip),%rdi
call   1070 <perror@plt>
jmp    13e8 <access_test+0x298>
lea    0xd9e(%rip),%rdi
jmp    13e1 <access_test+0x291>

LLVM IR (-O0):
@.str = [29 x i8] c"Test access F_OK (exists)...\00"
@.str.1 = [17 x i8] c"/app/flash/posix\00"
@F_OK = global i32 0
@stdout = global i32 0
@.str.2 = [7 x i8] c"failed\00"
@.str.3 = [8 x i8] c"passed\0A\00"
@.str.4 = [36 x i8] c"Test access F_OK (doesn't exist)...\00"
@.str.5 = [19 x i8] c"/nomount/some/file\00"
@.str.6 = [41 x i8] c"failed (should have indicated an error)\0A\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.7 = [40 x i8] c"failed (errno should be ENOENT not %d)\0A\00"
@.str.8 = [35 x i8] c"Test access ENAMETOOLONG (name)...\00"
@.str.9 = [72 x i8] c"/0123456789012345678901234567890123456789012345678901234567890123456789\00"
@ENAMETOOLONG = global i64 0
@.str.10 = [46 x i8] c"failed (errno should be ENAMETOOLONG not %d)\0A\00"
@.str.11 = [35 x i8] c"Test access ENAMETOOLONG (path)...\00"
@.str.12 = [80 x i8] c"/0123456789/01234567890/123456789/0123/4567890/123456789012345/67890123/456/789\00"
@.str.13 = [20 x i8] c"Test access W_OK...\00"
@W_OK = global i32 0
@EACCES = global i64 0
@.str.14 = [40 x i8] c"failed (errno should be EACCES not %d)\0A\00"
@.str.15 = [31 x i8] c"Test access W_OK (no write)...\00"
@.str.16 = [2 x i8] c"/\00"
@.str.17 = [20 x i8] c"Test access R_OK...\00"
@R_OK = global i32 0
@.str.18 = [30 x i8] c"Test access R_OK (no read)...\00"
@.str.19 = [14 x i8] c"/app/.install\00"
@.str.20 = [20 x i8] c"Test access X_OK...\00"
@X_OK = global i32 0
@.str.21 = [30 x i8] c"Test access X_OK (no exec)...\00"
define i32 @access_test() {
%1 = alloca i32
%2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%3 = load i32, i32* @F_OK
%4 = call i64 @access(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i32, i32* @stdout
%8 = call i32 @fflush(i32 %7)
%9 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %137
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%13 = load i32, i32* @F_OK
%14 = call i64 @access(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %1
br label %137
18: ; preds = %10
%19 = load i64, i64* @errno
%20 = load i64, i64* @ENOENT
%21 = icmp ne i64 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i64, i64* @errno
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), i64 %23)
store i32 -1, i32* %1
br label %137
25: ; preds = %18
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0))
%28 = load i32, i32* @F_OK
%29 = call i64 @access(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.9, i64 0, i64 0), i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %1
br label %137
33: ; preds = %25
%34 = load i64, i64* @errno
%35 = load i64, i64* @ENAMETOOLONG
%36 = icmp ne i64 %34, %35
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = load i64, i64* @errno
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.10, i64 0, i64 0), i64 %38)
store i32 -1, i32* %1
br label %137
40: ; preds = %33
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0))
%43 = load i32, i32* @F_OK
%44 = call i64 @access(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.12, i64 0, i64 0), i32 %43)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %40
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %1
br label %137
48: ; preds = %40
%49 = load i64, i64* @errno
%50 = load i64, i64* @ENAMETOOLONG
%51 = icmp ne i64 %49, %50
br i1 %51, label %52, label %55
52: ; preds = %48
%53 = load i64, i64* @errno
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.10, i64 0, i64 0), i64 %53)
store i32 -1, i32* %1
br label %137
55: ; preds = %48
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.13, i64 0, i64 0))
%58 = load i32, i32* @W_OK
%59 = call i64 @access(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %58)
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %55
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %1
br label %137
63: ; preds = %55
%64 = load i64, i64* @errno
%65 = load i64, i64* @EACCES
%66 = icmp ne i64 %64, %65
br i1 %66, label %67, label %70
67: ; preds = %63
%68 = load i64, i64* @errno
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.14, i64 0, i64 0), i64 %68)
store i32 -1, i32* %1
br label %137
70: ; preds = %63
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.15, i64 0, i64 0))
%73 = load i32, i32* @W_OK
%74 = call i64 @access(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.16, i64 0, i64 0), i32 %73)
%75 = icmp eq i64 %74, 0
br i1 %75, label %76, label %78
76: ; preds = %70
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %1
br label %137
78: ; preds = %70
%79 = load i64, i64* @errno
%80 = load i64, i64* @EACCES
%81 = icmp ne i64 %79, %80
br i1 %81, label %82, label %85
82: ; preds = %78
%83 = load i64, i64* @errno
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.14, i64 0, i64 0), i64 %83)
store i32 -1, i32* %1
br label %137
85: ; preds = %78
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.17, i64 0, i64 0))
%88 = load i32, i32* @R_OK
%89 = call i64 @access(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %88)
%90 = icmp slt i64 %89, 0
br i1 %90, label %91, label %95
91: ; preds = %85
%92 = load i32, i32* @stdout
%93 = call i32 @fflush(i32 %92)
%94 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %137
95: ; preds = %85
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.18, i64 0, i64 0))
%98 = load i32, i32* @R_OK
%99 = call i64 @access(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.19, i64 0, i64 0), i32 %98)
%100 = icmp eq i64 %99, 0
br i1 %100, label %101, label %103
101: ; preds = %95
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %1
br label %137
103: ; preds = %95
%104 = load i64, i64* @errno
%105 = load i64, i64* @EACCES
%106 = icmp ne i64 %104, %105
br i1 %106, label %107, label %110
107: ; preds = %103
%108 = load i64, i64* @errno
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.14, i64 0, i64 0), i64 %108)
store i32 -1, i32* %1
br label %137
110: ; preds = %103
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.20, i64 0, i64 0))
%113 = load i32, i32* @X_OK
%114 = call i64 @access(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %113)
%115 = icmp slt i64 %114, 0
br i1 %115, label %116, label %120
116: ; preds = %110
%117 = load i32, i32* @stdout
%118 = call i32 @fflush(i32 %117)
%119 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %137
120: ; preds = %110
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.21, i64 0, i64 0))
%123 = load i32, i32* @X_OK
%124 = call i64 @access(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.19, i64 0, i64 0), i32 %123)
%125 = icmp eq i64 %124, 0
br i1 %125, label %126, label %128
126: ; preds = %120
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %1
br label %137
128: ; preds = %120
%129 = load i64, i64* @errno
%130 = load i64, i64* @EACCES
%131 = icmp ne i64 %129, %130
br i1 %131, label %132, label %135
132: ; preds = %128
%133 = load i64, i64* @errno
%134 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.14, i64 0, i64 0), i64 %133)
store i32 -1, i32* %1
br label %137
135: ; preds = %128
%136 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %137
137: ; preds = %135, %132, %126, %116, %107, %101, %91, %82, %76, %67, %61, %52, %46, %37, %31, %22, %16, %6
%138 = load i32, i32* %1
ret i32 %138
}

LLVM IR (-O2):
@.str = [29 x i8] c"Test access F_OK (exists)...\00"
@.str.1 = [17 x i8] c"/app/flash/posix\00"
@F_OK = global i32 0
@stdout = global i32 0
@.str.2 = [7 x i8] c"failed\00"
@.str.4 = [36 x i8] c"Test access F_OK (doesn't exist)...\00"
@.str.5 = [19 x i8] c"/nomount/some/file\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.7 = [40 x i8] c"failed (errno should be ENOENT not %d)\0A\00"
@.str.8 = [35 x i8] c"Test access ENAMETOOLONG (name)...\00"
@.str.9 = [72 x i8] c"/0123456789012345678901234567890123456789012345678901234567890123456789\00"
@ENAMETOOLONG = global i64 0
@.str.10 = [46 x i8] c"failed (errno should be ENAMETOOLONG not %d)\0A\00"
@.str.11 = [35 x i8] c"Test access ENAMETOOLONG (path)...\00"
@.str.12 = [80 x i8] c"/0123456789/01234567890/123456789/0123/4567890/123456789012345/67890123/456/789\00"
@.str.13 = [20 x i8] c"Test access W_OK...\00"
@W_OK = global i32 0
@EACCES = global i64 0
@.str.14 = [40 x i8] c"failed (errno should be EACCES not %d)\0A\00"
@.str.15 = [31 x i8] c"Test access W_OK (no write)...\00"
@.str.16 = [2 x i8] c"/\00"
@.str.17 = [20 x i8] c"Test access R_OK...\00"
@R_OK = global i32 0
@.str.18 = [30 x i8] c"Test access R_OK (no read)...\00"
@.str.19 = [14 x i8] c"/app/.install\00"
@.str.20 = [20 x i8] c"Test access X_OK...\00"
@X_OK = global i32 0
@.str.21 = [30 x i8] c"Test access X_OK (no exec)...\00"
@str.30 = [7 x i8] c"passed\00"
@str.37 = [40 x i8] c"failed (should have indicated an error)\00"
define i32 @access_test() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%2 = load i32, i32* @F_OK
%3 = tail call i64 @access(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = load i32, i32* @stdout
%7 = tail call i32 @fflush(i32 %6)
%8 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %129
9: ; preds = %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.30, i64 0, i64 0))
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%12 = load i32, i32* @F_OK
%13 = tail call i64 @access(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.37, i64 0, i64 0))
br label %129
17: ; preds = %9
%18 = load i64, i64* @errno
%19 = load i64, i64* @ENOENT
%20 = icmp eq i64 %18, %19
br i1 %20, label %23, label %21
21: ; preds = %17
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), i64 %18)
br label %129
23: ; preds = %17
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.30, i64 0, i64 0))
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0))
%26 = load i32, i32* @F_OK
%27 = tail call i64 @access(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.9, i64 0, i64 0), i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.37, i64 0, i64 0))
br label %129
31: ; preds = %23
%32 = load i64, i64* @errno
%33 = load i64, i64* @ENAMETOOLONG
%34 = icmp eq i64 %32, %33
br i1 %34, label %37, label %35
35: ; preds = %31
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.10, i64 0, i64 0), i64 %32)
br label %129
37: ; preds = %31
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.30, i64 0, i64 0))
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0))
%40 = load i32, i32* @F_OK
%41 = tail call i64 @access(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.12, i64 0, i64 0), i32 %40)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.37, i64 0, i64 0))
br label %129
45: ; preds = %37
%46 = load i64, i64* @errno
%47 = load i64, i64* @ENAMETOOLONG
%48 = icmp eq i64 %46, %47
br i1 %48, label %51, label %49
49: ; preds = %45
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.10, i64 0, i64 0), i64 %46)
br label %129
51: ; preds = %45
%52 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.30, i64 0, i64 0))
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.13, i64 0, i64 0))
%54 = load i32, i32* @W_OK
%55 = tail call i64 @access(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %54)
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %51
%58 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.37, i64 0, i64 0))
br label %129
59: ; preds = %51
%60 = load i64, i64* @errno
%61 = load i64, i64* @EACCES
%62 = icmp eq i64 %60, %61
br i1 %62, label %65, label %63
63: ; preds = %59
%64 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.14, i64 0, i64 0), i64 %60)
br label %129
65: ; preds = %59
%66 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.30, i64 0, i64 0))
%67 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.15, i64 0, i64 0))
%68 = load i32, i32* @W_OK
%69 = tail call i64 @access(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.16, i64 0, i64 0), i32 %68)
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %65
%72 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.37, i64 0, i64 0))
br label %129
73: ; preds = %65
%74 = load i64, i64* @errno
%75 = load i64, i64* @EACCES
%76 = icmp eq i64 %74, %75
br i1 %76, label %79, label %77
77: ; preds = %73
%78 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.14, i64 0, i64 0), i64 %74)
br label %129
79: ; preds = %73
%80 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.30, i64 0, i64 0))
%81 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.17, i64 0, i64 0))
%82 = load i32, i32* @R_OK
%83 = tail call i64 @access(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %82)
%84 = icmp slt i64 %83, 0
br i1 %84, label %85, label %89
85: ; preds = %79
%86 = load i32, i32* @stdout
%87 = tail call i32 @fflush(i32 %86)
%88 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %129
89: ; preds = %79
%90 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.30, i64 0, i64 0))
%91 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.18, i64 0, i64 0))
%92 = load i32, i32* @R_OK
%93 = tail call i64 @access(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.19, i64 0, i64 0), i32 %92)
%94 = icmp eq i64 %93, 0
br i1 %94, label %95, label %97
95: ; preds = %89
%96 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.37, i64 0, i64 0))
br label %129
97: ; preds = %89
%98 = load i64, i64* @errno
%99 = load i64, i64* @EACCES
%100 = icmp eq i64 %98, %99
br i1 %100, label %103, label %101
101: ; preds = %97
%102 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.14, i64 0, i64 0), i64 %98)
br label %129
103: ; preds = %97
%104 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.30, i64 0, i64 0))
%105 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.20, i64 0, i64 0))
%106 = load i32, i32* @X_OK
%107 = tail call i64 @access(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %106)
%108 = icmp slt i64 %107, 0
br i1 %108, label %109, label %113
109: ; preds = %103
%110 = load i32, i32* @stdout
%111 = tail call i32 @fflush(i32 %110)
%112 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %129
113: ; preds = %103
%114 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.30, i64 0, i64 0))
%115 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.21, i64 0, i64 0))
%116 = load i32, i32* @X_OK
%117 = tail call i64 @access(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.19, i64 0, i64 0), i32 %116)
%118 = icmp eq i64 %117, 0
br i1 %118, label %119, label %121
119: ; preds = %113
%120 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.37, i64 0, i64 0))
br label %129
121: ; preds = %113
%122 = load i64, i64* @errno
%123 = load i64, i64* @EACCES
%124 = icmp eq i64 %122, %123
br i1 %124, label %127, label %125
125: ; preds = %121
%126 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.14, i64 0, i64 0), i64 %122)
br label %129
127: ; preds = %121
%128 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.30, i64 0, i64 0))
br label %129
129: ; preds = %127, %125, %119, %109, %101, %95, %85, %77, %71, %63, %57, %49, %43, %35, %29, %21, %15, %5
%130 = phi i32 [ -1, %5 ], [ -1, %15 ], [ -1, %21 ], [ -1, %29 ], [ -1, %35 ], [ -1, %43 ], [ -1, %49 ], [ -1, %57 ], [ -1, %63 ], [ -1, %71 ], [ -1, %77 ], [ -1, %85 ], [ -1, %95 ], [ -1, %101 ], [ -1, %109 ], [ -1, %119 ], [ -1, %125 ], [ 0, %127 ]
ret i32 %130
}