#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 */
#define EACCES 134
#define EFAULT 133
#define ELOOP 132
#define ENAMETOOLONG 131
#define ENOENT 130
#define ENOMEM 129
#define ENOTDIR 128
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int errno;
int open(char const *, int /*<<< orphan*/);
int iso_eaccess(const char *path) {
  int access;
  int fd = open(path, O_RDONLY);
  if (fd != -1) {
    close(fd);
    access = 1;
  } else {
    access = 0;
  }
  if (!access) {
    int err;
    switch (errno) {
    case EACCES:
      err = 0xE830FF7E;
      break;
    case ENOTDIR:
    case ENAMETOOLONG:
    case ELOOP:
      err = 0xE830FF7D;
      break;
    case ENOENT:
      err = 0xE830FF7C;
      break;
    case EFAULT:
    case ENOMEM:
      err = 0xF030FFFA;
      break;
    default:
      err = 0xE830FF80;
      break;
    }
    return err;
  }
  return 1;
}


x86 assembly (clang, -O0):
<iso_eaccess>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2eb1(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
je     115f <iso_eaccess+0x3f>
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
movl   $0x1,-0x14(%rbp)
jmp    1166 <iso_eaccess+0x46>
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11e1 <iso_eaccess+0xc1>
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x6,%eax
ja     11cf <iso_eaccess+0xaf>
mov    -0x28(%rbp),%rax
lea    0xe6a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0xe830ff7e,-0x1c(%rbp)
jmp    11d6 <iso_eaccess+0xb6>
movl   $0xe830ff7d,-0x1c(%rbp)
jmp    11d6 <iso_eaccess+0xb6>
movl   $0xe830ff7c,-0x1c(%rbp)
jmp    11d6 <iso_eaccess+0xb6>
movl   $0xf030fffa,-0x1c(%rbp)
jmp    11d6 <iso_eaccess+0xb6>
movl   $0xe830ff80,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e8 <iso_eaccess+0xc8>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iso_eaccess>:
push   %rax
mov    0x2ec0(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
cmp    $0xffffffff,%eax
je     1142 <iso_eaccess+0x22>
mov    %eax,%edi
call   1030 <close@plt>
mov    $0x1,%eax
pop    %rcx
ret
mov    0x2e8f(%rip),%rax
mov    (%rax),%ecx
add    $0xffffff80,%ecx
mov    $0xe830ff80,%eax
cmp    $0x6,%ecx
ja     1165 <iso_eaccess+0x45>
movslq %ecx,%rax
lea    0xe9e(%rip),%rcx
mov    (%rcx,%rax,4),%eax
pop    %rcx
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@errno = global i32 0
define i32 @iso_eaccess(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* %7, i32 %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i32, i32* %5
%14 = call i32 @close(i32 %13)
store i32 1, i32* %4
br label %16
15: ; preds = %1
store i32 0, i32* %4
br label %16
16: ; preds = %15, %12
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 0
br i1 %18, label %28, label %19
19: ; preds = %16
%20 = load i32, i32* @errno
switch i32 %20, label %25 [
i32 134, label %21
i32 128, label %22
i32 131, label %22
i32 132, label %22
i32 130, label %23
i32 133, label %24
i32 129, label %24
]
21: ; preds = %19
store i32 -399442050, i32* %6
br label %26
22: ; preds = %19, %19, %19
store i32 -399442051, i32* %6
br label %26
23: ; preds = %19
store i32 -399442052, i32* %6
br label %26
24: ; preds = %19, %19
store i32 -265224198, i32* %6
br label %26
25: ; preds = %19
store i32 -399442048, i32* %6
br label %26
26: ; preds = %25, %24, %23, %22, %21
%27 = load i32, i32* %6
store i32 %27, i32* %2
br label %29
28: ; preds = %16
store i32 1, i32* %2
br label %29
29: ; preds = %28, %26
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@errno = global i32 0
@switch.table.iso_eaccess = [7 x i32] [i32 -399442051, i32 -265224198, i32 -399442052, i32 -399442051, i32 -399442051, i32 -265224198, i32 -399442050]
define i32 @iso_eaccess(i8* nocapture %0) {
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* %0, i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = tail call i32 @close(i32 %3)
br label %15
7: ; preds = %1
%8 = load i32, i32* @errno
%9 = add i32 %8, -128
%10 = icmp ult i32 %9, 7
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = sext i32 %9 to i64
%13 = getelementptr inbounds [7 x i32], [7 x i32]* @switch.table.iso_eaccess, i64 0, i64 %12
%14 = load i32, i32* %13
br label %15
15: ; preds = %7, %11, %5
%16 = phi i32 [ 1, %5 ], [ %14, %11 ], [ -399442048, %7 ]
ret i32 %16
}