#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*/ EXIT_FAILURE;
int /*<<< orphan*/ F_OK;
int access(char const *const, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ error(int /*<<< orphan*/, scalar_t__, char *,
                         char const *const);
int p_file_exists(const char *const filename) {
  if (access(filename, F_OK) == -1) {
    if (errno != ENOENT) {
      error(EXIT_FAILURE, errno, "access(file=[%s])", filename);
    }
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<p_file_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
cmp    $0xffffffff,%eax
jne    1190 <p_file_exists+0x70>
mov    0x2e92(%rip),%rax
mov    (%rax),%rax
mov    0x2e70(%rip),%rcx
cmp    (%rcx),%rax
je     1184 <p_file_exists+0x64>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
mov    0x2e6f(%rip),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rcx
lea    0xe81(%rip),%rdx
call   1030 <error@plt>
movl   $0x0,-0x4(%rbp)
jmp    1197 <p_file_exists+0x77>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p_file_exists>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
mov    $0x1,%ebp
cmp    $0xffffffff,%eax
jne    116e <p_file_exists+0x4e>
mov    0x2e9b(%rip),%rax
mov    (%rax),%rsi
mov    0x2e79(%rip),%rax
xor    %ebp,%ebp
cmp    (%rax),%rsi
je     116e <p_file_exists+0x4e>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
lea    0xe9a(%rip),%rdx
mov    %rbx,%rcx
call   1030 <error@plt>
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
@EXIT_FAILURE = global i32 0
@.str = [18 x i8] c"access(file=[%s])\00"
define i32 @p_file_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 i32 @access(i8* %4, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %18
8: ; preds = %1
%9 = load i64, i64* @errno
%10 = load i64, i64* @ENOENT
%11 = icmp ne i64 %9, %10
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i32, i32* @EXIT_FAILURE
%14 = load i64, i64* @errno
%15 = load i8*, i8** %3
%16 = call i32 @error(i32 %13, i64 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %12, %8
store i32 0, i32* %2
br label %19
18: ; preds = %1
store i32 1, i32* %2
br label %19
19: ; preds = %18, %17
%20 = load i32, i32* %2
ret i32 %20
}

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