#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 st_mode;
};

/* 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 *mode_to_device_string(struct stat *stat_buffer) {
  switch (stat_buffer->st_mode & S_IFMT) {
  case S_IFBLK:
    return "block device\n";
    break;
  case S_IFCHR:
    return "character device\n";
    break;
  case S_IFDIR:
    return "directory\n";
    break;
  case S_IFIFO:
    return "FIFO/pipe\n";
    break;
  case S_IFLNK:
    return "symlink\n";
    break;
  case S_IFREG:
    return "regular file\n";
    break;
  case S_IFSOCK:
    return "socket\n";
    break;
  default:
    return "unknown?\n";
    break;
  }
}


x86 assembly (clang, -O0):
<mode_to_device_string>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    0x2ecb(%rip),%rcx
mov    (%rcx),%ecx
and    %ecx,%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x6,%eax
ja     11af <mode_to_device_string+0xaf>
mov    -0x18(%rbp),%rax
lea    0xeca(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xed6(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ba <mode_to_device_string+0xba>
lea    0xed4(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ba <mode_to_device_string+0xba>
lea    0xed6(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ba <mode_to_device_string+0xba>
lea    0xed1(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ba <mode_to_device_string+0xba>
lea    0xecc(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ba <mode_to_device_string+0xba>
lea    0xec5(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ba <mode_to_device_string+0xba>
lea    0xec3(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ba <mode_to_device_string+0xba>
lea    0xebb(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<mode_to_device_string>:
mov    0x2ed9(%rip),%rax
mov    (%rax),%eax
and    (%rdi),%eax
add    $0xffffff80,%eax
cmp    $0x6,%eax
ja     1124 <mode_to_device_string+0x24>
cltq
lea    0xf44(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret
lea    0xf2a(%rip),%rax
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@S_IFMT = global i32 0
@.str = [14 x i8] c"block device\0A\00"
@.str.1 = [18 x i8] c"character device\0A\00"
@.str.2 = [11 x i8] c"directory\0A\00"
@.str.3 = [11 x i8] c"FIFO/pipe\0A\00"
@.str.4 = [9 x i8] c"symlink\0A\00"
@.str.5 = [14 x i8] c"regular file\0A\00"
@.str.6 = [8 x i8] c"socket\0A\00"
@.str.7 = [10 x i8] c"unknown?\0A\00"
define i8* @mode_to_device_string(%struct.stat* %0) {
%2 = alloca i8*
%3 = alloca %struct.stat*
store %struct.stat* %0, %struct.stat** %3
%4 = load %struct.stat*, %struct.stat** %3
%5 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%6 = load i32, i32* %5
%7 = load i32, i32* @S_IFMT
%8 = and i32 %6, %7
switch i32 %8, label %16 [
i32 134, label %9
i32 133, label %10
i32 132, label %11
i32 131, label %12
i32 130, label %13
i32 129, label %14
i32 128, label %15
]
9: ; preds = %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %2
br label %17
10: ; preds = %1
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %17
11: ; preds = %1
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %17
12: ; preds = %1
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %17
13: ; preds = %1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %17
14: ; preds = %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %17
15: ; preds = %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %17
16: ; preds = %1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8** %2
br label %17
17: ; preds = %16, %15, %14, %13, %12, %11, %10, %9
%18 = load i8*, i8** %2
ret i8* %18
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@S_IFMT = global i32 0
@.str = [14 x i8] c"block device\0A\00"
@.str.1 = [18 x i8] c"character device\0A\00"
@.str.2 = [11 x i8] c"directory\0A\00"
@.str.3 = [11 x i8] c"FIFO/pipe\0A\00"
@.str.4 = [9 x i8] c"symlink\0A\00"
@.str.5 = [14 x i8] c"regular file\0A\00"
@.str.6 = [8 x i8] c"socket\0A\00"
@.str.7 = [10 x i8] c"unknown?\0A\00"
@reltable.mode_to_device_string = [7 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.6 to i64), i64 ptrtoint ([7 x i32]* @reltable.mode_to_device_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.5 to i64), i64 ptrtoint ([7 x i32]* @reltable.mode_to_device_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.4 to i64), i64 ptrtoint ([7 x i32]* @reltable.mode_to_device_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.3 to i64), i64 ptrtoint ([7 x i32]* @reltable.mode_to_device_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.2 to i64), i64 ptrtoint ([7 x i32]* @reltable.mode_to_device_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @.str.1 to i64), i64 ptrtoint ([7 x i32]* @reltable.mode_to_device_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str to i64), i64 ptrtoint ([7 x i32]* @reltable.mode_to_device_string to i64)) to i32)]
define i8* @mode_to_device_string(%struct.stat* nocapture %0) {
%2 = getelementptr inbounds %struct.stat, %struct.stat* %0, i64 0, i32 0
%3 = load i32, i32* %2
%4 = load i32, i32* @S_IFMT
%5 = and i32 %4, %3
%6 = add i32 %5, -128
%7 = icmp ult i32 %6, 7
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = sext i32 %6 to i64
%10 = shl i64 %9, 2
%11 = call i8* @llvm.load.relative.i64(i8* bitcast ([7 x i32]* @reltable.mode_to_device_string to i8*), i64 %10)
br label %12
12: ; preds = %1, %8
%13 = phi i8* [ %11, %8 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), %1 ]
ret i8* %13
}