#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__ EINVAL;
scalar_t__ ENOENT;
int R_OK;
int W_OK;
int X_OK;
int access(char *, int);
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
int test_access_basic(void) {
  assert(access("/bin/mandelbrot", R_OK) == 0);
  assert(access("/bin/mandelbrot", 0) == 0);
  assert(access("/bin/mandelbrot", R_OK | W_OK | X_OK) == 0);
  assert(access("/tests/ascii", X_OK) == -1 && errno == EACCES);
  assert(access("/bin/mandelbrot", (R_OK | W_OK | X_OK) + 1) == -1 &&
         errno == EINVAL);
  assert(access("/dont/exist", X_OK) == -1 && errno == ENOENT);
  assert(access("dont/exist", X_OK) == -1 && errno == ENOENT);
  return 0;
}


x86 assembly (clang, -O0):
<test_access_basic>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xec8(%rip),%rdi
call   1040 <access@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
lea    0xeac(%rip),%rdi
xor    %esi,%esi
call   1040 <access@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
mov    0x2e6d(%rip),%rax
or     (%rax),%esi
mov    0x2e5c(%rip),%rax
or     (%rax),%esi
lea    0xe73(%rip),%rdi
call   1040 <access@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
lea    0xe5e(%rip),%rdi
call   1040 <access@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x1(%rbp)
jne    11e1 <test_access_basic+0xc1>
mov    0x2dfa(%rip),%rax
mov    (%rax),%rax
mov    0x2e00(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x1(%rbp)
mov    -0x1(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
mov    0x2dea(%rip),%rax
or     (%rax),%esi
mov    0x2dd9(%rip),%rax
or     (%rax),%esi
add    $0x1,%esi
lea    0xded(%rip),%rdi
call   1040 <access@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x2(%rbp)
jne    1242 <test_access_basic+0x122>
mov    0x2d99(%rip),%rax
mov    (%rax),%rax
mov    0x2d87(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x2(%rbp)
mov    -0x2(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%esi
lea    0xdbe(%rip),%rdi
call   1040 <access@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x3(%rbp)
jne    128e <test_access_basic+0x16e>
mov    0x2d4d(%rip),%rax
mov    (%rax),%rax
mov    0x2d23(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x3(%rbp)
mov    -0x3(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    0x2d3e(%rip),%rax
mov    (%rax),%esi
lea    0xd73(%rip),%rdi
call   1040 <access@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x4(%rbp)
jne    12da <test_access_basic+0x1ba>
mov    0x2d01(%rip),%rax
mov    (%rax),%rax
mov    0x2cd7(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x4(%rbp)
mov    -0x4(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_access_basic>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e86(%rip),%r15
mov    (%r15),%esi
lea    0xec4(%rip),%r14
mov    %r14,%rdi
call   1040 <access@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1030 <assert@plt>
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <access@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1030 <assert@plt>
mov    0x2e79(%rip),%r13
mov    0x0(%r13),%esi
or     (%r15),%esi
mov    0x2e63(%rip),%rbp
or     0x0(%rbp),%esi
mov    %r14,%rdi
call   1040 <access@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1030 <assert@plt>
mov    0x0(%rbp),%esi
lea    0xe71(%rip),%rdi
call   1040 <access@plt>
cmp    $0xffffffff,%eax
sete   %al
mov    0x2e17(%rip),%r12
mov    (%r12),%rcx
mov    0x2e1c(%rip),%rdx
cmp    (%rdx),%rcx
sete   %cl
and    %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
mov    0x0(%r13),%esi
or     (%r15),%esi
or     0x0(%rbp),%esi
add    $0x1,%esi
mov    %r14,%rdi
call   1040 <access@plt>
cmp    $0xffffffff,%eax
sete   %al
mov    (%r12),%rcx
mov    0x2dce(%rip),%rdx
cmp    (%rdx),%rcx
sete   %cl
and    %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
mov    0x0(%rbp),%esi
lea    0xe11(%rip),%rdi
call   1040 <access@plt>
cmp    $0xffffffff,%eax
sete   %al
mov    (%r12),%rcx
mov    0x2d86(%rip),%rbx
cmp    (%rbx),%rcx
sete   %cl
and    %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
mov    0x0(%rbp),%esi
lea    0xde2(%rip),%rdi
call   1040 <access@plt>
cmp    $0xffffffff,%eax
sete   %al
mov    (%r12),%rcx
cmp    (%rbx),%rcx
sete   %cl
and    %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"/bin/mandelbrot\00"
@R_OK = global i32 0
@W_OK = global i32 0
@X_OK = global i32 0
@.str.1 = [13 x i8] c"/tests/ascii\00"
@errno = global i64 0
@EACCES = global i64 0
@EINVAL = global i64 0
@.str.2 = [12 x i8] c"/dont/exist\00"
@ENOENT = global i64 0
@.str.3 = [11 x i8] c"dont/exist\00"
define i32 @test_access_basic() {
%1 = load i32, i32* @R_OK
%2 = call i32 @access(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %2, 0
%4 = zext i1 %3 to i32
%5 = call i32 @assert(i32 %4)
%6 = call i32 @access(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 0)
%7 = icmp eq i32 %6, 0
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i32, i32* @R_OK
%11 = load i32, i32* @W_OK
%12 = or i32 %10, %11
%13 = load i32, i32* @X_OK
%14 = or i32 %12, %13
%15 = call i32 @access(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = icmp eq i32 %15, 0
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i32, i32* @X_OK
%20 = call i32 @access(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %26
22: ; preds = %0
%23 = load i64, i64* @errno
%24 = load i64, i64* @EACCES
%25 = icmp eq i64 %23, %24
br label %26
26: ; preds = %22, %0
%27 = phi i1 [ false, %0 ], [ %25, %22 ]
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = load i32, i32* @R_OK
%31 = load i32, i32* @W_OK
%32 = or i32 %30, %31
%33 = load i32, i32* @X_OK
%34 = or i32 %32, %33
%35 = add nsw i32 %34, 1
%36 = call i32 @access(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %35)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %42
38: ; preds = %26
%39 = load i64, i64* @errno
%40 = load i64, i64* @EINVAL
%41 = icmp eq i64 %39, %40
br label %42
42: ; preds = %38, %26
%43 = phi i1 [ false, %26 ], [ %41, %38 ]
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = load i32, i32* @X_OK
%47 = call i32 @access(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %46)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %53
49: ; preds = %42
%50 = load i64, i64* @errno
%51 = load i64, i64* @ENOENT
%52 = icmp eq i64 %50, %51
br label %53
53: ; preds = %49, %42
%54 = phi i1 [ false, %42 ], [ %52, %49 ]
%55 = zext i1 %54 to i32
%56 = call i32 @assert(i32 %55)
%57 = load i32, i32* @X_OK
%58 = call i32 @access(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %57)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %64
60: ; preds = %53
%61 = load i64, i64* @errno
%62 = load i64, i64* @ENOENT
%63 = icmp eq i64 %61, %62
br label %64
64: ; preds = %60, %53
%65 = phi i1 [ false, %53 ], [ %63, %60 ]
%66 = zext i1 %65 to i32
%67 = call i32 @assert(i32 %66)
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"/bin/mandelbrot\00"
@R_OK = global i32 0
@W_OK = global i32 0
@X_OK = global i32 0
@.str.1 = [13 x i8] c"/tests/ascii\00"
@errno = global i64 0
@EACCES = global i64 0
@EINVAL = global i64 0
@.str.2 = [12 x i8] c"/dont/exist\00"
@ENOENT = global i64 0
@.str.3 = [11 x i8] c"dont/exist\00"
define i32 @test_access_basic() {
%1 = load i32, i32* @R_OK
%2 = tail call i32 @access(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %2, 0
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = tail call i32 @access(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 0)
%7 = icmp eq i32 %6, 0
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = load i32, i32* @R_OK
%11 = load i32, i32* @W_OK
%12 = or i32 %11, %10
%13 = load i32, i32* @X_OK
%14 = or i32 %12, %13
%15 = tail call i32 @access(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = icmp eq i32 %15, 0
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
%19 = load i32, i32* @X_OK
%20 = tail call i32 @access(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = icmp eq i32 %20, -1
%22 = load i64, i64* @errno
%23 = load i64, i64* @EACCES
%24 = icmp eq i64 %22, %23
%25 = select i1 %21, i1 %24, i1 false
%26 = zext i1 %25 to i32
%27 = tail call i32 @assert(i32 %26)
%28 = load i32, i32* @R_OK
%29 = load i32, i32* @W_OK
%30 = or i32 %29, %28
%31 = load i32, i32* @X_OK
%32 = or i32 %30, %31
%33 = add nsw i32 %32, 1
%34 = tail call i32 @access(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %33)
%35 = icmp eq i32 %34, -1
%36 = load i64, i64* @errno
%37 = load i64, i64* @EINVAL
%38 = icmp eq i64 %36, %37
%39 = select i1 %35, i1 %38, i1 false
%40 = zext i1 %39 to i32
%41 = tail call i32 @assert(i32 %40)
%42 = load i32, i32* @X_OK
%43 = tail call i32 @access(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = icmp eq i32 %43, -1
%45 = load i64, i64* @errno
%46 = load i64, i64* @ENOENT
%47 = icmp eq i64 %45, %46
%48 = select i1 %44, i1 %47, i1 false
%49 = zext i1 %48 to i32
%50 = tail call i32 @assert(i32 %49)
%51 = load i32, i32* @X_OK
%52 = tail call i32 @access(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %51)
%53 = icmp eq i32 %52, -1
%54 = load i64, i64* @errno
%55 = load i64, i64* @ENOENT
%56 = icmp eq i64 %54, %55
%57 = select i1 %53, i1 %56, i1 false
%58 = zext i1 %57 to i32
%59 = tail call i32 @assert(i32 %58)
ret i32 0
}