#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*/ EX_NOINPUT;
size_t *calloc(size_t, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int maxSizeInFile(char *);
int /*<<< orphan*/ stderr;
int strlen(char *);
size_t *histogram(char *filename) {
  FILE *f = fopen(filename, "r");
  if (f == NULL) {
    fprintf(stderr, "Cannot open file in filename.\n");
    exit(EX_NOINPUT);
  }
  size_t tabSize = maxSizeInFile(filename) + 1;
  size_t *hist = calloc(tabSize, sizeof(size_t));
  char word[30];
  while (fgets(word, 40, f) != NULL) {
    ++hist[strlen(word) - 1];
  }
  hist[0] = tabSize;
  fclose(f);
  return hist;
}


x86 assembly (clang, -O0):
<histogram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ce <histogram+0x4e>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rdi
call   10a0 <maxSizeInFile@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x28,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     123c <histogram+0xbc>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
add    $0x1,%rdx
mov    %rdx,(%rax,%rcx,8)
jmp    11f2 <histogram+0x72>
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<histogram>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
lea    0xe6b(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1220 <histogram+0xa0>
mov    %rax,%r15
mov    %rbx,%rdi
call   10a0 <maxSizeInFile@plt>
add    $0x1,%eax
movslq %eax,%r14
mov    %r14,%rdi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%r12
mov    %rsp,%rdi
mov    $0x28,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1205 <histogram+0x85>
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
addq   $0x1,-0x8(%r12,%rax,8)
mov    %rbx,%rdi
mov    $0x28,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11e0 <histogram+0x60>
mov    %r14,(%r12)
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %r12,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
lea    0xdd2(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"Cannot open file in filename.\0A\00"
@EX_NOINPUT = global i32 0
define i64* @histogram(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i64*
%6 = alloca [30 x i8]
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @EX_NOINPUT
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %1
%17 = load i8*, i8** %2
%18 = call i32 @maxSizeInFile(i8* %17)
%19 = add nsw i32 %18, 1
%20 = sext i32 %19 to i64
store i64 %20, i64* %4
%21 = load i64, i64* %4
%22 = call i64* @calloc(i64 %21, i32 8)
store i64* %22, i64** %5
br label %23
23: ; preds = %28, %16
%24 = getelementptr inbounds [30 x i8], [30 x i8]* %6, i64 0, i64 0
%25 = load i32*, i32** %3
%26 = call i32* @fgets(i8* %24, i32 40, i32* %25)
%27 = icmp ne i32* %26, null
br i1 %27, label %28, label %37
28: ; preds = %23
%29 = load i64*, i64** %5
%30 = getelementptr inbounds [30 x i8], [30 x i8]* %6, i64 0, i64 0
%31 = call i32 @strlen(i8* %30)
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i64, i64* %29, i64 %33
%35 = load i64, i64* %34
%36 = add i64 %35, 1
store i64 %36, i64* %34
br label %23
37: ; preds = %23
%38 = load i64, i64* %4
%39 = load i64*, i64** %5
%40 = getelementptr inbounds i64, i64* %39, i64 0
store i64 %38, i64* %40
%41 = load i32*, i32** %3
%42 = call i32 @fclose(i32* %41)
%43 = load i64*, i64** %5
ret i64* %43
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"Cannot open file in filename.\0A\00"
@EX_NOINPUT = global i32 0
define i64* @histogram(i8* %0) {
%2 = alloca [30 x i8]
%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 %5, label %10
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* @EX_NOINPUT
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %1
%11 = tail call i32 @maxSizeInFile(i8* %0)
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = tail call i64* @calloc(i64 %13, i32 8)
%15 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%16 = call i32* @fgets(i8* %15, i32 40, i32* %3)
%17 = icmp eq i32* %16, null
br i1 %17, label %27, label %18
18: ; preds = %10, %18
%19 = call i32 @strlen(i8* %15)
%20 = add nsw i32 %19, -1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i64, i64* %14, i64 %21
%23 = load i64, i64* %22
%24 = add i64 %23, 1
store i64 %24, i64* %22
%25 = call i32* @fgets(i8* %15, i32 40, i32* %3)
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %18
27: ; preds = %18, %10
store i64 %13, i64* %14
%28 = call i32 @fclose(i32* %3)
ret i64* %14
}