#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 */
struct WordCounts {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ word_counts_free(struct WordCounts *);
int /*<<< orphan*/ word_counts_increment(struct WordCounts *, char *);
struct WordCounts *word_counts_make();
int /*<<< orphan*/ word_counts_print(struct WordCounts *);
bool print_word_frequencies(char *path) {
  FILE *f;
  struct WordCounts *wc;
  char str[200 + 1];
  f = fopen(path, "r");
  if (f == NULL) {
    fprintf(stderr, "error: could not open '%s'", path);
    return false;
  }
  wc = word_counts_make();
  if (wc == NULL) {
    fprintf(stderr, "error: out of memory");
    fclose(f);
    return false;
  }
  fprintf(stderr, "processing '%s'...", path);
  while (fscanf(f, "%s", str) != EOF) {
    if (!word_counts_increment(wc, str)) {
      fprintf(stderr, "\nerror: out of memory");
      fclose(f);
      word_counts_free(wc);
      return false;
    }
  }
  fclose(f);
  fprintf(stderr, "done\n");
  word_counts_print(wc);
  word_counts_free(wc);
  return true;
}


x86 assembly (clang, -O0):
<print_word_frequencies>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe66(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d5 <print_word_frequencies+0x55>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e5 <print_word_frequencies+0x165>
mov    $0x0,%al
call   1040 <word_counts_make@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1217 <print_word_frequencies+0x97>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e5 <print_word_frequencies+0x165>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdf2(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0xf0(%rbp),%rdx
lea    0xdec(%rip),%rsi
call   1070 <fscanf@plt>
mov    0x2d98(%rip),%rcx
cmp    (%rcx),%rax
je     12ac <print_word_frequencies+0x12c>
mov    -0x20(%rbp),%rdi
lea    -0xf0(%rbp),%rsi
call   1050 <word_counts_increment@plt>
cmp    $0x0,%eax
jne    12a7 <print_word_frequencies+0x127>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
lea    0xdb1(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <word_counts_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e5 <print_word_frequencies+0x165>
jmp    1232 <print_word_frequencies+0xb2>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
lea    0xd84(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <word_counts_print@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <word_counts_free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_word_frequencies>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
mov    %rdi,%rbp
lea    0xe65(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     123a <print_word_frequencies+0xba>
mov    %rax,%rbx
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <word_counts_make@plt>
mov    0x2e1b(%rip),%r12
mov    (%r12),%edi
test   %rax,%rax
je     1259 <print_word_frequencies+0xd9>
mov    %rax,%r14
lea    0xe49(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xe4b(%rip),%r15
mov    %rsp,%rbp
mov    0x2df9(%rip),%r13
nop
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1070 <fscanf@plt>
cmp    0x0(%r13),%rax
je     1271 <print_word_frequencies+0xf1>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1050 <word_counts_increment@plt>
test   %eax,%eax
jne    11f0 <print_word_frequencies+0x70>
mov    (%r12),%edi
lea    0xe15(%rip),%rsi
xor    %r15d,%r15d
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
call   10a0 <word_counts_free@plt>
jmp    12a1 <print_word_frequencies+0x121>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
lea    0xdb8(%rip),%rsi
xor    %r15d,%r15d
mov    %rbp,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    12a1 <print_word_frequencies+0x121>
lea    0xdd4(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
jmp    12a1 <print_word_frequencies+0x121>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    (%r12),%edi
lea    0xdc5(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r14,%rdi
call   1030 <word_counts_print@plt>
mov    %r14,%rdi
call   10a0 <word_counts_free@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.WordCounts = type { i32 }
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"error: could not open '%s'\00"
@.str.2 = [21 x i8] c"error: out of memory\00"
@.str.3 = [19 x i8] c"processing '%s'...\00"
@.str.4 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.5 = [22 x i8] c"\0Aerror: out of memory\00"
@.str.6 = [6 x i8] c"done\0A\00"
define i32 @print_word_frequencies(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca %struct.WordCounts*
%6 = alloca [201 x i8]
store i8* %0, i8** %3
%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** %4
%9 = load i32*, i32** %4
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %3
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %13)
store i32 0, i32* %2
br label %56
15: ; preds = %1
%16 = call %struct.WordCounts* (...) @word_counts_make()
store %struct.WordCounts* %16, %struct.WordCounts** %5
%17 = load %struct.WordCounts*, %struct.WordCounts** %5
%18 = icmp eq %struct.WordCounts* %17, null
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32*, i32** %4
%23 = call i32 @fclose(i32* %22)
store i32 0, i32* %2
br label %56
24: ; preds = %15
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %3
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %46, %24
%29 = load i32*, i32** %4
%30 = getelementptr inbounds [201 x i8], [201 x i8]* %6, i64 0, i64 0
%31 = call i64 @fscanf(i32* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %30)
%32 = load i64, i64* @EOF
%33 = icmp ne i64 %31, %32
br i1 %33, label %34, label %47
34: ; preds = %28
%35 = load %struct.WordCounts*, %struct.WordCounts** %5
%36 = getelementptr inbounds [201 x i8], [201 x i8]* %6, i64 0, i64 0
%37 = call i32 @word_counts_increment(%struct.WordCounts* %35, i8* %36)
%38 = icmp ne i32 %37, 0
br i1 %38, label %46, label %39
39: ; preds = %34
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%42 = load i32*, i32** %4
%43 = call i32 @fclose(i32* %42)
%44 = load %struct.WordCounts*, %struct.WordCounts** %5
%45 = call i32 @word_counts_free(%struct.WordCounts* %44)
store i32 0, i32* %2
br label %56
46: ; preds = %34
br label %28
47: ; preds = %28
%48 = load i32*, i32** %4
%49 = call i32 @fclose(i32* %48)
%50 = load i32, i32* @stderr
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%52 = load %struct.WordCounts*, %struct.WordCounts** %5
%53 = call i32 @word_counts_print(%struct.WordCounts* %52)
%54 = load %struct.WordCounts*, %struct.WordCounts** %5
%55 = call i32 @word_counts_free(%struct.WordCounts* %54)
store i32 1, i32* %2
br label %56
56: ; preds = %47, %39, %19, %11
%57 = load i32, i32* %2
ret i32 %57
}

LLVM IR (-O2):
%struct.WordCounts = type { i32 }
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"error: could not open '%s'\00"
@.str.2 = [21 x i8] c"error: out of memory\00"
@.str.3 = [19 x i8] c"processing '%s'...\00"
@.str.4 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.5 = [22 x i8] c"\0Aerror: out of memory\00"
@.str.6 = [6 x i8] c"done\0A\00"
define i32 @print_word_frequencies(i8* %0) {
%2 = alloca [201 x i8]
%3 = getelementptr inbounds [201 x i8], [201 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %36
9: ; preds = %1
%10 = tail call %struct.WordCounts* (...) @word_counts_make()
%11 = icmp eq %struct.WordCounts* %10, null
%12 = load i32, i32* @stderr
br i1 %11, label %13, label %16
13: ; preds = %9
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @fclose(i32* %4)
br label %36
16: ; preds = %9
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %18
18: ; preds = %22, %16
%19 = call i64 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %3)
%20 = load i64, i64* @EOF
%21 = icmp eq i64 %19, %20
br i1 %21, label %30, label %22
22: ; preds = %18
%23 = call i32 @word_counts_increment(%struct.WordCounts* %10, i8* %3)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %18
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%28 = call i32 @fclose(i32* %4)
%29 = call i32 @word_counts_free(%struct.WordCounts* %10)
br label %36
30: ; preds = %18
%31 = call i32 @fclose(i32* %4)
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%34 = call i32 @word_counts_print(%struct.WordCounts* %10)
%35 = call i32 @word_counts_free(%struct.WordCounts* %10)
br label %36
36: ; preds = %30, %25, %13, %6
%37 = phi i32 [ 0, %6 ], [ 0, %13 ], [ 0, %25 ], [ 1, %30 ]
ret i32 %37
}