#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 */
scalar_t__ ENOENT;
int /*<<< orphan*/ F_OK;
scalar_t__ access(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ die_errno(char *, char const *);
scalar_t__ errno;
int path_exists(const char *path) {
  if (access(path, F_OK) == 0) {
    return 1;
  } else if (errno != ENOENT) {
    die_errno("access('%s', F_OK) failed", path);
  }
  return 0;
}


x86 assembly (clang, -O0):
<path_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
cmp    $0x0,%rax
jne    1154 <path_exists+0x34>
movl   $0x1,-0x4(%rbp)
jmp    118a <path_exists+0x6a>
mov    0x2e85(%rip),%rax
mov    (%rax),%rax
mov    0x2e6b(%rip),%rcx
cmp    (%rcx),%rax
je     117e <path_exists+0x5e>
mov    -0x10(%rbp),%rsi
lea    0xe87(%rip),%rdi
call   1030 <die_errno@plt>
jmp    1183 <path_exists+0x63>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_exists>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
test   %rax,%rax
je     1162 <path_exists+0x42>
mov    0x2ea0(%rip),%rax
mov    (%rax),%rax
mov    0x2e86(%rip),%rcx
xor    %ebp,%ebp
cmp    (%rcx),%rax
je     1167 <path_exists+0x47>
lea    0xea8(%rip),%rdi
mov    %rbx,%rsi
call   1030 <die_errno@plt>
jmp    1167 <path_exists+0x47>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@F_OK = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@.str = [26 x i8] c"access('%s', F_OK) failed\00"
define i32 @path_exists(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = load i32, i32* @F_OK
%6 = call i64 @access(i8* %4, i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 1, i32* %2
br label %18
9: ; preds = %1
%10 = load i64, i64* @errno
%11 = load i64, i64* @ENOENT
%12 = icmp ne i64 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = call i32 @die_errno(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %13, %9
br label %17
17: ; preds = %16
store i32 0, i32* %2
br label %18
18: ; preds = %17, %8
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
@F_OK = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@.str = [26 x i8] c"access('%s', F_OK) failed\00"
define i32 @path_exists(i8* %0) {
%2 = load i32, i32* @F_OK
%3 = tail call i64 @access(i8* %0, i32 %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %11, label %5
5: ; preds = %1
%6 = load i64, i64* @errno
%7 = load i64, i64* @ENOENT
%8 = icmp eq i64 %6, %7
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call i32 @die_errno(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %11
11: ; preds = %9, %5, %1
%12 = phi i32 [ 1, %1 ], [ 0, %5 ], [ 0, %9 ]
ret i32 %12
}