#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, unsigned int, size_t);
size_t *histogram(char *);
int main() {
  FILE *f = fopen("hist.txt", "w");
  if (f == NULL)
    return 1;
  size_t *hist = histogram("dict.txt");
  for (unsigned int i = 1; i < hist[0]; ++i) {
    fprintf(f, "%u\t%lu\n", i, hist[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    0xebc(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116d <main+0x3d>
movl   $0x1,-0x4(%rbp)
jmp    11c7 <main+0x97>
lea    0xe97(%rip),%rdi
call   1030 <histogram@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
jae    11c0 <main+0x90>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    (%rax,%rcx,8),%rcx
lea    0xe67(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1184 <main+0x54>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xec1(%rip),%rdi
lea    0xec3(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     119d <main+0x6d>
mov    %rax,%r15
lea    0xeb1(%rip),%rdi
call   1030 <histogram@plt>
xor    %r14d,%r14d
cmpq   $0x2,(%rax)
jb     11a3 <main+0x73>
mov    %rax,%rbp
mov    $0x1,%ebx
lea    0xe9d(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    0x0(%rbp,%rbx,8),%rcx
mov    %r15,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1040 <fprintf@plt>
add    $0x1,%ebx
cmp    %rbx,0x0(%rbp)
ja     1180 <main+0x50>
jmp    11a3 <main+0x73>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"hist.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [9 x i8] c"dict.txt\00"
@.str.3 = [8 x i8] c"%u\09%lu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i64*
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 1, i32* %1
br label %31
9: ; preds = %0
%10 = call i64* @histogram(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i64* %10, i64** %3
store i32 1, i32* %4
br label %11
11: ; preds = %27, %9
%12 = load i32, i32* %4
%13 = zext i32 %12 to i64
%14 = load i64*, i64** %3
%15 = getelementptr inbounds i64, i64* %14, i64 0
%16 = load i64, i64* %15
%17 = icmp ult i64 %13, %16
br i1 %17, label %18, label %30
18: ; preds = %11
%19 = load i32*, i32** %2
%20 = load i32, i32* %4
%21 = load i64*, i64** %3
%22 = load i32, i32* %4
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i64, i64* %21, i64 %23
%25 = load i64, i64* %24
%26 = call i32 @fprintf(i32* %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %20, i64 %25)
br label %27
27: ; preds = %18
%28 = load i32, i32* %4
%29 = add i32 %28, 1
store i32 %29, i32* %4
br label %11
30: ; preds = %11
store i32 0, i32* %1
br label %31
31: ; preds = %30, %8
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
@.str = [9 x i8] c"hist.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [9 x i8] c"dict.txt\00"
@.str.3 = [8 x i8] c"%u\09%lu\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %17, label %3
3: ; preds = %0
%4 = tail call i64* @histogram(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%5 = load i64, i64* %4
%6 = icmp ugt i64 %5, 1
br i1 %6, label %7, label %17
7: ; preds = %3, %7
%8 = phi i64 [ %14, %7 ], [ 1, %3 ]
%9 = trunc i64 %8 to i32
%10 = getelementptr inbounds i64, i64* %4, i64 %8
%11 = load i64, i64* %10
%12 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %9, i64 %11)
%13 = add nuw nsw i64 %8, 1
%14 = and i64 %13, 4294967295
%15 = load i64, i64* %4
%16 = icmp ugt i64 %15, %14
br i1 %16, label %7, label %17
17: ; preds = %7, %3, %0
%18 = phi i32 [ 1, %0 ], [ 0, %3 ], [ 0, %7 ]
ret i32 %18
}