#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*/ err(int, char *, char *);
scalar_t__ errno;
scalar_t__ stat(char *, struct stat *);
int path_is_valid(char *path) {
  struct stat sb;
  if (stat(path, &sb) != 0) {
    if (errno == ENOENT) {
      return (0);
    }
    err(1, "stat() failed on %s", path);
  }
  return (1);
}


x86 assembly (clang, -O0):
<path_is_valid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
je     117e <path_is_valid+0x5e>
mov    0x2e96(%rip),%rax
mov    (%rax),%rax
mov    0x2e7c(%rip),%rcx
cmp    (%rcx),%rax
jne    1169 <path_is_valid+0x49>
movl   $0x0,-0x4(%rbp)
jmp    1185 <path_is_valid+0x65>
mov    -0x10(%rbp),%rdx
mov    $0x1,%edi
lea    0xe87(%rip),%rsi
call   1040 <err@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_is_valid>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1030 <stat@plt>
test   %rax,%rax
je     1166 <path_is_valid+0x46>
mov    0x2ea6(%rip),%rax
mov    (%rax),%rax
mov    0x2e8c(%rip),%rcx
xor    %ebp,%ebp
cmp    (%rcx),%rax
je     116b <path_is_valid+0x4b>
lea    0xeae(%rip),%rsi
mov    $0x1,%ebp
mov    $0x1,%edi
mov    %rbx,%rdx
call   1040 <err@plt>
jmp    116b <path_is_valid+0x4b>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
@.str = [20 x i8] c"stat() failed on %s\00"
define i32 @path_is_valid(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 %16
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 %17
13: ; preds = %8
%14 = load i8*, i8** %3
%15 = call i32 @err(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %13, %1
store i32 1, i32* %2
br label %17
17: ; preds = %16, %12
%18 = load i32, i32* %2
ret i32 %18
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
@.str = [20 x i8] c"stat() failed on %s\00"
define i32 @path_is_valid(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 %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 = call i32 @err(i32 1, i8* getelementptr inbounds ([20 x i8], [20 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
}