#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;
int /*<<< orphan*/ die_errno(char *, char const *);
scalar_t__ errno;
int /*<<< orphan*/ lstat(char const *, struct stat *);
int exists(const char *file) {
  struct stat sb;
  if (!lstat(file, &sb))
    return 1;
  if (errno == ENOENT)
    return 0;
  die_errno("cannot get status of %s", file);
}


x86 assembly (clang, -O0):
<exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <lstat@plt>
cmp    $0x0,%eax
jne    114e <exists+0x2e>
movl   $0x1,-0x4(%rbp)
jmp    1184 <exists+0x64>
mov    0x2e8b(%rip),%rax
mov    (%rax),%rax
mov    0x2e71(%rip),%rcx
cmp    (%rcx),%rax
jne    1174 <exists+0x54>
movl   $0x0,-0x4(%rbp)
jmp    1184 <exists+0x64>
mov    -0x10(%rbp),%rsi
lea    0xe81(%rip),%rdi
call   1040 <die_errno@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exists>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1030 <lstat@plt>
test   %eax,%eax
je     115f <exists+0x3f>
mov    0x2ea3(%rip),%rax
mov    (%rax),%rcx
mov    0x2e89(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
je     1164 <exists+0x44>
lea    0xeab(%rip),%rdi
mov    %rbx,%rsi
call   1040 <die_errno@plt>
jmp    1164 <exists+0x44>
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 = [24 x i8] c"cannot get status of %s\00"
define i32 @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 i32 @lstat(i8* %5, %struct.stat* %4)
%7 = icmp ne i32 %6, 0
br i1 %7, label %9, label %8
8: ; preds = %1
store i32 1, i32* %2
br label %17
9: ; preds = %1
%10 = load i64, i64* @errno
%11 = load i64, i64* @ENOENT
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %9
store i32 0, i32* %2
br label %17
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = call i32 @die_errno(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %14, %13, %8
%18 = load i32, i32* %2
ret i32 %18
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
@.str = [24 x i8] c"cannot get status of %s\00"
define i32 @exists(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @lstat(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 @die_errno(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %12
12: ; preds = %6, %1, %10
%13 = phi i32 [ undef, %10 ], [ 1, %1 ], [ 0, %6 ]
ret i32 %13
}