#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
void frequency_count(char *Filename, int *frequency) {
  int ch;
  FILE *fp = fopen(Filename, "r");
  if (fp == NULL)
    return;
  for (ch = 0; ch < 127; ch++)
    frequency[ch] = 0;
  while (1) {
    ch = fgetc(fp);
    if (ch == EOF)
      break;
    frequency[ch]++;
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<frequency_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1164 <frequency_count+0x34>
jmp    11d9 <frequency_count+0xa9>
movl   $0x0,-0x14(%rbp)
cmpl   $0x7f,-0x14(%rbp)
jge    1192 <frequency_count+0x62>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116b <frequency_count+0x3b>
jmp    1197 <frequency_count+0x67>
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e3b(%rip),%rcx
cmp    (%rcx),%eax
jne    11ba <frequency_count+0x8a>
jmp    11d0 <frequency_count+0xa0>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
jmp    1197 <frequency_count+0x67>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<frequency_count>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
lea    0xeb1(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a1 <frequency_count+0x61>
mov    %rax,%rbx
mov    $0x1fc,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    0x2e6e(%rip),%r15
cmp    (%r15),%eax
je     1194 <frequency_count+0x54>
nop
cltq
addl   $0x1,(%r14,%rax,4)
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r15),%eax
jne    1180 <frequency_count+0x40>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
define void @frequency_count(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
store i8* %0, i8** %3
store i32* %1, i32** %4
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
br label %42
12: ; preds = %2
store i32 0, i32* %5
br label %13
13: ; preds = %21, %12
%14 = load i32, i32* %5
%15 = icmp slt i32 %14, 127
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = load i32*, i32** %4
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
store i32 0, i32* %20
br label %21
21: ; preds = %16
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %13
24: ; preds = %13
br label %25
25: ; preds = %24, %32
%26 = load i32*, i32** %6
%27 = call i32 @fgetc(i32* %26)
store i32 %27, i32* %5
%28 = load i32, i32* %5
%29 = load i32, i32* @EOF
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %25
br label %39
32: ; preds = %25
%33 = load i32*, i32** %4
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
%38 = add nsw i32 %37, 1
store i32 %38, i32* %36
br label %25
39: ; preds = %31
%40 = load i32*, i32** %6
%41 = call i32 @fclose(i32* %40)
br label %42
42: ; preds = %39, %11
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
define void @frequency_count(i8* nocapture %0, i32* nocapture %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %21, label %5
5: ; preds = %2
%6 = bitcast i32* %1 to i8*
%7 = tail call i32 @fgetc(i32* %3)
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %19, label %10
10: ; preds = %5, %10
%11 = phi i32 [ %16, %10 ], [ %7, %5 ]
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i32, i32* %1, i64 %12
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 1
store i32 %15, i32* %13
%16 = tail call i32 @fgetc(i32* %3)
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %10
19: ; preds = %10, %5
%20 = tail call i32 @fclose(i32* %3)
br label %21
21: ; preds = %2, %19
ret void
}