#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 stat(char const *, struct stat *);
int /*<<< orphan*/ sys_die(char *, char const *);
extern int sys_exists(const char *path) {
  struct stat st;
  int res = stat(path, &st);
  if (res < 0) {
    if (errno == ENOENT)
      return 0;
    else
      sys_die("sys: cannot check %s existance\n", path);
  }
  return 1;
}


x86 assembly (clang, -O0):
<sys_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1181 <sys_exists+0x61>
mov    0x2e93(%rip),%rax
mov    (%rax),%rax
mov    0x2e79(%rip),%rcx
cmp    (%rcx),%rax
jne    116c <sys_exists+0x4c>
movl   $0x0,-0x4(%rbp)
jmp    1188 <sys_exists+0x68>
mov    -0x10(%rbp),%rsi
lea    0xe89(%rip),%rdi
call   1030 <sys_die@plt>
jmp    1181 <sys_exists+0x61>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_exists>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
mov    %eax,%ecx
mov    $0x1,%eax
test   %ecx,%ecx
jns    1169 <sys_exists+0x49>
mov    0x2e9c(%rip),%rax
mov    (%rax),%rcx
mov    0x2e82(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
je     1169 <sys_exists+0x49>
lea    0xea4(%rip),%rdi
mov    %rbx,%rsi
call   1030 <sys_die@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
@.str = [32 x i8] c"sys: cannot check %s existance\0A\00"
define i32 @sys_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 = call i32 @stat(i8* %6, %struct.stat* %4)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 0
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 %14, label %15
14: ; preds = %10
store i32 0, i32* %2
br label %20
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = call i32 @sys_die(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %15
br label %19
19: ; preds = %18, %1
store i32 1, i32* %2
br label %20
20: ; preds = %19, %14
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
@.str = [32 x i8] c"sys: cannot check %s existance\0A\00"
define i32 @sys_exists(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @stat(i8* %0, %struct.stat* %2)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %12
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 @sys_die(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %12
12: ; preds = %1, %10, %6
%13 = phi i32 [ 0, %6 ], [ 1, %10 ], [ 1, %1 ]
ret i32 %13
}