#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 */
struct directory_entry {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ ENOENT;
int /*<<< orphan*/ EPERM;
int /*<<< orphan*/ errno;
struct directory_entry *lookup_file(char const *);
int access(const char *path, int mode) {
  struct directory_entry *entry;
  entry = lookup_file(path);
  if (!entry) {
    errno = ENOENT;
    return -1;
  }
  if (mode & 2) {
    errno = EPERM;
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<access>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <lookup_file@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1155 <access+0x45>
mov    0x2e92(%rip),%rax
mov    (%rax),%ecx
mov    0x2e99(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1189 <access+0x79>
mov    -0x14(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     1182 <access+0x72>
mov    0x2e5d(%rip),%rax
mov    (%rax),%ecx
mov    0x2e6c(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1189 <access+0x79>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<access>:
push   %rbx
mov    %esi,%ebx
call   1030 <lookup_file@plt>
test   %rax,%rax
je     112d <access+0x1d>
xor    %eax,%eax
test   $0x2,%bl
je     1144 <access+0x34>
mov    0x2e9d(%rip),%rax
jmp    1134 <access+0x24>
mov    0x2e9c(%rip),%rax
mov    (%rax),%eax
mov    0x2ea3(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.directory_entry = type { i32 }
@ENOENT = global i32 0
@errno = global i32 0
@EPERM = global i32 0
define i32 @access(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.directory_entry*
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = call %struct.directory_entry* @lookup_file(i8* %7)
store %struct.directory_entry* %8, %struct.directory_entry** %6
%9 = load %struct.directory_entry*, %struct.directory_entry** %6
%10 = icmp ne %struct.directory_entry* %9, null
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = load i32, i32* @ENOENT
store i32 %12, i32* @errno
store i32 -1, i32* %3
br label %20
13: ; preds = %2
%14 = load i32, i32* %5
%15 = and i32 %14, 2
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = load i32, i32* @EPERM
store i32 %18, i32* @errno
store i32 -1, i32* %3
br label %20
19: ; preds = %13
store i32 0, i32* %3
br label %20
20: ; preds = %19, %17, %11
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
%struct.directory_entry = type { i32 }
@ENOENT = global i32 0
@errno = global i32 0
@EPERM = global i32 0
define i32 @access(i8* %0, i32 %1) {
%3 = tail call %struct.directory_entry* @lookup_file(i8* %0)
%4 = icmp eq %struct.directory_entry* %3, null
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = and i32 %1, 2
%7 = icmp eq i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5, %2
%9 = phi i32* [ @ENOENT, %2 ], [ @EPERM, %5 ]
%10 = load i32, i32* %9
store i32 %10, i32* @errno
br label %11
11: ; preds = %8, %5
%12 = phi i32 [ 0, %5 ], [ -1, %8 ]
ret i32 %12
}