#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 EINVAL;
int /*<<< orphan*/ R_OK;
int /*<<< orphan*/ W_OK;
int /*<<< orphan*/ access(char const *, int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char const *, char *);
int main(int argc, const char **argv) {
  if (argc != 3 || (strcmp(argv[2], "R_OK") && strcmp(argv[2], "W_OK"))) {
    fprintf(stderr, "Usage %s <file> R_OK|W_OK\n", argv[0]);
    return EINVAL;
  }
  errno = 0;
  access(argv[1], strcmp(argv[2], "R_OK") == 0 ? R_OK : W_OK);
  return errno;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    118c <main+0x5c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xea1(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     11b9 <main+0x89>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe88(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     11b9 <main+0x89>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe67(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1225 <main+0xf5>
mov    0x2e10(%rip),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe1f(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1201 <main+0xd1>
mov    0x2dc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    120d <main+0xdd>
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <access@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1167 <main+0x37>
mov    0x10(%rbx),%rdi
lea    0xeb8(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1188 <main+0x58>
mov    0x10(%rbx),%rdi
lea    0xea8(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1188 <main+0x58>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe90(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e42(%rip),%r15
jmp    11c9 <main+0x99>
mov    0x2e41(%rip),%r15
movl   $0x0,(%r15)
mov    0x8(%rbx),%r14
mov    0x10(%rbx),%rdi
lea    0xe5b(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
jne    11b8 <main+0x88>
mov    0x2e0a(%rip),%rax
jmp    11bf <main+0x8f>
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1050 <access@plt>
mov    (%r15),%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"R_OK\00"
@.str.1 = [5 x i8] c"W_OK\00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"Usage %s <file> R_OK|W_OK\0A\00"
@EINVAL = global i32 0
@errno = global i32 0
@R_OK = global i32 0
@W_OK = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 3
br i1 %7, label %20, label %8
8: ; preds = %2
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 2
%11 = load i8*, i8** %10
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %27
14: ; preds = %8
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 2
%17 = load i8*, i8** %16
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %14, %2
%21 = load i32, i32* @stderr
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = load i32, i32* @EINVAL
store i32 %26, i32* %3
br label %44
27: ; preds = %14, %8
store i32 0, i32* @errno
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %27
%37 = load i32, i32* @R_OK
br label %40
38: ; preds = %27
%39 = load i32, i32* @W_OK
br label %40
40: ; preds = %38, %36
%41 = phi i32 [ %37, %36 ], [ %39, %38 ]
%42 = call i32 @access(i8* %30, i32 %41)
%43 = load i32, i32* @errno
store i32 %43, i32* %3
br label %44
44: ; preds = %40, %20
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@.str = [5 x i8] c"R_OK\00"
@.str.1 = [5 x i8] c"W_OK\00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"Usage %s <file> R_OK|W_OK\0A\00"
@EINVAL = global i32 0
@errno = global i32 0
@R_OK = global i32 0
@W_OK = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %4, label %13
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 2
%6 = load i8*, i8** %5
%7 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %4
%10 = load i8*, i8** %5
%11 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %9, %2
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %1
%16 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %15)
br label %27
17: ; preds = %9, %4
store i32 0, i32* @errno
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = load i8*, i8** %5
%21 = tail call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
%23 = load i32, i32* @R_OK
%24 = load i32, i32* @W_OK
%25 = select i1 %22, i32 %23, i32 %24
%26 = tail call i32 @access(i8* %19, i32 %25)
br label %27
27: ; preds = %17, %13
%28 = phi i32* [ @EINVAL, %13 ], [ @errno, %17 ]
%29 = load i32, i32* %28
ret i32 %29
}