#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 R_OK;
int W_OK;
int X_OK;
scalar_t__ access(char *, int);
int errno;
int access_file(char *path, int r, int w, int x) {
  int mode = 0;
  if (r)
    mode = R_OK;
  if (w)
    mode |= W_OK;
  if (x)
    mode |= X_OK;
  if (access(path, mode) != 0)
    return -errno;
  else
    return 0;
}


x86 assembly (clang, -O0):
<access_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1142 <access_file+0x32>
mov    0x2e8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     115b <access_file+0x4b>
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1174 <access_file+0x64>
mov    0x2e74(%rip),%rax
mov    (%rax),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1030 <access@plt>
cmp    $0x0,%rax
je     119d <access_file+0x8d>
xor    %eax,%eax
mov    0x2e3d(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11a4 <access_file+0x94>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<access_file>:
push   %rax
test   %esi,%esi
je     111e <access_file+0xe>
mov    0x2eac(%rip),%rax
mov    (%rax),%esi
test   %edx,%edx
je     112b <access_file+0x1b>
mov    0x2ebf(%rip),%rax
mov    (%rax),%edx
or     %esi,%edx
test   %ecx,%ecx
je     113a <access_file+0x2a>
mov    0x2ea8(%rip),%rax
mov    (%rax),%ecx
or     %ecx,%edx
mov    %edx,%esi
call   1030 <access@plt>
mov    0x2e86(%rip),%rdx
xor    %ecx,%ecx
sub    (%rdx),%ecx
xor    %edx,%edx
test   %rax,%rax
cmove  %edx,%ecx
mov    %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
@R_OK = global i32 0
@W_OK = global i32 0
@X_OK = global i32 0
@errno = global i32 0
define i32 @access_file(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 0, i32* %10
%11 = load i32, i32* %7
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %4
%14 = load i32, i32* @R_OK
store i32 %14, i32* %10
br label %15
15: ; preds = %13, %4
%16 = load i32, i32* %8
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i32, i32* @W_OK
%20 = load i32, i32* %10
%21 = or i32 %20, %19
store i32 %21, i32* %10
br label %22
22: ; preds = %18, %15
%23 = load i32, i32* %9
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i32, i32* @X_OK
%27 = load i32, i32* %10
%28 = or i32 %27, %26
store i32 %28, i32* %10
br label %29
29: ; preds = %25, %22
%30 = load i8*, i8** %6
%31 = load i32, i32* %10
%32 = call i64 @access(i8* %30, i32 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = load i32, i32* @errno
%36 = sub nsw i32 0, %35
store i32 %36, i32* %5
br label %38
37: ; preds = %29
store i32 0, i32* %5
br label %38
38: ; preds = %37, %34
%39 = load i32, i32* %5
ret i32 %39
}

LLVM IR (-O2):
@R_OK = global i32 0
@W_OK = global i32 0
@X_OK = global i32 0
@errno = global i32 0
define i32 @access_file(i8* nocapture %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %1, 0
%6 = load i32, i32* @R_OK
%7 = select i1 %5, i32 0, i32 %6
%8 = icmp eq i32 %2, 0
%9 = load i32, i32* @W_OK
%10 = select i1 %8, i32 0, i32 %9
%11 = or i32 %10, %7
%12 = icmp eq i32 %3, 0
%13 = load i32, i32* @X_OK
%14 = select i1 %12, i32 0, i32 %13
%15 = or i32 %11, %14
%16 = tail call i64 @access(i8* %0, i32 %15)
%17 = icmp eq i64 %16, 0
%18 = load i32, i32* @errno
%19 = sub nsw i32 0, %18
%20 = select i1 %17, i32 0, i32 %19
ret i32 %20
}