#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 */
typedef int /*<<< orphan*/ numbers;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char EOF;
int cast_int(char);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char, int);
int main() {
  char numbers[] = "0123456789";
  int n = sizeof(numbers) / sizeof(char);
  int freq[n - 1], x;
  memset(freq, 0, n);
  FILE *f = fopen("./text.txt", "r");
  char cursor;
  for (cursor = fgetc(f); cursor != EOF; cursor = fgetc(f)) {
    x = cast_int(cursor);
    if (x != -1)
      freq[x] += 1;
  }
  int i;
  for (i = 0; i < 10; ++i)
    printf("%c: %d\n", numbers[i], freq[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movabs $0x3736353433323130,%rax
35 36 37
mov    %rax,-0x10(%rbp)
movl   $0x393837,-0x9(%rbp)
movl   $0xb,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
lea    0xe55(%rip),%rdi
lea    0xe59(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x39(%rbp)
movsbl -0x39(%rbp),%eax
mov    0x2e0b(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1225 <main+0xd5>
movsbl -0x39(%rbp),%edi
call   1070 <cast_int@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
je     120f <main+0xbf>
mov    -0x48(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
jmp    1214 <main+0xc4>
mov    -0x38(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x39(%rbp)
jmp    11d2 <main+0x82>
movl   $0x0,-0x40(%rbp)
cmpl   $0xa,-0x40(%rbp)
jge    1266 <main+0x116>
mov    -0x48(%rbp),%rcx
movslq -0x40(%rbp),%rax
mov    -0x10(%rbp,%rax,1),%al
movslq -0x40(%rbp),%rdx
mov    (%rcx,%rdx,4),%edx
lea    0xdc8(%rip),%rdi
movsbl %al,%esi
call   1030 <printf@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    122c <main+0xdc>
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   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xb,%edx
call   1040 <memset@plt>
lea    0xe93(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    0x2e5d(%rip),%r14
jmp    1198 <main+0x48>
nopl   (%rax)
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r14),%al
je     11b2 <main+0x62>
movsbl %al,%edi
call   1070 <cast_int@plt>
cmp    $0xffffffff,%eax
je     1190 <main+0x40>
cltq
addl   $0x1,(%rsp,%rax,4)
jmp    1190 <main+0x40>
mov    (%rsp),%edx
lea    0xe51(%rip),%rbx
mov    %rbx,%rdi
mov    $0x30,%esi
call   1030 <printf@plt>
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
mov    $0x31,%esi
call   1030 <printf@plt>
mov    0x8(%rsp),%edx
mov    %rbx,%rdi
mov    $0x32,%esi
call   1030 <printf@plt>
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
mov    $0x33,%esi
call   1030 <printf@plt>
mov    0x10(%rsp),%edx
mov    %rbx,%rdi
mov    $0x34,%esi
call   1030 <printf@plt>
mov    0x14(%rsp),%edx
mov    %rbx,%rdi
mov    $0x35,%esi
call   1030 <printf@plt>
mov    0x18(%rsp),%edx
mov    %rbx,%rdi
mov    $0x36,%esi
call   1030 <printf@plt>
mov    0x1c(%rsp),%edx
mov    %rbx,%rdi
mov    $0x37,%esi
call   1030 <printf@plt>
mov    0x20(%rsp),%edx
mov    %rbx,%rdi
mov    $0x38,%esi
call   1030 <printf@plt>
mov    0x24(%rsp),%edx
mov    %rbx,%rdi
mov    $0x39,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.numbers = [11 x i8] c"0123456789\00"
@.str = [11 x i8] c"./text.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.2 = [8 x i8] c"%c: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [11 x i8]
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8
%9 = alloca i32
store i32 0, i32* %1
%10 = bitcast [11 x i8]* %2 to i8*
store i32 11, i32* %3
%11 = load i32, i32* %3
%12 = sub nsw i32 %11, 1
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %4
%15 = alloca i32, i64 %13
store i64 %13, i64* %5
%16 = load i32, i32* %3
%17 = call i32 @memset(i32* %15, i32 0, i32 %16)
%18 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %7
%19 = load i32*, i32** %7
%20 = call signext i8 @fgetc(i32* %19)
store i8 %20, i8* %8
br label %21
21: ; preds = %39, %0
%22 = load i8, i8* %8
%23 = sext i8 %22 to i32
%24 = load i8, i8* @EOF
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %23, %25
br i1 %26, label %27, label %42
27: ; preds = %21
%28 = load i8, i8* %8
%29 = call i32 @cast_int(i8 signext %28)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = icmp ne i32 %30, -1
br i1 %31, label %32, label %38
32: ; preds = %27
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %15, i64 %34
%36 = load i32, i32* %35
%37 = add nsw i32 %36, 1
store i32 %37, i32* %35
br label %38
38: ; preds = %32, %27
br label %39
39: ; preds = %38
%40 = load i32*, i32** %7
%41 = call signext i8 @fgetc(i32* %40)
store i8 %41, i8* %8
br label %21
42: ; preds = %21
store i32 0, i32* %9
br label %43
43: ; preds = %56, %42
%44 = load i32, i32* %9
%45 = icmp slt i32 %44, 10
br i1 %45, label %46, label %59
46: ; preds = %43
%47 = load i32, i32* %9
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = load i32, i32* %9
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %15, i64 %52
%54 = load i32, i32* %53
%55 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8 signext %50, i32 %54)
br label %56
56: ; preds = %46
%57 = load i32, i32* %9
%58 = add nsw i32 %57, 1
store i32 %58, i32* %9
br label %43
59: ; preds = %43
store i32 0, i32* %1
%60 = load i8*, i8** %4
%61 = load i32, i32* %1
ret i32 %61
}

LLVM IR (-O2):
@.str = [11 x i8] c"./text.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.2 = [8 x i8] c"%c: %d\0A\00"
define i32 @main() {
%1 = alloca [10 x i32]
%2 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%3 = call i32 @memset(i32* %2, i32 0, i32 11)
%4 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = call signext i8 @fgetc(i32* %4)
%6 = load i8, i8* @EOF
%7 = icmp eq i8 %5, %6
br i1 %7, label %8, label %38
8: ; preds = %47, %0
%9 = load i32, i32* %2
%10 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8 signext 48, i32 %9)
%11 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 1
%12 = load i32, i32* %11
%13 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8 signext 49, i32 %12)
%14 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 2
%15 = load i32, i32* %14
%16 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8 signext 50, i32 %15)
%17 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 3
%18 = load i32, i32* %17
%19 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8 signext 51, i32 %18)
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 4
%21 = load i32, i32* %20
%22 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8 signext 52, i32 %21)
%23 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 5
%24 = load i32, i32* %23
%25 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8 signext 53, i32 %24)
%26 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 6
%27 = load i32, i32* %26
%28 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8 signext 54, i32 %27)
%29 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 7
%30 = load i32, i32* %29
%31 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8 signext 55, i32 %30)
%32 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 8
%33 = load i32, i32* %32
%34 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8 signext 56, i32 %33)
%35 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 9
%36 = load i32, i32* %35
%37 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8 signext 57, i32 %36)
ret i32 0
38: ; preds = %0, %47
%39 = phi i8 [ %48, %47 ], [ %5, %0 ]
%40 = call i32 @cast_int(i8 signext %39)
%41 = icmp eq i32 %40, -1
br i1 %41, label %47, label %42
42: ; preds = %38
%43 = sext i32 %40 to i64
%44 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %43
%45 = load i32, i32* %44
%46 = add nsw i32 %45, 1
store i32 %46, i32* %44
br label %47
47: ; preds = %38, %42
%48 = call signext i8 @fgetc(i32* %4)
%49 = load i8, i8* @EOF
%50 = icmp eq i8 %48, %49
br i1 %50, label %8, label %38
}