#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*/ snprintf(char *, size_t, char *, int, char *);
void addSuffix(int num, char *buf, size_t len) {
  char *suffixes[4] = {"th", "st", "nd", "rd"};
  int i;
  switch (num % 10) {
  case 1:
    i = (num % 100 == 11) ? 0 : 1;
    break;
  case 2:
    i = (num % 100 == 12) ? 0 : 2;
    break;
  case 3:
    i = (num % 100 == 13) ? 0 : 3;
    break;
  default:
    i = 0;
  }
  snprintf(buf, len, "%d%s", num, suffixes[i]);
}


x86 assembly (clang, -O0):
<addSuffix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movaps 0x2ce6(%rip),%xmm0
movaps %xmm0,-0x30(%rbp)
movaps 0x2ccb(%rip),%xmm0
movaps %xmm0,-0x40(%rbp)
movslq -0x4(%rbp),%rcx
mov    %ecx,%eax
imul   $0x66666667,%rcx,%rdx
mov    %rdx,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rdx
add    %ecx,%edx
add    %edx,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
mov    %eax,-0x48(%rbp)
sub    $0x1,%eax
je     118f <addSuffix+0x7f>
jmp    116d <addSuffix+0x5d>
mov    -0x48(%rbp),%eax
sub    $0x2,%eax
je     11af <addSuffix+0x9f>
jmp    117e <addSuffix+0x6e>
mov    -0x48(%rbp),%eax
sub    $0x3,%eax
je     11cf <addSuffix+0xbf>
jmp    11ef <addSuffix+0xdf>
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0xb,%edx
cmove  %ecx,%eax
mov    %eax,-0x44(%rbp)
jmp    11f6 <addSuffix+0xe6>
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    $0x2,%eax
xor    %ecx,%ecx
cmp    $0xc,%edx
cmove  %ecx,%eax
mov    %eax,-0x44(%rbp)
jmp    11f6 <addSuffix+0xe6>
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    $0x3,%eax
xor    %ecx,%ecx
cmp    $0xd,%edx
cmove  %ecx,%eax
mov    %eax,-0x44(%rbp)
jmp    11f6 <addSuffix+0xe6>
movl   $0x0,-0x44(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x4(%rbp),%ecx
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%r8
lea    0xdfb(%rip),%rdx
call   1030 <snprintf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addSuffix>:
mov    %rsi,%r9
mov    %edi,%ecx
movslq %edi,%rax
imul   $0x66666667,%rax,%rdi
mov    %rdi,%rsi
shr    $0x3f,%rsi
sar    $0x22,%rdi
add    %esi,%edi
add    %edi,%edi
lea    (%rdi,%rdi,4),%esi
mov    %eax,%edi
sub    %esi,%edi
cmp    $0x3,%edi
je     1168 <addSuffix+0x58>
cmp    $0x2,%edi
je     1190 <addSuffix+0x80>
cmp    $0x1,%edi
jne    11b7 <addSuffix+0xa7>
imul   $0x51eb851f,%rax,%rsi
mov    %rsi,%rdi
shr    $0x3f,%rdi
sar    $0x25,%rsi
add    %edi,%esi
imul   $0x64,%esi,%esi
sub    %esi,%eax
xor    %edi,%edi
cmp    $0xb,%eax
setne  %dil
jmp    11b9 <addSuffix+0xa9>
imul   $0x51eb851f,%rax,%rsi
mov    %rsi,%rdi
shr    $0x3f,%rdi
sar    $0x25,%rsi
add    %edi,%esi
imul   $0x64,%esi,%esi
sub    %esi,%eax
xor    %esi,%esi
cmp    $0xd,%eax
setne  %sil
lea    (%rsi,%rsi,2),%rdi
jmp    11b9 <addSuffix+0xa9>
imul   $0x51eb851f,%rax,%rsi
mov    %rsi,%rdi
shr    $0x3f,%rdi
sar    $0x25,%rsi
add    %edi,%esi
imul   $0x64,%esi,%esi
sub    %esi,%eax
xor    %edi,%edi
cmp    $0xc,%eax
setne  %dil
add    %rdi,%rdi
jmp    11b9 <addSuffix+0xa9>
xor    %edi,%edi
lea    0xe54(%rip),%rax
movslq (%rax,%rdi,4),%r8
add    %rax,%r8
lea    0xe3e(%rip),%rax
mov    %r9,%rdi
mov    %rdx,%rsi
mov    %rax,%rdx
jmp    1030 <snprintf@plt>

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"
@.str.3 = [3 x i8] c"rd\00"
@__const.addSuffix.suffixes = [4 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i32 0, i32 0)]
@.str.4 = [5 x i8] c"%d%s\00"
define void @addSuffix(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca [4 x i8*]
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = bitcast [4 x i8*]* %7 to i8*
%10 = load i32, i32* %4
%11 = srem i32 %10, 10
switch i32 %11, label %30 [
i32 1, label %12
i32 2, label %18
i32 3, label %24
]
12: ; preds = %3
%13 = load i32, i32* %4
%14 = srem i32 %13, 100
%15 = icmp eq i32 %14, 11
%16 = zext i1 %15 to i64
%17 = select i1 %15, i32 0, i32 1
store i32 %17, i32* %8
br label %31
18: ; preds = %3
%19 = load i32, i32* %4
%20 = srem i32 %19, 100
%21 = icmp eq i32 %20, 12
%22 = zext i1 %21 to i64
%23 = select i1 %21, i32 0, i32 2
store i32 %23, i32* %8
br label %31
24: ; preds = %3
%25 = load i32, i32* %4
%26 = srem i32 %25, 100
%27 = icmp eq i32 %26, 13
%28 = zext i1 %27 to i64
%29 = select i1 %27, i32 0, i32 3
store i32 %29, i32* %8
br label %31
30: ; preds = %3
store i32 0, i32* %8
br label %31
31: ; preds = %30, %24, %18, %12
%32 = load i8*, i8** %5
%33 = load i64, i64* %6
%34 = load i32, i32* %4
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [4 x i8*], [4 x i8*]* %7, i64 0, i64 %36
%38 = load i8*, i8** %37
%39 = call i32 @snprintf(i8* %32, i64 %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %34, i8* %38)
ret void
}

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"
@.str.3 = [3 x i8] c"rd\00"
@reltable.addSuffix = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str to i64), i64 ptrtoint ([4 x i32]* @reltable.addSuffix to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.1 to i64), i64 ptrtoint ([4 x i32]* @reltable.addSuffix to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.2 to i64), i64 ptrtoint ([4 x i32]* @reltable.addSuffix to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.3 to i64), i64 ptrtoint ([4 x i32]* @reltable.addSuffix to i64)) to i32)]
@.str.4 = [5 x i8] c"%d%s\00"
define void @addSuffix(i32 %0, i8* %1, i64 %2) {
%4 = srem i32 %0, 10
switch i32 %4, label %17 [
i32 1, label %5
i32 2, label %9
i32 3, label %13
]
5: ; preds = %3
%6 = srem i32 %0, 100
%7 = icmp ne i32 %6, 11
%8 = zext i1 %7 to i64
br label %17
9: ; preds = %3
%10 = srem i32 %0, 100
%11 = icmp eq i32 %10, 12
%12 = select i1 %11, i64 0, i64 2
br label %17
13: ; preds = %3
%14 = srem i32 %0, 100
%15 = icmp eq i32 %14, 13
%16 = select i1 %15, i64 0, i64 3
br label %17
17: ; preds = %3, %13, %9, %5
%18 = phi i64 [ %16, %13 ], [ %12, %9 ], [ %8, %5 ], [ 0, %3 ]
%19 = shl i64 %18, 2
%20 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.addSuffix to i8*), i64 %19)
%21 = tail call i32 @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %0, i8* %20)
ret void
}