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

/* Variables and functions */
int /*<<< orphan*/ MakeFullPath(char const *, char const *, char *);
int S_IFDIR;
scalar_t__ stat(char *, struct stat *);
int IsDirectory(const char *root, const char *path) {
  char fullpath[300];
  struct stat statbuf;
  if (path == NULL)
    return (0);
  MakeFullPath(root, path, fullpath);
  if (stat(fullpath, &statbuf))
    return (0);
  if (statbuf.st_mode & S_IFDIR)
    return (1);
  else
    return (0);
}


x86 assembly (clang, -O0):
<IsDirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    114a <IsDirectory+0x2a>
movl   $0x0,-0x4(%rbp)
jmp    11b2 <IsDirectory+0x92>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x150(%rbp),%rdx
call   1030 <MakeFullPath@plt>
lea    -0x150(%rbp),%rdi
lea    -0x158(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
je     1187 <IsDirectory+0x67>
movl   $0x0,-0x4(%rbp)
jmp    11b2 <IsDirectory+0x92>
mov    -0x158(%rbp),%eax
mov    0x2e44(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11ab <IsDirectory+0x8b>
movl   $0x1,-0x4(%rbp)
jmp    11b2 <IsDirectory+0x92>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IsDirectory>:
push   %r14
push   %rbx
sub    $0x148,%rsp
xor    %ebx,%ebx
test   %rsi,%rsi
je     1162 <IsDirectory+0x42>
lea    0x10(%rsp),%r14
mov    %r14,%rdx
call   1030 <MakeFullPath@plt>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1040 <stat@plt>
test   %rax,%rax
jne    1162 <IsDirectory+0x42>
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
xor    %ebx,%ebx
test   %eax,0x8(%rsp)
setne  %bl
mov    %ebx,%eax
add    $0x148,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@S_IFDIR = global i32 0
define i32 @IsDirectory(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [300 x i8]
%7 = alloca %struct.stat
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 0, i32* %3
br label %28
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i8*, i8** %5
%14 = getelementptr inbounds [300 x i8], [300 x i8]* %6, i64 0, i64 0
%15 = call i32 @MakeFullPath(i8* %12, i8* %13, i8* %14)
%16 = getelementptr inbounds [300 x i8], [300 x i8]* %6, i64 0, i64 0
%17 = call i64 @stat(i8* %16, %struct.stat* %7)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %11
store i32 0, i32* %3
br label %28
20: ; preds = %11
%21 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%22 = load i32, i32* %21
%23 = load i32, i32* @S_IFDIR
%24 = and i32 %22, %23
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %20
store i32 1, i32* %3
br label %28
27: ; preds = %20
store i32 0, i32* %3
br label %28
28: ; preds = %27, %26, %19, %10
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@S_IFDIR = global i32 0
define i32 @IsDirectory(i8* %0, i8* %1) {
%3 = alloca [300 x i8]
%4 = alloca %struct.stat
%5 = getelementptr inbounds [300 x i8], [300 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.stat* %4 to i8*
%7 = icmp eq i8* %1, null
br i1 %7, label %19, label %8
8: ; preds = %2
%9 = call i32 @MakeFullPath(i8* %0, i8* %1, i8* %5)
%10 = call i64 @stat(i8* %5, %struct.stat* %4)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %8
%13 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%14 = load i32, i32* %13
%15 = load i32, i32* @S_IFDIR
%16 = and i32 %15, %14
%17 = icmp ne i32 %16, 0
%18 = zext i1 %17 to i32
br label %19
19: ; preds = %12, %8, %2
%20 = phi i32 [ 0, %2 ], [ 0, %8 ], [ %18, %12 ]
ret i32 %20
}