#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 /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int PathExists(char *sPath) {
  struct stat st_buf;
  int status = stat(sPath, &st_buf);
  if (status != 0) {
    fprintf(stderr, "PathExists: unknown path %s\n", sPath);
    return -1;
  }
  if (S_ISDIR(st_buf.st_mode)) {
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<PathExists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     117b <PathExists+0x4b>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe96(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a0 <PathExists+0x70>
mov    -0x18(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1199 <PathExists+0x69>
movl   $0x0,-0x4(%rbp)
jmp    11a0 <PathExists+0x70>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PathExists>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1050 <stat@plt>
test   %eax,%eax
je     1165 <PathExists+0x35>
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
lea    0xeaa(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1174 <PathExists+0x44>
mov    0x8(%rsp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x1,%rax
sbb    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [29 x i8] c"PathExists: unknown path %s\0A\00"
define i32 @PathExists(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 ne i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %3
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %12)
store i32 -1, i32* %2
br label %21
14: ; preds = %1
%15 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i64 @S_ISDIR(i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %14
store i32 0, i32* %2
br label %21
20: ; preds = %14
store i32 -1, i32* %2
br label %21
21: ; preds = %20, %19, %10
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [29 x i8] c"PathExists: unknown path %s\0A\00"
define i32 @PathExists(i8* %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 %9, label %6
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %15
9: ; preds = %1
%10 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%11 = load i32, i32* %10
%12 = tail call i64 @S_ISDIR(i32 %11)
%13 = icmp eq i64 %12, 0
%14 = sext i1 %13 to i32
br label %15
15: ; preds = %9, %6
%16 = phi i32 [ -1, %6 ], [ %14, %9 ]
ret i32 %16
}