#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 main() {
  int character, i, white_count, character_count;
  int digits_count[10];
  white_count = character_count = 0;
  for (i = 0; i < 10; ++i) {
    digits_count[i] = 0;
  }
  printf("Input text below, i'll count characters, digits and white spaces for "
         "you:\n");
  while ((character = getchar()) != EOF) {
    if (character >= 48 && character <= 57) {
      ++digits_count[character - 48];
    } else if (character == ' ' || character == '\n' || character == '\t') {
      ++white_count;
    } else {
      ++character_count;
    }
  }
  printf("Digits Table:\n\n");
  printf("%5s %6s\n", "Digit", "Amount");
  for (i = 0; i < 10; ++i) {
    printf("%5d %6d\n", i, digits_count[i]);
  }
  printf("Amount of white spaces: %d\n", white_count);
  printf("Amount of characters: %d\n", character_count);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    1168 <main+0x48>
movslq -0xc(%rbp),%rax
movl   $0x0,-0x40(%rbp,%rax,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1144 <main+0x24>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e61(%rip),%rcx
cmp    (%rcx),%eax
je     11fa <main+0xda>
cmpl   $0x30,-0x8(%rbp)
jl     11bb <main+0x9b>
cmpl   $0x39,-0x8(%rbp)
jg     11bb <main+0x9b>
mov    -0x8(%rbp),%eax
sub    $0x30,%eax
cltq
mov    -0x40(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x40(%rbp,%rax,4)
jmp    11f5 <main+0xd5>
cmpl   $0x20,-0x8(%rbp)
je     11d9 <main+0xb9>
cmpl   $0xa,-0x8(%rbp)
je     11d9 <main+0xb9>
cmpl   $0x9,-0x8(%rbp)
jne    11e7 <main+0xc7>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11f0 <main+0xd0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f5 <main+0xd5>
jmp    1176 <main+0x56>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe4c(%rip),%rdi
lea    0xe4e(%rip),%rsi
lea    0xe4d(%rip),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    125c <main+0x13c>
mov    -0xc(%rbp),%esi
movslq -0xc(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%edx
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    122b <main+0x10b>
mov    -0x10(%rbp),%esi
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movq   $0x0,0x40(%rsp)
lea    0xefa(%rip),%rdi
call   1030 <puts@plt>
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e77(%rip),%rbx
mov    $0x0,%ecx
mov    $0x0,%edx
mov    $0x0,%r10d
mov    $0x0,%edi
mov    $0x0,%r8d
mov    $0x0,%r15d
mov    $0x0,%r9d
mov    $0x0,%r13d
mov    $0x0,%r12d
mov    $0x0,%ebp
mov    $0x0,%esi
cmp    (%rbx),%eax
je     1234 <main+0x104>
movabs $0x100000600,%r14
xor    %r15d,%r15d
xor    %ebp,%ebp
jmp    11e2 <main+0xb2>
nopw   0x0(%rax,%rax,1)
mov    %ecx,%eax
addl   $0x1,0x20(%rsp,%rax,4)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%rbx),%eax
je     1202 <main+0xd2>
lea    -0x30(%rax),%ecx
cmp    $0x9,%ecx
jbe    11d0 <main+0xa0>
cmp    $0x20,%eax
ja     11fc <main+0xcc>
mov    %eax,%eax
bt     %rax,%r14
jae    11fc <main+0xcc>
add    $0x1,%ebp
jmp    11d7 <main+0xa7>
add    $0x1,%r15d
jmp    11d7 <main+0xa7>
mov    0x20(%rsp),%r12d
mov    0x24(%rsp),%r13d
mov    0x28(%rsp),%r9d
mov    %r15d,%esi
mov    0x2c(%rsp),%r15d
mov    0x30(%rsp),%r8d
mov    0x34(%rsp),%edi
mov    0x38(%rsp),%r10d
mov    0x3c(%rsp),%edx
mov    0x40(%rsp),%ecx
mov    0x44(%rsp),%r14d
mov    %r8d,0x4(%rsp)
mov    %edi,0x8(%rsp)
mov    %r10d,0xc(%rsp)
mov    %esi,0x10(%rsp)
mov    %edx,0x14(%rsp)
mov    %r14d,0x18(%rsp)
mov    %ecx,0x1c(%rsp)
lea    0xe45(%rip),%rdi
mov    %r9d,%ebx
call   1030 <puts@plt>
lea    0xd97(%rip),%rdi
lea    0xd99(%rip),%rsi
lea    0xd98(%rip),%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd91(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r13d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x2,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x3,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x4,%esi
mov    0x4(%rsp),%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x5,%esi
mov    0x8(%rsp),%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x6,%esi
mov    0xc(%rsp),%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x7,%esi
mov    0x14(%rsp),%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x8,%esi
mov    0x1c(%rsp),%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x9,%esi
mov    0x18(%rsp),%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xcdd(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xce9(%rip),%rdi
mov    0x10(%rsp),%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [75 x i8] c"Input text below, i'll count characters, digits and white spaces for you:\0A\00"
@EOF = global i32 0
@.str.1 = [16 x i8] c"Digits Table:\0A\0A\00"
@.str.2 = [9 x i8] c"%5s %6s\0A\00"
@.str.3 = [6 x i8] c"Digit\00"
@.str.4 = [7 x i8] c"Amount\00"
@.str.5 = [9 x i8] c"%5d %6d\0A\00"
@.str.6 = [28 x i8] c"Amount of white spaces: %d\0A\00"
@.str.7 = [26 x i8] c"Amount of characters: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [10 x i32]
store i32 0, i32* %1
store i32 0, i32* %5
store i32 0, i32* %4
store i32 0, i32* %3
br label %7
7: ; preds = %14, %0
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 10
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %12
store i32 0, i32* %13
br label %14
14: ; preds = %10
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
br label %7
17: ; preds = %7
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %52, %17
%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 %53
23: ; preds = %19
%24 = load i32, i32* %2
%25 = icmp sge i32 %24, 48
br i1 %25, label %26, label %36
26: ; preds = %23
%27 = load i32, i32* %2
%28 = icmp sle i32 %27, 57
br i1 %28, label %29, label %36
29: ; preds = %26
%30 = load i32, i32* %2
%31 = sub nsw i32 %30, 48
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = add nsw i32 %34, 1
store i32 %35, i32* %33
br label %52
36: ; preds = %26, %23
%37 = load i32, i32* %2
%38 = icmp eq i32 %37, 32
br i1 %38, label %45, label %39
39: ; preds = %36
%40 = load i32, i32* %2
%41 = icmp eq i32 %40, 10
br i1 %41, label %45, label %42
42: ; preds = %39
%43 = load i32, i32* %2
%44 = icmp eq i32 %43, 9
br i1 %44, label %45, label %48
45: ; preds = %42, %39, %36
%46 = load i32, i32* %4
%47 = add nsw i32 %46, 1
store i32 %47, i32* %4
br label %51
48: ; preds = %42
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
store i32 %50, i32* %5
br label %51
51: ; preds = %48, %45
br label %52
52: ; preds = %51, %29
br label %19
53: ; preds = %19
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %56
56: ; preds = %66, %53
%57 = load i32, i32* %3
%58 = icmp slt i32 %57, 10
br i1 %58, label %59, label %69
59: ; preds = %56
%60 = load i32, i32* %3
%61 = load i32, i32* %3
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %62
%64 = load i32, i32* %63
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %60, i32 %64)
br label %66
66: ; preds = %59
%67 = load i32, i32* %3
%68 = add nsw i32 %67, 1
store i32 %68, i32* %3
br label %56
69: ; preds = %56
%70 = load i32, i32* %4
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %70)
%72 = load i32, i32* %5
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i32 %72)
%74 = load i32, i32* %1
ret i32 %74
}

