#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 /*<<< orphan*/ assert(int);
int errno;
int /*<<< orphan*/ puts(char *);
int access_test(void) {
  assert(access("/etc/hosts", F_OK) == 0);
  assert(access("/etc/hosts", R_OK) == 0);
  assert(access("/etc/hosts", W_OK) == -1);
  assert(errno == 13);
  errno = 0;
  assert(access("/etc/hosts", X_OK) == -1);
  assert(errno == 13);
  puts("access_test ok");
  return 1;
}


x86 assembly (clang, -O0):
<access_test>:
push   %rbp
mov    %rsp,%rbp
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
lea    0xebc(%rip),%rdi
call   1050 <access@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
lea    0xe97(%rip),%rdi
call   1050 <access@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
lea    0xe72(%rip),%rdi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2e26(%rip),%rax
cmpl   $0xd,(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2e0f(%rip),%rax
movl   $0x0,(%rax)
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
lea    0xe29(%rip),%rdi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2ddd(%rip),%rax
cmpl   $0xd,(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xe01(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<access_test>:
push   %r14
push   %rbx
push   %rax
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
lea    0xebc(%rip),%r14
mov    %r14,%rdi
call   1050 <access@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1050 <access@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1050 <access@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1040 <assert@plt>
mov    0x2e33(%rip),%rbx
xor    %edi,%edi
cmpl   $0xd,(%rbx)
sete   %dil
call   1040 <assert@plt>
movl   $0x0,(%rbx)
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1050 <access@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1040 <assert@plt>
xor    %edi,%edi
cmpl   $0xd,(%rbx)
sete   %dil
call   1040 <assert@plt>
lea    0xe26(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/etc/hosts\00"
@F_OK = global i32 0
@R_OK = global i32 0
@W_OK = global i32 0
@errno = global i32 0
@X_OK = global i32 0
@.str.1 = [15 x i8] c"access_test ok\00"
define i32 @access_test() {
%1 = load i32, i32* @F_OK
%2 = call i32 @access(i8* getelementptr inbounds ([11 x i8], [11 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 = load i32, i32* @R_OK
%7 = call i32 @access(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp eq i32 %7, 0
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i32, i32* @W_OK
%12 = call i32 @access(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp eq i32 %12, -1
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i32, i32* @errno
%17 = icmp eq i32 %16, 13
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
store i32 0, i32* @errno
%20 = load i32, i32* @X_OK
%21 = call i32 @access(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = icmp eq i32 %21, -1
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load i32, i32* @errno
%26 = icmp eq i32 %25, 13
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
ret i32 1
}

LLVM IR (-O2):
@.str = [11 x i8] c"/etc/hosts\00"
@F_OK = global i32 0
@R_OK = global i32 0
@W_OK = global i32 0
@errno = global i32 0
@X_OK = global i32 0
@.str.1 = [15 x i8] c"access_test ok\00"
define i32 @access_test() {
%1 = load i32, i32* @F_OK
%2 = tail call i32 @access(i8* getelementptr inbounds ([11 x i8], [11 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 = load i32, i32* @R_OK
%7 = tail call i32 @access(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp eq i32 %7, 0
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = load i32, i32* @W_OK
%12 = tail call i32 @access(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp eq i32 %12, -1
%14 = zext i1 %13 to i32
%15 = tail call i32 @assert(i32 %14)
%16 = load i32, i32* @errno
%17 = icmp eq i32 %16, 13
%18 = zext i1 %17 to i32
%19 = tail call i32 @assert(i32 %18)
store i32 0, i32* @errno
%20 = load i32, i32* @X_OK
%21 = tail call i32 @access(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = icmp eq i32 %21, -1
%23 = zext i1 %22 to i32
%24 = tail call i32 @assert(i32 %23)
%25 = load i32, i32* @errno
%26 = icmp eq i32 %25, 13
%27 = zext i1 %26 to i32
%28 = tail call i32 @assert(i32 %27)
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
ret i32 1
}