const char *suffix(int n) {
  n %= 100;
  const char *s123[] = {"th", "st", "nd", "rd"};
  if (n % 10 <= 3 && n / 10 != 1)
    return s123[n % 10];
  return s123[0];
}


x86 assembly (clang, -O0):
<suffix>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    0x2d14(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d11(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2d0e(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2d0b(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x3,%edx
jg     1185 <suffix+0x85>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x1,%eax
je     1185 <suffix+0x85>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    -0x30(%rbp,%rax,8),%rax
mov    %rax,-0x8(%rbp)
jmp    118d <suffix+0x8d>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<suffix>:
movslq %edi,%rcx
imul   $0x51eb851f,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rax
add    %edx,%eax
imul   $0x64,%eax,%edx
sub    %edx,%ecx
movsbl %cl,%eax
imul   $0x67,%eax,%eax
movzwl %ax,%eax
movswl %ax,%esi
shr    $0xf,%eax
shr    $0xa,%esi
add    %al,%sil
movzbl %sil,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %al,%cl
lea    0xebd(%rip),%rax
cmp    $0x3,%cl
jg     1166 <suffix+0x66>
neg    %edx
add    %edi,%edx
add    $0xfffffff6,%edx
cmp    $0xa,%edx
jb     1166 <suffix+0x66>
movsbq %cl,%rax
lea    0xead(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret

LLVM IR (-O0):
@.str = [3 x i8] c"th\00"
@.str.1 = [3 x i8] c"st\00"
@.str.2 = [3 x i8] c"nd\00"
@.str.3 = [3 x i8] c"rd\00"
@__const.suffix.s123 = [4 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i32 0, i32 0)]
define i8* @suffix(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [4 x i8*]
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = srem i32 %5, 100
store i32 %6, i32* %3
%7 = bitcast [4 x i8*]* %4 to i8*
%8 = load i32, i32* %3
%9 = srem i32 %8, 10
%10 = icmp sle i32 %9, 3
br i1 %10, label %11, label %21
11: ; preds = %1
%12 = load i32, i32* %3
%13 = sdiv i32 %12, 10
%14 = icmp ne i32 %13, 1
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = load i32, i32* %3
%17 = srem i32 %16, 10
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 %18
%20 = load i8*, i8** %19
store i8* %20, i8** %2
br label %24
21: ; preds = %11, %1
%22 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 0
%23 = load i8*, i8** %22
store i8* %23, i8** %2
br label %24
24: ; preds = %21, %15
%25 = load i8*, i8** %2
ret i8* %25
}

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