LLVM IR (-O2):
@EOF = global i32 0
@.str.2 = [9 x i8] c"%5s %6s\0A\00"
@.str.3 = [6 x i8] c"Digit\00"
@.str.4 = [7 x i8] c"Amount\00"
@.str.5 = [9 x i8] c"%5d %6d\0A\00"
@.str.6 = [28 x i8] c"Amount of white spaces: %d\0A\00"
@.str.7 = [26 x i8] c"Amount of characters: %d\0A\00"
@str = [74 x i8] c"Input text below, i'll count characters, digits and white spaces for you:\00"
@str.8 = [15 x i8] c"Digits Table:\0A\00"
define i32 @main() {
%1 = alloca [10 x i32]
%2 = bitcast [10 x i32]* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 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 %50, label %7
7: ; preds = %0, %23
%8 = phi i32 [ %26, %23 ], [ %4, %0 ]
%9 = phi i32 [ %25, %23 ], [ 0, %0 ]
%10 = phi i32 [ %24, %23 ], [ 0, %0 ]
%11 = add i32 %8, -48
%12 = icmp ult i32 %11, 10
br i1 %12, label %13, label %18
13: ; preds = %7
%14 = zext i32 %11 to i64
%15 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %14
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1
store i32 %17, i32* %15
br label %23
18: ; preds = %7
switch i32 %8, label %21 [
i32 32, label %19
i32 10, label %19
i32 9, label %19
]
19: ; preds = %18, %18, %18
%20 = add nsw i32 %10, 1
br label %23
21: ; preds = %18
%22 = add nsw i32 %9, 1
br label %23
23: ; preds = %19, %21, %13
%24 = phi i32 [ %10, %13 ], [ %20, %19 ], [ %10, %21 ]
%25 = phi i32 [ %9, %13 ], [ %9, %19 ], [ %22, %21 ]
%26 = tail call i32 (...) @getchar()
%27 = load i32, i32* @EOF
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %7
29: ; preds = %23
%30 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%31 = load i32, i32* %30
%32 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 1
%33 = load i32, i32* %32
%34 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 2
%35 = load i32, i32* %34
%36 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 3
%37 = load i32, i32* %36
%38 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 4
%39 = load i32, i32* %38
%40 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 5
%41 = load i32, i32* %40
%42 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 6
%43 = load i32, i32* %42
%44 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 7
%45 = load i32, i32* %44
%46 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 8
%47 = load i32, i32* %46
%48 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 9
%49 = load i32, i32* %48
br label %50
50: ; preds = %29, %0
%51 = phi i32 [ 0, %0 ], [ %49, %29 ]
%52 = phi i32 [ 0, %0 ], [ %47, %29 ]
%53 = phi i32 [ 0, %0 ], [ %45, %29 ]
%54 = phi i32 [ 0, %0 ], [ %43, %29 ]
%55 = phi i32 [ 0, %0 ], [ %41, %29 ]
%56 = phi i32 [ 0, %0 ], [ %39, %29 ]
%57 = phi i32 [ 0, %0 ], [ %37, %29 ]
%58 = phi i32 [ 0, %0 ], [ %35, %29 ]
%59 = phi i32 [ 0, %0 ], [ %33, %29 ]
%60 = phi i32 [ 0, %0 ], [ %31, %29 ]
%61 = phi i32 [ 0, %0 ], [ %24, %29 ]
%62 = phi i32 [ 0, %0 ], [ %25, %29 ]
%63 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.8, i64 0, i64 0))
%64 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%65 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 0, i32 %60)
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 1, i32 %59)
%67 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 2, i32 %58)
%68 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 3, i32 %57)
%69 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 4, i32 %56)
%70 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 5, i32 %55)
%71 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 6, i32 %54)
%72 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 7, i32 %53)
%73 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 8, i32 %52)
%74 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 9, i32 %51)
%75 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %61)
%76 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i32 %62)
ret i32 0
}