#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);
int main() {
  int character, i, characters[128];
  for (i = 0; i < 128; ++i) {
    characters[i] = 0;
  }
  printf("Input text below, to count characters:\n");
  while ((character = getchar()) != EOF) {
    ++characters[character];
  }
  printf("\nHorizontal Histogram of the input:\n");
  for (i = 0; i < 128; ++i) {
    if (!(characters[i] > 0)) {
      continue;
    }
    if (i == '\b') {
      printf("\\b:\t");
    } else if (i == '\n') {
      printf("\\n:\t");
    } else if (i == '\t') {
      printf("\\t:\t");
    } else {
      printf("%2c:\t", i);
    }
    int j;
    j = 0;
    while (j < characters[i]) {
      putchar('#');
      ++j;
    }
    putchar('\n');
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x80,-0xc(%rbp)
jge    1173 <main+0x43>
movslq -0xc(%rbp),%rax
movl   $0x0,-0x210(%rbp,%rax,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1149 <main+0x19>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e56(%rip),%rcx
cmp    (%rcx),%eax
je     11b4 <main+0x84>
movslq -0x8(%rbp),%rax
mov    -0x210(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x210(%rbp,%rax,4)
jmp    1181 <main+0x51>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x80,-0xc(%rbp)
jge    12b6 <main+0x186>
movslq -0xc(%rbp),%rax
cmpl   $0x0,-0x210(%rbp,%rax,4)
jg     11ed <main+0xbd>
jmp    12a8 <main+0x178>
cmpl   $0x8,-0xc(%rbp)
jne    120a <main+0xda>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    125f <main+0x12f>
cmpl   $0xa,-0xc(%rbp)
jne    1227 <main+0xf7>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    125a <main+0x12a>
cmpl   $0x9,-0xc(%rbp)
jne    1244 <main+0x114>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1255 <main+0x125>
mov    -0xc(%rbp),%esi
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    125a <main+0x12a>
jmp    125f <main+0x12f>
movl   $0x0,-0x214(%rbp)
mov    -0x214(%rbp),%eax
movslq -0xc(%rbp),%rcx
cmp    -0x210(%rbp,%rcx,4),%eax
jge    129e <main+0x16e>
mov    $0x23,%edi
call   1030 <putchar@plt>
mov    -0x214(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x214(%rbp)
jmp    1269 <main+0x139>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11c9 <main+0x99>
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rsp,%rdi
mov    $0x200,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    0xe9e(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    0x2e5e(%rip),%rbx
cmp    (%rbx),%eax
je     11a1 <main+0x51>
xchg   %ax,%ax
cltq
addl   $0x1,(%rsp,%rax,4)
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    (%rbx),%eax
jne    1190 <main+0x40>
lea    0xe94(%rip),%rdi
call   1040 <puts@plt>
lea    0xe51(%rip),%r14
lea    0xe4f(%rip),%r12
lea    0xe3e(%rip),%r15
lea    0xe46(%rip),%r13
xor    %ebx,%ebx
jmp    11dd <main+0x8d>
nopl   (%rax)
add    $0x1,%rbx
cmp    $0x80,%rbx
je     123b <main+0xeb>
mov    (%rsp,%rbx,4),%ebp
test   %ebp,%ebp
jle    11d0 <main+0x80>
cmp    $0xa,%ebx
je     11fd <main+0xad>
cmp    $0x9,%ebx
je     11f8 <main+0xa8>
cmp    $0x8,%ebx
jne    1209 <main+0xb9>
mov    %r15,%rdi
jmp    1200 <main+0xb0>
mov    %r12,%rdi
jmp    1200 <main+0xb0>
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1220 <main+0xd0>
mov    %r13,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x23,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    1220 <main+0xd0>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11d0 <main+0x80>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@EOF = global i32 0
@.str.2 = [5 x i8] c"\\b:\09\00"
@.str.3 = [5 x i8] c"\\n:\09\00"
@.str.4 = [5 x i8] c"\\t:\09\00"
@.str.5 = [6 x i8] c"%2c:\09\00"
@str = [39 x i8] c"Input text below, to count characters:\00"
@str.6 = [36 x i8] c"\0AHorizontal Histogram of the input:\00"
define i32 @main() {
%1 = alloca [128 x i32]
%2 = bitcast [128 x i32]* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 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 %16, label %7
7: ; preds = %0, %7
%8 = phi i32 [ %13, %7 ], [ %4, %0 ]
%9 = sext i32 %8 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 = tail call i32 (...) @getchar()
%14 = load i32, i32* @EOF
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %7
16: ; preds = %7, %0
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.6, i64 0, i64 0))
br label %18
18: ; preds = %16, %41
%19 = phi i64 [ 0, %16 ], [ %42, %41 ]
%20 = getelementptr inbounds [128 x i32], [128 x i32]* %1, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %41
23: ; preds = %18
%24 = trunc i64 %19 to i32
switch i32 %24, label %31 [
i32 8, label %25
i32 10, label %27
i32 9, label %29
]
25: ; preds = %23
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %33
27: ; preds = %23
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %33
29: ; preds = %23
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %33
31: ; preds = %23
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %24)
br label %33
33: ; preds = %25, %29, %31, %27
br label %34
34: ; preds = %33, %34
%35 = phi i32 [ %37, %34 ], [ 0, %33 ]
%36 = tail call i32 @putchar(i8 signext 35)
%37 = add nuw nsw i32 %35, 1
%38 = icmp eq i32 %37, %21
br i1 %38, label %39, label %34
39: ; preds = %34
%40 = tail call i32 @putchar(i8 signext 10)
br label %41
41: ; preds = %18, %39
%42 = add nuw nsw i64 %19, 1
%43 = icmp eq i64 %42, 128
br i1 %43, label %44, label %18
44: ; preds = %41
ret i32 0
}