#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 */
int /*<<< orphan*/ SPC_MSG(int, char *);
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*/ errno;
scalar_t__ lstat(char const *, struct stat *);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int /*<<< orphan*/);
void print_file_type(const char *path) {
  struct stat buf;
  char file_type[30];
  memset(file_type, 0x00, 30);
  if (lstat(path, &buf) < 0) {
    SPC_MSG(2, strerror(errno));
    return;
  }
  if (S_ISREG(buf.st_mode)) {
    strcpy(file_type, "Regular file");
  } else if (S_ISDIR(buf.st_mode)) {
    strcpy(file_type, "Directory");
  } else if (S_ISCHR(buf.st_mode)) {
    strcpy(file_type, "Character device");
  } else if (S_ISBLK(buf.st_mode)) {
    strcpy(file_type, "Block device");
  } else if (S_ISFIFO(buf.st_mode)) {
    strcpy(file_type, "FIFO");
  } else if (S_ISLNK(buf.st_mode)) {
    strcpy(file_type, "Symbolic link");
  } else if (S_ISSOCK(buf.st_mode)) {
    strcpy(file_type, "SOCKET");
  }
  SPC_MSG(0, file_type);
  return;
}


x86 assembly (clang, -O0):
<print_file_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x1e,%edx
call   1080 <memset@plt>
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1090 <lstat@plt>
cmp    $0x0,%rax
jge    1213 <print_file_type+0x53>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    %rax,%rsi
mov    $0x2,%edi
call   10a0 <SPC_MSG@plt>
jmp    1348 <print_file_type+0x188>
mov    -0x10(%rbp),%edi
call   10b0 <S_ISREG@plt>
cmp    $0x0,%rax
je     123a <print_file_type+0x7a>
lea    -0x30(%rbp),%rdi
lea    0xdd0(%rip),%rsi
call   1030 <strcpy@plt>
jmp    133d <print_file_type+0x17d>
mov    -0x10(%rbp),%edi
call   1070 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1261 <print_file_type+0xa1>
lea    -0x30(%rbp),%rdi
lea    0xdb6(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1338 <print_file_type+0x178>
mov    -0x10(%rbp),%edi
call   10c0 <S_ISCHR@plt>
cmp    $0x0,%rax
je     1288 <print_file_type+0xc8>
lea    -0x30(%rbp),%rdi
lea    0xd99(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1333 <print_file_type+0x173>
mov    -0x10(%rbp),%edi
call   10d0 <S_ISBLK@plt>
cmp    $0x0,%rax
je     12af <print_file_type+0xef>
lea    -0x30(%rbp),%rdi
lea    0xd83(%rip),%rsi
call   1030 <strcpy@plt>
jmp    132e <print_file_type+0x16e>
mov    -0x10(%rbp),%edi
call   1050 <S_ISFIFO@plt>
cmp    $0x0,%rax
je     12d6 <print_file_type+0x116>
lea    -0x30(%rbp),%rdi
lea    0xd69(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1329 <print_file_type+0x169>
mov    -0x10(%rbp),%edi
call   1040 <S_ISLNK@plt>
cmp    $0x0,%rax
je     12fd <print_file_type+0x13d>
lea    -0x30(%rbp),%rdi
lea    0xd47(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1324 <print_file_type+0x164>
mov    -0x10(%rbp),%edi
call   1060 <S_ISSOCK@plt>
cmp    $0x0,%rax
je     131f <print_file_type+0x15f>
lea    -0x30(%rbp),%rdi
lea    0xd2e(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1324 <print_file_type+0x164>
jmp    1329 <print_file_type+0x169>
jmp    132e <print_file_type+0x16e>
jmp    1333 <print_file_type+0x173>
jmp    1338 <print_file_type+0x178>
jmp    133d <print_file_type+0x17d>
lea    -0x30(%rbp),%rsi
xor    %edi,%edi
call   10a0 <SPC_MSG@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_file_type>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x1e,%edx
call   1080 <memset@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <lstat@plt>
test   %rax,%rax
js     1207 <print_file_type+0x47>
mov    0x8(%rsp),%ebx
mov    %ebx,%edi
call   10b0 <S_ISREG@plt>
test   %rax,%rax
je     1222 <print_file_type+0x62>
lea    0xdfe(%rip),%rsi
jmp    129e <print_file_type+0xde>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    $0x2,%edi
mov    %rax,%rsi
jmp    12af <print_file_type+0xef>
mov    %ebx,%edi
call   1070 <S_ISDIR@plt>
test   %rax,%rax
je     1237 <print_file_type+0x77>
lea    0xdd8(%rip),%rsi
jmp    129e <print_file_type+0xde>
mov    %ebx,%edi
call   10c0 <S_ISCHR@plt>
test   %rax,%rax
je     124c <print_file_type+0x8c>
lea    0xdcd(%rip),%rsi
jmp    129e <print_file_type+0xde>
mov    %ebx,%edi
call   10d0 <S_ISBLK@plt>
test   %rax,%rax
je     1261 <print_file_type+0xa1>
lea    0xdc9(%rip),%rsi
jmp    129e <print_file_type+0xde>
mov    %ebx,%edi
call   1050 <S_ISFIFO@plt>
test   %rax,%rax
je     1276 <print_file_type+0xb6>
lea    0xdc1(%rip),%rsi
jmp    129e <print_file_type+0xde>
mov    %ebx,%edi
call   1040 <S_ISLNK@plt>
test   %rax,%rax
je     128b <print_file_type+0xcb>
lea    0xdb1(%rip),%rsi
jmp    129e <print_file_type+0xde>
mov    %ebx,%edi
call   1060 <S_ISSOCK@plt>
test   %rax,%rax
je     12a8 <print_file_type+0xe8>
lea    0xdaa(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1030 <strcpy@plt>
lea    0x10(%rsp),%rsi
xor    %edi,%edi
call   10a0 <SPC_MSG@plt>
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@errno = global i32 0
@.str = [13 x i8] c"Regular file\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 = [14 x i8] c"Symbolic link\00"
@.str.6 = [7 x i8] c"SOCKET\00"
define void @print_file_type(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.stat
%4 = alloca [30 x i8]
store i8* %0, i8** %2
%5 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 30)
%7 = load i8*, i8** %2
%8 = call i64 @lstat(i8* %7, %struct.stat* %3)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @SPC_MSG(i32 2, i8* %12)
br label %79
14: ; preds = %1
%15 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i64 @S_ISREG(i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%21 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %76
22: ; preds = %14
%23 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i64 @S_ISDIR(i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%29 = call i32 @strcpy(i8* %28, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %75
30: ; preds = %22
%31 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%32 = load i32, i32* %31
%33 = call i64 @S_ISCHR(i32 %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%37 = call i32 @strcpy(i8* %36, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %74
38: ; preds = %30
%39 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i64 @S_ISBLK(i32 %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %38
%44 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%45 = call i32 @strcpy(i8* %44, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %73
46: ; preds = %38
%47 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%48 = load i32, i32* %47
%49 = call i64 @S_ISFIFO(i32 %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %46
%52 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%53 = call i32 @strcpy(i8* %52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %72
54: ; preds = %46
%55 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%56 = load i32, i32* %55
%57 = call i64 @S_ISLNK(i32 %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %54
%60 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%61 = call i32 @strcpy(i8* %60, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %71
62: ; preds = %54
%63 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%64 = load i32, i32* %63
%65 = call i64 @S_ISSOCK(i32 %64)
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %62
%68 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%69 = call i32 @strcpy(i8* %68, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %70
70: ; preds = %67, %62
br label %71
71: ; preds = %70, %59
br label %72
72: ; preds = %71, %51
br label %73
73: ; preds = %72, %43
br label %74
74: ; preds = %73, %35
br label %75
75: ; preds = %74, %27
br label %76
76: ; preds = %75, %19
%77 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%78 = call i32 @SPC_MSG(i32 0, i8* %77)
br label %79
79: ; preds = %76, %10
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@errno = global i32 0
@.str = [13 x i8] c"Regular file\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 = [14 x i8] c"Symbolic link\00"
@.str.6 = [7 x i8] c"SOCKET\00"
define void @print_file_type(i8* nocapture %0) {
%2 = alloca %struct.stat
%3 = alloca [30 x i8]
%4 = bitcast %struct.stat* %2 to i8*
%5 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 30)
%7 = call i64 @lstat(i8* %0, %struct.stat* %2)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i32, i32* @errno
%11 = call i8* @strerror(i32 %10)
%12 = call i32 @SPC_MSG(i32 2, i8* %11)
br label %41
13: ; preds = %1
%14 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%15 = load i32, i32* %14
%16 = call i64 @S_ISREG(i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %36
18: ; preds = %13
%19 = call i64 @S_ISDIR(i32 %15)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %36
21: ; preds = %18
%22 = call i64 @S_ISCHR(i32 %15)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %36
24: ; preds = %21
%25 = call i64 @S_ISBLK(i32 %15)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %36
27: ; preds = %24
%28 = call i64 @S_ISFIFO(i32 %15)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = call i64 @S_ISLNK(i32 %15)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = call i64 @S_ISSOCK(i32 %15)
%35 = icmp eq i64 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %33, %30, %27, %24, %21, %18, %13
%37 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %13 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), %18 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), %21 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), %24 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), %27 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), %30 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), %33 ]
%38 = call i32 @strcpy(i8* %5, i8* %37)
br label %39
39: ; preds = %36, %33
%40 = call i32 @SPC_MSG(i32 0, i8* %5)
br label %41
41: ; preds = %39, %9
ret void
}