#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 132
#define S_IFCHR 131
#define S_IFLNK 130
int S_IFMT;
#define S_IFREG 129
#define S_IFSOCK 128
int /*<<< orphan*/ printf(char *);
void stmode_handler(mode_t mode) {
  switch (mode & S_IFMT) {
  case S_IFREG:
    printf("regular file\n");
    break;
  case S_IFBLK:
    printf("block device file\n");
    break;
  case S_IFCHR:
    printf("char device file\n");
    break;
  case S_IFLNK:
    printf("symbolic link file\n");
    break;
  case S_IFSOCK:
    printf("socket file\n");
    break;
  default:
    printf("unkown file type\n");
    break;
  }
}


x86 assembly (clang, -O0):
<stmode_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2ebb(%rip),%rcx
mov    (%rcx),%ecx
and    %ecx,%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x4,%eax
ja     11a4 <stmode_handler+0x94>
mov    -0x10(%rbp),%rax
lea    0xeba(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xebe(%rip),%rdi
call   1030 <printf@plt>
jmp    11b0 <stmode_handler+0xa0>
lea    0xebb(%rip),%rdi
call   1030 <printf@plt>
jmp    11b0 <stmode_handler+0xa0>
lea    0xebd(%rip),%rdi
call   1030 <printf@plt>
jmp    11b0 <stmode_handler+0xa0>
lea    0xebe(%rip),%rdi
call   1030 <printf@plt>
jmp    11b0 <stmode_handler+0xa0>
lea    0xec1(%rip),%rdi
call   1030 <printf@plt>
jmp    11b0 <stmode_handler+0xa0>
lea    0xebd(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stmode_handler>:
mov    0x2ec9(%rip),%rax
and    (%rax),%edi
add    $0xffffff80,%edi
cmp    $0x4,%edi
ja     1137 <stmode_handler+0x27>
movslq %edi,%rax
lea    0xf35(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
jmp    1030 <puts@plt>
lea    0xf11(%rip),%rdi
jmp    1030 <puts@plt>

LLVM IR (-O0):
@S_IFMT = global i32 0
@.str = [14 x i8] c"regular file\0A\00"
@.str.1 = [19 x i8] c"block device file\0A\00"
@.str.2 = [18 x i8] c"char device file\0A\00"
@.str.3 = [20 x i8] c"symbolic link file\0A\00"
@.str.4 = [13 x i8] c"socket file\0A\00"
@.str.5 = [18 x i8] c"unkown file type\0A\00"
define void @stmode_handler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = load i32, i32* @S_IFMT
%5 = and i32 %3, %4
switch i32 %5, label %16 [
i32 129, label %6
i32 132, label %8
i32 131, label %10
i32 130, label %12
i32 128, label %14
]
6: ; preds = %1
%7 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %18
8: ; preds = %1
%9 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %18
10: ; preds = %1
%11 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %18
12: ; preds = %1
%13 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %18
14: ; preds = %1
%15 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %18
16: ; preds = %1
%17 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %18
18: ; preds = %16, %14, %12, %10, %8, %6
ret void
}

LLVM IR (-O2):
@S_IFMT = global i32 0
@str = [12 x i8] c"socket file\00"
@str.6 = [19 x i8] c"symbolic link file\00"
@str.7 = [17 x i8] c"char device file\00"
@str.8 = [18 x i8] c"block device file\00"
@str.9 = [13 x i8] c"regular file\00"
@str.10 = [17 x i8] c"unkown file type\00"
@reltable.stmode_handler = [5 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @str to i64), i64 ptrtoint ([5 x i32]* @reltable.stmode_handler to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @str.9 to i64), i64 ptrtoint ([5 x i32]* @reltable.stmode_handler to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @str.6 to i64), i64 ptrtoint ([5 x i32]* @reltable.stmode_handler to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([17 x i8]* @str.7 to i64), i64 ptrtoint ([5 x i32]* @reltable.stmode_handler to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @str.8 to i64), i64 ptrtoint ([5 x i32]* @reltable.stmode_handler to i64)) to i32)]
define void @stmode_handler(i32 %0) {
%2 = load i32, i32* @S_IFMT
%3 = and i32 %2, %0
%4 = add i32 %3, -128
%5 = icmp ult i32 %4, 5
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 ([5 x i32]* @reltable.stmode_handler to i8*), i64 %8)
br label %10
10: ; preds = %1, %6
%11 = phi i8* [ %9, %6 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @str.10, i64 0, i64 0), %1 ]
%12 = tail call i32 @puts(i8* dereferenceable(1) %11)
ret void
}