char *ordinal_century_suffix(int cardinal) {
  if (cardinal < 0) {
    cardinal = -cardinal;
  }
  ++cardinal;
  if ((cardinal % 10 == 1) && (cardinal != 11)) {
    return "st";
  } else if ((cardinal % 10 == 2) && (cardinal != 12)) {
    return "nd";
  } else if ((cardinal % 10 == 3) && (cardinal != 13)) {
    return "rd";
  } else {
    return "th";
  }
}


x86 assembly (clang, -O0):
<ordinal_century_suffix>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1119 <ordinal_century_suffix+0x19>
xor    %eax,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    1150 <ordinal_century_suffix+0x50>
cmpl   $0xb,-0xc(%rbp)
je     1150 <ordinal_century_suffix+0x50>
lea    0xeb9(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b7 <ordinal_century_suffix+0xb7>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x2,%edx
jne    117e <ordinal_century_suffix+0x7e>
cmpl   $0xc,-0xc(%rbp)
je     117e <ordinal_century_suffix+0x7e>
lea    0xe8e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b7 <ordinal_century_suffix+0xb7>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x3,%edx
jne    11ac <ordinal_century_suffix+0xac>
cmpl   $0xd,-0xc(%rbp)
je     11ac <ordinal_century_suffix+0xac>
lea    0xe63(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b7 <ordinal_century_suffix+0xb7>
lea    0xe56(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ordinal_century_suffix>:
mov    %edi,%ecx
neg    %ecx
cmovs  %edi,%ecx
add    $0x1,%ecx
mov    $0xcccccccd,%eax
imul   %rcx,%rax
shr    $0x23,%rax
add    %eax,%eax
lea    (%rax,%rax,4),%edx
mov    %ecx,%eax
sub    %edx,%eax
cmp    $0xb,%ecx
je     1132 <ordinal_century_suffix+0x32>
cmp    $0x1,%eax
jne    1132 <ordinal_century_suffix+0x32>
lea    0xecf(%rip),%rax
ret
cmp    $0xc,%ecx
je     1144 <ordinal_century_suffix+0x44>
cmp    $0x2,%eax
jne    1144 <ordinal_century_suffix+0x44>
lea    0xec0(%rip),%rax
ret
cmp    $0x3,%eax
lea    0xeb8(%rip),%rax
lea    0xeb4(%rip),%rdx
cmovne %rdx,%rax
cmp    $0xd,%ecx
cmove  %rdx,%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* @ordinal_century_suffix(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* %3
%8 = sub nsw i32 0, %7
store i32 %8, i32* %3
br label %9
9: ; preds = %6, %1
%10 = load i32, i32* %3
%11 = add nsw i32 %10, 1
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = srem i32 %12, 10
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %19
15: ; preds = %9
%16 = load i32, i32* %3
%17 = icmp ne i32 %16, 11
br i1 %17, label %18, label %19
18: ; preds = %15
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %2
br label %36
19: ; preds = %15, %9
%20 = load i32, i32* %3
%21 = srem i32 %20, 10
%22 = icmp eq i32 %21, 2
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i32, i32* %3
%25 = icmp ne i32 %24, 12
br i1 %25, label %26, label %27
26: ; preds = %23
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %36
27: ; preds = %23, %19
%28 = load i32, i32* %3
%29 = srem i32 %28, 10
%30 = icmp eq i32 %29, 3
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = load i32, i32* %3
%33 = icmp ne i32 %32, 13
br i1 %33, label %34, label %35
34: ; preds = %31
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %36
35: ; preds = %31, %27
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %36
36: ; preds = %35, %34, %26, %18
%37 = load i8*, i8** %2
ret i8* %37
}

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"
define i8* @ordinal_century_suffix(i32 %0) {
%2 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
%3 = add nuw nsw i32 %2, 1
%4 = urem i32 %3, 10
%5 = icmp eq i32 %4, 1
%6 = icmp ne i32 %3, 11
%7 = and i1 %6, %5
br i1 %7, label %17, label %8
8: ; preds = %1
%9 = icmp eq i32 %4, 2
%10 = icmp ne i32 %3, 12
%11 = and i1 %10, %9
br i1 %11, label %17, label %12
12: ; preds = %8
%13 = icmp eq i32 %4, 3
%14 = icmp ne i32 %3, 13
%15 = and i1 %14, %13
%16 = select i1 %15, 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.3, i64 0, i64 0)
br label %17
17: ; preds = %12, %8, %1
%18 = 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), %8 ], [ %16, %12 ]
ret i8* %18
}