#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
char *strtok(char *, char *);
int main() {
  char str[4000];
  char *word;
  fgets(str, 4000, stdin);
  if (strcmp(str, "\n") == 0) {
    printf("There is no box\n");
    return 0;
  }
  word = strtok(str, "\n ,.-");
  int i = 1;
  while (word != NULL) {
    if (strcmp(word, "cat") == 0) {
      if (!(i % 100 >= 10 && i % 100 <= 19)) {
        switch (i % 10) {
        case 1:
          printf("The cat is the %dst item in the box\n", i);
          return 0;
        case 2:
          printf("The cat is the %dnd item in the box\n", i);
          return 0;
        case 3:
          printf("The cat is the %drd item in the box\n", i);
          return 0;
        default:
          printf("The cat is the %dth item in the box\n", i);
          return 0;
        }
      } else {
        printf("The cat is the %dth item in the box\n", i);
        return 0;
      }
    }
    word = strtok(NULL, "\n ,.-");
    i++;
  }
  printf("No cat yet\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xfb0(%rbp),%rdi
mov    0x2e88(%rip),%rax
mov    (%rax),%edx
mov    $0xfa0,%esi
call   1040 <fgets@plt>
lea    -0xfb0(%rbp),%rdi
lea    0xf3f(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11a3 <main+0x63>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1362 <main+0x222>
lea    -0xfb0(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0xfb8(%rbp)
movl   $0x1,-0xfbc(%rbp)
cmpq   $0x0,-0xfb8(%rbp)
je     134d <main+0x20d>
mov    -0xfb8(%rbp),%rdi
lea    0xe34(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1322 <main+0x1e2>
mov    -0xfbc(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0xa,%edx
jl     1220 <main+0xe0>
mov    -0xfbc(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0x13,%edx
jle    1302 <main+0x1c2>
movslq -0xfbc(%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,-0xfc0(%rbp)
sub    $0x1,%eax
je     1282 <main+0x142>
jmp    125a <main+0x11a>
mov    -0xfc0(%rbp),%eax
sub    $0x2,%eax
je     12a2 <main+0x162>
jmp    126e <main+0x12e>
mov    -0xfc0(%rbp),%eax
sub    $0x3,%eax
je     12c2 <main+0x182>
jmp    12e2 <main+0x1a2>
mov    -0xfbc(%rbp),%esi
lea    0xd8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1362 <main+0x222>
mov    -0xfbc(%rbp),%esi
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1362 <main+0x222>
mov    -0xfbc(%rbp),%esi
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1362 <main+0x222>
mov    -0xfbc(%rbp),%esi
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1362 <main+0x222>
mov    -0xfbc(%rbp),%esi
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1362 <main+0x222>
xor    %eax,%eax
mov    %eax,%edi
lea    0xce4(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0xfb8(%rbp)
mov    -0xfbc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfbc(%rbp)
jmp    11c7 <main+0x87>
lea    0xd5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xfc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xfa8,%rsp
mov    0x2e84(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xfa0,%esi
call   1050 <fgets@plt>
lea    0xed5(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11ee <main+0x9e>
lea    0xe6f(%rip),%rsi
mov    %rsp,%rdi
call   1070 <strtok@plt>
test   %rax,%rax
je     11e5 <main+0x95>
mov    $0x1,%ebx
mov    $0xfffffff7,%ebp
lea    0xe57(%rip),%r14
lea    0xe4a(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11fc <main+0xac>
xor    %edi,%edi
mov    %r15,%rsi
call   1070 <strtok@plt>
add    $0x1,%ebx
add    $0x1,%ebp
test   %rax,%rax
jne    11c0 <main+0x70>
lea    0xeb2(%rip),%rdi
jmp    11f5 <main+0xa5>
lea    0xeb4(%rip),%rdi
call   1030 <puts@plt>
jmp    1223 <main+0xd3>
mov    %ebx,%eax
imul   $0x51eb851f,%rax,%rcx
shr    $0x25,%rcx
imul   $0x64,%ecx,%ecx
sub    %ecx,%ebp
cmp    $0xa,%ebp
jae    1233 <main+0xe3>
lea    0xe5f(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xfa8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xcccccccd,%ecx
imul   %rax,%rcx
shr    $0x23,%rcx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %ebx,%eax
sub    %ecx,%eax
cmp    $0x3,%eax
je     1261 <main+0x111>
cmp    $0x2,%eax
je     126a <main+0x11a>
cmp    $0x1,%eax
jne    1213 <main+0xc3>
lea    0xdab(%rip),%rdi
jmp    121a <main+0xca>
lea    0xdec(%rip),%rdi
jmp    121a <main+0xca>
lea    0xdbe(%rip),%rdi
jmp    121a <main+0xca>

LLVM IR (-O0):
@stdin = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.1 = [17 x i8] c"There is no box\0A\00"
@.str.2 = [6 x i8] c"\0A ,.-\00"
@.str.3 = [4 x i8] c"cat\00"
@.str.4 = [37 x i8] c"The cat is the %dst item in the box\0A\00"
@.str.5 = [37 x i8] c"The cat is the %dnd item in the box\0A\00"
@.str.6 = [37 x i8] c"The cat is the %drd item in the box\0A\00"
@.str.7 = [37 x i8] c"The cat is the %dth item in the box\0A\00"
@.str.8 = [12 x i8] c"No cat yet\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4000 x i8]
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
%5 = getelementptr inbounds [4000 x i8], [4000 x i8]* %2, i64 0, i64 0
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %5, i32 4000, i32 %6)
%8 = getelementptr inbounds [4000 x i8], [4000 x i8]* %2, i64 0, i64 0
%9 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %55
13: ; preds = %0
%14 = getelementptr inbounds [4000 x i8], [4000 x i8]* %2, i64 0, i64 0
%15 = call i8* @strtok(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i8* %15, i8** %3
store i32 1, i32* %4
br label %16
16: ; preds = %49, %13
%17 = load i8*, i8** %3
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %53
19: ; preds = %16
%20 = load i8*, i8** %3
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %49
23: ; preds = %19
%24 = load i32, i32* %4
%25 = srem i32 %24, 100
%26 = icmp sge i32 %25, 10
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i32, i32* %4
%29 = srem i32 %28, 100
%30 = icmp sle i32 %29, 19
br i1 %30, label %46, label %31
31: ; preds = %27, %23
%32 = load i32, i32* %4
%33 = srem i32 %32, 10
switch i32 %33, label %43 [
i32 1, label %34
i32 2, label %37
i32 3, label %40
]
34: ; preds = %31
%35 = load i32, i32* %4
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i32 %35)
store i32 0, i32* %1
br label %55
37: ; preds = %31
%38 = load i32, i32* %4
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 %38)
store i32 0, i32* %1
br label %55
40: ; preds = %31
%41 = load i32, i32* %4
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0), i32 %41)
store i32 0, i32* %1
br label %55
43: ; preds = %31
%44 = load i32, i32* %4
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i32 %44)
store i32 0, i32* %1
br label %55
46: ; preds = %27
%47 = load i32, i32* %4
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i32 %47)
store i32 0, i32* %1
br label %55
49: ; preds = %19
%50 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i8* %50, i8** %3
%51 = load i32, i32* %4
%52 = add nsw i32 %51, 1
store i32 %52, i32* %4
br label %16
53: ; preds = %16
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %1
br label %55
55: ; preds = %53, %46, %43, %40, %37, %34, %11
%56 = load i32, i32* %1
ret i32 %56
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.2 = [6 x i8] c"\0A ,.-\00"
@.str.3 = [4 x i8] c"cat\00"
@.str.4 = [37 x i8] c"The cat is the %dst item in the box\0A\00"
@.str.5 = [37 x i8] c"The cat is the %dnd item in the box\0A\00"
@.str.6 = [37 x i8] c"The cat is the %drd item in the box\0A\00"
@.str.7 = [37 x i8] c"The cat is the %dth item in the box\0A\00"
@str = [11 x i8] c"No cat yet\00"
@str.9 = [16 x i8] c"There is no box\00"
define i32 @main() {
%1 = alloca [4000 x i8]
%2 = getelementptr inbounds [4000 x i8], [4000 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = call i32 @fgets(i8* %2, i32 4000, i32 %3)
%5 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.9, i64 0, i64 0))
br label %39
9: ; preds = %0
%10 = call i8* @strtok(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %37, label %12
12: ; preds = %9, %33
%13 = phi i32 [ %35, %33 ], [ 1, %9 ]
%14 = phi i8* [ %34, %33 ], [ %10, %9 ]
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %33
17: ; preds = %12
%18 = urem i32 %13, 100
%19 = add nsw i32 %18, -10
%20 = icmp ult i32 %19, 10
br i1 %20, label %31, label %21
21: ; preds = %17
%22 = urem i32 %13, 10
switch i32 %22, label %29 [
i32 1, label %23
i32 2, label %25
i32 3, label %27
]
23: ; preds = %21
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i32 %13)
br label %39
25: ; preds = %21
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 %13)
br label %39
27: ; preds = %21
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0), i32 %13)
br label %39
29: ; preds = %21
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i32 %13)
br label %39
31: ; preds = %17
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i32 %13)
br label %39
33: ; preds = %12
%34 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%35 = add nuw nsw i32 %13, 1
%36 = icmp eq i8* %34, null
br i1 %36, label %37, label %12
37: ; preds = %33, %9
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %39
39: ; preds = %23, %25, %27, %29, %31, %37, %7
ret i32 0
}