const char *monkey_stringify(unsigned int profile) {
  static const char na[] = "unknown";
  static const char *Names[] = {na,     "Fast",       "Normal",
                                "High", "Extra-High", "Insane"};
  unsigned int profile2 = profile / 1000;
  return (profile2 >= sizeof(Names) / sizeof(*Names)) ? na : Names[(profile2)];
}


x86 assembly (clang, -O0):
<monkey_stringify>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    $0x6,%rax
jb     1133 <monkey_stringify+0x33>
lea    0xed6(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1147 <monkey_stringify+0x47>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
lea    0x2ef1(%rip),%rax
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<monkey_stringify>:
cmp    $0x176f,%edi
jbe    1110 <monkey_stringify+0x10>
lea    0xef1(%rip),%rax
ret
movzwl %di,%eax
shr    $0x3,%eax
imul   $0x20c5,%eax,%eax
shr    $0x14,%eax
lea    0xee2(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret

LLVM IR (-O0):
@monkey_stringify.na = internal constant [8 x i8] c"unknown\00"
@monkey_stringify.Names = internal global [6 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @monkey_stringify.na, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i32 0, i32 0)]
@.str = [5 x i8] c"Fast\00"
@.str.1 = [7 x i8] c"Normal\00"
@.str.2 = [5 x i8] c"High\00"
@.str.3 = [11 x i8] c"Extra-High\00"
@.str.4 = [7 x i8] c"Insane\00"
define i8* @monkey_stringify(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = udiv i32 %4, 1000
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = zext i32 %6 to i64
%8 = icmp uge i64 %7, 6
br i1 %8, label %9, label %10
9: ; preds = %1
br label %15
10: ; preds = %1
%11 = load i32, i32* %3
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds [6 x i8*], [6 x i8*]* @monkey_stringify.Names, i64 0, i64 %12
%14 = load i8*, i8** %13
br label %15
15: ; preds = %10, %9
%16 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @monkey_stringify.na, i64 0, i64 0), %9 ], [ %14, %10 ]
ret i8* %16
}

LLVM IR (-O2):
@monkey_stringify.na = internal constant [8 x i8] c"unknown\00"
@reltable.monkey_stringify = internal unnamed_addr constant [6 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @monkey_stringify.na to i64), i64 ptrtoint ([6 x i32]* @reltable.monkey_stringify to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str to i64), i64 ptrtoint ([6 x i32]* @reltable.monkey_stringify to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.1 to i64), i64 ptrtoint ([6 x i32]* @reltable.monkey_stringify to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.2 to i64), i64 ptrtoint ([6 x i32]* @reltable.monkey_stringify to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.3 to i64), i64 ptrtoint ([6 x i32]* @reltable.monkey_stringify to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.4 to i64), i64 ptrtoint ([6 x i32]* @reltable.monkey_stringify to i64)) to i32)]
@.str = [5 x i8] c"Fast\00"
@.str.1 = [7 x i8] c"Normal\00"
@.str.2 = [5 x i8] c"High\00"
@.str.3 = [11 x i8] c"Extra-High\00"
@.str.4 = [7 x i8] c"Insane\00"
define i8* @monkey_stringify(i32 %0) {
%2 = icmp ugt i32 %0, 5999
br i1 %2, label %9, label %3
3: ; preds = %1
%4 = trunc i32 %0 to i16
%5 = udiv i16 %4, 1000
%6 = zext i16 %5 to i64
%7 = shl i64 %6, 2
%8 = call i8* @llvm.load.relative.i64(i8* bitcast ([6 x i32]* @reltable.monkey_stringify to i8*), i64 %7)
br label %9
9: ; preds = %1, %3
%10 = phi i8* [ %8, %3 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @monkey_stringify.na, i64 0, i64 0), %1 ]
ret i8* %10
}