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

/* 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_ISREG(int /*<<< orphan*/);
char *filetype(mode_t mode) {
  char *type;
  if (S_ISREG(mode))
    type = "regular file";
  else if (S_ISDIR(mode))
    type = "directory";
  else if (S_ISCHR(mode))
    type = "character special file";
  else if (S_ISBLK(mode))
    type = "block special file";
  else if (S_ISFIFO(mode))
    type = "FIFO";
  else
    type = "unknown";
  return (type);
}


x86 assembly (clang, -O0):
<filetype>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%rax
je     117d <filetype+0x2d>
lea    0xe8c(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1224 <filetype+0xd4>
mov    -0x4(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
je     119f <filetype+0x4f>
lea    0xe77(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    121f <filetype+0xcf>
mov    -0x4(%rbp),%edi
call   1060 <S_ISCHR@plt>
cmp    $0x0,%rax
je     11c1 <filetype+0x71>
lea    0xe5f(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    121a <filetype+0xca>
mov    -0x4(%rbp),%edi
call   1070 <S_ISBLK@plt>
cmp    $0x0,%rax
je     11e3 <filetype+0x93>
lea    0xe54(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1215 <filetype+0xc5>
mov    -0x4(%rbp),%edi
call   1030 <S_ISFIFO@plt>
cmp    $0x0,%rax
je     1205 <filetype+0xb5>
lea    0xe45(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1210 <filetype+0xc0>
lea    0xe3a(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1215 <filetype+0xc5>
jmp    121a <filetype+0xca>
jmp    121f <filetype+0xcf>
jmp    1224 <filetype+0xd4>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filetype>:
push   %rbx
mov    %edi,%ebx
call   1050 <S_ISREG@plt>
test   %rax,%rax
je     1166 <filetype+0x16>
lea    0xe9c(%rip),%rax
pop    %rbx
ret
mov    %ebx,%edi
call   1040 <S_ISDIR@plt>
test   %rax,%rax
je     117b <filetype+0x2b>
lea    0xe94(%rip),%rax
pop    %rbx
ret
mov    %ebx,%edi
call   1060 <S_ISCHR@plt>
test   %rax,%rax
je     1190 <filetype+0x40>
lea    0xe89(%rip),%rax
pop    %rbx
ret
mov    %ebx,%edi
call   1070 <S_ISBLK@plt>
test   %rax,%rax
je     11a5 <filetype+0x55>
lea    0xe8b(%rip),%rax
pop    %rbx
ret
mov    %ebx,%edi
call   1030 <S_ISFIFO@plt>
test   %rax,%rax
lea    0xe90(%rip),%rcx
lea    0xe84(%rip),%rax
cmove  %rcx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"regular file\00"
@.str.1 = [10 x i8] c"directory\00"
@.str.2 = [23 x i8] c"character special file\00"
@.str.3 = [19 x i8] c"block special file\00"
@.str.4 = [5 x i8] c"FIFO\00"
@.str.5 = [8 x i8] c"unknown\00"
define i8* @filetype(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i64 @S_ISREG(i32 %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %3
br label %33
8: ; preds = %1
%9 = load i32, i32* %2
%10 = call i64 @S_ISDIR(i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %8
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %32
13: ; preds = %8
%14 = load i32, i32* %2
%15 = call i64 @S_ISCHR(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8** %3
br label %31
18: ; preds = %13
%19 = load i32, i32* %2
%20 = call i64 @S_ISBLK(i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8** %3
br label %30
23: ; preds = %18
%24 = load i32, i32* %2
%25 = call i64 @S_ISFIFO(i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %23
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8** %3
br label %29
28: ; preds = %23
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8** %3
br label %29
29: ; preds = %28, %27
br label %30
30: ; preds = %29, %22
br label %31
31: ; preds = %30, %17
br label %32
32: ; preds = %31, %12
br label %33
33: ; preds = %32, %7
%34 = load i8*, i8** %3
ret i8* %34
}

LLVM IR (-O2):
@.str = [13 x i8] c"regular file\00"
@.str.1 = [10 x i8] c"directory\00"
@.str.2 = [23 x i8] c"character special file\00"
@.str.3 = [19 x i8] c"block special file\00"
@.str.4 = [5 x i8] c"FIFO\00"
@.str.5 = [8 x i8] c"unknown\00"
define i8* @filetype(i32 %0) {
%2 = tail call i64 @S_ISREG(i32 %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %17
4: ; preds = %1
%5 = tail call i64 @S_ISDIR(i32 %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %17
7: ; preds = %4
%8 = tail call i64 @S_ISCHR(i32 %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = tail call i64 @S_ISBLK(i32 %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = tail call i64 @S_ISFIFO(i32 %0)
%15 = icmp eq i64 %14, 0
%16 = select i1 %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0)
br label %17
17: ; preds = %13, %10, %7, %4, %1
%18 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), %4 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), %7 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), %10 ], [ %16, %13 ]
ret i8* %18
}