#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 EOF;
int getchar();
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, int *);
int main() {
  int c;
  int MAX;
  int cnt = 0;
  int i, iRC;
  iRC = 0;
  printf("This program is show the word's long of the input\n");
  printf("It support the longest word's is:");
  iRC = scanf("%d", &MAX);
  if (iRC != 1) {
    printf("Input err, I will used the defult number(20)\n");
    MAX = 20;
  } else if (MAX <= 0) {
    printf("Input err, please input a positive number\n");
    return 0;
  } else {
    printf("you set the longest word's is %d\n", MAX);
  }
  int a[MAX];
  for (i = 0; i < MAX; i++)
    a[i] = 0;
  while ((c = getchar()) != EOF) {
    if (c != ' ' && c != '\t' && c != '\n') {
      cnt++;
    } else {
      a[cnt - 1]++;
      cnt = 0;
    }
  }
  printf("the result is:\n");
  printf("long        word\n");
  for (i = 0; i < MAX; i++) {
    printf("%-12d%d\n", (i + 1), a[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee5(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
je     11a0 <main+0x70>
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x14,-0xc(%rbp)
jmp    11da <main+0xaa>
cmpl   $0x0,-0xc(%rbp)
jg     11c4 <main+0x94>
lea    0xed5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1307 <main+0x1d7>
mov    -0xc(%rbp),%esi
lea    0xee3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11da <main+0xaa>
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1231 <main+0x101>
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1208 <main+0xd8>
jmp    1236 <main+0x106>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2da1(%rip),%rcx
cmp    (%rcx),%eax
je     129d <main+0x16d>
cmpl   $0x20,-0x8(%rbp)
je     127b <main+0x14b>
cmpl   $0x9,-0x8(%rbp)
je     127b <main+0x14b>
cmpl   $0xa,-0x8(%rbp)
je     127b <main+0x14b>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1298 <main+0x168>
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
movl   $0x0,-0x10(%rbp)
jmp    1236 <main+0x106>
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12f9 <main+0x1c9>
mov    -0x30(%rbp),%rax
mov    -0x14(%rbp),%esi
add    $0x1,%esi
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12c0 <main+0x190>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%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   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeeb(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea3(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1070 <scanf@plt>
cmp    $0x1,%eax
jne    11ab <main+0x5b>
mov    -0x2c(%rbp),%esi
test   %esi,%esi
jle    128a <main+0x13a>
lea    0xe86(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
jmp    11c3 <main+0x73>
lea    0xf1a(%rip),%rdi
call   1030 <puts@plt>
movl   $0x14,-0x2c(%rbp)
mov    $0x14,%eax
mov    %rsp,%r12
mov    %rsp,%r15
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    -0x2c(%rbp),%edx
test   %edx,%edx
jle    11f0 <main+0xa0>
shl    $0x2,%rdx
mov    %r15,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0x2dea(%rip),%r13
cmp    0x0(%r13),%eax
jne    1252 <main+0x102>
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7a(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    124d <main+0xfd>
lea    0xe1e(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbx,4),%edx
add    $0x1,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movslq -0x2c(%rbp),%rax
cmp    %rax,%rbx
jl     1230 <main+0xe0>
mov    %r12,%rsp
jmp    1296 <main+0x146>
movabs $0x100000600,%r14
xor    %ebx,%ebx
jmp    1270 <main+0x120>
add    $0x1,%ebx
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    0x0(%r13),%eax
je     1204 <main+0xb4>
cmp    $0x20,%eax
ja     1260 <main+0x110>
mov    %eax,%eax
bt     %rax,%r14
jae    1260 <main+0x110>
movslq %ebx,%rax
addl   $0x1,-0x4(%r15,%rax,4)
xor    %ebx,%ebx
jmp    1263 <main+0x113>
lea    0xe11(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [51 x i8] c"This program is show the word's long of the input\0A\00"
@.str.1 = [34 x i8] c"It support the longest word's is:\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [46 x i8] c"Input err, I will used the defult number(20)\0A\00"
@.str.4 = [43 x i8] c"Input err, please input a positive number\0A\00"
@.str.5 = [34 x i8] c"you set the longest word's is %d\0A\00"
@EOF = global i32 0
@.str.6 = [16 x i8] c"the result is:\0A\00"
@.str.7 = [18 x i8] c"long word\0A\00"
@.str.8 = [9 x i8] c"%-12d%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i32 0, i32* %1
store i32 0, i32* %4
store i32 0, i32* %6
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp ne i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
store i32 20, i32* %3
br label %25
16: ; preds = %0
%17 = load i32, i32* %3
%18 = icmp sle i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %86
21: ; preds = %16
%22 = load i32, i32* %3
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %21
br label %25
25: ; preds = %24, %14
%26 = load i32, i32* %3
%27 = zext i32 %26 to i64
%28 = call i8* @llvm.stacksave()
store i8* %28, i8** %7
%29 = alloca i32, i64 %27
store i64 %27, i64* %8
store i32 0, i32* %5
br label %30
30: ; preds = %38, %25
%31 = load i32, i32* %5
%32 = load i32, i32* %3
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %41
34: ; preds = %30
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %29, i64 %36
store i32 0, i32* %37
br label %38
38: ; preds = %34
%39 = load i32, i32* %5
%40 = add nsw i32 %39, 1
store i32 %40, i32* %5
br label %30
41: ; preds = %30
br label %42
42: ; preds = %65, %41
%43 = call i32 (...) @getchar()
store i32 %43, i32* %2
%44 = load i32, i32* @EOF
%45 = icmp ne i32 %43, %44
br i1 %45, label %46, label %66
46: ; preds = %42
%47 = load i32, i32* %2
%48 = icmp ne i32 %47, 32
br i1 %48, label %49, label %58
49: ; preds = %46
%50 = load i32, i32* %2
%51 = icmp ne i32 %50, 9
br i1 %51, label %52, label %58
52: ; preds = %49
%53 = load i32, i32* %2
%54 = icmp ne i32 %53, 10
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = load i32, i32* %4
%57 = add nsw i32 %56, 1
store i32 %57, i32* %4
br label %65
58: ; preds = %52, %49, %46
%59 = load i32, i32* %4
%60 = sub nsw i32 %59, 1
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32, i32* %29, i64 %61
%63 = load i32, i32* %62
%64 = add nsw i32 %63, 1
store i32 %64, i32* %62
store i32 0, i32* %4
br label %65
65: ; preds = %58, %55
br label %42
66: ; preds = %42
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %5
br label %69
69: ; preds = %81, %66
%70 = load i32, i32* %5
%71 = load i32, i32* %3
%72 = icmp slt i32 %70, %71
br i1 %72, label %73, label %84
73: ; preds = %69
%74 = load i32, i32* %5
%75 = add nsw i32 %74, 1
%76 = load i32, i32* %5
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i32, i32* %29, i64 %77
%79 = load i32, i32* %78
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i32 %75, i32 %79)
br label %81
81: ; preds = %73
%82 = load i32, i32* %5
%83 = add nsw i32 %82, 1
store i32 %83, i32* %5
br label %69
84: ; preds = %69
store i32 0, i32* %1
%85 = load i8*, i8** %7
br label %86
86: ; preds = %84, %19
%87 = load i32, i32* %1
ret i32 %87
}

LLVM IR (-O2):
@.str.1 = [34 x i8] c"It support the longest word's is:\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.5 = [34 x i8] c"you set the longest word's is %d\0A\00"
@EOF = global i32 0
@.str.8 = [9 x i8] c"%-12d%d\0A\00"
@str = [50 x i8] c"This program is show the word's long of the input\00"
@str.9 = [15 x i8] c"the result is:\00"
@str.10 = [17 x i8] c"long word\00"
@str.11 = [42 x i8] c"Input err, please input a positive number\00"
@str.12 = [45 x i8] c"Input err, I will used the defult number(20)\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%6 = icmp eq i32 %5, 1
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.12, i64 0, i64 0))
store i32 20, i32* %1
br label %18
9: ; preds = %0
%10 = load i32, i32* %1
%11 = icmp slt i32 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.11, i64 0, i64 0))
br label %64
14: ; preds = %9
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %10)
%16 = load i32, i32* %1
%17 = zext i32 %16 to i64
br label %18
18: ; preds = %14, %7
%19 = phi i64 [ %17, %14 ], [ 20, %7 ]
%20 = call i8* @llvm.stacksave()
%21 = alloca i32, i64 %19
%22 = load i32, i32* %1
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %18
%25 = bitcast i32* %21 to i8*
%26 = zext i32 %22 to i64
%27 = shl nuw nsw i64 %26, 2
br label %28
28: ; preds = %24, %18
%29 = call i32 (...) @getchar()
%30 = load i32, i32* @EOF
%31 = icmp eq i32 %29, %30
br i1 %31, label %48, label %32
32: ; preds = %28, %43
%33 = phi i32 [ %45, %43 ], [ %29, %28 ]
%34 = phi i32 [ %44, %43 ], [ 0, %28 ]
switch i32 %33, label %35 [
i32 32, label %37
i32 10, label %37
i32 9, label %37
]
35: ; preds = %32
%36 = add nsw i32 %34, 1
br label %43
37: ; preds = %32, %32, %32
%38 = add nsw i32 %34, -1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %21, i64 %39
%41 = load i32, i32* %40
%42 = add nsw i32 %41, 1
store i32 %42, i32* %40
br label %43
43: ; preds = %37, %35
%44 = phi i32 [ %36, %35 ], [ 0, %37 ]
%45 = call i32 (...) @getchar()
%46 = load i32, i32* @EOF
%47 = icmp eq i32 %45, %46
br i1 %47, label %48, label %32
48: ; preds = %43, %28
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.9, i64 0, i64 0))
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.10, i64 0, i64 0))
%51 = load i32, i32* %1
%52 = icmp sgt i32 %51, 0
br i1 %52, label %53, label %63
53: ; preds = %48, %53
%54 = phi i64 [ %55, %53 ], [ 0, %48 ]
%55 = add nuw nsw i64 %54, 1
%56 = getelementptr inbounds i32, i32* %21, i64 %54
%57 = load i32, i32* %56
%58 = trunc i64 %55 to i32
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i32 %58, i32 %57)
%60 = load i32, i32* %1
%61 = sext i32 %60 to i64
%62 = icmp slt i64 %55, %61
br i1 %62, label %53, label %63
63: ; preds = %53, %48
br label %64
64: ; preds = %63, %12
ret i32 0
}