#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 *);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int fileExists(char *name) {
  struct stat st;
  if (stat(name, &st)) {
    if (errno == ENOENT) {
      return 0;
    } else {
      fprintf(stderr,
              "Warning: Stat of %s failed for reason other than not found\n",
              name);
      perror(NULL);
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<fileExists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
je     11a7 <fileExists+0x77>
mov    0x2e7e(%rip),%rax
mov    (%rax),%rax
mov    0x2e64(%rip),%rcx
cmp    (%rcx),%rax
jne    1179 <fileExists+0x49>
movl   $0x0,-0x4(%rbp)
jmp    11ae <fileExists+0x7e>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe73(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ae <fileExists+0x7e>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fileExists>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rsp,%rsi
call   1040 <stat@plt>
test   %rax,%rax
je     117f <fileExists+0x4f>
mov    0x2e8d(%rip),%rax
mov    (%rax),%rax
mov    0x2e73(%rip),%rcx
xor    %ebx,%ebx
cmp    (%rcx),%rax
je     1184 <fileExists+0x54>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
lea    0xe94(%rip),%rsi
mov    %r14,%rdx
call   1030 <fprintf@plt>
xor    %ebx,%ebx
xor    %edi,%edi
call   1050 <perror@plt>
jmp    1184 <fileExists+0x54>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
@stderr = global i32 0
@.str = [60 x i8] c"Warning: Stat of %s failed for reason other than not found\0A\00"
define i32 @fileExists(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 %18
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 %19
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %3
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @perror(i32* null)
store i32 0, i32* %2
br label %19
18: ; preds = %1
store i32 1, i32* %2
br label %19
19: ; preds = %18, %13, %12
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
@stderr = global i32 0
@.str = [60 x i8] c"Warning: Stat of %s failed for reason other than not found\0A\00"
define i32 @fileExists(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 %14, 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 %14, label %10
10: ; preds = %6
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i8* %0)
%13 = call i32 @perror(i32* null)
br label %14
14: ; preds = %1, %6, %10
%15 = phi i32 [ 0, %10 ], [ 0, %6 ], [ 1, %1 ]
ret i32 %15
}