char *Num_sufx(int d) {
  register int i = d % 10;
  if (i == 1 && d != 11)
    return "st";
  else if (i == 2 && d != 12)
    return "nd";
  else if (i == 3 && d != 13)
    return "rd";
  else
    return "th";
}


x86 assembly (clang, -O0):
<Num_sufx>:
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    1139 <Num_sufx+0x39>
cmpl   $0xb,-0xc(%rbp)
je     1139 <Num_sufx+0x39>
lea    0xed0(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    118c <Num_sufx+0x8c>
cmpl   $0x2,-0x10(%rbp)
jne    115d <Num_sufx+0x5d>
cmpl   $0xc,-0xc(%rbp)
je     115d <Num_sufx+0x5d>
lea    0xeaf(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    118c <Num_sufx+0x8c>
cmpl   $0x3,-0x10(%rbp)
jne    1181 <Num_sufx+0x81>
cmpl   $0xd,-0xc(%rbp)
je     1181 <Num_sufx+0x81>
lea    0xe8e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    118c <Num_sufx+0x8c>
lea    0xe81(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<Num_sufx>:
movslq %edi,%rcx
imul   $0x66666667,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rax
add    %edx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%edx
mov    %ecx,%eax
sub    %edx,%eax
cmp    $0xb,%ecx
je     1132 <Num_sufx+0x32>
cmp    $0x1,%eax
jne    1132 <Num_sufx+0x32>
lea    0xecf(%rip),%rax
ret
cmp    $0xc,%edi
je     1144 <Num_sufx+0x44>
cmp    $0x2,%eax
jne    1144 <Num_sufx+0x44>
lea    0xec0(%rip),%rax
ret
cmp    $0x3,%eax
lea    0xeb8(%rip),%rax
lea    0xeb4(%rip),%rcx
cmovne %rcx,%rax
cmp    $0xd,%edi
cmove  %rcx,%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* @Num_sufx(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 %13
9: ; preds = %1
%10 = load i32, i32* %3
%11 = icmp ne i32 %10, 11
br i1 %11, label %12, label %13
12: ; preds = %9
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %2
br label %28
13: ; preds = %9, %1
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 2
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i32, i32* %3
%18 = icmp ne i32 %17, 12
br i1 %18, label %19, label %20
19: ; preds = %16
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %28
20: ; preds = %16, %13
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 3
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32, i32* %3
%25 = icmp ne i32 %24, 13
br i1 %25, label %26, label %27
26: ; preds = %23
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %28
27: ; preds = %23, %20
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %28
28: ; preds = %27, %26, %19, %12
%29 = load i8*, i8** %2
ret i8* %29
}

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* @Num_sufx(i32 %0) {
%2 = srem i32 %0, 10
%3 = icmp eq i32 %2, 1
%4 = icmp ne i32 %0, 11
%5 = and i1 %4, %3
br i1 %5, label %15, label %6
6: ; preds = %1
%7 = icmp eq i32 %2, 2
%8 = icmp ne i32 %0, 12
%9 = and i1 %8, %7
br i1 %9, label %15, label %10
10: ; preds = %6
%11 = icmp eq i32 %2, 3
%12 = icmp ne i32 %0, 13
%13 = and 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.3, i64 0, i64 0)
br label %15
15: ; preds = %10, %6, %1
%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), %6 ], [ %14, %10 ]
ret i8* %16
}