#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int word_lengths(char const *, int *, int);
void test7(int max_length) {
  int file_result, length, total = 0, lengths[21] = {0};
  const char *dictionary = "allwords.txt";
  printf("\nTest7--------------------------------------------------------\n");
  printf("Dictionary: %s\n", dictionary);
  file_result = word_lengths(dictionary, lengths, max_length);
  if (file_result == -2) {
    printf("Can't open %s\n", dictionary);
    return;
  }
  for (length = 1; length <= max_length; length++) {
    printf("Number of words of length %2i is %6i\n", length, lengths[length]);
    total += lengths[length];
  }
  printf("Total number of words counted: %i\n", total);
}


x86 assembly (clang, -O0):
<test7>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x54,%edx
call   1040 <memset@plt>
lea    0xea4(%rip),%rax
mov    %rax,-0x78(%rbp)
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x78(%rbp),%rsi
lea    0xed4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x78(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    -0x4(%rbp),%edx
call   1050 <word_lengths@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xfffffffe,-0x8(%rbp)
jne    11b4 <test7+0x84>
mov    -0x78(%rbp),%rsi
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120d <test7+0xdd>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11fc <test7+0xcc>
mov    -0xc(%rbp),%esi
movslq -0xc(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%edx
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0xc(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11bb <test7+0x8b>
mov    -0x10(%rbp),%esi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test7>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %edi,%r14d
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x50(%rsp)
lea    0xf0e(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9a(%rip),%rdi
lea    0xe86(%rip),%rbx
xor    %ebp,%ebp
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1050 <word_lengths@plt>
cmp    $0xfffffffe,%eax
jne    11b0 <test7+0x80>
lea    0xe7d(%rip),%rdi
lea    0xe59(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11fb <test7+0xcb>
test   %r14d,%r14d
jle    11eb <test7+0xbb>
add    $0x1,%r14d
mov    $0x1,%ebx
lea    0xe67(%rip),%r15
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    (%rsp,%rbx,4),%edx
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    (%rsp,%rbx,4),%ebp
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11d0 <test7+0xa0>
lea    0xe60(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"allwords.txt\00"
@.str.1 = [64 x i8] c"\0ATest7--------------------------------------------------------\0A\00"
@.str.2 = [16 x i8] c"Dictionary: %s\0A\00"
@.str.3 = [15 x i8] c"Can't open %s\0A\00"
@.str.4 = [38 x i8] c"Number of words of length %2i is %6i\0A\00"
@.str.5 = [35 x i8] c"Total number of words counted: %i\0A\00"
define void @test7(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [21 x i32]
%7 = alloca i8*
store i32 %0, i32* %2
store i32 0, i32* %5
%8 = bitcast [21 x i32]* %6 to i8*
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %7
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0))
%10 = load i8*, i8** %7
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %7
%13 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 0
%14 = load i32, i32* %2
%15 = call i32 @word_lengths(i8* %12, i32* %13, i32 %14)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, -2
br i1 %17, label %18, label %21
18: ; preds = %1
%19 = load i8*, i8** %7
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %19)
br label %45
21: ; preds = %1
store i32 1, i32* %4
br label %22
22: ; preds = %39, %21
%23 = load i32, i32* %4
%24 = load i32, i32* %2
%25 = icmp sle i32 %23, %24
br i1 %25, label %26, label %42
26: ; preds = %22
%27 = load i32, i32* %4
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %27, i32 %31)
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = load i32, i32* %5
%38 = add nsw i32 %37, %36
store i32 %38, i32* %5
br label %39
39: ; preds = %26
%40 = load i32, i32* %4
%41 = add nsw i32 %40, 1
store i32 %41, i32* %4
br label %22
42: ; preds = %22
%43 = load i32, i32* %5
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %42, %18
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"allwords.txt\00"
@.str.2 = [16 x i8] c"Dictionary: %s\0A\00"
@.str.3 = [15 x i8] c"Can't open %s\0A\00"
@.str.4 = [38 x i8] c"Number of words of length %2i is %6i\0A\00"
@.str.5 = [35 x i8] c"Total number of words counted: %i\0A\00"
@str = [63 x i8] c"\0ATest7--------------------------------------------------------\00"
define void @test7(i32 %0) {
%2 = alloca [21 x i32]
%3 = bitcast [21 x i32]* %2 to i8*
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [21 x i32], [21 x i32]* %2, i64 0, i64 0
%7 = call i32 @word_lengths(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32* %6, i32 %0)
%8 = icmp eq i32 %7, -2
br i1 %8, label %14, label %9
9: ; preds = %1
%10 = icmp slt i32 %0, 1
br i1 %10, label %27, label %11
11: ; preds = %9
%12 = add nuw i32 %0, 1
%13 = zext i32 %12 to i64
br label %16
14: ; preds = %1
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %30
16: ; preds = %11, %16
%17 = phi i64 [ 1, %11 ], [ %25, %16 ]
%18 = phi i32 [ 0, %11 ], [ %24, %16 ]
%19 = getelementptr inbounds [21 x i32], [21 x i32]* %2, i64 0, i64 %17
%20 = load i32, i32* %19
%21 = trunc i64 %17 to i32
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %21, i32 %20)
%23 = load i32, i32* %19
%24 = add nsw i32 %23, %18
%25 = add nuw nsw i64 %17, 1
%26 = icmp eq i64 %25, %13
br i1 %26, label %27, label %16
27: ; preds = %16, %9
%28 = phi i32 [ 0, %9 ], [ %24, %16 ]
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %27, %14
ret void
}