const char *shit(int n) {
  if (n % 100 == 11 || n % 100 == 12)
    return "th";
  if (n % 10 == 1 || n == 1)
    return "st";
  if (n % 10 == 2 || n == 2)
    return "nd";
  return "th";
}


x86 assembly (clang, -O0):
<shit>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0xb,%edx
je     112f <shit+0x2f>
mov    -0xc(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0xc,%edx
jne    113f <shit+0x3f>
lea    0xeca(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11a6 <shit+0xa6>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
je     115d <shit+0x5d>
cmpl   $0x1,-0xc(%rbp)
jne    116d <shit+0x6d>
lea    0xe9f(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11a6 <shit+0xa6>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x2,%edx
je     118b <shit+0x8b>
cmpl   $0x2,-0xc(%rbp)
jne    119b <shit+0x9b>
lea    0xe74(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11a6 <shit+0xa6>
lea    0xe5e(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<shit>:
movslq %edi,%rcx
imul   $0x51eb851f,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rax
add    %edx,%eax
imul   $0x64,%eax,%eax
neg    %eax
add    %ecx,%eax
add    $0xfffffff5,%eax
cmp    $0x2,%eax
jae    112e <shit+0x2e>
lea    0xed3(%rip),%rax
ret
lea    0xece(%rip),%rax
cmp    $0x1,%edi
je     1176 <shit+0x76>
imul   $0x66666667,%rcx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x22,%rdx
add    %esi,%edx
add    %edx,%edx
lea    (%rdx,%rdx,4),%edx
sub    %edx,%ecx
cmp    $0x1,%ecx
je     1176 <shit+0x76>
cmp    $0x2,%ecx
lea    0xea2(%rip),%rcx
lea    0xe95(%rip),%rax
cmove  %rcx,%rax
cmp    $0x2,%edi
cmove  %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"
define i8* @shit(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = srem i32 %4, 100
%6 = icmp eq i32 %5, 11
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = load i32, i32* %3
%9 = srem i32 %8, 100
%10 = icmp eq i32 %9, 12
br i1 %10, label %11, label %12
11: ; preds = %7, %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %2
br label %29
12: ; preds = %7
%13 = load i32, i32* %3
%14 = srem i32 %13, 10
%15 = icmp eq i32 %14, 1
br i1 %15, label %19, label %16
16: ; preds = %12
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %20
19: ; preds = %16, %12
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %29
20: ; preds = %16
%21 = load i32, i32* %3
%22 = srem i32 %21, 10
%23 = icmp eq i32 %22, 2
br i1 %23, label %27, label %24
24: ; preds = %20
%25 = load i32, i32* %3
%26 = icmp eq i32 %25, 2
br i1 %26, label %27, label %28
27: ; preds = %24, %20
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %29
28: ; preds = %24
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %2
br label %29
29: ; preds = %28, %27, %19, %11
%30 = load i8*, i8** %2
ret i8* %30
}

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"
define i8* @shit(i32 %0) {
%2 = srem i32 %0, 100
%3 = add nsw i32 %2, -11
%4 = icmp ult i32 %3, 2
br i1 %4, label %15, label %5
5: ; preds = %1
%6 = srem i32 %0, 10
%7 = icmp eq i32 %6, 1
%8 = icmp eq i32 %0, 1
%9 = or i1 %8, %7
br i1 %9, label %15, label %10
10: ; preds = %5
%11 = icmp eq i32 %6, 2
%12 = icmp eq i32 %0, 2
%13 = or i1 %12, %11
%14 = select i1 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0)
br label %15
15: ; preds = %1, %10, %5
%16 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %5 ], [ %14, %10 ]
ret i8* %16
}