#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 BUFSIZ;
int /*<<< orphan*/ *gets(char *);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
main() {
  char categ[BUFSIZ];
  char precat[BUFSIZ];
  int freq;
  gets(precat);
  freq = 1;
  while (gets(categ) != NULL) {
    if (!strcmp(precat, categ)) {
      freq++;
    } else {
      printf("%s %d\n", precat, freq);
      freq = 1;
      strcpy(precat, categ);
    }
  }
  if (!strcmp(precat, categ)) {
    printf("%s %d\n", precat, freq);
  } else {
    printf("%s %d\n", precat, freq);
    printf("%s %d\n", categ, 1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x10(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x38(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x18(%rbp)
mov    (%rax),%eax
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
call   1060 <gets@plt>
movl   $0x1,-0x24(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <gets@plt>
cmp    $0x0,%rax
je     1208 <main+0xc8>
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11dc <main+0x9c>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1203 <main+0xc3>
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    0xe16(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
movl   $0x1,-0x24(%rbp)
call   1030 <strcpy@plt>
jmp    11a5 <main+0x65>
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1236 <main+0xf6>
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    0xdd4(%rip),%rdi
call   1040 <printf@plt>
jmp    125e <main+0x11e>
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    0xdbc(%rip),%rdi
call   1040 <printf@plt>
mov    -0x38(%rbp),%rsi
lea    0xdac(%rip),%rdi
mov    $0x1,%edx
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e8e(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
mov    %r15,%rdi
call   1060 <gets@plt>
mov    %r14,%rdi
call   1060 <gets@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     11de <main+0x9e>
lea    0xe71(%rip),%r12
jmp    11ca <main+0x8a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    $0x1,%ebx
mov    %r14,%rdi
call   1060 <gets@plt>
test   %rax,%rax
je     11de <main+0x9e>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
jne    11a0 <main+0x60>
add    $0x1,%ebx
jmp    11bd <main+0x7d>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
mov    %eax,%r12d
lea    0xe0d(%rip),%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <printf@plt>
test   %r12d,%r12d
je     1216 <main+0xd6>
lea    0xdf7(%rip),%rdi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <printf@plt>
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [7 x i8] c"%s %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @BUFSIZ
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %2
%9 = alloca i8, i64 %7
store i64 %7, i64* %3
%10 = load i32, i32* @BUFSIZ
%11 = zext i32 %10 to i64
%12 = alloca i8, i64 %11
store i64 %11, i64* %4
%13 = call i32* @gets(i8* %12)
store i32 1, i32* %5
br label %14
14: ; preds = %27, %0
%15 = call i32* @gets(i8* %9)
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %28
17: ; preds = %14
%18 = call i32 @strcmp(i8* %12, i8* %9)
%19 = icmp ne i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %27
23: ; preds = %17
%24 = load i32, i32* %5
%25 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %12, i32 %24)
store i32 1, i32* %5
%26 = call i32 @strcpy(i8* %12, i8* %9)
br label %27
27: ; preds = %23, %20
br label %14
28: ; preds = %14
%29 = call i32 @strcmp(i8* %12, i8* %9)
%30 = icmp ne i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = load i32, i32* %5
%33 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %12, i32 %32)
br label %38
34: ; preds = %28
%35 = load i32, i32* %5
%36 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %12, i32 %35)
%37 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %9, i32 1)
br label %38
38: ; preds = %34, %31
%39 = load i8*, i8** %2
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [7 x i8] c"%s %d\0A\00"
define i32 @main() {
%1 = load i32, i32* @BUFSIZ
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = alloca i8, i64 %2
%5 = call i32* @gets(i8* %4)
%6 = call i32* @gets(i8* %3)
%7 = icmp eq i32* %6, null
br i1 %7, label %21, label %8
8: ; preds = %0, %17
%9 = phi i32 [ %18, %17 ], [ 1, %0 ]
%10 = call i32 @strcmp(i8* %4, i8* %3)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = add nsw i32 %9, 1
br label %17
14: ; preds = %8
%15 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %4, i32 %9)
%16 = call i32 @strcpy(i8* %4, i8* %3)
br label %17
17: ; preds = %14, %12
%18 = phi i32 [ 1, %14 ], [ %13, %12 ]
%19 = call i32* @gets(i8* %3)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %8
21: ; preds = %17, %0
%22 = phi i32 [ 1, %0 ], [ %18, %17 ]
%23 = call i32 @strcmp(i8* %4, i8* %3)
%24 = icmp eq i32 %23, 0
%25 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %4, i32 %22)
br i1 %24, label %28, label %26
26: ; preds = %21
%27 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %3, i32 1)
br label %28
28: ; preds = %21, %26
ret i32 0
}