#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int F_OK;
int R_OK;
int W_OK;
int X_OK;
scalar_t__ eaccess(char *, int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char);
int /*<<< orphan*/ helpAndLeave(char *, int /*<<< orphan*/);
int /*<<< orphan*/ pexit(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc != 3) {
    helpAndLeave(argv[0], EXIT_FAILURE);
  }
  char *accessString, *filename, *p;
  int mode;
  accessString = argv[1];
  filename = argv[2];
  mode = 0;
  for (p = accessString; *p != '\0'; ++p) {
    switch (*p) {
    case 'f':
      mode |= F_OK;
      break;
    case 'r':
      mode |= R_OK;
      break;
    case 'w':
      mode |= W_OK;
      break;
    case 'x':
      mode |= X_OK;
      break;
    default:
      fprintf(stderr, "%s: unknown flag %c\n", argv[0], *p);
      exit(EXIT_FAILURE);
    }
  }
  errno = 0;
  if (eaccess(filename, mode) == 0) {
    printf("%s: permission granted\n", filename);
  } else {
    if (errno != 0) {
      pexit("eaccess");
    }
    printf("%s: permission denied\n", filename);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1195 <main+0x35>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
call   1060 <helpAndLeave@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1290 <main+0x130>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffff9a,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x12,%eax
ja     1249 <main+0xe9>
mov    -0x38(%rbp),%rax
lea    0xe10(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2da0(%rip),%rax
mov    (%rax),%eax
or     -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    127a <main+0x11a>
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
or     -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    127a <main+0x11a>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
or     -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    127a <main+0x11a>
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
or     -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    127a <main+0x11a>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x28(%rbp),%rax
lea    0xde8(%rip),%rsi
movsbl (%rax),%ecx
call   1050 <fprintf@plt>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    127f <main+0x11f>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11bc <main+0x5c>
mov    0x2d31(%rip),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1030 <eaccess@plt>
cmp    $0x0,%rax
jne    12c9 <main+0x169>
mov    -0x20(%rbp),%rsi
lea    0xda2(%rip),%rdi
call   1040 <printf@plt>
jmp    12f6 <main+0x196>
mov    0x2cf8(%rip),%rax
cmpq   $0x0,(%rax)
je     12e6 <main+0x186>
lea    0xd98(%rip),%rdi
call   1080 <pexit@plt>
mov    -0x20(%rbp),%rsi
lea    0xd90(%rip),%rdi
call   1040 <printf@plt>
mov    0x2cb3(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
cmp    $0x3,%edi
je     117e <main+0x1e>
mov    (%r15),%rdi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
call   1060 <helpAndLeave@plt>
mov    0x8(%r15),%rax
mov    0x10(%r15),%r14
mov    (%rax),%cl
xor    %esi,%esi
test   %cl,%cl
jne    11b2 <main+0x52>
mov    0x2e33(%rip),%r15
movq   $0x0,(%r15)
mov    %r14,%rdi
call   1030 <eaccess@plt>
test   %rax,%rax
jne    1215 <main+0xb5>
lea    0xeb1(%rip),%rbx
jmp    122e <main+0xce>
add    $0x1,%rax
xor    %esi,%esi
mov    0x2de1(%rip),%r11
lea    0xe3a(%rip),%rdi
mov    0x2deb(%rip),%r8
mov    0x2e14(%rip),%r9
mov    0x2e05(%rip),%r10
jmp    11f0 <main+0x90>
nopl   (%rax)
mov    %r8,%rdx
or     (%rdx),%esi
movzbl (%rax),%ecx
add    $0x1,%rax
test   %cl,%cl
je     118e <main+0x2e>
movsbl %cl,%ecx
lea    -0x66(%rcx),%edx
cmp    $0x12,%edx
ja     1247 <main+0xe7>
movslq (%rdi,%rdx,4),%rbx
add    %rdi,%rbx
mov    %r11,%rdx
jmp    *%rbx
mov    %r9,%rdx
jmp    11e3 <main+0x83>
nopl   0x0(%rax)
mov    %r10,%rdx
jmp    11e3 <main+0x83>
lea    0xe65(%rip),%rbx
cmpq   $0x0,(%r15)
je     122e <main+0xce>
lea    0xe50(%rip),%rdi
call   1080 <pexit@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xdf2(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@F_OK = global i32 0
@R_OK = global i32 0
@W_OK = global i32 0
@X_OK = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"%s: unknown flag %c\0A\00"
@errno = global i64 0
@.str.1 = [24 x i8] c"%s: permission granted\0A\00"
@.str.2 = [8 x i8] c"eaccess\00"
@.str.3 = [23 x i8] c"%s: permission denied\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @helpAndLeave(i8* %15, i32 %16)
br label %18
18: ; preds = %12, %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
store i8* %21, i8** %6
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
store i8* %24, i8** %7
store i32 0, i32* %9
%25 = load i8*, i8** %6
store i8* %25, i8** %8
br label %26
26: ; preds = %62, %18
%27 = load i8*, i8** %8
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %65
31: ; preds = %26
%32 = load i8*, i8** %8
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
switch i32 %34, label %51 [
i32 102, label %35
i32 114, label %39
i32 119, label %43
i32 120, label %47
]
35: ; preds = %31
%36 = load i32, i32* @F_OK
%37 = load i32, i32* %9
%38 = or i32 %37, %36
store i32 %38, i32* %9
br label %61
39: ; preds = %31
%40 = load i32, i32* @R_OK
%41 = load i32, i32* %9
%42 = or i32 %41, %40
store i32 %42, i32* %9
br label %61
43: ; preds = %31
%44 = load i32, i32* @W_OK
%45 = load i32, i32* %9
%46 = or i32 %45, %44
store i32 %46, i32* %9
br label %61
47: ; preds = %31
%48 = load i32, i32* @X_OK
%49 = load i32, i32* %9
%50 = or i32 %49, %48
store i32 %50, i32* %9
br label %61
51: ; preds = %31
%52 = load i32, i32* @stderr
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 0
%55 = load i8*, i8** %54
%56 = load i8*, i8** %8
%57 = load i8, i8* %56
%58 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %55, i8 signext %57)
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %47, %43, %39, %35
br label %62
62: ; preds = %61
%63 = load i8*, i8** %8
%64 = getelementptr inbounds i8, i8* %63, i32 1
store i8* %64, i8** %8
br label %26
65: ; preds = %26
store i64 0, i64* @errno
%66 = load i8*, i8** %7
%67 = load i32, i32* %9
%68 = call i64 @eaccess(i8* %66, i32 %67)
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %65
%71 = load i8*, i8** %7
%72 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %71)
br label %81
73: ; preds = %65
%74 = load i64, i64* @errno
%75 = icmp ne i64 %74, 0
br i1 %75, label %76, label %78
76: ; preds = %73
%77 = call i32 @pexit(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %78
78: ; preds = %76, %73
%79 = load i8*, i8** %7
%80 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %79)
br label %81
81: ; preds = %78, %70
%82 = load i32, i32* @EXIT_SUCCESS
%83 = call i32 @exit(i32 %82)
unreachable
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@F_OK = global i32 0
@R_OK = global i32 0
@W_OK = global i32 0
@X_OK = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"%s: unknown flag %c\0A\00"
@errno = global i64 0
@.str.1 = [24 x i8] c"%s: permission granted\0A\00"
@.str.2 = [8 x i8] c"eaccess\00"
@.str.3 = [23 x i8] c"%s: permission denied\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @helpAndLeave(i8* %5, i32 %6)
br label %8
8: ; preds = %4, %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = load i8, i8* %10
%14 = icmp eq i8 %13, 0
br i1 %14, label %36, label %15
15: ; preds = %8, %29
%16 = phi i8 [ %34, %29 ], [ %13, %8 ]
%17 = phi i32 [ %32, %29 ], [ 0, %8 ]
%18 = phi i8* [ %33, %29 ], [ %10, %8 ]
%19 = sext i8 %16 to i32
switch i32 %19, label %23 [
i32 102, label %29
i32 114, label %20
i32 119, label %21
i32 120, label %22
]
20: ; preds = %15
br label %29
21: ; preds = %15
br label %29
22: ; preds = %15
br label %29
23: ; preds = %15
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %1
%26 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %25, i8 signext %16)
%27 = load i32, i32* @EXIT_FAILURE
%28 = tail call i32 @exit(i32 %27)
unreachable
29: ; preds = %15, %20, %21, %22
%30 = phi i32* [ @X_OK, %22 ], [ @W_OK, %21 ], [ @R_OK, %20 ], [ @F_OK, %15 ]
%31 = load i32, i32* %30
%32 = or i32 %31, %17
%33 = getelementptr inbounds i8, i8* %18, i64 1
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 0
br i1 %35, label %36, label %15
36: ; preds = %29, %8
%37 = phi i32 [ 0, %8 ], [ %32, %29 ]
store i64 0, i64* @errno
%38 = tail call i64 @eaccess(i8* %12, i32 %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %45, label %40
40: ; preds = %36
%41 = load i64, i64* @errno
%42 = icmp eq i64 %41, 0
br i1 %42, label %45, label %43
43: ; preds = %40
%44 = tail call i32 @pexit(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %40, %43, %36
%46 = phi i8* [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), %36 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), %43 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), %40 ]
%47 = tail call i32 @printf(i8* %46, i8* %12)
%48 = load i32, i32* @EXIT_SUCCESS
%49 = tail call i32 @exit(i32 %48)
unreachable
}