#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*/ perror(char *);
int stat(char *, struct stat *);
int fileExists(char *fn) {
  struct stat sbuf;
  int statrc, rv = 0;
  statrc = stat(fn, &sbuf);
  if (statrc == 0) {
    rv = 1;
  } else {
    if (errno != ENOENT) {
      perror("WARNING: fileExists");
    }
  }
  return rv;
}


x86 assembly (clang, -O0):
<fileExists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1159 <fileExists+0x39>
movl   $0x1,-0x18(%rbp)
jmp    1184 <fileExists+0x64>
mov    0x2e80(%rip),%rax
mov    (%rax),%rax
mov    0x2e66(%rip),%rcx
cmp    (%rcx),%rax
je     117f <fileExists+0x5f>
lea    0xe86(%rip),%rdi
call   1040 <perror@plt>
jmp    1184 <fileExists+0x64>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fileExists>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rsi
call   1030 <stat@plt>
test   %eax,%eax
je     1159 <fileExists+0x39>
mov    0x2ea6(%rip),%rax
mov    (%rax),%rax
mov    0x2e8c(%rip),%rcx
xor    %ebx,%ebx
cmp    (%rcx),%rax
je     115e <fileExists+0x3e>
lea    0xeae(%rip),%rdi
call   1040 <perror@plt>
jmp    115e <fileExists+0x3e>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
@.str = [20 x i8] c"WARNING: fileExists\00"
define i32 @fileExists(i8* nocapture %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @stat(i8* %0, %struct.stat* %2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %12, 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 %12, label %10
10: ; preds = %6
%11 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %1, %6, %10
%13 = phi i32 [ 0, %10 ], [ 0, %6 ], [ 1, %1 ]
ret i32 %13
}