#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 st_mode, int flag) {
  switch (st_mode & S_IFMT) {
  case S_IFBLK:
    return (flag == 1) ? "block device" : "b";
  case S_IFCHR:
    return (flag == 1) ? "character device" : "c";
  case S_IFDIR:
    return (flag == 1) ? "directory" : "d";
  case S_IFIFO:
    return (flag == 1) ? "FIFO/pipe" : "p";
  case S_IFLNK:
    return (flag == 1) ? "symlink" : "l";
  case S_IFREG:
    return (flag == 1) ? "regular file" : "-";
  case S_IFSOCK:
    return (flag == 1) ? "socket" : "s";
  default:
    return (flag == 1) ? "unknown" : "?";
  }
}


x86 assembly (clang, -O0):
<filetype>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2ecc(%rip),%rcx
mov    (%rcx),%ecx
and    %ecx,%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x6,%eax
ja     1225 <filetype+0x125>
mov    -0x18(%rbp),%rax
lea    0xecb(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%edx
lea    0xee1(%rip),%rax
lea    0xecd(%rip),%rcx
cmp    $0x1,%edx
cmove  %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    1241 <filetype+0x141>
mov    -0x10(%rbp),%edx
lea    0xed3(%rip),%rax
lea    0xebb(%rip),%rcx
cmp    $0x1,%edx
cmove  %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    1241 <filetype+0x141>
mov    -0x10(%rbp),%edx
lea    0xebe(%rip),%rax
lea    0xead(%rip),%rcx
cmp    $0x1,%edx
cmove  %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    1241 <filetype+0x141>
mov    -0x10(%rbp),%edx
lea    0xea9(%rip),%rax
lea    0xe98(%rip),%rcx
cmp    $0x1,%edx
cmove  %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    1241 <filetype+0x141>
mov    -0x10(%rbp),%edx
lea    0xe92(%rip),%rax
lea    0xe83(%rip),%rcx
cmp    $0x1,%edx
cmove  %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    1241 <filetype+0x141>
mov    -0x10(%rbp),%edx
lea    0xe80(%rip),%rax
lea    0xe6c(%rip),%rcx
cmp    $0x1,%edx
cmove  %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    1241 <filetype+0x141>
mov    -0x10(%rbp),%edx
lea    0xe68(%rip),%rax
lea    0xe5a(%rip),%rcx
cmp    $0x1,%edx
cmove  %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    1241 <filetype+0x141>
mov    -0x10(%rbp),%edx
lea    0xe51(%rip),%rax
lea    0xe42(%rip),%rcx
cmp    $0x1,%edx
cmove  %rcx,%rax
mov    %rax,-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     1137 <filetype+0x37>
lea    0xee8(%rip),%rax
movslq (%rax,%rdi,4),%rcx
add    %rax,%rcx
jmp    *%rcx
cmp    $0x1,%esi
lea    0xf44(%rip),%rcx
lea    0xf44(%rip),%rax
cmove  %rcx,%rax
ret
cmp    $0x1,%esi
lea    0xf37(%rip),%rcx
lea    0xf38(%rip),%rax
cmove  %rcx,%rax
ret
cmp    $0x1,%esi
lea    0xf09(%rip),%rcx
lea    0xf0f(%rip),%rax
cmove  %rcx,%rax
ret
cmp    $0x1,%esi
lea    0xee9(%rip),%rcx
lea    0xeea(%rip),%rax
cmove  %rcx,%rax
ret
cmp    $0x1,%esi
lea    0xec7(%rip),%rcx
lea    0xeca(%rip),%rax
cmove  %rcx,%rax
ret
cmp    $0x1,%esi
lea    0xea5(%rip),%rcx
lea    0xea8(%rip),%rax
cmove  %rcx,%rax
ret
cmp    $0x1,%esi
lea    0xe7c(%rip),%rcx
lea    0xe86(%rip),%rax
cmove  %rcx,%rax
ret
cmp    $0x1,%esi
lea    0xe57(%rip),%rcx
lea    0xe5d(%rip),%rax
cmove  %rcx,%rax
ret

LLVM IR (-O0):
@S_IFMT = global i32 0
@.str = [13 x i8] c"block device\00"
@.str.1 = [2 x i8] c"b\00"
@.str.2 = [17 x i8] c"character device\00"
@.str.3 = [2 x i8] c"c\00"
@.str.4 = [10 x i8] c"directory\00"
@.str.5 = [2 x i8] c"d\00"
@.str.6 = [10 x i8] c"FIFO/pipe\00"
@.str.7 = [2 x i8] c"p\00"
@.str.8 = [8 x i8] c"symlink\00"
@.str.9 = [2 x i8] c"l\00"
@.str.10 = [13 x i8] c"regular file\00"
@.str.11 = [2 x i8] c"-\00"
@.str.12 = [7 x i8] c"socket\00"
@.str.13 = [2 x i8] c"s\00"
@.str.14 = [8 x i8] c"unknown\00"
@.str.15 = [2 x i8] c"?\00"
define i8* @filetype(i32 %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %4
%7 = load i32, i32* @S_IFMT
%8 = and i32 %6, %7
switch i32 %8, label %44 [
i32 134, label %9
i32 133, label %14
i32 132, label %19
i32 131, label %24
i32 130, label %29
i32 129, label %34
i32 128, label %39
]
9: ; preds = %2
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, 1
%12 = zext i1 %11 to i64
%13 = select i1 %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
store i8* %13, i8** %3
br label %49
14: ; preds = %2
%15 = load i32, i32* %5
%16 = icmp eq i32 %15, 1
%17 = zext i1 %16 to i64
%18 = select i1 %16, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0)
store i8* %18, i8** %3
br label %49
19: ; preds = %2
%20 = load i32, i32* %5
%21 = icmp eq i32 %20, 1
%22 = zext i1 %21 to i64
%23 = select i1 %21, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0)
store i8* %23, i8** %3
br label %49
24: ; preds = %2
%25 = load i32, i32* %5
%26 = icmp eq i32 %25, 1
%27 = zext i1 %26 to i64
%28 = select i1 %26, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0)
store i8* %28, i8** %3
br label %49
29: ; preds = %2
%30 = load i32, i32* %5
%31 = icmp eq i32 %30, 1
%32 = zext i1 %31 to i64
%33 = select i1 %31, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0)
store i8* %33, i8** %3
br label %49
34: ; preds = %2
%35 = load i32, i32* %5
%36 = icmp eq i32 %35, 1
%37 = zext i1 %36 to i64
%38 = select i1 %36, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0)
store i8* %38, i8** %3
br label %49
39: ; preds = %2
%40 = load i32, i32* %5
%41 = icmp eq i32 %40, 1
%42 = zext i1 %41 to i64
%43 = select i1 %41, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0)
store i8* %43, i8** %3
br label %49
44: ; preds = %2
%45 = load i32, i32* %5
%46 = icmp eq i32 %45, 1
%47 = zext i1 %46 to i64
%48 = select i1 %46, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.14, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0)
store i8* %48, i8** %3
br label %49
49: ; preds = %44, %39, %34, %29, %24, %19, %14, %9
%50 = load i8*, i8** %3
ret i8* %50
}

