#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
int /*<<< orphan*/ printf(char *, int, int, int);
char *byConstant(struct stat buf) {
  char *fileType;
  printf("%d & %d: %d\t", buf.st_mode, S_IFMT, buf.st_mode & S_IFMT);
  switch (buf.st_mode & S_IFMT) {
  case S_IFREG:
    fileType = "regular";
    break;
  case S_IFDIR:
    fileType = "directory";
    break;
  case S_IFCHR:
    fileType = "character special";
    break;
  case S_IFBLK:
    fileType = "block special";
    break;
  case S_IFIFO:
    fileType = "fifo";
    break;
  case S_IFLNK:
    fileType = "symbolic link";
    break;
  case S_IFSOCK:
    fileType = "socket";
    break;
  default:
    fileType = "unknown";
    break;
  }
  return fileType;
}


x86 assembly (clang, -O0):
<byConstant>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%esi
mov    0x2ebb(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    (%rax),%edx
mov    %esi,%ecx
and    %edx,%ecx
lea    0xee6(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%eax
mov    (%rcx),%ecx
and    %ecx,%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x6,%eax
ja     11dc <byConstant+0xcc>
mov    -0x18(%rbp),%rax
lea    0xe9d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xeb6(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11e7 <byConstant+0xd7>
lea    0xeae(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11e7 <byConstant+0xd7>
lea    0xea8(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11e7 <byConstant+0xd7>
lea    0xeaa(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11e7 <byConstant+0xd7>
lea    0xea8(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11e7 <byConstant+0xd7>
lea    0xe9d(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11e7 <byConstant+0xd7>
lea    0xe9b(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11e7 <byConstant+0xd7>
lea    0xe92(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<byConstant>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2ec3(%rip),%r14
mov    (%r14),%edx
mov    %edx,%ecx
and    %edi,%ecx
lea    0xed5(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
and    (%r14),%ebx
add    $0xffffff80,%ebx
cmp    $0x6,%ebx
ja     1150 <byConstant+0x40>
movslq %ebx,%rax
lea    0xf1d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    1157 <byConstant+0x47>
lea    0xf02(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [13 x i8] c"%d & %d: %d\09\00"
@S_IFMT = global i32 0
@.str.1 = [8 x i8] c"regular\00"
@.str.2 = [10 x i8] c"directory\00"
@.str.3 = [18 x i8] c"character special\00"
@.str.4 = [14 x i8] c"block special\00"
@.str.5 = [5 x i8] c"fifo\00"
@.str.6 = [14 x i8] c"symbolic link\00"
@.str.7 = [7 x i8] c"socket\00"
@.str.8 = [8 x i8] c"unknown\00"
define i8* @byConstant(i32 %0) {
%2 = alloca %struct.stat
%3 = alloca i8*
%4 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
store i32 %0, i32* %4
%5 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%6 = load i32, i32* %5
%7 = load i32, i32* @S_IFMT
%8 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%9 = load i32, i32* %8
%10 = load i32, i32* @S_IFMT
%11 = and i32 %9, %10
%12 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %7, i32 %11)
%13 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%14 = load i32, i32* %13
%15 = load i32, i32* @S_IFMT
%16 = and i32 %14, %15
switch i32 %16, label %24 [
i32 129, label %17
i32 132, label %18
i32 133, label %19
i32 134, label %20
i32 131, label %21
i32 130, label %22
i32 128, label %23
]
17: ; preds = %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %25
18: ; preds = %1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8** %3
br label %25
19: ; preds = %1
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8** %3
br label %25
20: ; preds = %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8** %3
br label %25
21: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8** %3
br label %25
22: ; preds = %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8** %3
br label %25
23: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8** %3
br label %25
24: ; preds = %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8** %3
br label %25
25: ; preds = %24, %23, %22, %21, %20, %19, %18, %17
%26 = load i8*, i8** %3
ret i8* %26
}

LLVM IR (-O2):
@.str = [13 x i8] c"%d & %d: %d\09\00"
@S_IFMT = global i32 0
@.str.1 = [8 x i8] c"regular\00"
@.str.2 = [10 x i8] c"directory\00"
@.str.3 = [18 x i8] c"character special\00"
@.str.4 = [14 x i8] c"block special\00"
@.str.5 = [5 x i8] c"fifo\00"
@.str.6 = [14 x i8] c"symbolic link\00"
@.str.7 = [7 x i8] c"socket\00"
@.str.8 = [8 x i8] c"unknown\00"
@reltable.byConstant = [7 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.7 to i64), i64 ptrtoint ([7 x i32]* @reltable.byConstant to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.1 to i64), i64 ptrtoint ([7 x i32]* @reltable.byConstant to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.6 to i64), i64 ptrtoint ([7 x i32]* @reltable.byConstant to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.5 to i64), i64 ptrtoint ([7 x i32]* @reltable.byConstant to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.2 to i64), i64 ptrtoint ([7 x i32]* @reltable.byConstant to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @.str.3 to i64), i64 ptrtoint ([7 x i32]* @reltable.byConstant to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.4 to i64), i64 ptrtoint ([7 x i32]* @reltable.byConstant to i64)) to i32)]
define i8* @byConstant(i32 %0) {
%2 = load i32, i32* @S_IFMT
%3 = and i32 %2, %0
%4 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %2, i32 %3)
%5 = load i32, i32* @S_IFMT
%6 = and i32 %5, %0
%7 = add i32 %6, -128
%8 = icmp ult i32 %7, 7
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = sext i32 %7 to i64
%11 = shl i64 %10, 2
%12 = call i8* @llvm.load.relative.i64(i8* bitcast ([7 x i32]* @reltable.byConstant to i8*), i64 %11)
br label %13
13: ; preds = %1, %9
%14 = phi i8* [ %12, %9 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), %1 ]
ret i8* %14
}