#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ assert(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
unsigned long ftell(int /*<<< orphan*/ *);
char getc(int /*<<< orphan*/ *);
double log2(double);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  if (argc != 2)
    return 0;
  int count[256], i;
  for (i = 0; i < 256; ++i)
    count[i] = 0;
  FILE *input = fopen(argv[1], "r");
  assert(input);
  fseek(input, -1L, SEEK_END);
  unsigned long d = ftell(input);
  fseek(input, 0, SEEK_SET);
  char ch;
  unsigned long c = 0;
  bool ind;
  while (ch = getc(input)) {
    ind = false;
    ++c;
    count[ch]++;
    if (ftell(input) == d)
      break;
  }
  double e = 0;
  double tmp;
  printf("Symbol\t\t\tSymbol Count\t\t\tProbability\n");
  for (i = 0; i < 256; ++i) {
    if (!count[i])
      continue;
    tmp = (double)count[i] / (double)c;
    printf("\"%c\"\t\t\t%i\t\t\t%f\n", (char)i, count[i], tmp);
    e -= tmp * log2(tmp);
  }
  printf("Entropy: %f\n", e);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     119f <main+0x2f>
movl   $0x0,-0x4(%rbp)
jmp    1413 <main+0x2a3>
movl   $0x0,-0x414(%rbp)
cmpl   $0x100,-0x414(%rbp)
jge    11df <main+0x6f>
movslq -0x414(%rbp),%rax
movl   $0x0,-0x410(%rbp,%rax,4)
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    11a9 <main+0x39>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe32(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x420(%rbp)
mov    -0x420(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x420(%rbp),%rdi
mov    0x2dd4(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffffffffffff,%rsi
call   1070 <fseek@plt>
mov    -0x420(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x428(%rbp)
mov    -0x420(%rbp),%rdi
mov    0x2d95(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1070 <fseek@plt>
movq   $0x0,-0x438(%rbp)
mov    -0x420(%rbp),%rdi
call   1090 <getc@plt>
mov    %al,-0x429(%rbp)
cmp    $0x0,%al
je     12cb <main+0x15b>
movl   $0x0,-0x43c(%rbp)
mov    -0x438(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x438(%rbp)
movsbq -0x429(%rbp),%rax
ff
mov    -0x410(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x410(%rbp,%rax,4)
mov    -0x420(%rbp),%rdi
call   1060 <ftell@plt>
cmp    -0x428(%rbp),%rax
jne    12c6 <main+0x156>
jmp    12cb <main+0x15b>
jmp    1259 <main+0xe9>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x448(%rbp)
ff
lea    0xd45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x414(%rbp)
cmpl   $0x100,-0x414(%rbp)
jge    13f6 <main+0x286>
movslq -0x414(%rbp),%rax
cmpl   $0x0,-0x410(%rbp,%rax,4)
jne    1318 <main+0x1a8>
jmp    13e2 <main+0x272>
movslq -0x414(%rbp),%rax
cvtsi2sdl -0x410(%rbp,%rax,4),%xmm0
ff ff
movaps 0xcd1(%rip),%xmm2
movq   -0x438(%rbp),%xmm1
ff
punpckldq %xmm2,%xmm1
movapd 0xccd(%rip),%xmm2
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x450(%rbp)
ff
mov    -0x414(%rbp),%eax
movsbl %al,%esi
movslq -0x414(%rbp),%rax
mov    -0x410(%rbp,%rax,4),%edx
movsd  -0x450(%rbp),%xmm0
ff
lea    0xcc3(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x450(%rbp),%xmm0
ff
movsd  %xmm0,-0x458(%rbp)
ff
movsd  -0x450(%rbp),%xmm0
ff
call   1030 <log2@plt>
movaps %xmm0,%xmm2
movsd  -0x458(%rbp),%xmm0
ff
movsd  -0x448(%rbp),%xmm1
ff
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x448(%rbp)
ff
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    12ee <main+0x17e>
movsd  -0x448(%rbp),%xmm0
ff
lea    0xc52(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x420,%rsp
cmp    $0x2,%edi
jne    12fc <main+0x16c>
mov    %rsi,%r14
lea    0x20(%rsp),%rdi
xor    %ebx,%ebx
mov    $0x400,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    0x8(%r14),%rdi
lea    0xe5a(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1070 <assert@plt>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    $0xffffffffffffffff,%rsi
call   1090 <fseek@plt>
mov    %r15,%rdi
call   1080 <ftell@plt>
mov    %rax,%r14
mov    0x2dd8(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
nopl   0x0(%rax)
mov    %r15,%rdi
call   10b0 <getc@plt>
test   %al,%al
je     1236 <main+0xa6>
add    $0x1,%rbx
movsbq %al,%rax
addl   $0x1,0x20(%rsp,%rax,4)
mov    %r15,%rdi
call   1080 <ftell@plt>
cmp    %r14,%rax
jne    1210 <main+0x80>
lea    0xe02(%rip),%rdi
call   1040 <puts@plt>
movq   %rbx,%xmm0
punpckldq 0xdb1(%rip),%xmm0
subpd  0xdb9(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,0x10(%rsp)
xorpd  %xmm0,%xmm0
xor    %r15d,%r15d
lea    0xdab(%rip),%r14
xor    %ebx,%ebx
jmp    1294 <main+0x104>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
add    $0x1000000,%r15d
cmp    $0x100,%rbx
je     12ee <main+0x15e>
mov    0x20(%rsp,%rbx,4),%edx
test   %edx,%edx
je     1280 <main+0xf0>
xorps  %xmm1,%xmm1
cvtsi2sd %edx,%xmm1
divsd  0x10(%rsp),%xmm1
movsd  %xmm1,0x8(%rsp)
mov    %r15d,%esi
sar    $0x18,%esi
mov    %r14,%rdi
movsd  %xmm0,(%rsp)
movapd %xmm1,%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x8(%rsp),%xmm0
call   1030 <log2@plt>
mulsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
jmp    1280 <main+0xf0>
lea    0xd3d(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [37 x i8] c"Symbol\09\09\09Symbol Count\09\09\09Probability\0A\00"
@.str.2 = [16 x i8] c"\22%c\22\09\09\09%i\09\09\09%f\0A\00"
@.str.3 = [13 x i8] c"Entropy: %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i32]
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i8
%11 = alloca i64
%12 = alloca i32
%13 = alloca double
%14 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %18
17: ; preds = %2
store i32 0, i32* %3
br label %104
18: ; preds = %2
store i32 0, i32* %7
br label %19
19: ; preds = %26, %18
%20 = load i32, i32* %7
%21 = icmp slt i32 %20, 256
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [256 x i32], [256 x i32]* %6, i64 0, i64 %24
store i32 0, i32* %25
br label %26
26: ; preds = %22
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %19
29: ; preds = %19
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %33, i32** %8
%34 = load i32*, i32** %8
%35 = call i32 @assert(i32* %34)
%36 = load i32*, i32** %8
%37 = load i32, i32* @SEEK_END
%38 = call i32 @fseek(i32* %36, i64 -1, i32 %37)
%39 = load i32*, i32** %8
%40 = call i64 @ftell(i32* %39)
store i64 %40, i64* %9
%41 = load i32*, i32** %8
%42 = load i32, i32* @SEEK_SET
%43 = call i32 @fseek(i32* %41, i64 0, i32 %42)
store i64 0, i64* %11
br label %44
44: ; preds = %61, %29
%45 = load i32*, i32** %8
%46 = call signext i8 @getc(i32* %45)
store i8 %46, i8* %10
%47 = icmp ne i8 %46, 0
br i1 %47, label %48, label %62
48: ; preds = %44
store i32 0, i32* %12
%49 = load i64, i64* %11
%50 = add i64 %49, 1
store i64 %50, i64* %11
%51 = load i8, i8* %10
%52 = sext i8 %51 to i64
%53 = getelementptr inbounds [256 x i32], [256 x i32]* %6, i64 0, i64 %52
%54 = load i32, i32* %53
%55 = add nsw i32 %54, 1
store i32 %55, i32* %53
%56 = load i32*, i32** %8
%57 = call i64 @ftell(i32* %56)
%58 = load i64, i64* %9
%59 = icmp eq i64 %57, %58
br i1 %59, label %60, label %61
60: ; preds = %48
br label %62
61: ; preds = %48
br label %44
62: ; preds = %60, %44
store double 0.000000e+00, double* %13
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %7
br label %64
64: ; preds = %98, %62
%65 = load i32, i32* %7
%66 = icmp slt i32 %65, 256
br i1 %66, label %67, label %101
67: ; preds = %64
%68 = load i32, i32* %7
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [256 x i32], [256 x i32]* %6, i64 0, i64 %69
%71 = load i32, i32* %70
%72 = icmp ne i32 %71, 0
br i1 %72, label %74, label %73
73: ; preds = %67
br label %98
74: ; preds = %67
%75 = load i32, i32* %7
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [256 x i32], [256 x i32]* %6, i64 0, i64 %76
%78 = load i32, i32* %77
%79 = sitofp i32 %78 to double
%80 = load i64, i64* %11
%81 = uitofp i64 %80 to double
%82 = fdiv double %79, %81
store double %82, double* %14
%83 = load i32, i32* %7
%84 = trunc i32 %83 to i8
%85 = sext i8 %84 to i32
%86 = load i32, i32* %7
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds [256 x i32], [256 x i32]* %6, i64 0, i64 %87
%89 = load i32, i32* %88
%90 = load double, double* %14
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %85, i32 %89, double %90)
%92 = load double, double* %14
%93 = load double, double* %14
%94 = call double @log2(double %93)
%95 = load double, double* %13
%96 = fneg double %92
%97 = call double @llvm.fmuladd.f64(double %96, double %94, double %95)
store double %97, double* %13
br label %98
98: ; preds = %74, %73
%99 = load i32, i32* %7
%100 = add nsw i32 %99, 1
store i32 %100, i32* %7
br label %64
101: ; preds = %64
%102 = load double, double* %13
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), double %102)
store i32 0, i32* %3
br label %104
104: ; preds = %101, %17
%105 = load i32, i32* %3
ret i32 %105
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [16 x i8] c"\22%c\22\09\09\09%i\09\09\09%f\0A\00"
@.str.3 = [13 x i8] c"Entropy: %f\0A\00"
@str = [36 x i8] c"Symbol\09\09\09Symbol Count\09\09\09Probability\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i32]
%4 = bitcast [256 x i32]* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %54
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @assert(i32* %9)
%11 = load i32, i32* @SEEK_END
%12 = tail call i32 @fseek(i32* %9, i64 -1, i32 %11)
%13 = tail call i64 @ftell(i32* %9)
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @fseek(i32* %9, i64 0, i32 %14)
br label %16
16: ; preds = %20, %6
%17 = phi i64 [ 0, %6 ], [ %21, %20 ]
%18 = tail call signext i8 @getc(i32* %9)
%19 = icmp eq i8 %18, 0
br i1 %19, label %28, label %20
20: ; preds = %16
%21 = add i64 %17, 1
%22 = sext i8 %18 to i64
%23 = getelementptr inbounds [256 x i32], [256 x i32]* %3, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = add nsw i32 %24, 1
store i32 %25, i32* %23
%26 = tail call i64 @ftell(i32* %9)
%27 = icmp eq i64 %26, %13
br i1 %27, label %28, label %16
28: ; preds = %20, %16
%29 = phi i64 [ %21, %20 ], [ %17, %16 ]
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%31 = uitofp i64 %29 to double
br label %32
32: ; preds = %28, %48
%33 = phi i64 [ 0, %28 ], [ %50, %48 ]
%34 = phi double [ 0.000000e+00, %28 ], [ %49, %48 ]
%35 = getelementptr inbounds [256 x i32], [256 x i32]* %3, i64 0, i64 %33
%36 = load i32, i32* %35
%37 = icmp eq i32 %36, 0
br i1 %37, label %48, label %38
38: ; preds = %32
%39 = sitofp i32 %36 to double
%40 = fdiv double %39, %31
%41 = trunc i64 %33 to i32
%42 = shl i32 %41, 24
%43 = ashr exact i32 %42, 24
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %43, i32 %36, double %40)
%45 = tail call double @log2(double %40)
%46 = fneg double %40
%47 = tail call double @llvm.fmuladd.f64(double %46, double %45, double %34)
br label %48
48: ; preds = %32, %38
%49 = phi double [ %47, %38 ], [ %34, %32 ]
%50 = add nuw nsw i64 %33, 1
%51 = icmp eq i64 %50, 256
br i1 %51, label %52, label %32
52: ; preds = %48
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), double %49)
br label %54
54: ; preds = %2, %52
ret i32 0
}