#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 */
int /*<<< orphan*/ Debug_ErrorMsgArg(char *, char *);
scalar_t__ ENOENT;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ errno;
int stat(char *, struct stat *);
int DirCheckExistence(char *path) {
  struct stat s;
  int err = stat(path, &s);
  if (err == -1) {
    if (errno == ENOENT) {
      return 0;
    } else {
      return 0;
    }
  } else {
    if (S_ISDIR(s.st_mode)) {
      return 1;
    } else {
      Debug_ErrorMsgArg("Not a directory, but a file: %s", path);
      return 0;
    }
  }
}


x86 assembly (clang, -O0):
<DirCheckExistence>:
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   $0xffffffff,-0x1c(%rbp)
jne    1188 <DirCheckExistence+0x58>
mov    0x2e83(%rip),%rax
mov    (%rax),%rax
mov    0x2e69(%rip),%rcx
cmp    (%rcx),%rax
jne    117c <DirCheckExistence+0x4c>
movl   $0x0,-0x4(%rbp)
jmp    11bd <DirCheckExistence+0x8d>
movl   $0x0,-0x4(%rbp)
jmp    11bd <DirCheckExistence+0x8d>
mov    -0x18(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11a6 <DirCheckExistence+0x76>
movl   $0x1,-0x4(%rbp)
jmp    11bd <DirCheckExistence+0x8d>
mov    -0x10(%rbp),%rsi
lea    0xe4f(%rip),%rdi
call   1050 <Debug_ErrorMsgArg@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DirCheckExistence>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
je     1172 <DirCheckExistence+0x42>
mov    0x8(%rsp),%edi
call   1030 <S_ISDIR@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    1172 <DirCheckExistence+0x42>
lea    0xe98(%rip),%rdi
mov    %rbx,%rsi
call   1050 <Debug_ErrorMsgArg@plt>
xor    %eax,%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"Not a directory, but a file: %s\00"
define i32 @DirCheckExistence(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 eq i32 %8, -1
br i1 %9, label %10, label %16
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 %25
15: ; preds = %10
store i32 0, i32* %2
br label %25
16: ; preds = %1
%17 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i64 @S_ISDIR(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 1, i32* %2
br label %25
22: ; preds = %16
%23 = load i8*, i8** %3
%24 = call i32 @Debug_ErrorMsgArg(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %23)
store i32 0, i32* %2
br label %25
25: ; preds = %22, %21, %15, %14
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
@.str = [32 x i8] c"Not a directory, but a file: %s\00"
define i32 @DirCheckExistence(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, -1
br i1 %5, label %13, label %6
6: ; preds = %1
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%8 = load i32, i32* %7
%9 = tail call i64 @S_ISDIR(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @Debug_ErrorMsgArg(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %13
13: ; preds = %6, %1, %11
%14 = phi i32 [ 0, %11 ], [ 0, %1 ], [ 1, %6 ]
ret i32 %14
}