const char *enumstr(int i) {
  int last = i % 10;
  if (last == 1)
    return "st";
  if (last == 2)
    return "nd";
  if (last == 3)
    return "rd";
  return "th";
}


x86 assembly (clang, -O0):
<enumstr>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jne    112f <enumstr+0x2f>
lea    0xeda(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    116e <enumstr+0x6e>
cmpl   $0x2,-0x10(%rbp)
jne    1149 <enumstr+0x49>
lea    0xec3(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    116e <enumstr+0x6e>
cmpl   $0x3,-0x10(%rbp)
jne    1163 <enumstr+0x63>
lea    0xeac(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    116e <enumstr+0x6e>
lea    0xe9f(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<enumstr>:
movslq %edi,%rax
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
not    %ecx
add    %ecx,%eax
cmp    $0x2,%eax
ja     1136 <enumstr+0x36>
cltq
lea    0xede(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret
lea    0xecc(%rip),%rax
ret

LLVM IR (-O0):
@.str = [3 x i8] c"st\00"
@.str.1 = [3 x i8] c"nd\00"
@.str.2 = [3 x i8] c"rd\00"
@.str.3 = [3 x i8] c"th\00"
define i8* @enumstr(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = srem i32 %5, 10
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %2
br label %19
10: ; preds = %1
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 2
br i1 %12, label %13, label %14
13: ; preds = %10
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %19
14: ; preds = %10
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 3
br i1 %16, label %17, label %18
17: ; preds = %14
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %19
18: ; preds = %14
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %19
19: ; preds = %18, %17, %13, %9
%20 = load i8*, i8** %2
ret i8* %20
}

LLVM IR (-O2):
@.str = [3 x i8] c"st\00"
@.str.1 = [3 x i8] c"nd\00"
@.str.2 = [3 x i8] c"rd\00"
@.str.3 = [3 x i8] c"th\00"
@reltable.enumstr = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str to i64), i64 ptrtoint ([3 x i32]* @reltable.enumstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.1 to i64), i64 ptrtoint ([3 x i32]* @reltable.enumstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.enumstr to i64)) to i32)]
define i8* @enumstr(i32 %0) {
%2 = srem i32 %0, 10
%3 = add nsw i32 %2, -1
%4 = icmp ult i32 %3, 3
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = sext i32 %3 to i64
%7 = shl i64 %6, 2
%8 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.enumstr to i8*), i64 %7)
br label %9
9: ; preds = %1, %5
%10 = phi i8* [ %8, %5 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), %1 ]
ret i8* %10
}