#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 S_IFDIR;
int S_IFMT;
int /*<<< orphan*/ err(int, char *);
scalar_t__ stat(char *, struct stat *);
int es_dir(char *path) {
  struct stat st;
  if (stat(path, &st) < 0) {
    err(1, "path\n");
  }
  if ((st.st_mode & S_IFMT) == S_IFDIR)
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<es_dir>:
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
jge    1154 <es_dir+0x34>
mov    $0x1,%edi
lea    0xeb1(%rip),%rsi
call   1040 <err@plt>
mov    -0x18(%rbp),%eax
mov    0x2e82(%rip),%rcx
and    (%rcx),%eax
mov    0x2e69(%rip),%rcx
cmp    (%rcx),%eax
jne    117b <es_dir+0x5b>
movl   $0x1,-0x4(%rbp)
jmp    1182 <es_dir+0x62>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<es_dir>:
push   %rax
mov    %rsp,%rsi
call   1030 <stat@plt>
test   %rax,%rax
jns    113f <es_dir+0x1f>
lea    0xecb(%rip),%rsi
mov    $0x1,%edi
call   1040 <err@plt>
mov    0x2e9a(%rip),%rax
mov    (%rax),%ecx
and    (%rsp),%ecx
mov    0x2e7e(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%ecx
sete   %al
pop    %rcx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [6 x i8] c"path\0A\00"
@S_IFMT = global i32 0
@S_IFDIR = global i32 0
define i32 @es_dir(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 slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %1
%11 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%12 = load i32, i32* %11
%13 = load i32, i32* @S_IFMT
%14 = and i32 %12, %13
%15 = load i32, i32* @S_IFDIR
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %10
store i32 1, i32* %2
br label %19
18: ; preds = %10
store i32 0, i32* %2
br label %19
19: ; preds = %18, %17
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [6 x i8] c"path\0A\00"
@S_IFMT = global i32 0
@S_IFDIR = global i32 0
define i32 @es_dir(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i64 @stat(i8* %0, %struct.stat* %2)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%10 = load i32, i32* %9
%11 = load i32, i32* @S_IFMT
%12 = and i32 %11, %10
%13 = load i32, i32* @S_IFDIR
%14 = icmp eq i32 %12, %13
%15 = zext i1 %14 to i32
ret i32 %15
}