#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*/ sprintf(char *, char *, int);
char *instance(int n) {
  static char buff[10];
  if (n > 10 && n < 20) {
    sprintf(buff, "%dth", n);
    return buff;
  }
  switch (n % 10) {
  case 1:
    sprintf(buff, "%dst", n);
    break;
  case 2:
    sprintf(buff, "%dnd", n);
    break;
  case 3:
    sprintf(buff, "%drd", n);
    break;
  default:
    sprintf(buff, "%dth", n);
    break;
  }
  return buff;
}


x86 assembly (clang, -O0):
<instance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jle    1155 <instance+0x45>
cmpl   $0x14,-0xc(%rbp)
jge    1155 <instance+0x45>
mov    -0xc(%rbp),%edx
lea    0x2ef0(%rip),%rdi
lea    0xec0(%rip),%rsi
call   1030 <sprintf@plt>
lea    0x2edd(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    121d <instance+0x10d>
movslq -0xc(%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,-0x10(%rbp)
sub    $0x1,%eax
je     11ab <instance+0x9b>
jmp    1189 <instance+0x79>
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
je     11c6 <instance+0xb6>
jmp    119a <instance+0x8a>
mov    -0x10(%rbp),%eax
sub    $0x3,%eax
je     11e1 <instance+0xd1>
jmp    11fc <instance+0xec>
mov    -0xc(%rbp),%edx
lea    0x2e74(%rip),%rdi
lea    0xe49(%rip),%rsi
call   1030 <sprintf@plt>
jmp    1212 <instance+0x102>
mov    -0xc(%rbp),%edx
lea    0x2e59(%rip),%rdi
lea    0xe33(%rip),%rsi
call   1030 <sprintf@plt>
jmp    1212 <instance+0x102>
mov    -0xc(%rbp),%edx
lea    0x2e3e(%rip),%rdi
lea    0xe1d(%rip),%rsi
call   1030 <sprintf@plt>
jmp    1212 <instance+0x102>
mov    -0xc(%rbp),%edx
lea    0x2e23(%rip),%rdi
lea    0xdf3(%rip),%rsi
call   1030 <sprintf@plt>
lea    0x2e10(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<instance>:
push   %rbx
mov    %edi,%edx
lea    -0xb(%rdx),%eax
lea    0xee3(%rip),%rsi
cmp    $0x9,%eax
jb     1157 <instance+0x47>
movslq %edx,%rax
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
not    %eax
add    %edx,%eax
cmp    $0x2,%eax
ja     1157 <instance+0x47>
cltq
lea    0xec4(%rip),%rcx
movslq (%rcx,%rax,4),%rsi
add    %rcx,%rsi
lea    0x2ecb(%rip),%rbx
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@instance.buff = internal global [10 x i8] zeroinitializer
@.str = [5 x i8] c"%dth\00"
@.str.1 = [5 x i8] c"%dst\00"
@.str.2 = [5 x i8] c"%dnd\00"
@.str.3 = [5 x i8] c"%drd\00"
define i8* @instance(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp sgt i32 %4, 10
br i1 %5, label %6, label %12
6: ; preds = %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 20
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = load i32, i32* %3
%11 = call i32 @sprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @instance.buff, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %10)
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @instance.buff, i64 0, i64 0), i8** %2
br label %28
12: ; preds = %6, %1
%13 = load i32, i32* %3
%14 = srem i32 %13, 10
switch i32 %14, label %24 [
i32 1, label %15
i32 2, label %18
i32 3, label %21
]
15: ; preds = %12
%16 = load i32, i32* %3
%17 = call i32 @sprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @instance.buff, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %27
18: ; preds = %12
%19 = load i32, i32* %3
%20 = call i32 @sprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @instance.buff, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %19)
br label %27
21: ; preds = %12
%22 = load i32, i32* %3
%23 = call i32 @sprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @instance.buff, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %22)
br label %27
24: ; preds = %12
%25 = load i32, i32* %3
%26 = call i32 @sprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @instance.buff, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %24, %21, %18, %15
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @instance.buff, i64 0, i64 0), i8** %2
br label %28
28: ; preds = %27, %9
%29 = load i8*, i8** %2
ret i8* %29
}

LLVM IR (-O2):
@instance.buff = internal global [10 x i8] zeroinitializer
@.str = [5 x i8] c"%dth\00"
@.str.1 = [5 x i8] c"%dst\00"
@.str.2 = [5 x i8] c"%dnd\00"
@.str.3 = [5 x i8] c"%drd\00"
@reltable.instance = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.1 to i64), i64 ptrtoint ([3 x i32]* @reltable.instance to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.instance to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.3 to i64), i64 ptrtoint ([3 x i32]* @reltable.instance to i64)) to i32)]
define i8* @instance(i32 %0) {
%2 = add i32 %0, -11
%3 = icmp ult i32 %2, 9
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = srem i32 %0, 10
%6 = add nsw i32 %5, -1
%7 = icmp ult i32 %6, 3
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = sext i32 %6 to i64
%10 = shl i64 %9, 2
%11 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.instance to i8*), i64 %10)
br label %12
12: ; preds = %4, %8, %1
%13 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %1 ], [ %11, %8 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %4 ]
%14 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @instance.buff, i64 0, i64 0), i8* dereferenceable(1) %13, i32 %0)
ret i8* getelementptr inbounds ([10 x i8], [10 x i8]* @instance.buff, i64 0, i64 0)
}