#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EACCES;
scalar_t__ EINVAL;
scalar_t__ ENOENT;
int F_OK;
int R_OK;
int S_IRUSR;
int S_IWUSR;
int S_IXUSR;
int W_OK;
int X_OK;
int access(char const *, int);
int /*<<< orphan*/ assert(int);
int chmod(char const *, int);
scalar_t__ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ remove(char const *);
int main() {
  int ret = 0;
  if ((ret = access("", F_OK)) != -1) {
    assert(ret == 0);
    return 1;
  }
  assert(errno == ENOENT);
  if ((ret = access("this file should not exist", F_OK)) != -1) {
    assert(ret == 0);
    return 2;
  }
  assert(errno == ENOENT);
  const char *test_filename = "sulong_access_test_file";
  FILE *test_file = fopen(test_filename, "w");
  if (!test_file) {
    return 3;
  }
  fclose(test_file);
  if ((ret = access(test_filename, (R_OK | W_OK | X_OK) + 1)) != -1) {
    assert(ret == 0);
    return 4;
  }
  assert(errno == EINVAL);
  if (chmod(test_filename, S_IRUSR) == -1) {
    return 5;
  }
  if ((ret = access(test_filename, R_OK)) == -1) {
    assert(errno == EACCES);
    return 6;
  }
  assert(ret == 0);
  if ((ret = access(test_filename, R_OK | W_OK)) != -1) {
    assert(ret == 0);
    return 7;
  }
  assert(errno == EACCES);
  if ((ret = access(test_filename, X_OK)) != -1) {
    assert(ret == 0);
    return 8;
  }
  assert(errno == EACCES);
  if (chmod(test_filename, S_IRUSR | S_IWUSR) == -1) {
    return 9;
  }
  if ((ret = access(test_filename, R_OK | W_OK)) == -1) {
    assert(errno == EACCES);
    return 10;
  }
  assert(ret == 0);
  if ((ret = access(test_filename, F_OK)) == -1) {
    assert(errno == EACCES);
    return 11;
  }
  assert(ret == 0);
  if (chmod(test_filename, S_IXUSR) == -1) {
    return 12;
  }
  if ((ret = access(test_filename, R_OK | W_OK)) != -1) {
    assert(ret == 0);
    return 13;
  }
  assert(errno == EACCES);
  (void)remove(test_filename);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
lea    0xeac(%rip),%rdi
call   1070 <access@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
je     11b4 <main+0x54>
cmpl   $0x0,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movl   $0x1,-0x4(%rbp)
jmp    15b5 <main+0x455>
mov    0x2dfd(%rip),%rax
mov    (%rax),%rax
mov    0x2dcb(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
lea    0xe1b(%rip),%rdi
call   1070 <access@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
je     1213 <main+0xb3>
cmpl   $0x0,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movl   $0x2,-0x4(%rbp)
jmp    15b5 <main+0x455>
mov    0x2d9e(%rip),%rax
mov    (%rax),%rax
mov    0x2d6c(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xde0(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xde9(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    126a <main+0x10a>
movl   $0x3,-0x4(%rbp)
jmp    15b5 <main+0x455>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rdi
mov    0x2d22(%rip),%rax
mov    (%rax),%esi
mov    0x2d59(%rip),%rax
or     (%rax),%esi
mov    0x2d40(%rip),%rax
or     (%rax),%esi
add    $0x1,%esi
call   1070 <access@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
je     12c3 <main+0x163>
cmpl   $0x0,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movl   $0x4,-0x4(%rbp)
jmp    15b5 <main+0x455>
mov    0x2cee(%rip),%rax
mov    (%rax),%rax
mov    0x2cd4(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    0x2cc1(%rip),%rax
mov    (%rax),%esi
call   1060 <chmod@plt>
cmp    $0xffffffff,%eax
jne    130b <main+0x1ab>
movl   $0x5,-0x4(%rbp)
jmp    15b5 <main+0x455>
mov    -0x10(%rbp),%rdi
mov    0x2c8a(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    1356 <main+0x1f6>
mov    0x2c88(%rip),%rax
mov    (%rax),%rax
mov    0x2c8e(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movl   $0x6,-0x4(%rbp)
jmp    15b5 <main+0x455>
cmpl   $0x0,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    0x2c2e(%rip),%rax
mov    (%rax),%esi
mov    0x2c65(%rip),%rax
or     (%rax),%esi
call   1070 <access@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
je     13ab <main+0x24b>
cmpl   $0x0,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movl   $0x7,-0x4(%rbp)
jmp    15b5 <main+0x455>
mov    0x2c06(%rip),%rax
mov    (%rax),%rax
mov    0x2c0c(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    0x2bf9(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
je     1407 <main+0x2a7>
cmpl   $0x0,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movl   $0x8,-0x4(%rbp)
jmp    15b5 <main+0x455>
mov    0x2baa(%rip),%rax
mov    (%rax),%rax
mov    0x2bb0(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    0x2b7d(%rip),%rax
mov    (%rax),%esi
mov    0x2b9c(%rip),%rax
or     (%rax),%esi
call   1060 <chmod@plt>
cmp    $0xffffffff,%eax
jne    1458 <main+0x2f8>
movl   $0x9,-0x4(%rbp)
jmp    15b5 <main+0x455>
mov    -0x10(%rbp),%rdi
mov    0x2b3d(%rip),%rax
mov    (%rax),%esi
mov    0x2b74(%rip),%rax
or     (%rax),%esi
call   1070 <access@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    14ac <main+0x34c>
mov    0x2b32(%rip),%rax
mov    (%rax),%rax
mov    0x2b38(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movl   $0xa,-0x4(%rbp)
jmp    15b5 <main+0x455>
cmpl   $0x0,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    0x2ac0(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    1508 <main+0x3a8>
mov    0x2ad6(%rip),%rax
mov    (%rax),%rax
mov    0x2adc(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movl   $0xb,-0x4(%rbp)
jmp    15b5 <main+0x455>
cmpl   $0x0,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    0x2ac4(%rip),%rax
mov    (%rax),%esi
call   1060 <chmod@plt>
cmp    $0xffffffff,%eax
jne    1540 <main+0x3e0>
movl   $0xc,-0x4(%rbp)
jmp    15b5 <main+0x455>
mov    -0x10(%rbp),%rdi
mov    0x2a55(%rip),%rax
mov    (%rax),%esi
mov    0x2a8c(%rip),%rax
or     (%rax),%esi
call   1070 <access@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
je     1584 <main+0x424>
cmpl   $0x0,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movl   $0xd,-0x4(%rbp)
jmp    15b5 <main+0x455>
mov    0x2a2d(%rip),%rax
mov    (%rax),%rax
mov    0x2a33(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <remove@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e16(%rip),%rbx
mov    (%rbx),%esi
lea    0xeb7(%rip),%rdi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     1199 <main+0x39>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
mov    $0x1,%eax
jmp    11de <main+0x7e>
mov    0x2e18(%rip),%r14
mov    (%r14),%rax
mov    0x2de6(%rip),%rbp
xor    %edi,%edi
cmp    0x0(%rbp),%rax
sete   %dil
call   1050 <assert@plt>
mov    (%rbx),%esi
lea    0xe3e(%rip),%rdi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     11ed <main+0x8d>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
mov    $0x2,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r14),%rax
xor    %edi,%edi
cmp    0x0(%rbp),%rax
sete   %dil
call   1050 <assert@plt>
lea    0xe15(%rip),%rdi
lea    0xe26(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1269 <main+0x109>
mov    %rax,%rdi
call   1040 <fclose@plt>
mov    0x2d7a(%rip),%r15
mov    0x2db3(%rip),%r12
mov    (%r12),%esi
or     (%r15),%esi
mov    0x2d95(%rip),%rbp
or     0x0(%rbp),%esi
add    $0x1,%esi
lea    0xdd3(%rip),%rdi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     1273 <main+0x113>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
mov    $0x4,%eax
jmp    11de <main+0x7e>
mov    $0x3,%eax
jmp    11de <main+0x7e>
mov    (%r14),%rax
mov    0x2d2b(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%rax
sete   %dil
call   1050 <assert@plt>
mov    0x2d1e(%rip),%r13
mov    0x0(%r13),%esi
lea    0xd7e(%rip),%rdi
call   1060 <chmod@plt>
cmp    $0xffffffff,%eax
je     12f7 <main+0x197>
mov    (%r15),%esi
lea    0xd6a(%rip),%rdi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     1301 <main+0x1a1>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
mov    (%r12),%esi
or     (%r15),%esi
lea    0xd45(%rip),%rdi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     1323 <main+0x1c3>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
mov    $0x7,%eax
jmp    11de <main+0x7e>
mov    $0x5,%eax
jmp    11de <main+0x7e>
mov    (%r14),%rax
mov    0x2cbd(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%rax
sete   %dil
call   1050 <assert@plt>
mov    $0x6,%eax
jmp    11de <main+0x7e>
mov    (%r14),%rax
mov    0x2c9b(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%rax
sete   %dil
call   1050 <assert@plt>
mov    0x0(%rbp),%esi
lea    0xcd6(%rip),%rdi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     1366 <main+0x206>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
mov    $0x8,%eax
jmp    11de <main+0x7e>
mov    (%r14),%rax
xor    %edi,%edi
mov    0x2c56(%rip),%rbp
cmp    0x0(%rbp),%rax
sete   %dil
call   1050 <assert@plt>
mov    0x2c52(%rip),%rax
mov    (%rax),%esi
or     0x0(%r13),%esi
lea    0xc88(%rip),%rdi
call   1060 <chmod@plt>
cmp    $0xffffffff,%eax
je     1433 <main+0x2d3>
mov    (%r12),%esi
or     (%r15),%esi
lea    0xc6c(%rip),%rdi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     143d <main+0x2dd>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
mov    (%rbx),%esi
lea    0xc48(%rip),%rdi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     1459 <main+0x2f9>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
mov    0x2bf7(%rip),%rax
mov    (%rax),%esi
lea    0xc21(%rip),%rdi
call   1060 <chmod@plt>
cmp    $0xffffffff,%eax
je     1475 <main+0x315>
mov    (%r12),%esi
or     (%r15),%esi
lea    0xc09(%rip),%rdi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     147f <main+0x31f>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
mov    $0xd,%eax
jmp    11de <main+0x7e>
mov    $0x9,%eax
jmp    11de <main+0x7e>
mov    (%r14),%rax
xor    %edi,%edi
cmp    0x0(%rbp),%rax
sete   %dil
call   1050 <assert@plt>
mov    $0xa,%eax
jmp    11de <main+0x7e>
mov    (%r14),%rax
xor    %edi,%edi
cmp    0x0(%rbp),%rax
sete   %dil
call   1050 <assert@plt>
mov    $0xb,%eax
jmp    11de <main+0x7e>
mov    $0xc,%eax
jmp    11de <main+0x7e>
mov    (%r14),%rax
xor    %edi,%edi
cmp    0x0(%rbp),%rax
sete   %dil
call   1050 <assert@plt>
lea    0xb83(%rip),%rdi
call   1030 <remove@plt>
xor    %eax,%eax
jmp    11de <main+0x7e>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@F_OK = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@.str.1 = [27 x i8] c"this file should not exist\00"
@.str.2 = [24 x i8] c"sulong_access_test_file\00"
@.str.3 = [2 x i8] c"w\00"
@R_OK = global i32 0
@W_OK = global i32 0
@X_OK = global i32 0
@EINVAL = global i64 0
@S_IRUSR = global i32 0
@EACCES = global i64 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %2
%5 = load i32, i32* @F_OK
%6 = call i32 @access(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %2
%7 = icmp ne i32 %6, -1
br i1 %7, label %8, label %13
8: ; preds = %0
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 0
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
store i32 1, i32* %1
br label %179
13: ; preds = %0
%14 = load i64, i64* @errno
%15 = load i64, i64* @ENOENT
%16 = icmp eq i64 %14, %15
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i32, i32* @F_OK
%20 = call i32 @access(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %19)
store i32 %20, i32* %2
%21 = icmp ne i32 %20, -1
br i1 %21, label %22, label %27
22: ; preds = %13
%23 = load i32, i32* %2
%24 = icmp eq i32 %23, 0
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
store i32 2, i32* %1
br label %179
27: ; preds = %13
%28 = load i64, i64* @errno
%29 = load i64, i64* @ENOENT
%30 = icmp eq i64 %28, %29
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
store i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8** %3
%33 = load i8*, i8** %3
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %34, i32** %4
%35 = load i32*, i32** %4
%36 = icmp ne i32* %35, null
br i1 %36, label %38, label %37
37: ; preds = %27
store i32 3, i32* %1
br label %179
38: ; preds = %27
%39 = load i32*, i32** %4
%40 = call i32 @fclose(i32* %39)
%41 = load i8*, i8** %3
%42 = load i32, i32* @R_OK
%43 = load i32, i32* @W_OK
%44 = or i32 %42, %43
%45 = load i32, i32* @X_OK
%46 = or i32 %44, %45
%47 = add nsw i32 %46, 1
%48 = call i32 @access(i8* %41, i32 %47)
store i32 %48, i32* %2
%49 = icmp ne i32 %48, -1
br i1 %49, label %50, label %55
50: ; preds = %38
%51 = load i32, i32* %2
%52 = icmp eq i32 %51, 0
%53 = zext i1 %52 to i32
%54 = call i32 @assert(i32 %53)
store i32 4, i32* %1
br label %179
55: ; preds = %38
%56 = load i64, i64* @errno
%57 = load i64, i64* @EINVAL
%58 = icmp eq i64 %56, %57
%59 = zext i1 %58 to i32
%60 = call i32 @assert(i32 %59)
%61 = load i8*, i8** %3
%62 = load i32, i32* @S_IRUSR
%63 = call i32 @chmod(i8* %61, i32 %62)
%64 = icmp eq i32 %63, -1
br i1 %64, label %65, label %66
65: ; preds = %55
store i32 5, i32* %1
br label %179
66: ; preds = %55
%67 = load i8*, i8** %3
%68 = load i32, i32* @R_OK
%69 = call i32 @access(i8* %67, i32 %68)
store i32 %69, i32* %2
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %77
71: ; preds = %66
%72 = load i64, i64* @errno
%73 = load i64, i64* @EACCES
%74 = icmp eq i64 %72, %73
%75 = zext i1 %74 to i32
%76 = call i32 @assert(i32 %75)
store i32 6, i32* %1
br label %179
77: ; preds = %66
%78 = load i32, i32* %2
%79 = icmp eq i32 %78, 0
%80 = zext i1 %79 to i32
%81 = call i32 @assert(i32 %80)
%82 = load i8*, i8** %3
%83 = load i32, i32* @R_OK
%84 = load i32, i32* @W_OK
%85 = or i32 %83, %84
%86 = call i32 @access(i8* %82, i32 %85)
store i32 %86, i32* %2
%87 = icmp ne i32 %86, -1
br i1 %87, label %88, label %93
88: ; preds = %77
%89 = load i32, i32* %2
%90 = icmp eq i32 %89, 0
%91 = zext i1 %90 to i32
%92 = call i32 @assert(i32 %91)
store i32 7, i32* %1
br label %179
93: ; preds = %77
%94 = load i64, i64* @errno
%95 = load i64, i64* @EACCES
%96 = icmp eq i64 %94, %95
%97 = zext i1 %96 to i32
%98 = call i32 @assert(i32 %97)
%99 = load i8*, i8** %3
%100 = load i32, i32* @X_OK
%101 = call i32 @access(i8* %99, i32 %100)
store i32 %101, i32* %2
%102 = icmp ne i32 %101, -1
br i1 %102, label %103, label %108
103: ; preds = %93
%104 = load i32, i32* %2
%105 = icmp eq i32 %104, 0
%106 = zext i1 %105 to i32
%107 = call i32 @assert(i32 %106)
store i32 8, i32* %1
br label %179
108: ; preds = %93
%109 = load i64, i64* @errno
%110 = load i64, i64* @EACCES
%111 = icmp eq i64 %109, %110
%112 = zext i1 %111 to i32
%113 = call i32 @assert(i32 %112)
%114 = load i8*, i8** %3
%115 = load i32, i32* @S_IRUSR
%116 = load i32, i32* @S_IWUSR
%117 = or i32 %115, %116
%118 = call i32 @chmod(i8* %114, i32 %117)
%119 = icmp eq i32 %118, -1
br i1 %119, label %120, label %121
120: ; preds = %108
store i32 9, i32* %1
br label %179
121: ; preds = %108
%122 = load i8*, i8** %3
%123 = load i32, i32* @R_OK
%124 = load i32, i32* @W_OK
%125 = or i32 %123, %124
%126 = call i32 @access(i8* %122, i32 %125)
store i32 %126, i32* %2
%127 = icmp eq i32 %126, -1
br i1 %127, label %128, label %134
128: ; preds = %121
%129 = load i64, i64* @errno
%130 = load i64, i64* @EACCES
%131 = icmp eq i64 %129, %130
%132 = zext i1 %131 to i32
%133 = call i32 @assert(i32 %132)
store i32 10, i32* %1
br label %179
134: ; preds = %121
%135 = load i32, i32* %2
%136 = icmp eq i32 %135, 0
%137 = zext i1 %136 to i32
%138 = call i32 @assert(i32 %137)
%139 = load i8*, i8** %3
%140 = load i32, i32* @F_OK
%141 = call i32 @access(i8* %139, i32 %140)
store i32 %141, i32* %2
%142 = icmp eq i32 %141, -1
br i1 %142, label %143, label %149
143: ; preds = %134
%144 = load i64, i64* @errno
%145 = load i64, i64* @EACCES
%146 = icmp eq i64 %144, %145
%147 = zext i1 %146 to i32
%148 = call i32 @assert(i32 %147)
store i32 11, i32* %1
br label %179
149: ; preds = %134
%150 = load i32, i32* %2
%151 = icmp eq i32 %150, 0
%152 = zext i1 %151 to i32
%153 = call i32 @assert(i32 %152)
%154 = load i8*, i8** %3
%155 = load i32, i32* @S_IXUSR
%156 = call i32 @chmod(i8* %154, i32 %155)
%157 = icmp eq i32 %156, -1
br i1 %157, label %158, label %159
158: ; preds = %149
store i32 12, i32* %1
br label %179
159: ; preds = %149
%160 = load i8*, i8** %3
%161 = load i32, i32* @R_OK
%162 = load i32, i32* @W_OK
%163 = or i32 %161, %162
%164 = call i32 @access(i8* %160, i32 %163)
store i32 %164, i32* %2
%165 = icmp ne i32 %164, -1
br i1 %165, label %166, label %171
166: ; preds = %159
%167 = load i32, i32* %2
%168 = icmp eq i32 %167, 0
%169 = zext i1 %168 to i32
%170 = call i32 @assert(i32 %169)
store i32 13, i32* %1
br label %179
171: ; preds = %159
%172 = load i64, i64* @errno
%173 = load i64, i64* @EACCES
%174 = icmp eq i64 %172, %173
%175 = zext i1 %174 to i32
%176 = call i32 @assert(i32 %175)
%177 = load i8*, i8** %3
%178 = call i32 @remove(i8* %177)
store i32 0, i32* %1
br label %179
179: ; preds = %171, %166, %158, %143, %128, %120, %103, %88, %71, %65, %50, %37, %22, %8
%180 = load i32, i32* %1
ret i32 %180
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@F_OK = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@.str.1 = [27 x i8] c"this file should not exist\00"
@.str.2 = [24 x i8] c"sulong_access_test_file\00"
@.str.3 = [2 x i8] c"w\00"
@R_OK = global i32 0
@W_OK = global i32 0
@X_OK = global i32 0
@EINVAL = global i64 0
@S_IRUSR = global i32 0
@EACCES = global i64 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
define i32 @main() {
%1 = load i32, i32* @F_OK
%2 = tail call i32 @access(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %2, -1
br i1 %3, label %8, label %4
4: ; preds = %0
%5 = icmp eq i32 %2, 0
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
br label %148
8: ; preds = %0
%9 = load i64, i64* @errno
%10 = load i64, i64* @ENOENT
%11 = icmp eq i64 %9, %10
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = load i32, i32* @F_OK
%15 = tail call i32 @access(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %21, label %17
17: ; preds = %8
%18 = icmp eq i32 %15, 0
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
br label %148
21: ; preds = %8
%22 = load i64, i64* @errno
%23 = load i64, i64* @ENOENT
%24 = icmp eq i64 %22, %23
%25 = zext i1 %24 to i32
%26 = tail call i32 @assert(i32 %25)
%27 = tail call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %148, label %29
29: ; preds = %21
%30 = tail call i32 @fclose(i32* %27)
%31 = load i32, i32* @R_OK
%32 = load i32, i32* @W_OK
%33 = or i32 %32, %31
%34 = load i32, i32* @X_OK
%35 = or i32 %33, %34
%36 = add nsw i32 %35, 1
%37 = tail call i32 @access(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %36)
%38 = icmp eq i32 %37, -1
br i1 %38, label %43, label %39
39: ; preds = %29
%40 = icmp eq i32 %37, 0
%41 = zext i1 %40 to i32
%42 = tail call i32 @assert(i32 %41)
br label %148
43: ; preds = %29
%44 = load i64, i64* @errno
%45 = load i64, i64* @EINVAL
%46 = icmp eq i64 %44, %45
%47 = zext i1 %46 to i32
%48 = tail call i32 @assert(i32 %47)
%49 = load i32, i32* @S_IRUSR
%50 = tail call i32 @chmod(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %49)
%51 = icmp eq i32 %50, -1
br i1 %51, label %148, label %52
52: ; preds = %43
%53 = load i32, i32* @R_OK
%54 = tail call i32 @access(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %53)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %62
56: ; preds = %52
%57 = load i64, i64* @errno
%58 = load i64, i64* @EACCES
%59 = icmp eq i64 %57, %58
%60 = zext i1 %59 to i32
%61 = tail call i32 @assert(i32 %60)
br label %148
62: ; preds = %52
%63 = icmp eq i32 %54, 0
%64 = zext i1 %63 to i32
%65 = tail call i32 @assert(i32 %64)
%66 = load i32, i32* @R_OK
%67 = load i32, i32* @W_OK
%68 = or i32 %67, %66
%69 = tail call i32 @access(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %68)
%70 = icmp eq i32 %69, -1
br i1 %70, label %75, label %71
71: ; preds = %62
%72 = icmp eq i32 %69, 0
%73 = zext i1 %72 to i32
%74 = tail call i32 @assert(i32 %73)
br label %148
75: ; preds = %62
%76 = load i64, i64* @errno
%77 = load i64, i64* @EACCES
%78 = icmp eq i64 %76, %77
%79 = zext i1 %78 to i32
%80 = tail call i32 @assert(i32 %79)
%81 = load i32, i32* @X_OK
%82 = tail call i32 @access(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %81)
%83 = icmp eq i32 %82, -1
br i1 %83, label %88, label %84
84: ; preds = %75
%85 = icmp eq i32 %82, 0
%86 = zext i1 %85 to i32
%87 = tail call i32 @assert(i32 %86)
br label %148
88: ; preds = %75
%89 = load i64, i64* @errno
%90 = load i64, i64* @EACCES
%91 = icmp eq i64 %89, %90
%92 = zext i1 %91 to i32
%93 = tail call i32 @assert(i32 %92)
%94 = load i32, i32* @S_IRUSR
%95 = load i32, i32* @S_IWUSR
%96 = or i32 %95, %94
%97 = tail call i32 @chmod(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %96)
%98 = icmp eq i32 %97, -1
br i1 %98, label %148, label %99
99: ; preds = %88
%100 = load i32, i32* @R_OK
%101 = load i32, i32* @W_OK
%102 = or i32 %101, %100
%103 = tail call i32 @access(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %102)
%104 = icmp eq i32 %103, -1
br i1 %104, label %105, label %111
105: ; preds = %99
%106 = load i64, i64* @errno
%107 = load i64, i64* @EACCES
%108 = icmp eq i64 %106, %107
%109 = zext i1 %108 to i32
%110 = tail call i32 @assert(i32 %109)
br label %148
111: ; preds = %99
%112 = icmp eq i32 %103, 0
%113 = zext i1 %112 to i32
%114 = tail call i32 @assert(i32 %113)
%115 = load i32, i32* @F_OK
%116 = tail call i32 @access(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %115)
%117 = icmp eq i32 %116, -1
br i1 %117, label %118, label %124
118: ; preds = %111
%119 = load i64, i64* @errno
%120 = load i64, i64* @EACCES
%121 = icmp eq i64 %119, %120
%122 = zext i1 %121 to i32
%123 = tail call i32 @assert(i32 %122)
br label %148
124: ; preds = %111
%125 = icmp eq i32 %116, 0
%126 = zext i1 %125 to i32
%127 = tail call i32 @assert(i32 %126)
%128 = load i32, i32* @S_IXUSR
%129 = tail call i32 @chmod(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %128)
%130 = icmp eq i32 %129, -1
br i1 %130, label %148, label %131
131: ; preds = %124
%132 = load i32, i32* @R_OK
%133 = load i32, i32* @W_OK
%134 = or i32 %133, %132
%135 = tail call i32 @access(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %134)
%136 = icmp eq i32 %135, -1
br i1 %136, label %141, label %137
137: ; preds = %131
%138 = icmp eq i32 %135, 0
%139 = zext i1 %138 to i32
%140 = tail call i32 @assert(i32 %139)
br label %148
141: ; preds = %131
%142 = load i64, i64* @errno
%143 = load i64, i64* @EACCES
%144 = icmp eq i64 %142, %143
%145 = zext i1 %144 to i32
%146 = tail call i32 @assert(i32 %145)
%147 = tail call i32 @remove(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %148
148: ; preds = %39, %56, %71, %84, %105, %118, %137, %141, %21, %43, %88, %124, %17, %4
%149 = phi i32 [ 1, %4 ], [ 2, %17 ], [ 4, %39 ], [ 6, %56 ], [ 7, %71 ], [ 8, %84 ], [ 10, %105 ], [ 11, %118 ], [ 13, %137 ], [ 0, %141 ], [ 3, %21 ], [ 5, %43 ], [ 9, %88 ], [ 12, %124 ]
ret i32 %149
}