LLVM IR (-O2):
@S_IFMT = global i32 0
@.str = [13 x i8] c"block device\00"
@.str.1 = [2 x i8] c"b\00"
@.str.2 = [17 x i8] c"character device\00"
@.str.3 = [2 x i8] c"c\00"
@.str.4 = [10 x i8] c"directory\00"
@.str.5 = [2 x i8] c"d\00"
@.str.6 = [10 x i8] c"FIFO/pipe\00"
@.str.7 = [2 x i8] c"p\00"
@.str.8 = [8 x i8] c"symlink\00"
@.str.9 = [2 x i8] c"l\00"
@.str.10 = [13 x i8] c"regular file\00"
@.str.11 = [2 x i8] c"-\00"
@.str.12 = [7 x i8] c"socket\00"
@.str.13 = [2 x i8] c"s\00"
@.str.14 = [8 x i8] c"unknown\00"
@.str.15 = [2 x i8] c"?\00"
define i8* @filetype(i32 %0, i32 %1) {
%3 = load i32, i32* @S_IFMT
%4 = and i32 %3, %0
switch i32 %4, label %26 [
i32 134, label %5
i32 133, label %8
i32 132, label %11
i32 131, label %14
i32 130, label %17
i32 129, label %20
i32 128, label %23
]
5: ; preds = %2
%6 = icmp eq i32 %1, 1
%7 = select i1 %6, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
br label %29
8: ; preds = %2
%9 = icmp eq i32 %1, 1
%10 = select i1 %9, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0)
br label %29
11: ; preds = %2
%12 = icmp eq i32 %1, 1
%13 = select i1 %12, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0)
br label %29
14: ; preds = %2
%15 = icmp eq i32 %1, 1
%16 = select i1 %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0)
br label %29
17: ; preds = %2
%18 = icmp eq i32 %1, 1
%19 = select i1 %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0)
br label %29
20: ; preds = %2
%21 = icmp eq i32 %1, 1
%22 = select i1 %21, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0)
br label %29
23: ; preds = %2
%24 = icmp eq i32 %1, 1
%25 = select i1 %24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0)
br label %29
26: ; preds = %2
%27 = icmp eq i32 %1, 1
%28 = select i1 %27, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.14, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0)
br label %29
29: ; preds = %26, %23, %20, %17, %14, %11, %8, %5
%30 = phi i8* [ %28, %26 ], [ %25, %23 ], [ %22, %20 ], [ %19, %17 ], [ %16, %14 ], [ %13, %11 ], [ %10, %8 ], [ %7, %5 ]
ret i8* %30
}