#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__ ENOTDIR;
scalar_t__ errno;
int stat(char *, struct stat *);
extern int file_exists(char *path) {
  int st;
  struct stat sbuf;
  st = stat(path, &sbuf);
  if (st == -1 && (errno == ENOENT || errno == ENOTDIR))
    return 0;
  else
    return 1;
}


x86 assembly (clang, -O0):
<file_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1176 <file_exists+0x66>
mov    0x2e9b(%rip),%rax
mov    (%rax),%rax
mov    0x2e81(%rip),%rcx
cmp    (%rcx),%rax
je     116a <file_exists+0x5a>
mov    0x2e81(%rip),%rax
mov    (%rax),%rax
mov    0x2e97(%rip),%rcx
cmp    (%rcx),%rax
jne    1176 <file_exists+0x66>
movl   $0x0,-0x4(%rbp)
jmp    117d <file_exists+0x6d>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_exists>:
push   %rax
mov    %rsp,%rsi
call   1030 <stat@plt>
cmp    $0xffffffff,%eax
jne    1142 <file_exists+0x32>
mov    0x2eb3(%rip),%rax
mov    (%rax),%rcx
mov    0x2e99(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
je     1147 <file_exists+0x37>
mov    0x2ebb(%rip),%rdx
cmp    (%rdx),%rcx
je     1147 <file_exists+0x37>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
@ENOTDIR = global i64 0
define i32 @file_exists(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.stat
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @stat(i8* %6, %struct.stat* %5)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %19
10: ; preds = %1
%11 = load i64, i64* @errno
%12 = load i64, i64* @ENOENT
%13 = icmp eq i64 %11, %12
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = load i64, i64* @errno
%16 = load i64, i64* @ENOTDIR
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %14, %10
store i32 0, i32* %2
br label %20
19: ; preds = %14, %1
store i32 1, i32* %2
br label %20
20: ; preds = %19, %18
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
@ENOTDIR = global i64 0
define i32 @file_exists(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, -1
br i1 %5, label %6, label %13
6: ; preds = %1
%7 = load i64, i64* @errno
%8 = load i64, i64* @ENOENT
%9 = icmp eq i64 %7, %8
%10 = load i64, i64* @ENOTDIR
%11 = icmp eq i64 %7, %10
%12 = select i1 %9, i1 true, i1 %11
br i1 %12, label %14, label %13
13: ; preds = %6, %1
br label %14
14: ; preds = %6, %13
%15 = phi i32 [ 1, %13 ], [ 0, %6 ]
ret i32 %15
}