#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ CountSort();
int DoWord(char *);
int /*<<< orphan*/ Output();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int /*<<< orphan*/);
int main() {
  FILE *cinfile;
  char buf[(4096)];
  cinfile = fopen("phone.cin", "r");
  if (!cinfile) {
    printf("Error opening the file %s\n", "phone.cin");
    return 1;
  }
  do {
    fgets(buf, (4096), cinfile);
  } while (strncmp(buf, "%chardef  begin", strlen("%chardef  begin")));
  for (;;) {
    fgets(buf, (4096), cinfile);
    if (buf[0] == '%')
      break;
    if (DoWord(buf) == (1)) {
      printf("%s file error!\n", "phone.cin");
      return 1;
    }
  }
  fclose(cinfile);
  if (strncmp(buf, "%chardef  end", strlen("%chardef  end"))) {
    printf("The end of the file %s is error!\n", "phone.cin");
    return 1;
  }
  CountSort();
  Output();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe57(%rip),%rdi
lea    0xe5a(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e3 <main+0x53>
lea    0xe41(%rip),%rdi
lea    0xe2e(%rip),%rsi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1314 <main+0x184>
jmp    11e8 <main+0x58>
lea    -0x1010(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x1000,%esi
call   1080 <fgets@plt>
lea    -0x1010(%rbp),%rax
mov    %rax,-0x1018(%rbp)
lea    0xe15(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x1018(%rbp),%rdi
mov    %eax,%edx
lea    0xe00(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11e8 <main+0x58>
jmp    123b <main+0xab>
lea    -0x1010(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x1000,%esi
call   1080 <fgets@plt>
movsbl -0x1010(%rbp),%eax
cmp    $0x25,%eax
jne    1265 <main+0xd5>
jmp    129e <main+0x10e>
lea    -0x1010(%rbp),%rdi
call   1070 <DoWord@plt>
cmp    $0x1,%eax
jne    1299 <main+0x109>
lea    0xdb6(%rip),%rdi
lea    0xd78(%rip),%rsi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1314 <main+0x184>
jmp    123b <main+0xab>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x1010(%rbp),%rax
mov    %rax,-0x1020(%rbp)
lea    0xd8b(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x1020(%rbp),%rdi
mov    %eax,%edx
lea    0xd76(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     12ff <main+0x16f>
lea    0xd6e(%rip),%rdi
lea    0xd12(%rip),%rsi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1314 <main+0x184>
mov    $0x0,%al
call   10a0 <CountSort@plt>
mov    $0x0,%al
call   1090 <Output@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
lea    0xe5d(%rip),%rdi
lea    0xe60(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     122c <main+0x9c>
mov    %rax,%r15
mov    %rsp,%r14
lea    0xe66(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x1000,%esi
mov    %r15,%rdx
call   1080 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11d0 <main+0x40>
mov    %rsp,%rbx
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r15,%rdx
call   1080 <fgets@plt>
cmpb   $0x25,(%rsp)
je     1235 <main+0xa5>
mov    %rbx,%rdi
call   1070 <DoWord@plt>
cmp    $0x1,%eax
jne    1200 <main+0x70>
lea    0xe0d(%rip),%rdi
jmp    1265 <main+0xd5>
lea    0xdd9(%rip),%rdi
jmp    1265 <main+0xd5>
mov    %r15,%rdi
call   1040 <fclose@plt>
lea    0xe03(%rip),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rsp,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1285 <main+0xf5>
lea    0xdf0(%rip),%rdi
lea    0xd94(%rip),%rsi
call   1060 <printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
xor    %ebx,%ebx
xor    %eax,%eax
call   10a0 <CountSort@plt>
xor    %eax,%eax
call   1090 <Output@plt>
jmp    1276 <main+0xe6>

LLVM IR (-O0):
@.str = [10 x i8] c"phone.cin\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [27 x i8] c"Error opening the file %s\0A\00"
@.str.3 = [16 x i8] c"%chardef begin\00"
@.str.4 = [16 x i8] c"%s file error!\0A\00"
@.str.5 = [14 x i8] c"%chardef end\00"
@.str.6 = [34 x i8] c"The end of the file %s is error!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [4096 x i8]
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp ne i32* %5, null
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %48
9: ; preds = %0
br label %10
10: ; preds = %14, %9
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%12 = load i32*, i32** %2
%13 = call i32 @fgets(i8* %11, i32 4096, i32* %12)
br label %14
14: ; preds = %10
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%16 = call i32 @strlen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%17 = call i64 @strncmp(i8* %15, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %10, label %19
19: ; preds = %14
br label %20
20: ; preds = %35, %19
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%22 = load i32*, i32** %2
%23 = call i32 @fgets(i8* %21, i32 4096, i32* %22)
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 37
br i1 %27, label %28, label %29
28: ; preds = %20
br label %36
29: ; preds = %20
%30 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%31 = call i32 @DoWord(i8* %30)
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %48
35: ; preds = %29
br label %20
36: ; preds = %28
%37 = load i32*, i32** %2
%38 = call i32 @fclose(i32* %37)
%39 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%40 = call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%41 = call i64 @strncmp(i8* %39, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %36
%44 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %48
45: ; preds = %36
%46 = call i32 (...) @CountSort()
%47 = call i32 (...) @Output()
store i32 0, i32* %1
br label %48
48: ; preds = %45, %43, %33, %7
%49 = load i32, i32* %1
ret i32 %49
}

LLVM IR (-O2):
@.str = [10 x i8] c"phone.cin\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [27 x i8] c"Error opening the file %s\0A\00"
@.str.3 = [16 x i8] c"%chardef begin\00"
@.str.4 = [16 x i8] c"%s file error!\0A\00"
@.str.5 = [14 x i8] c"%chardef end\00"
@.str.6 = [34 x i8] c"The end of the file %s is error!\0A\00"
define i32 @main() {
%1 = alloca [4096 x i8]
%2 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %31
7: ; preds = %0, %7
%8 = call i32 @fgets(i8* %2, i32 4096, i32* %3)
%9 = call i32 @strlen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%10 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %7
12: ; preds = %7, %16
%13 = call i32 @fgets(i8* %2, i32 4096, i32* %3)
%14 = load i8, i8* %2
%15 = icmp eq i8 %14, 37
br i1 %15, label %21, label %16
16: ; preds = %12
%17 = call i32 @DoWord(i8* %2)
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %12
19: ; preds = %16
%20 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %31
21: ; preds = %12
%22 = call i32 @fclose(i32* %3)
%23 = call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%24 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %21
%27 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %31
28: ; preds = %21
%29 = call i32 (...) @CountSort()
%30 = call i32 (...) @Output()
br label %31
31: ; preds = %28, %26, %19, %5
%32 = phi i32 [ 1, %26 ], [ 0, %28 ], [ 1, %19 ], [ 1, %5 ]
ret i32 %32
}