#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 mode_t;

/* Variables and functions */
#define S_IFBLK 134
#define S_IFCHR 133
#define S_IFDIR 132
#define S_IFIFO 131
#define S_IFLNK 130
int S_IFMT;
#define S_IFREG 129
#define S_IFSOCK 128
char *filetype(mode_t mode) {
  switch (mode & S_IFMT) {
  case S_IFDIR:
    return "directory";
  case S_IFCHR:
    return "C_oriented device file";
  case S_IFBLK:
    return "B_oriented device file";
  case S_IFREG:
    return "regular file";
  case S_IFLNK:
    return "symbolic link";
  case S_IFSOCK:
    return "socket file";
  case S_IFIFO:
    return "pipe file";
  default:
    return NULL;
  }
}


x86 assembly (clang, -O0):
<filetype>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2ecf(%rip),%rcx
mov    (%rcx),%ecx
and    %ecx,%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x6,%eax
ja     11ab <filetype+0xab>
mov    -0x18(%rbp),%rax
lea    0xece(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xeda(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b3 <filetype+0xb3>
lea    0xed4(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b3 <filetype+0xb3>
lea    0xedb(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b3 <filetype+0xb3>
lea    0xee2(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b3 <filetype+0xb3>
lea    0xedf(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b3 <filetype+0xb3>
lea    0xedd(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b3 <filetype+0xb3>
lea    0xed9(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b3 <filetype+0xb3>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<filetype>:
mov    0x2ed9(%rip),%rax
and    (%rax),%edi
add    $0xffffff80,%edi
cmp    $0x6,%edi
ja     1123 <filetype+0x23>
movslq %edi,%rax
lea    0xf51(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
@S_IFMT = global i32 0
@.str = [10 x i8] c"directory\00"
@.str.1 = [23 x i8] c"C_oriented device file\00"
@.str.2 = [23 x i8] c"B_oriented device file\00"
@.str.3 = [13 x i8] c"regular file\00"
@.str.4 = [14 x i8] c"symbolic link\00"
@.str.5 = [12 x i8] c"socket file\00"
@.str.6 = [10 x i8] c"pipe file\00"
define i8* @filetype(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = load i32, i32* @S_IFMT
%6 = and i32 %4, %5
switch i32 %6, label %14 [
i32 132, label %7
i32 133, label %8
i32 134, label %9
i32 129, label %10
i32 130, label %11
i32 128, label %12
i32 131, label %13
]
7: ; preds = %1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %2
br label %15
8: ; preds = %1
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %15
9: ; preds = %1
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %15
10: ; preds = %1
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %15
11: ; preds = %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %15
12: ; preds = %1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %15
13: ; preds = %1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %15
14: ; preds = %1
store i8* null, i8** %2
br label %15
15: ; preds = %14, %13, %12, %11, %10, %9, %8, %7
%16 = load i8*, i8** %2
ret i8* %16
}

LLVM IR (-O2):
@S_IFMT = global i32 0
@.str = [10 x i8] c"directory\00"
@.str.1 = [23 x i8] c"C_oriented device file\00"
@.str.2 = [23 x i8] c"B_oriented device file\00"
@.str.3 = [13 x i8] c"regular file\00"
@.str.4 = [14 x i8] c"symbolic link\00"
@.str.5 = [12 x i8] c"socket file\00"
@.str.6 = [10 x i8] c"pipe file\00"
@reltable.filetype = [7 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.5 to i64), i64 ptrtoint ([7 x i32]* @reltable.filetype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.3 to i64), i64 ptrtoint ([7 x i32]* @reltable.filetype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.4 to i64), i64 ptrtoint ([7 x i32]* @reltable.filetype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.6 to i64), i64 ptrtoint ([7 x i32]* @reltable.filetype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str to i64), i64 ptrtoint ([7 x i32]* @reltable.filetype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([23 x i8]* @.str.1 to i64), i64 ptrtoint ([7 x i32]* @reltable.filetype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([23 x i8]* @.str.2 to i64), i64 ptrtoint ([7 x i32]* @reltable.filetype to i64)) to i32)]
define i8* @filetype(i32 %0) {
%2 = load i32, i32* @S_IFMT
%3 = and i32 %2, %0
%4 = add i32 %3, -128
%5 = icmp ult i32 %4, 7
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = sext i32 %4 to i64
%8 = shl i64 %7, 2
%9 = call i8* @llvm.load.relative.i64(i8* bitcast ([7 x i32]* @reltable.filetype to i8*), i64 %8)
br label %10
10: ; preds = %1, %6
%11 = phi i8* [ %9, %6 ], [ null, %1 ]
ret i8* %11
}