#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 */
struct stat {
  int dummy;
};
typedef int /*<<< orphan*/ st;

/* Variables and functions */
scalar_t__ ENOENT;
scalar_t__ errno;
int /*<<< orphan*/ memset(struct stat *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *, char *);
int stat(char *, struct stat *);
char *strerror(scalar_t__);
int eslib_file_exists(char *path) {
  struct stat st;
  int ret;
  if (path == NULL)
    return -1;
  memset(&st, 0, sizeof(st));
  ret = stat(path, &st);
  if (ret != -1)
    return 1;
  if (errno == ENOENT)
    return 0;
  printf("stat(%s): %s\n", path, strerror(errno));
  return -1;
}


x86 assembly (clang, -O0):
<eslib_file_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1163 <eslib_file_exists+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f0 <eslib_file_exists+0xb0>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
je     1199 <eslib_file_exists+0x59>
movl   $0x1,-0x4(%rbp)
jmp    11f0 <eslib_file_exists+0xb0>
mov    0x2e40(%rip),%rax
mov    (%rax),%rax
mov    0x2e26(%rip),%rcx
cmp    (%rcx),%rax
jne    11bf <eslib_file_exists+0x7f>
movl   $0x0,-0x4(%rbp)
jmp    11f0 <eslib_file_exists+0xb0>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e12(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
lea    0xe1c(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eslib_file_exists>:
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     11b1 <eslib_file_exists+0x71>
mov    %rdi,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <stat@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0xffffffff,%ecx
jne    11b1 <eslib_file_exists+0x71>
mov    0x2e5f(%rip),%rax
mov    (%rax),%rdi
mov    0x2e45(%rip),%rcx
mov    $0x0,%eax
cmp    (%rcx),%rdi
je     11b1 <eslib_file_exists+0x71>
call   1060 <strerror@plt>
lea    0xe5f(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <printf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
@.str = [14 x i8] c"stat(%s): %s\0A\00"
define i32 @eslib_file_exists(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %26
9: ; preds = %1
%10 = call i32 @memset(%struct.stat* %4, i32 0, i32 4)
%11 = load i8*, i8** %3
%12 = call i32 @stat(i8* %11, %struct.stat* %4)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %9
store i32 1, i32* %2
br label %26
16: ; preds = %9
%17 = load i64, i64* @errno
%18 = load i64, i64* @ENOENT
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 0, i32* %2
br label %26
21: ; preds = %16
%22 = load i8*, i8** %3
%23 = load i64, i64* @errno
%24 = call i8* @strerror(i64 %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %22, i8* %24)
store i32 -1, i32* %2
br label %26
26: ; preds = %21, %20, %15, %8
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
@.str = [14 x i8] c"stat(%s): %s\0A\00"
define i32 @eslib_file_exists(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %16, label %5
5: ; preds = %1
%6 = call i32 @memset(%struct.stat* %2, i32 0, i32 4)
%7 = call i32 @stat(i8* %0, %struct.stat* %2)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %16
9: ; preds = %5
%10 = load i64, i64* @errno
%11 = load i64, i64* @ENOENT
%12 = icmp eq i64 %10, %11
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = call i8* @strerror(i64 %10)
%15 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %14)
br label %16
16: ; preds = %9, %5, %1, %13
%17 = phi i32 [ -1, %13 ], [ -1, %1 ], [ 1, %5 ], [ 0, %9 ]
ret i32 %17
}