#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int strlen(char *);
int word_lengths(const char *dictionary, int lengths[], int count) {
  int i, wordLength;
  char buffer[50 + 2];
  FILE *infile;
  for (i = 0; i <= count; i++) {
    lengths[i] = 0;
  }
  infile = fopen(dictionary, "rt");
  if (infile != NULL) {
    while (!feof(infile)) {
      fgets(buffer, 50 + 1, infile);
      wordLength = strlen(buffer);
      if (!feof(infile)) {
        buffer[wordLength - 1] = '\0';
        wordLength--;
        if (wordLength <= count) {
          lengths[wordLength]++;
        }
      }
    }
    fclose(infile);
  } else {
    return -2;
  }
  return -1;
}


x86 assembly (clang, -O0):
<word_lengths>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     1193 <word_lengths+0x43>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    116a <word_lengths+0x1a>
mov    -0x10(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     1250 <word_lengths+0x100>
jmp    11b7 <word_lengths+0x67>
mov    -0x68(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11d5 <word_lengths+0x85>
jmp    1242 <word_lengths+0xf2>
lea    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rdx
mov    $0x33,%esi
call   1050 <fgets@plt>
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x68(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
jne    123d <word_lengths+0xed>
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x60(%rbp,%rax,1)
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     1238 <word_lengths+0xe8>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
jmp    123d <word_lengths+0xed>
jmp    11b7 <word_lengths+0x67>
mov    -0x68(%rbp),%rdi
call   1030 <fclose@plt>
jmp    125c <word_lengths+0x10c>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1263 <word_lengths+0x113>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<word_lengths>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
test   %edx,%edx
js     118e <word_lengths+0x2e>
mov    %r15d,%eax
lea    0x4(,%rax,4),%rdx
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xe6b(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11c0 <word_lengths+0x60>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11d2 <word_lengths+0x72>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0xffffffff,%eax
jmp    11c5 <word_lengths+0x65>
mov    $0xfffffffe,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%r12
jmp    11ec <word_lengths+0x8c>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11b1 <word_lengths+0x51>
mov    %r12,%rdi
mov    $0x33,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11e0 <word_lengths+0x80>
movslq %ebp,%rax
lea    -0x1(%rax),%rcx
movb   $0x0,-0x1(%rsp,%rax,1)
cmp    %r15d,%ecx
jg     11e0 <word_lengths+0x80>
addl   $0x1,-0x4(%r14,%rax,4)
jmp    11e0 <word_lengths+0x80>

LLVM IR (-O0):
@.str = [3 x i8] c"rt\00"
define i32 @word_lengths(i8* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [52 x i8]
%11 = alloca i32*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 0, i32* %8
br label %12
12: ; preds = %21, %3
%13 = load i32, i32* %8
%14 = load i32, i32* %7
%15 = icmp sle i32 %13, %14
br i1 %15, label %16, label %24
16: ; preds = %12
%17 = load i32*, i32** %6
%18 = load i32, i32* %8
%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* %8
%23 = add nsw i32 %22, 1
store i32 %23, i32* %8
br label %12
24: ; preds = %12
%25 = load i8*, i8** %5
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %26, i32** %11
%27 = load i32*, i32** %11
%28 = icmp ne i32* %27, null
br i1 %28, label %29, label %66
29: ; preds = %24
br label %30
30: ; preds = %62, %29
%31 = load i32*, i32** %11
%32 = call i32 @feof(i32* %31)
%33 = icmp ne i32 %32, 0
%34 = xor i1 %33, true
br i1 %34, label %35, label %63
35: ; preds = %30
%36 = getelementptr inbounds [52 x i8], [52 x i8]* %10, i64 0, i64 0
%37 = load i32*, i32** %11
%38 = call i32 @fgets(i8* %36, i32 51, i32* %37)
%39 = getelementptr inbounds [52 x i8], [52 x i8]* %10, i64 0, i64 0
%40 = call i32 @strlen(i8* %39)
store i32 %40, i32* %9
%41 = load i32*, i32** %11
%42 = call i32 @feof(i32* %41)
%43 = icmp ne i32 %42, 0
br i1 %43, label %62, label %44
44: ; preds = %35
%45 = load i32, i32* %9
%46 = sub nsw i32 %45, 1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [52 x i8], [52 x i8]* %10, i64 0, i64 %47
store i8 0, i8* %48
%49 = load i32, i32* %9
%50 = add nsw i32 %49, -1
store i32 %50, i32* %9
%51 = load i32, i32* %9
%52 = load i32, i32* %7
%53 = icmp sle i32 %51, %52
br i1 %53, label %54, label %61
54: ; preds = %44
%55 = load i32*, i32** %6
%56 = load i32, i32* %9
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32, i32* %55, i64 %57
%59 = load i32, i32* %58
%60 = add nsw i32 %59, 1
store i32 %60, i32* %58
br label %61
61: ; preds = %54, %44
br label %62
62: ; preds = %61, %35
br label %30
63: ; preds = %30
%64 = load i32*, i32** %11
%65 = call i32 @fclose(i32* %64)
br label %67
66: ; preds = %24
store i32 -2, i32* %4
br label %68
67: ; preds = %63
store i32 -1, i32* %4
br label %68
68: ; preds = %67, %66
%69 = load i32, i32* %4
ret i32 %69
}

LLVM IR (-O2):
@.str = [3 x i8] c"rt\00"
define i32 @word_lengths(i8* nocapture %0, i32* nocapture %1, i32 %2) {
%4 = alloca [52 x i8]
%5 = getelementptr inbounds [52 x i8], [52 x i8]* %4, i64 0, i64 0
%6 = icmp slt i32 %2, 0
br i1 %6, label %12, label %7
7: ; preds = %3
%8 = bitcast i32* %1 to i8*
%9 = zext i32 %2 to i64
%10 = shl nuw nsw i64 %9, 2
%11 = add nuw nsw i64 %10, 4
br label %12
12: ; preds = %7, %3
%13 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %37, label %15
15: ; preds = %12
%16 = call i32 @feof(i32* %13)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %35
18: ; preds = %15, %32
%19 = call i32 @fgets(i8* %5, i32 51, i32* %13)
%20 = call i32 @strlen(i8* %5)
%21 = call i32 @feof(i32* %13)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %32
23: ; preds = %18
%24 = add nsw i32 %20, -1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [52 x i8], [52 x i8]* %4, i64 0, i64 %25
store i8 0, i8* %26
%27 = icmp sgt i32 %24, %2
br i1 %27, label %32, label %28
28: ; preds = %23
%29 = getelementptr inbounds i32, i32* %1, i64 %25
%30 = load i32, i32* %29
%31 = add nsw i32 %30, 1
store i32 %31, i32* %29
br label %32
32: ; preds = %23, %28, %18
%33 = call i32 @feof(i32* %13)
%34 = icmp eq i32 %33, 0
br i1 %34, label %18, label %35
35: ; preds = %32, %15
%36 = call i32 @fclose(i32* %13)
br label %37
37: ; preds = %12, %35
%38 = phi i32 [ -1, %35 ], [ -2, %12 ]
ret i32 %38
}