#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;
  int frequencies[128];
  int maxcount = 0;
  int cc = 0;
  int i, j;
  for (i = 0; i < 128; ++i) {
    frequencies[i] = 0;
  }
  while ((c = getchar()) != EOF) {
    cc = ++frequencies[c];
    if (cc > maxcount) {
      maxcount = cc;
    }
  }
  printf("\n\nHORIZONTAL HISTOGRAM\n\n");
  printf("      +-");
  for (i = 0; i < maxcount; ++i) {
    putchar('-');
  }
  putchar('\n');
  for (i = 0; i < 128; ++i) {
    if (frequencies[i] > 0) {
      printf("%4d  | ", i);
      for (j = 0; j < maxcount; ++j) {
        if (frequencies[i] > j) {
          putchar('*');
        }
      }
      putchar('\n');
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x214(%rbp)
movl   $0x0,-0x218(%rbp)
movl   $0x0,-0x21c(%rbp)
cmpl   $0x80,-0x21c(%rbp)
jge    1196 <main+0x66>
movslq -0x21c(%rbp),%rax
movl   $0x0,-0x210(%rbp,%rax,4)
mov    -0x21c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x21c(%rbp)
jmp    1160 <main+0x30>
jmp    119b <main+0x6b>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e3c(%rip),%rcx
cmp    (%rcx),%eax
je     11f2 <main+0xc2>
movslq -0x8(%rbp),%rcx
mov    -0x210(%rbp,%rcx,4),%eax
add    $0x1,%eax
mov    %eax,-0x210(%rbp,%rcx,4)
mov    %eax,-0x218(%rbp)
mov    -0x218(%rbp),%eax
cmp    -0x214(%rbp),%eax
jle    11ed <main+0xbd>
mov    -0x218(%rbp),%eax
mov    %eax,-0x214(%rbp)
jmp    119b <main+0x6b>
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x21c(%rbp)
mov    -0x21c(%rbp),%eax
cmp    -0x214(%rbp),%eax
jge    1248 <main+0x118>
mov    $0x2d,%edi
call   1030 <putchar@plt>
mov    -0x21c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x21c(%rbp)
jmp    1218 <main+0xe8>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x0,-0x21c(%rbp)
cmpl   $0x80,-0x21c(%rbp)
jge    1311 <main+0x1e1>
movslq -0x21c(%rbp),%rax
cmpl   $0x0,-0x210(%rbp,%rax,4)
jle    12f8 <main+0x1c8>
mov    -0x21c(%rbp),%esi
lea    0xd94(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x220(%rbp)
mov    -0x220(%rbp),%eax
cmp    -0x214(%rbp),%eax
jge    12ee <main+0x1be>
movslq -0x21c(%rbp),%rax
mov    -0x210(%rbp,%rax,4),%eax
cmp    -0x220(%rbp),%eax
jle    12d5 <main+0x1a5>
mov    $0x2a,%edi
call   1030 <putchar@plt>
jmp    12da <main+0x1aa>
mov    -0x220(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x220(%rbp)
jmp    129f <main+0x16f>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    12fd <main+0x1cd>
mov    -0x21c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x21c(%rbp)
jmp    125c <main+0x12c>
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %rsp,%rdi
xor    %r15d,%r15d
mov    $0x200,%edx
xor    %esi,%esi
call   1060 <memset@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    0x2e69(%rip),%rbx
cmp    (%rbx),%eax
je     11ad <main+0x5d>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
cltq
mov    (%rsp,%rax,4),%ecx
lea    0x1(%rcx),%edx
mov    %edx,(%rsp,%rax,4)
cmp    %r15d,%ecx
cmovge %edx,%r15d
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    (%rbx),%eax
jne    1190 <main+0x40>
lea    0xe5d(%rip),%rdi
call   1040 <puts@plt>
lea    0xe40(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r15d,%r15d
jle    11df <main+0x8f>
mov    %r15d,%ebx
nop
mov    $0x2d,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
jne    11d0 <main+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe19(%rip),%r14
xor    %r12d,%r12d
jmp    1217 <main+0xc7>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r12
cmp    $0x80,%r12
je     1258 <main+0x108>
mov    (%rsp,%r12,4),%ebp
test   %ebp,%ebp
jle    120a <main+0xba>
mov    %r14,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r15d,%r15d
jle    1200 <main+0xb0>
xor    %ebx,%ebx
jmp    1248 <main+0xf8>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebx
cmp    %ebx,%r15d
je     1200 <main+0xb0>
cmp    %ebx,%ebp
jle    1240 <main+0xf0>
mov    $0x2a,%edi
call   1030 <putchar@plt>
jmp    1240 <main+0xf0>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@EOF = global i32 0
@.str.1 = [9 x i8] c" +-\00"
@.str.2 = [8 x i8] c"%4d | \00"
@str = [24 x i8] c"\0A\0AHORIZONTAL HISTOGRAM\0A\00"
define i32 @main() {
%1 = alloca [128 x i32]
%2 = bitcast [128 x i32]* %1 to i8*
%3 = tail call i32 (...) @getchar()
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %18, label %6
6: ; preds = %0, %6
%7 = phi i32 [ %15, %6 ], [ %3, %0 ]
%8 = phi i32 [ %14, %6 ], [ 0, %0 ]
%9 = sext i32 %7 to i64
%10 = getelementptr inbounds [128 x i32], [128 x i32]* %1, i64 0, i64 %9
%11 = load i32, i32* %10
%12 = add nsw i32 %11, 1
store i32 %12, i32* %10
%13 = icmp slt i32 %11, %8
%14 = select i1 %13, i32 %8, i32 %12
%15 = tail call i32 (...) @getchar()
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %6
18: ; preds = %6, %0
%19 = phi i32 [ 0, %0 ], [ %14, %6 ]
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp sgt i32 %19, 0
br i1 %22, label %23, label %28
23: ; preds = %18, %23
%24 = phi i32 [ %26, %23 ], [ 0, %18 ]
%25 = tail call i32 @putchar(i8 signext 45)
%26 = add nuw nsw i32 %24, 1
%27 = icmp eq i32 %26, %19
br i1 %27, label %28, label %23
28: ; preds = %23, %18
%29 = tail call i32 @putchar(i8 signext 10)
br label %30
30: ; preds = %28, %48
%31 = phi i64 [ 0, %28 ], [ %49, %48 ]
%32 = getelementptr inbounds [128 x i32], [128 x i32]* %1, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %48
35: ; preds = %30
%36 = trunc i64 %31 to i32
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %36)
br i1 %22, label %38, label %46
38: ; preds = %35, %43
%39 = phi i32 [ %44, %43 ], [ 0, %35 ]
%40 = icmp sgt i32 %33, %39
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = tail call i32 @putchar(i8 signext 42)
br label %43
43: ; preds = %38, %41
%44 = add nuw nsw i32 %39, 1
%45 = icmp eq i32 %44, %19
br i1 %45, label %46, label %38
46: ; preds = %43, %35
%47 = tail call i32 @putchar(i8 signext 10)
br label %48
48: ; preds = %30, %46
%49 = add nuw nsw i64 %31, 1
%50 = icmp eq i64 %49, 128
br i1 %50, label %51, label %30
51: ; preds = %48
ret i32 0
}