#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_ISBLK(int /*<<< orphan*/);
scalar_t__ S_ISCHR(int /*<<< orphan*/);
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ S_ISFIFO(int /*<<< orphan*/);
scalar_t__ S_ISLNK(int /*<<< orphan*/);
scalar_t__ S_ISREG(int /*<<< orphan*/);
scalar_t__ S_ISSOCK(int /*<<< orphan*/);
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ lstat(char const *, struct stat *);
const char *get_file_type(const char *path) {
  struct stat st;
  lstat(path, &st);
  if (S_ISLNK(st.st_mode))
    return "symbolic link";
  else if (S_ISDIR(st.st_mode))
    return "directory";
  else if (S_ISCHR(st.st_mode))
    return "character device";
  else if (S_ISBLK(st.st_mode))
    return "block device";
  else if (S_ISFIFO(st.st_mode))
    return "fifo";
  else if (S_ISSOCK(st.st_mode))
    return "socket";
  else if (S_ISREG(st.st_mode))
    return "regular file";
  else
    assert(0);
}


x86 assembly (clang, -O0):
<get_file_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <lstat@plt>
mov    -0x18(%rbp),%edi
call   1030 <S_ISLNK@plt>
cmp    $0x0,%rax
je     11cb <get_file_type+0x3b>
lea    0xe3e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12bc <get_file_type+0x12c>
mov    -0x18(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11ed <get_file_type+0x5d>
lea    0xe2a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12bc <get_file_type+0x12c>
mov    -0x18(%rbp),%edi
call   10a0 <S_ISCHR@plt>
cmp    $0x0,%rax
je     120f <get_file_type+0x7f>
lea    0xe12(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12bc <get_file_type+0x12c>
mov    -0x18(%rbp),%edi
call   10b0 <S_ISBLK@plt>
cmp    $0x0,%rax
je     1231 <get_file_type+0xa1>
lea    0xe01(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12bc <get_file_type+0x12c>
mov    -0x18(%rbp),%edi
call   1040 <S_ISFIFO@plt>
cmp    $0x0,%rax
je     1253 <get_file_type+0xc3>
lea    0xdec(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12bc <get_file_type+0x12c>
mov    -0x18(%rbp),%edi
call   1050 <S_ISSOCK@plt>
cmp    $0x0,%rax
je     1275 <get_file_type+0xe5>
lea    0xdcf(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12bc <get_file_type+0x12c>
mov    -0x18(%rbp),%edi
call   1090 <S_ISREG@plt>
cmp    $0x0,%rax
je     1297 <get_file_type+0x107>
lea    0xdb4(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12bc <get_file_type+0x12c>
xor    %edi,%edi
call   1080 <assert@plt>
jmp    12a3 <get_file_type+0x113>
jmp    12a8 <get_file_type+0x118>
jmp    12ad <get_file_type+0x11d>
jmp    12b2 <get_file_type+0x122>
jmp    12b7 <get_file_type+0x127>
jmp    12bc <get_file_type+0x12c>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_type>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rsi
call   1070 <lstat@plt>
mov    0x8(%rsp),%ebx
mov    %ebx,%edi
call   1030 <S_ISLNK@plt>
test   %rax,%rax
je     11bb <get_file_type+0x2b>
lea    0xe4a(%rip),%rax
jmp    1240 <get_file_type+0xb0>
mov    %ebx,%edi
call   1060 <S_ISDIR@plt>
test   %rax,%rax
je     11d0 <get_file_type+0x40>
lea    0xe40(%rip),%rax
jmp    1240 <get_file_type+0xb0>
mov    %ebx,%edi
call   10a0 <S_ISCHR@plt>
test   %rax,%rax
je     11e5 <get_file_type+0x55>
lea    0xe35(%rip),%rax
jmp    1240 <get_file_type+0xb0>
mov    %ebx,%edi
call   10b0 <S_ISBLK@plt>
test   %rax,%rax
je     11fa <get_file_type+0x6a>
lea    0xe31(%rip),%rax
jmp    1240 <get_file_type+0xb0>
mov    %ebx,%edi
call   1040 <S_ISFIFO@plt>
test   %rax,%rax
je     120f <get_file_type+0x7f>
lea    0xe29(%rip),%rax
jmp    1240 <get_file_type+0xb0>
mov    %ebx,%edi
call   1050 <S_ISSOCK@plt>
test   %rax,%rax
je     1224 <get_file_type+0x94>
lea    0xe19(%rip),%rax
jmp    1240 <get_file_type+0xb0>
mov    %ebx,%edi
call   1090 <S_ISREG@plt>
test   %rax,%rax
je     1239 <get_file_type+0xa9>
lea    0xe0b(%rip),%rax
jmp    1240 <get_file_type+0xb0>
xor    %edi,%edi
call   1080 <assert@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [14 x i8] c"symbolic link\00"
@.str.1 = [10 x i8] c"directory\00"
@.str.2 = [17 x i8] c"character device\00"
@.str.3 = [13 x i8] c"block device\00"
@.str.4 = [5 x i8] c"fifo\00"
@.str.5 = [7 x i8] c"socket\00"
@.str.6 = [13 x i8] c"regular file\00"
define i8* @get_file_type(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca %struct.stat
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @lstat(i8* %5, %struct.stat* %4)
%7 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%8 = load i32, i32* %7
%9 = call i64 @S_ISLNK(i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %2
br label %56
12: ; preds = %1
%13 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i64 @S_ISDIR(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %56
18: ; preds = %12
%19 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i64 @S_ISCHR(i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %56
24: ; preds = %18
%25 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i64 @S_ISBLK(i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %24
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %56
30: ; preds = %24
%31 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%32 = load i32, i32* %31
%33 = call i64 @S_ISFIFO(i32 %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %30
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %56
36: ; preds = %30
%37 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%38 = load i32, i32* %37
%39 = call i64 @S_ISSOCK(i32 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %36
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %56
42: ; preds = %36
%43 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%44 = load i32, i32* %43
%45 = call i64 @S_ISREG(i32 %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %42
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %56
48: ; preds = %42
%49 = call i32 @assert(i32 0)
br label %50
50: ; preds = %48
br label %51
51: ; preds = %50
br label %52
52: ; preds = %51
br label %53
53: ; preds = %52
br label %54
54: ; preds = %53
br label %55
55: ; preds = %54
br label %56
56: ; preds = %11, %17, %23, %29, %35, %41, %47, %55
%57 = load i8*, i8** %2
ret i8* %57
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [14 x i8] c"symbolic link\00"
@.str.1 = [10 x i8] c"directory\00"
@.str.2 = [17 x i8] c"character device\00"
@.str.3 = [13 x i8] c"block device\00"
@.str.4 = [5 x i8] c"fifo\00"
@.str.5 = [7 x i8] c"socket\00"
@.str.6 = [13 x i8] c"regular file\00"
define i8* @get_file_type(i8* nocapture %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @lstat(i8* %0, %struct.stat* %2)
%5 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%6 = load i32, i32* %5
%7 = tail call i64 @S_ISLNK(i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %29
9: ; preds = %1
%10 = tail call i64 @S_ISDIR(i32 %6)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %29
12: ; preds = %9
%13 = tail call i64 @S_ISCHR(i32 %6)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %29
15: ; preds = %12
%16 = tail call i64 @S_ISBLK(i32 %6)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %15
%19 = tail call i64 @S_ISFIFO(i32 %6)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %18
%22 = tail call i64 @S_ISSOCK(i32 %6)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = tail call i64 @S_ISREG(i32 %6)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = tail call i32 @assert(i32 0)
br label %29
29: ; preds = %24, %21, %18, %15, %12, %9, %1, %27
%30 = phi i8* [ undef, %27 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), %9 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), %12 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), %15 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), %18 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), %21 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), %24 ]
ret i8* %30
}