#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;
};
typedef int /*<<< orphan*/ filename;

/* Variables and functions */
unsigned char DT_DIR;
unsigned char DT_UNKNOWN;
int PATH_MAX;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ lstat(char *, struct stat *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const *);
unsigned char util_get_dt(const char *parent, const char *name) {
  char filename[PATH_MAX];
  struct stat st;
  snprintf(filename, sizeof(filename), "%s/%s", parent, name);
  if (lstat(filename, &st) == 0 && S_ISDIR(st.st_mode))
    return DT_DIR;
  return DT_UNKNOWN;
}


x86 assembly (clang, -O0):
<util_get_dt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2ea9(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xe83(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x40(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <lstat@plt>
cmp    $0x0,%rax
jne    11c3 <util_get_dt+0x93>
mov    -0x30(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11c3 <util_get_dt+0x93>
mov    0x2e1e(%rip),%rax
mov    (%rax),%al
mov    %al,-0x1(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    11d6 <util_get_dt+0xa6>
mov    0x2e16(%rip),%rax
mov    (%rax),%al
mov    %al,-0x1(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
movzbl -0x1(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_get_dt>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
push   %rax
mov    %rsi,%r8
mov    %rdi,%rcx
mov    0x2ead(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xea0(%rip),%rdx
mov    %rbx,%rdi
call   1040 <snprintf@plt>
lea    -0x10(%rbp),%rsi
mov    %rbx,%rdi
call   1050 <lstat@plt>
test   %rax,%rax
je     1182 <util_get_dt+0x52>
mov    0x2e60(%rip),%rax
jmp    1196 <util_get_dt+0x66>
mov    -0x10(%rbp),%edi
call   1030 <S_ISDIR@plt>
test   %rax,%rax
je     1179 <util_get_dt+0x49>
mov    0x2e3a(%rip),%rax
mov    (%rax),%al
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
@.str = [6 x i8] c"%s/%s\00"
@DT_DIR = global i8 0
@DT_UNKNOWN = global i8 0
define zeroext i8 @util_get_dt(i8* %0, i8* %1) {
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca %struct.stat
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i32, i32* @PATH_MAX
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %6
%13 = alloca i8, i64 %11
store i64 %11, i64* %7
%14 = trunc i64 %11 to i32
%15 = load i8*, i8** %4
%16 = load i8*, i8** %5
%17 = call i32 @snprintf(i8* %13, i32 %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %16)
%18 = call i64 @lstat(i8* %13, %struct.stat* %8)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %2
%21 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i64 @S_ISDIR(i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = load i8, i8* @DT_DIR
store i8 %26, i8* %3
store i32 1, i32* %9
br label %29
27: ; preds = %20, %2
%28 = load i8, i8* @DT_UNKNOWN
store i8 %28, i8* %3
store i32 1, i32* %9
br label %29
29: ; preds = %27, %25
%30 = load i8*, i8** %6
%31 = load i8, i8* %3
ret i8 %31
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
@.str = [6 x i8] c"%s/%s\00"
@DT_DIR = global i8 0
@DT_UNKNOWN = global i8 0
define zeroext i8 @util_get_dt(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = load i32, i32* @PATH_MAX
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = bitcast %struct.stat* %3 to i8*
%8 = call i32 @snprintf(i8* %6, i32 %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%9 = call i64 @lstat(i8* %6, %struct.stat* %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%13 = load i32, i32* %12
%14 = call i64 @S_ISDIR(i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %11, %2
br label %17
17: ; preds = %11, %16
%18 = phi i8* [ @DT_UNKNOWN, %16 ], [ @DT_DIR, %11 ]
%19 = load i8, i8* %18
ret i8 %19
}