#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*/);
char *__imlib_FileRealFile(char const *);
scalar_t__ __imlib_IsRealFile(char const *);
int /*<<< orphan*/ free(char *);
scalar_t__ stat(char *, struct stat *);
char *strdup(char const *);
int __imlib_FileIsDir(const char *s) {
  struct stat st;
  char *fl;
  if ((!s) || (!*s))
    return 0;
  if (__imlib_IsRealFile(s))
    fl = strdup(s);
  else
    fl = __imlib_FileRealFile(s);
  if (!fl)
    return 0;
  if (stat(fl, &st) < 0) {
    free(fl);
    return 0;
  }
  if (S_ISDIR(st.st_mode)) {
    free(fl);
    return 1;
  }
  free(fl);
  return 0;
}


x86 assembly (clang, -O0):
<__imlib_FileIsDir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1184 <__imlib_FileIsDir+0x24>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1190 <__imlib_FileIsDir+0x30>
movl   $0x0,-0x4(%rbp)
jmp    123c <__imlib_FileIsDir+0xdc>
mov    -0x10(%rbp),%rdi
call   1070 <__imlib_IsRealFile@plt>
cmp    $0x0,%rax
je     11b5 <__imlib_FileIsDir+0x55>
mov    -0x10(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x20(%rbp)
jmp    11c2 <__imlib_FileIsDir+0x62>
mov    -0x10(%rbp),%rdi
call   1040 <__imlib_FileRealFile@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d9 <__imlib_FileIsDir+0x79>
movl   $0x0,-0x4(%rbp)
jmp    123c <__imlib_FileIsDir+0xdc>
mov    -0x20(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
jge    1205 <__imlib_FileIsDir+0xa5>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    123c <__imlib_FileIsDir+0xdc>
mov    -0x18(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%rax
je     122c <__imlib_FileIsDir+0xcc>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    123c <__imlib_FileIsDir+0xdc>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__imlib_FileIsDir>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %ebp,%ebp
test   %rdi,%rdi
je     11c7 <__imlib_FileIsDir+0x67>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     11c7 <__imlib_FileIsDir+0x67>
mov    %rbx,%rdi
call   1070 <__imlib_IsRealFile@plt>
mov    %rbx,%rdi
test   %rax,%rax
je     118e <__imlib_FileIsDir+0x2e>
call   1080 <strdup@plt>
jmp    1193 <__imlib_FileIsDir+0x33>
call   1040 <__imlib_FileRealFile@plt>
mov    %rax,%r14
test   %rax,%rax
je     11c7 <__imlib_FileIsDir+0x67>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1060 <stat@plt>
test   %rax,%rax
js     11bf <__imlib_FileIsDir+0x5f>
mov    0x8(%rsp),%edi
call   1050 <S_ISDIR@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
define i32 @__imlib_FileIsDir(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %8, %1
store i32 0, i32* %2
br label %45
13: ; preds = %8
%14 = load i8*, i8** %3
%15 = call i64 @__imlib_IsRealFile(i8* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i8*, i8** %3
%19 = call i8* @strdup(i8* %18)
store i8* %19, i8** %5
br label %23
20: ; preds = %13
%21 = load i8*, i8** %3
%22 = call i8* @__imlib_FileRealFile(i8* %21)
store i8* %22, i8** %5
br label %23
23: ; preds = %20, %17
%24 = load i8*, i8** %5
%25 = icmp ne i8* %24, null
br i1 %25, label %27, label %26
26: ; preds = %23
store i32 0, i32* %2
br label %45
27: ; preds = %23
%28 = load i8*, i8** %5
%29 = call i64 @stat(i8* %28, %struct.stat* %4)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i8*, i8** %5
%33 = call i32 @free(i8* %32)
store i32 0, i32* %2
br label %45
34: ; preds = %27
%35 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i64 @S_ISDIR(i32 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = load i8*, i8** %5
%41 = call i32 @free(i8* %40)
store i32 1, i32* %2
br label %45
42: ; preds = %34
%43 = load i8*, i8** %5
%44 = call i32 @free(i8* %43)
store i32 0, i32* %2
br label %45
45: ; preds = %42, %39, %31, %26, %12
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
%struct.stat = type { i32 }
define i32 @__imlib_FileIsDir(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %30, label %5
5: ; preds = %1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %30, label %8
8: ; preds = %5
%9 = tail call i64 @__imlib_IsRealFile(i8* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i8* @strdup(i8* %0)
br label %15
13: ; preds = %8
%14 = tail call i8* @__imlib_FileRealFile(i8* %0)
br label %15
15: ; preds = %13, %11
%16 = phi i8* [ %12, %11 ], [ %14, %13 ]
%17 = icmp eq i8* %16, null
br i1 %17, label %30, label %18
18: ; preds = %15
%19 = call i64 @stat(i8* %16, %struct.stat* %2)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @free(i8* %16)
br label %30
23: ; preds = %18
%24 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%25 = load i32, i32* %24
%26 = call i64 @S_ISDIR(i32 %25)
%27 = icmp ne i64 %26, 0
%28 = call i32 @free(i8* %16)
%29 = zext i1 %27 to i32
br label %30
30: ; preds = %23, %15, %1, %5, %21
%31 = phi i32 [ 0, %21 ], [ 0, %5 ], [ 0, %1 ], [ 0, %15 ], [ %29, %23 ]
ret i32 %31
}