#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 /*<<< orphan*/ putchar(char);
main() {
  int c, currentLength, i, j;
  int wordLengthFrequencies[45];
  for (i = 0; i <= 45; ++i) {
    wordLengthFrequencies[i] = 0;
  }
  printf("Enter a string of words to compute the word length frequency. Hit "
         "CTRL+D to compute\n");
  currentLength = 0;
  while ((c = getchar()) != EOF) {
    if (c != ' ' && c != '\t' && c != '\n') {
      ++currentLength;
    } else {
      ++wordLengthFrequencies[currentLength];
      currentLength = 0;
    }
  }
  ++wordLengthFrequencies[currentLength];
  printf("Length Histogram of inputted words\n");
  printf("====================================================================="
         "===========\n");
  for (i = 1; i <= 45; ++i) {
    int frequency = wordLengthFrequencies[i];
    if (frequency > 0) {
      printf("%d: ", i);
      for (j = 0; j < frequency; ++j) {
        putchar('#');
      }
      putchar('\n');
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x2d,-0x10(%rbp)
jg     1170 <main+0x40>
movslq -0x10(%rbp),%rax
movl   $0x0,-0xd0(%rbp,%rax,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1149 <main+0x19>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e52(%rip),%rcx
cmp    (%rcx),%eax
je     11eb <main+0xbb>
cmpl   $0x20,-0x8(%rbp)
je     11ca <main+0x9a>
cmpl   $0x9,-0x8(%rbp)
je     11ca <main+0x9a>
cmpl   $0xa,-0x8(%rbp)
je     11ca <main+0x9a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11e6 <main+0xb6>
movslq -0xc(%rbp),%rax
mov    -0xd0(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0xd0(%rbp,%rax,4)
movl   $0x0,-0xc(%rbp)
jmp    1185 <main+0x55>
movslq -0xc(%rbp),%rax
mov    -0xd0(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0xd0(%rbp,%rax,4)
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x10(%rbp)
cmpl   $0x2d,-0x10(%rbp)
jg     12a7 <main+0x177>
movslq -0x10(%rbp),%rax
mov    -0xd0(%rbp,%rax,4),%eax
mov    %eax,-0xd4(%rbp)
cmpl   $0x0,-0xd4(%rbp)
jle    1294 <main+0x164>
mov    -0x10(%rbp),%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xd4(%rbp),%eax
jge    128a <main+0x15a>
mov    $0x23,%edi
call   1030 <putchar@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1263 <main+0x133>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1299 <main+0x169>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1223 <main+0xf3>
mov    -0x4(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xb8,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movq   $0x0,0xb0(%rsp)
lea    0xe63(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0x2e31(%rip),%r14
cmp    (%r14),%eax
jne    123b <main+0xfb>
movslq %ebx,%rax
addl   $0x1,(%rsp,%rax,4)
lea    0xe8f(%rip),%rdi
call   1040 <puts@plt>
lea    0xea6(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebx
lea    0xe19(%rip),%r14
jmp    11fa <main+0xba>
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    $0x2e,%rbx
je     122b <main+0xeb>
mov    (%rsp,%rbx,4),%ebp
test   %ebp,%ebp
jle    11f0 <main+0xb0>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
nopl   (%rax)
mov    $0x23,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    1210 <main+0xd0>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11f0 <main+0xb0>
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
movabs $0x100000600,%r15
xor    %ebx,%ebx
jmp    1263 <main+0x123>
nopl   0x0(%rax)
add    $0x1,%ebx
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    (%r14),%eax
je     11bc <main+0x7c>
cmp    $0x20,%eax
ja     1250 <main+0x110>
mov    %eax,%eax
bt     %rax,%r15
jae    1250 <main+0x110>
movslq %ebx,%rax
addl   $0x1,(%rsp,%rax,4)
xor    %ebx,%ebx
jmp    1253 <main+0x113>

LLVM IR (-O0):
@.str = [85 x i8] c"Enter a string of words to compute the word length frequency. Hit CTRL+D to compute\0A\00"
@EOF = global i32 0
@.str.1 = [36 x i8] c"Length Histogram of inputted words\0A\00"
@.str.2 = [82 x i8] c"================================================================================\0A\00"
@.str.3 = [5 x i8] c"%d: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [45 x i32]
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
br label %8
8: ; preds = %15, %0
%9 = load i32, i32* %4
%10 = icmp sle i32 %9, 45
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [45 x i32], [45 x i32]* %6, i64 0, i64 %13
store i32 0, i32* %14
br label %15
15: ; preds = %11
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
store i32 %17, i32* %4
br label %8
18: ; preds = %8
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %20
20: ; preds = %42, %18
%21 = call i32 (...) @getchar()
store i32 %21, i32* %2
%22 = load i32, i32* @EOF
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %43
24: ; preds = %20
%25 = load i32, i32* %2
%26 = icmp ne i32 %25, 32
br i1 %26, label %27, label %36
27: ; preds = %24
%28 = load i32, i32* %2
%29 = icmp ne i32 %28, 9
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = load i32, i32* %2
%32 = icmp ne i32 %31, 10
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
br label %42
36: ; preds = %30, %27, %24
%37 = load i32, i32* %3
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [45 x i32], [45 x i32]* %6, i64 0, i64 %38
%40 = load i32, i32* %39
%41 = add nsw i32 %40, 1
store i32 %41, i32* %39
store i32 0, i32* %3
br label %42
42: ; preds = %36, %33
br label %20
43: ; preds = %20
%44 = load i32, i32* %3
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [45 x i32], [45 x i32]* %6, i64 0, i64 %45
%47 = load i32, i32* %46
%48 = add nsw i32 %47, 1
store i32 %48, i32* %46
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %4
br label %51
51: ; preds = %76, %43
%52 = load i32, i32* %4
%53 = icmp sle i32 %52, 45
br i1 %53, label %54, label %79
54: ; preds = %51
%55 = load i32, i32* %4
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [45 x i32], [45 x i32]* %6, i64 0, i64 %56
%58 = load i32, i32* %57
store i32 %58, i32* %7
%59 = load i32, i32* %7
%60 = icmp sgt i32 %59, 0
br i1 %60, label %61, label %75
61: ; preds = %54
%62 = load i32, i32* %4
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %62)
store i32 0, i32* %5
br label %64
64: ; preds = %70, %61
%65 = load i32, i32* %5
%66 = load i32, i32* %7
%67 = icmp slt i32 %65, %66
br i1 %67, label %68, label %73
68: ; preds = %64
%69 = call i32 @putchar(i8 signext 35)
br label %70
70: ; preds = %68
%71 = load i32, i32* %5
%72 = add nsw i32 %71, 1
store i32 %72, i32* %5
br label %64
73: ; preds = %64
%74 = call i32 @putchar(i8 signext 10)
br label %75
75: ; preds = %73, %54
br label %76
76: ; preds = %75
%77 = load i32, i32* %4
%78 = add nsw i32 %77, 1
store i32 %78, i32* %4
br label %51
79: ; preds = %51
%80 = load i32, i32* %1
ret i32 %80
}

LLVM IR (-O2):
@EOF = global i32 0
@.str.3 = [5 x i8] c"%d: \00"
@str = [84 x i8] c"Enter a string of words to compute the word length frequency. Hit CTRL+D to compute\00"
@str.4 = [35 x i8] c"Length Histogram of inputted words\00"
@str.5 = [81 x i8] c"================================================================================\00"
define i32 @main() {
%1 = alloca [45 x i32]
%2 = bitcast [45 x i32]* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([84 x i8], [84 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (...) @getchar()
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %22, label %7
7: ; preds = %0, %17
%8 = phi i32 [ %19, %17 ], [ %4, %0 ]
%9 = phi i32 [ %18, %17 ], [ 0, %0 ]
switch i32 %8, label %10 [
i32 32, label %12
i32 10, label %12
i32 9, label %12
]
10: ; preds = %7
%11 = add nsw i32 %9, 1
br label %17
12: ; preds = %7, %7, %7
%13 = sext i32 %9 to i64
%14 = getelementptr inbounds [45 x i32], [45 x i32]* %1, i64 0, i64 %13
%15 = load i32, i32* %14
%16 = add nsw i32 %15, 1
store i32 %16, i32* %14
br label %17
17: ; preds = %12, %10
%18 = phi i32 [ %11, %10 ], [ 0, %12 ]
%19 = tail call i32 (...) @getchar()
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %7
22: ; preds = %17, %0
%23 = phi i32 [ 0, %0 ], [ %18, %17 ]
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [45 x i32], [45 x i32]* %1, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = add nsw i32 %26, 1
store i32 %27, i32* %25
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.4, i64 0, i64 0))
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str.5, i64 0, i64 0))
br label %30
30: ; preds = %22, %45
%31 = phi i64 [ 1, %22 ], [ %46, %45 ]
%32 = getelementptr inbounds [45 x i32], [45 x i32]* %1, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %45
35: ; preds = %30
%36 = trunc i64 %31 to i32
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %35, %38
%39 = phi i32 [ 0, %35 ], [ %41, %38 ]
%40 = tail call i32 @putchar(i8 signext 35)
%41 = add nuw nsw i32 %39, 1
%42 = icmp eq i32 %41, %33
br i1 %42, label %43, label %38
43: ; preds = %38
%44 = tail call i32 @putchar(i8 signext 10)
br label %45
45: ; preds = %43, %30
%46 = add nuw nsw i64 %31, 1
%47 = icmp eq i64 %46, 46
br i1 %47, label %48, label %30
48: ; preds = %45
ret i32 0
}