#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
const char *getFileType(mode_t mode) {
  switch (mode & S_IFMT) {
  case S_IFBLK:
    return "Block device";
    break;
  case S_IFCHR:
    return "Character device";
    break;
  case S_IFIFO:
    return "FIFO";
    break;
  case S_IFREG:
    return "Regular file";
    break;
  case S_IFDIR:
    return "Directory";
    break;
  case S_IFLNK:
    return "Symbolic link";
    break;
  case S_IFSOCK:
    return "Socket";
    break;
  default:
    return "???";
    break;
  };
}


x86 assembly (clang, -O0):
<getFileType>:
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 <getFileType+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    11b6 <getFileType+0xb6>
lea    0xed7(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b6 <getFileType+0xb6>
lea    0xed8(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b6 <getFileType+0xb6>
lea    0xecd(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b6 <getFileType+0xb6>
lea    0xeca(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b6 <getFileType+0xb6>
lea    0xec4(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b6 <getFileType+0xb6>
lea    0xec2(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b6 <getFileType+0xb6>
lea    0xeb9(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

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

LLVM IR (-O0):
@S_IFMT = global i32 0
@.str = [13 x i8] c"Block device\00"
@.str.1 = [17 x i8] c"Character device\00"
@.str.2 = [5 x i8] c"FIFO\00"
@.str.3 = [13 x i8] c"Regular file\00"
@.str.4 = [10 x i8] c"Directory\00"
@.str.5 = [14 x i8] c"Symbolic link\00"
@.str.6 = [7 x i8] c"Socket\00"
@.str.7 = [4 x i8] c"???\00"
define i8* @getFileType(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 134, label %7
i32 133, label %8
i32 131, label %9
i32 129, label %10
i32 132, label %11
i32 130, label %12
i32 128, label %13
]
7: ; preds = %1
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %2
br label %15
8: ; preds = %1
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %15
9: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 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 ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %15
12: ; preds = %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %15
13: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %15
14: ; preds = %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), 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 = [13 x i8] c"Block device\00"
@.str.1 = [17 x i8] c"Character device\00"
@.str.2 = [5 x i8] c"FIFO\00"
@.str.3 = [13 x i8] c"Regular file\00"
@.str.4 = [10 x i8] c"Directory\00"
@.str.5 = [14 x i8] c"Symbolic link\00"
@.str.6 = [7 x i8] c"Socket\00"
@.str.7 = [4 x i8] c"???\00"
@reltable.getFileType = [7 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.6 to i64), i64 ptrtoint ([7 x i32]* @reltable.getFileType to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.3 to i64), i64 ptrtoint ([7 x i32]* @reltable.getFileType to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.5 to i64), i64 ptrtoint ([7 x i32]* @reltable.getFileType to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.2 to i64), i64 ptrtoint ([7 x i32]* @reltable.getFileType to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.4 to i64), i64 ptrtoint ([7 x i32]* @reltable.getFileType to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([17 x i8]* @.str.1 to i64), i64 ptrtoint ([7 x i32]* @reltable.getFileType to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str to i64), i64 ptrtoint ([7 x i32]* @reltable.getFileType to i64)) to i32)]
define i8* @getFileType(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.getFileType to i8*), i64 %8)
br label %10
10: ; preds = %1, %6
%11 = phi i8* [ %9, %6 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), %1 ]
ret i8* %11
}