#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 /*<<< orphan*/ assert(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void ordinalSuffix(unsigned n, char *str) {
  assert(strlen(str) >= 2);
  switch (n % 10) {
  case 1:
    strcpy(str, "st");
    break;
  case 2:
    strcpy(str, "nd");
    break;
  case 3:
    strcpy(str, "rd");
    break;
  default:
    strcpy(str, "th");
    break;
  }
}


x86 assembly (clang, -O0):
<ordinalSuffix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x2,%eax
setge  %al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
mov    %ecx,%eax
mov    $0xcccccccd,%edx
imul   %rdx,%rcx
shr    $0x23,%rcx
mov    %ecx,%edx
add    %edx,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
sub    $0x1,%eax
je     11a8 <ordinalSuffix+0x78>
jmp    1186 <ordinalSuffix+0x56>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
je     11bd <ordinalSuffix+0x8d>
jmp    1197 <ordinalSuffix+0x67>
mov    -0x14(%rbp),%eax
sub    $0x3,%eax
je     11d2 <ordinalSuffix+0xa2>
jmp    11e7 <ordinalSuffix+0xb7>
mov    -0x10(%rbp),%rdi
lea    0xe4d(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11f7 <ordinalSuffix+0xc7>
mov    -0x10(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11f7 <ordinalSuffix+0xc7>
mov    -0x10(%rbp),%rdi
lea    0xe29(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11f7 <ordinalSuffix+0xc7>
mov    -0x10(%rbp),%rdi
lea    0xe17(%rip),%rsi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ordinalSuffix>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
call   1040 <strlen@plt>
xor    %edi,%edi
cmp    $0x2,%eax
setge  %dil
call   1050 <assert@plt>
mov    %ebp,%eax
mov    $0xcccccccd,%ecx
imul   %rax,%rcx
shr    $0x23,%rcx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%eax
not    %eax
add    %ebp,%eax
cmp    $0x2,%eax
ja     117d <ordinalSuffix+0x4d>
cltq
lea    0xe98(%rip),%rcx
movslq (%rcx,%rax,4),%rsi
add    %rcx,%rsi
jmp    1184 <ordinalSuffix+0x54>
lea    0xe85(%rip),%rsi
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <strcpy@plt>

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 void @ordinalSuffix(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i8*, i8** %4
%6 = call i32 @strlen(i8* %5)
%7 = icmp sge i32 %6, 2
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i32, i32* %3
%11 = urem i32 %10, 10
switch i32 %11, label %21 [
i32 1, label %12
i32 2, label %15
i32 3, label %18
]
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32 @strcpy(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %24
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %24
18: ; preds = %2
%19 = load i8*, i8** %4
%20 = call i32 @strcpy(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %24
21: ; preds = %2
%22 = load i8*, i8** %4
%23 = call i32 @strcpy(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %21, %18, %15, %12
ret void
}

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"
@reltable.ordinalSuffix = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str to i64), i64 ptrtoint ([3 x i32]* @reltable.ordinalSuffix to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.1 to i64), i64 ptrtoint ([3 x i32]* @reltable.ordinalSuffix to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.ordinalSuffix to i64)) to i32)]
define void @ordinalSuffix(i32 %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = icmp sgt i32 %3, 1
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = urem i32 %0, 10
%8 = add nsw i32 %7, -1
%9 = icmp ult i32 %8, 3
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = sext i32 %8 to i64
%12 = shl i64 %11, 2
%13 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.ordinalSuffix to i8*), i64 %12)
br label %14
14: ; preds = %2, %10
%15 = phi i8* [ %13, %10 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), %2 ]
%16 = tail call i32 @strcpy(i8* %1, i8* %15)
ret void
}