#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int abs(int);
char *ordinal_suffix(int number) {
  int ones = abs(number) % 10;
  int is_not_ten = (abs(number) % 100 / 10) != 1;
  return (ones == 1 && is_not_ten   ? "st"
          : ones == 2 && is_not_ten ? "nd"
          : ones == 3 && is_not_ten ? "rd"
                                    : "th");
}


x86 assembly (clang, -O0):
<ordinal_suffix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <abs@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <abs@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x1,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    117a <ordinal_suffix+0x6a>
cmpl   $0x0,-0xc(%rbp)
je     117a <ordinal_suffix+0x6a>
lea    0xe8f(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11db <ordinal_suffix+0xcb>
cmpl   $0x2,-0x8(%rbp)
jne    119e <ordinal_suffix+0x8e>
cmpl   $0x0,-0xc(%rbp)
je     119e <ordinal_suffix+0x8e>
lea    0xe6e(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11d3 <ordinal_suffix+0xc3>
xor    %eax,%eax
cmpl   $0x3,-0x8(%rbp)
mov    %al,-0x21(%rbp)
jne    11b7 <ordinal_suffix+0xa7>
cmpl   $0x0,-0xc(%rbp)
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%dl
lea    0xe48(%rip),%rax
lea    0xe3e(%rip),%rcx
test   $0x1,%dl
cmovne %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ordinal_suffix>:
mov    %edi,%ecx
neg    %ecx
cmovs  %edi,%ecx
mov    $0xcccccccd,%eax
imul   %rcx,%rax
shr    $0x23,%rax
add    %eax,%eax
lea    (%rax,%rax,4),%edx
imul   $0x51eb851f,%rcx,%rax
shr    $0x25,%rax
imul   $0x64,%eax,%eax
neg    %eax
add    %ecx,%eax
add    $0xffffffec,%eax
sub    %edx,%ecx
cmp    $0x1,%ecx
jne    1142 <ordinal_suffix+0x42>
cmp    $0xfffffff6,%eax
jae    1142 <ordinal_suffix+0x42>
lea    0xebf(%rip),%rax
ret
cmp    $0x2,%ecx
jne    1154 <ordinal_suffix+0x54>
cmp    $0xfffffff6,%eax
jae    1154 <ordinal_suffix+0x54>
lea    0xeb0(%rip),%rax
ret
cmp    $0xfffffff6,%eax
lea    0xea8(%rip),%rax
lea    0xea4(%rip),%rdx
cmovae %rdx,%rax
cmp    $0x3,%ecx
cmovne %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_suffix(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i32 @abs(i32 %5)
%7 = srem i32 %6, 10
store i32 %7, i32* %3
%8 = load i32, i32* %2
%9 = call i32 @abs(i32 %8)
%10 = srem i32 %9, 100
%11 = sdiv i32 %10, 10
%12 = icmp ne i32 %11, 1
%13 = zext i1 %12 to i32
store i32 %13, i32* %4
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %20
16: ; preds = %1
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16
br label %39
20: ; preds = %16, %1
%21 = load i32, i32* %3
%22 = icmp eq i32 %21, 2
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32, i32* %4
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %23
br label %37
27: ; preds = %23, %20
%28 = load i32, i32* %3
%29 = icmp eq i32 %28, 3
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32, i32* %4
%32 = icmp ne i32 %31, 0
br label %33
33: ; preds = %30, %27
%34 = phi i1 [ false, %27 ], [ %32, %30 ]
%35 = zext i1 %34 to i64
%36 = select i1 %34, 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 %37
37: ; preds = %33, %26
%38 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %26 ], [ %36, %33 ]
br label %39
39: ; preds = %37, %19
%40 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %19 ], [ %38, %37 ]
ret i8* %40
}

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_suffix(i32 %0) {
%2 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
%3 = urem i32 %2, 10
%4 = urem i32 %2, 100
%5 = add nsw i32 %4, -20
%6 = icmp ult i32 %5, -10
%7 = icmp eq i32 %3, 1
%8 = select i1 %7, i1 %6, i1 false
br i1 %8, label %16, label %9
9: ; preds = %1
%10 = icmp eq i32 %3, 2
%11 = select i1 %10, i1 %6, i1 false
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = icmp eq i32 %3, 3
%14 = select i1 %13, i1 %6, i1 false
%15 = select i1 %14, 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 %16
16: ; preds = %12, %9, %1
%17 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %1 ], [ %15, %12 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %9 ]
ret i8* %17
}