#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*/ assert(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int strcspn(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int get_words(char *filename, char words[][16]) {
  FILE *fp;
  char buffer[4096];
  int numWords = 0;
  int pos = 0, pos2 = 0;
  int i;
  fp = fopen(filename, "rb");
  if (fp == 0) {
    printf("Could not load file.\n");
    return 0;
  }
  while (fgets(buffer, 4095, fp)) {
    pos = strcspn(buffer, " ");
    pos2 = strcspn(buffer, "\n");
    if (pos2 < pos) {
      pos = pos2;
    }
    strncpy(words[numWords], buffer, pos);
    for (i = 0; i < strlen(words[numWords]); i++) {
      assert(words[numWords][i] >= 'A' && words[numWords][i] <= 'Z');
    }
    numWords++;
  }
  fclose(fp);
  printf("Read %d words from file\n", numWords);
  return numWords;
}


x86 assembly (clang, -O0):
<get_words>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1024(%rbp)
movl   $0x0,-0x1028(%rbp)
movl   $0x0,-0x102c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ea <get_words+0x6a>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1374 <get_words+0x1f4>
jmp    11ef <get_words+0x6f>
lea    -0x1020(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0xfff,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     134e <get_words+0x1ce>
lea    -0x1020(%rbp),%rdi
lea    0xdfd(%rip),%rsi
call   1070 <strcspn@plt>
mov    %eax,-0x1028(%rbp)
lea    -0x1020(%rbp),%rdi
lea    0xde2(%rip),%rsi
call   1070 <strcspn@plt>
mov    %eax,-0x102c(%rbp)
mov    -0x102c(%rbp),%eax
cmp    -0x1028(%rbp),%eax
jge    125e <get_words+0xde>
mov    -0x102c(%rbp),%eax
mov    %eax,-0x1028(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x1024(%rbp),%rax
shl    $0x4,%rax
add    %rax,%rdi
lea    -0x1020(%rbp),%rsi
mov    -0x1028(%rbp),%edx
call   1030 <strncpy@plt>
movl   $0x0,-0x1030(%rbp)
mov    -0x1030(%rbp),%eax
mov    %eax,-0x1034(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x1024(%rbp),%rax
shl    $0x4,%rax
add    %rax,%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x1034(%rbp),%eax
cmp    %ecx,%eax
jge    133a <get_words+0x1ba>
mov    -0x18(%rbp),%rax
movslq -0x1024(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movslq -0x1030(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x41,%ecx
mov    %al,-0x1035(%rbp)
jl     1316 <get_words+0x196>
mov    -0x18(%rbp),%rax
movslq -0x1024(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movslq -0x1030(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5a,%eax
setle  %al
mov    %al,-0x1035(%rbp)
mov    -0x1035(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x1030(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1030(%rbp)
jmp    128c <get_words+0x10c>
mov    -0x1024(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1024(%rbp)
jmp    11ef <get_words+0x6f>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x1024(%rbp),%esi
lea    0xcb7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1024(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_words>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %rsi,0x8(%rsp)
lea    0xe53(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12a7 <get_words+0x117>
mov    %rax,%r14
lea    0x10(%rsp),%rdi
mov    $0xfff,%esi
mov    %rax,%rdx
call   1090 <fgets@plt>
xor    %r12d,%r12d
test   %rax,%rax
je     128c <get_words+0xfc>
lea    0x10(%rsp),%r13
mov    0x8(%rsp),%r15
jmp    120d <get_words+0x7d>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
mov    %r13,%rdi
mov    $0xfff,%esi
mov    %r14,%rdx
call   1090 <fgets@plt>
add    $0x10,%r15
test   %rax,%rax
je     128c <get_words+0xfc>
mov    %r13,%rdi
lea    0xdec(%rip),%rsi
call   1080 <strcspn@plt>
mov    %eax,%ebp
mov    %r13,%rdi
lea    0xdf4(%rip),%rsi
call   1080 <strcspn@plt>
cmp    %ebp,%eax
cmovl  %eax,%ebp
mov    %r12,%rbx
shl    $0x4,%rbx
add    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    11f0 <get_words+0x60>
xor    %ebp,%ebp
nopl   0x0(%rax)
movzbl (%r15,%rbp,1),%eax
add    $0xbf,%al
xor    %edi,%edi
cmp    $0x1a,%al
setb   %dil
call   10a0 <assert@plt>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1260 <get_words+0xd0>
jmp    11f0 <get_words+0x60>
mov    %r14,%rdi
call   1050 <fclose@plt>
lea    0xd6a(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    12b6 <get_words+0x126>
lea    0xd70(%rip),%rdi
call   1040 <puts@plt>
xor    %r12d,%r12d
mov    %r12d,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [22 x i8] c"Could not load file.\0A\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [25 x i8] c"Read %d words from file\0A\00"
define i32 @get_words(i8* %0, [16 x i8]* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [16 x i8]*
%6 = alloca i32*
%7 = alloca [4096 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %4
store [16 x i8]* %1, [16 x i8]** %5
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%12 = load i8*, i8** %4
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %90
18: ; preds = %2
br label %19
19: ; preds = %81, %18
%20 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%21 = load i32*, i32** %6
%22 = call i64 @fgets(i8* %20, i32 4095, i32* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %84
24: ; preds = %19
%25 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%26 = call i32 @strcspn(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 %26, i32* %9
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%28 = call i32 @strcspn(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 %28, i32* %10
%29 = load i32, i32* %10
%30 = load i32, i32* %9
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %34
32: ; preds = %24
%33 = load i32, i32* %10
store i32 %33, i32* %9
br label %34
34: ; preds = %32, %24
%35 = load [16 x i8]*, [16 x i8]** %5
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [16 x i8], [16 x i8]* %35, i64 %37
%39 = getelementptr inbounds [16 x i8], [16 x i8]* %38, i64 0, i64 0
%40 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%41 = load i32, i32* %9
%42 = call i32 @strncpy(i8* %39, i8* %40, i32 %41)
store i32 0, i32* %11
br label %43
43: ; preds = %78, %34
%44 = load i32, i32* %11
%45 = load [16 x i8]*, [16 x i8]** %5
%46 = load i32, i32* %8
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [16 x i8], [16 x i8]* %45, i64 %47
%49 = getelementptr inbounds [16 x i8], [16 x i8]* %48, i64 0, i64 0
%50 = call i32 @strlen(i8* %49)
%51 = icmp slt i32 %44, %50
br i1 %51, label %52, label %81
52: ; preds = %43
%53 = load [16 x i8]*, [16 x i8]** %5
%54 = load i32, i32* %8
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [16 x i8], [16 x i8]* %53, i64 %55
%57 = load i32, i32* %11
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [16 x i8], [16 x i8]* %56, i64 0, i64 %58
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp sge i32 %61, 65
br i1 %62, label %63, label %74
63: ; preds = %52
%64 = load [16 x i8]*, [16 x i8]** %5
%65 = load i32, i32* %8
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [16 x i8], [16 x i8]* %64, i64 %66
%68 = load i32, i32* %11
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [16 x i8], [16 x i8]* %67, i64 0, i64 %69
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp sle i32 %72, 90
br label %74
74: ; preds = %63, %52
%75 = phi i1 [ false, %52 ], [ %73, %63 ]
%76 = zext i1 %75 to i32
%77 = call i32 @assert(i32 %76)
br label %78
78: ; preds = %74
%79 = load i32, i32* %11
%80 = add nsw i32 %79, 1
store i32 %80, i32* %11
br label %43
81: ; preds = %43
%82 = load i32, i32* %8
%83 = add nsw i32 %82, 1
store i32 %83, i32* %8
br label %19
84: ; preds = %19
%85 = load i32*, i32** %6
%86 = call i32 @fclose(i32* %85)
%87 = load i32, i32* %8
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %87)
%89 = load i32, i32* %8
store i32 %89, i32* %3
br label %90
90: ; preds = %84, %16
%91 = load i32, i32* %3
ret i32 %91
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [25 x i8] c"Read %d words from file\0A\00"
@str = [21 x i8] c"Could not load file.\00"
define i32 @get_words(i8* nocapture %0, [16 x i8]* %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i64 @fgets(i8* %4, i32 4095, i32* %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %40, label %12
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %44
12: ; preds = %7, %34
%13 = phi i64 [ %35, %34 ], [ 0, %7 ]
%14 = call i32 @strcspn(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @strcspn(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp slt i32 %15, %14
%17 = select i1 %16, i32 %15, i32 %14
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 %13, i64 0
%19 = call i32 @strncpy(i8* %18, i8* %4, i32 %17)
%20 = call i32 @strlen(i8* %18)
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %34
22: ; preds = %12, %22
%23 = phi i64 [ %30, %22 ], [ 0, %12 ]
%24 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 %13, i64 %23
%25 = load i8, i8* %24
%26 = add i8 %25, -65
%27 = icmp ult i8 %26, 26
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = add nuw nsw i64 %23, 1
%31 = call i32 @strlen(i8* %18)
%32 = sext i32 %31 to i64
%33 = icmp slt i64 %30, %32
br i1 %33, label %22, label %34
34: ; preds = %22, %12
%35 = add nuw i64 %13, 1
%36 = call i64 @fgets(i8* %4, i32 4095, i32* %5)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %12
38: ; preds = %34
%39 = trunc i64 %35 to i32
br label %40
40: ; preds = %38, %7
%41 = phi i32 [ 0, %7 ], [ %39, %38 ]
%42 = call i32 @fclose(i32* %5)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %41)
br label %44
44: ; preds = %40, %10
%45 = phi i32 [ 0, %10 ], [ %41, %40 ]
ret i32 %45
}