#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;
};

/* Variables and functions */
scalar_t__ ENOENT;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *,
                           scalar_t__);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int _file_exists(char *path) {
  struct stat buf;
  if (stat(path, &buf)) {
    if (errno == ENOENT) {
      return 0;
    } else {
      fprintf(stderr, "Error while stat'ing symlink %s: %s (%d)\n", path,
              strerror(errno), errno);
      return -1;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<_file_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
je     11c8 <_file_exists+0x98>
mov    0x2e7e(%rip),%rax
mov    (%rax),%rax
mov    0x2e64(%rip),%rcx
cmp    (%rcx),%rax
jne    1179 <_file_exists+0x49>
movl   $0x0,-0x4(%rbp)
jmp    11cf <_file_exists+0x9f>
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e44(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
mov    0x2e2b(%rip),%rax
mov    (%rax),%r8
lea    0xe49(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cf <_file_exists+0x9f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_file_exists>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
test   %rax,%rax
je     1192 <_file_exists+0x62>
mov    0x2e87(%rip),%rbp
mov    0x0(%rbp),%rdi
mov    0x2e6c(%rip),%rcx
xor    %eax,%eax
cmp    (%rcx),%rdi
je     1197 <_file_exists+0x67>
mov    0x2e76(%rip),%rax
mov    (%rax),%r14d
call   1050 <strerror@plt>
mov    0x0(%rbp),%r8
lea    0xe83(%rip),%rsi
mov    %r14d,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1197 <_file_exists+0x67>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
@stderr = global i32 0
@.str = [42 x i8] c"Error while stat'ing symlink %s: %s (%d)\0A\00"
define i32 @_file_exists(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i64 @stat(i8* %5, %struct.stat* %4)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %20
8: ; preds = %1
%9 = load i64, i64* @errno
%10 = load i64, i64* @ENOENT
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %13
12: ; preds = %8
store i32 0, i32* %2
br label %21
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %3
%16 = load i64, i64* @errno
%17 = call i8* @strerror(i64 %16)
%18 = load i64, i64* @errno
%19 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %17, i64 %18)
store i32 -1, i32* %2
br label %21
20: ; preds = %1
store i32 1, i32* %2
br label %21
21: ; preds = %20, %13, %12
%22 = load i32, i32* %2
ret i32 %22
}

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