#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*/ printf(char *, int);
scalar_t__ scanf(char *, int *);
int main() {
  int a, b, c;
  while (scanf("%d", &a)) {
    if (a == 0)
      break;
    else {
      switch (a % 10) {
      case 1:
        printf("%dst\n", a);
        break;
      case 2:
        printf("%dnd\n", a);
        break;
      case 3:
        printf("%drd\n", a);
        break;
      case 4:
      case 5:
      case 6:
      case 7:
      case 8:
        printf("%dth\n", a);
        break;
      default:
        printf("%dth\n", a);
        break;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeea(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmp    $0x0,%rax
je     1209 <main+0xe9>
cmpl   $0x0,-0x8(%rbp)
jne    1158 <main+0x38>
jmp    1209 <main+0xe9>
movslq -0x8(%rbp),%rax
mov    %eax,%ecx
imul   $0x66666667,%rax,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x22,%rdx
add    %eax,%edx
add    %edx,%edx
mov    %edx,%eax
lea    (%rax,%rax,4),%eax
not    %eax
add    %ecx,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x7,%eax
ja     11f0 <main+0xd0>
mov    -0x18(%rbp),%rax
lea    0xe69(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%esi
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
jmp    11ff <main+0xdf>
mov    -0x8(%rbp),%esi
lea    0xe6b(%rip),%rdi
call   1030 <printf@plt>
jmp    11ff <main+0xdf>
mov    -0x8(%rbp),%esi
lea    0xe5d(%rip),%rdi
call   1030 <printf@plt>
jmp    11ff <main+0xdf>
mov    -0x8(%rbp),%esi
lea    0xe4f(%rip),%rdi
call   1030 <printf@plt>
jmp    11ff <main+0xdf>
mov    -0x8(%rbp),%esi
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
jmp    1204 <main+0xe4>
jmp    112f <main+0xf>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xed1(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
test   %rax,%rax
je     11ae <main+0x8e>
mov    0x4(%rsp),%esi
test   %esi,%esi
je     11ae <main+0x8e>
lea    0xec8(%rip),%r15
lea    0xec8(%rip),%r12
lea    0xea5(%rip),%r14
lea    0x4(%rsp),%rbx
movslq %esi,%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    %esi,%eax
mov    %r15,%rdi
cmp    $0x7,%eax
ja     1191 <main+0x71>
cltq
movslq (%r12,%rax,4),%rdi
add    %r12,%rdi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
test   %rax,%rax
je     11ae <main+0x8e>
mov    0x4(%rsp),%esi
test   %esi,%esi
jne    1160 <main+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%dst\0A\00"
@.str.2 = [6 x i8] c"%dnd\0A\00"
@.str.3 = [6 x i8] c"%drd\0A\00"
@.str.4 = [6 x i8] c"%dth\0A\00"
@reltable.main = [8 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.1 to i64), i64 ptrtoint ([8 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.2 to i64), i64 ptrtoint ([8 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.3 to i64), i64 ptrtoint ([8 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.4 to i64), i64 ptrtoint ([8 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.4 to i64), i64 ptrtoint ([8 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.4 to i64), i64 ptrtoint ([8 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.4 to i64), i64 ptrtoint ([8 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.4 to i64), i64 ptrtoint ([8 x i32]* @reltable.main to i64)) to i32)]
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = icmp eq i64 %3, 0
%5 = load i32, i32* %1
%6 = icmp eq i32 %5, 0
%7 = select i1 %4, i1 true, i1 %6
br i1 %7, label %25, label %8
8: ; preds = %0, %17
%9 = phi i32 [ %22, %17 ], [ %5, %0 ]
%10 = srem i32 %9, 10
%11 = add nsw i32 %10, -1
%12 = icmp ult i32 %11, 8
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = sext i32 %11 to i64
%15 = shl i64 %14, 2
%16 = call i8* @llvm.load.relative.i64(i8* bitcast ([8 x i32]* @reltable.main to i8*), i64 %15)
br label %17
17: ; preds = %8, %13
%18 = phi i8* [ %16, %13 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), %8 ]
%19 = call i32 @printf(i8* %18, i32 %9)
%20 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%21 = icmp eq i64 %20, 0
%22 = load i32, i32* %1
%23 = icmp eq i32 %22, 0
%24 = select i1 %21, i1 true, i1 %23
br i1 %24, label %25, label %8
25: ; preds = %17, %0
ret i32 0
}