#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*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ malloc(int);
scalar_t__ realloc(char **, int);
int /*<<< orphan*/ stderr;
int strlen(char *);
int readFile(char ***words_p, int lines_allocated) {
  char **words = *words_p;
  FILE *fp = fopen("words", "r");
  if (fp == NULL) {
    fprintf(stderr, "Error opening file.\n");
    exit(2);
  }
  int i;
  for (i = 0; 1; i++) {
    int j;
    if (i >= lines_allocated) {
      int new_size;
      new_size = lines_allocated * 2;
      words = (char **)realloc(words, sizeof(char *) * new_size);
      if (words == NULL) {
        fprintf(stderr, "Out of memory.\n");
        exit(3);
      }
      lines_allocated = new_size;
    }
    words[i] = (char *)malloc(sizeof(char) * 30);
    if (words[i] == NULL) {
      fprintf(stderr, "Out of memory.\n");
      exit(4);
    }
    if (fgets(words[i], 30 - 1, fp) == NULL)
      break;
    for (j = strlen(words[i]) - 1;
         j >= 0 && (words[i][j] == '\n' || words[i][j] == '\r'); j--)
      ;
    words[i][j + 1] = '\0';
  }
  *words_p = words;
  return i;
}


x86 assembly (clang, -O0):
<readFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
lea    0xe6f(%rip),%rdi
lea    0xe6e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11cb <readFile+0x5b>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
movl   $0x0,-0x24(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    11e1 <readFile+0x71>
jmp    1366 <readFile+0x1f6>
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     123d <readFile+0xcd>
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1070 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1237 <readFile+0xc7>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
lea    0xdf5(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x3,%edi
call   1090 <exit@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    $0x1e,%edi
call   1060 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    1288 <readFile+0x118>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
lea    0xda4(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x4,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x1d,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    12b1 <readFile+0x141>
jmp    1366 <readFile+0x1f6>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x28(%rbp)
mov    %al,-0x2d(%rbp)
jl     131c <readFile+0x1ac>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0x2e(%rbp)
je     1316 <readFile+0x1a6>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
sete   %al
mov    %al,-0x2e(%rbp)
mov    -0x2e(%rbp),%al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    132c <readFile+0x1bc>
jmp    133f <readFile+0x1cf>
jmp    1331 <readFile+0x1c1>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    12c8 <readFile+0x158>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d2 <readFile+0x62>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r12d
mov    %rdi,%r14
mov    (%rdi),%r13
lea    0xe75(%rip),%rdi
lea    0xe74(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12ac <readFile+0x13c>
mov    %rax,%r15
xor    %ebp,%ebp
jmp    11bc <readFile+0x4c>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
cltq
movb   $0x0,(%rcx,%rax,1)
add    $0x1,%rbp
movslq %r12d,%rax
cmp    %rax,%rbp
jl     11e1 <readFile+0x71>
mov    %r12d,%esi
shl    $0x4,%esi
mov    %r13,%rdi
call   1070 <realloc@plt>
test   %rax,%rax
je     128d <readFile+0x11d>
mov    %rax,%r13
add    %r12d,%r12d
mov    $0x1e,%edi
call   1060 <malloc@plt>
mov    %rax,0x0(%r13,%rbp,8)
test   %rax,%rax
je     126e <readFile+0xfe>
mov    %rax,%rdi
mov    $0x1d,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     125a <readFile+0xea>
mov    0x0(%r13,%rbp,8),%rdi
call   1030 <strlen@plt>
mov    0x0(%r13,%rbp,8),%rcx
test   %eax,%eax
jle    11b2 <readFile+0x42>
mov    %eax,%eax
jmp    1241 <readFile+0xd1>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x1(%rdx),%rsi
mov    %rdx,%rax
cmp    $0x1,%rsi
jbe    11b0 <readFile+0x40>
lea    -0x1(%rax),%rdx
mov    %edx,%esi
movzbl (%rcx,%rsi,1),%ebx
cmp    $0xd,%bl
je     1230 <readFile+0xc0>
cmp    $0xa,%bl
je     1230 <readFile+0xc0>
jmp    11b2 <readFile+0x42>
mov    %r13,(%r14)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
lea    0xd9f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x4,%edi
call   1090 <exit@plt>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
lea    0xd80(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x3,%edi
call   1090 <exit@plt>
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
lea    0xd4c(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"words\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [21 x i8] c"Error opening file.\0A\00"
@.str.3 = [16 x i8] c"Out of memory.\0A\00"
define i32 @readFile(i8*** %0, i32 %1) {
%3 = alloca i8***
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8*** %0, i8**** %3
store i32 %1, i32* %4
%10 = load i8***, i8**** %3
%11 = load i8**, i8*** %10
store i8** %11, i8*** %5
%12 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %6
%13 = load i32*, i32** %6
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @exit(i32 2)
unreachable
19: ; preds = %2
store i32 0, i32* %7
br label %20
20: ; preds = %123, %19
br i1 true, label %21, label %126
21: ; preds = %20
%22 = load i32, i32* %7
%23 = load i32, i32* %4
%24 = icmp sge i32 %22, %23
br i1 %24, label %25, label %43
25: ; preds = %21
%26 = load i32, i32* %4
%27 = mul nsw i32 %26, 2
store i32 %27, i32* %9
%28 = load i8**, i8*** %5
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = mul i64 8, %30
%32 = trunc i64 %31 to i32
%33 = call i64 @realloc(i8** %28, i32 %32)
%34 = inttoptr i64 %33 to i8**
store i8** %34, i8*** %5
%35 = load i8**, i8*** %5
%36 = icmp eq i8** %35, null
br i1 %36, label %37, label %41
37: ; preds = %25
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 @exit(i32 3)
unreachable
41: ; preds = %25
%42 = load i32, i32* %9
store i32 %42, i32* %4
br label %43
43: ; preds = %41, %21
%44 = call i64 @malloc(i32 30)
%45 = inttoptr i64 %44 to i8*
%46 = load i8**, i8*** %5
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8*, i8** %46, i64 %48
store i8* %45, i8** %49
%50 = load i8**, i8*** %5
%51 = load i32, i32* %7
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %50, i64 %52
%54 = load i8*, i8** %53
%55 = icmp eq i8* %54, null
br i1 %55, label %56, label %60
56: ; preds = %43
%57 = load i32, i32* @stderr
%58 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%59 = call i32 @exit(i32 4)
unreachable
60: ; preds = %43
%61 = load i8**, i8*** %5
%62 = load i32, i32* %7
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8*, i8** %61, i64 %63
%65 = load i8*, i8** %64
%66 = load i32*, i32** %6
%67 = call i32* @fgets(i8* %65, i32 29, i32* %66)
%68 = icmp eq i32* %67, null
br i1 %68, label %69, label %70
69: ; preds = %60
br label %126
70: ; preds = %60
%71 = load i8**, i8*** %5
%72 = load i32, i32* %7
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8*, i8** %71, i64 %73
%75 = load i8*, i8** %74
%76 = call i32 @strlen(i8* %75)
%77 = sub nsw i32 %76, 1
store i32 %77, i32* %8
br label %78
78: ; preds = %110, %70
%79 = load i32, i32* %8
%80 = icmp sge i32 %79, 0
br i1 %80, label %81, label %107
81: ; preds = %78
%82 = load i8**, i8*** %5
%83 = load i32, i32* %7
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8*, i8** %82, i64 %84
%86 = load i8*, i8** %85
%87 = load i32, i32* %8
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i8, i8* %86, i64 %88
%90 = load i8, i8* %89
%91 = sext i8 %90 to i32
%92 = icmp eq i32 %91, 10
br i1 %92, label %105, label %93
93: ; preds = %81
%94 = load i8**, i8*** %5
%95 = load i32, i32* %7
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i8*, i8** %94, i64 %96
%98 = load i8*, i8** %97
%99 = load i32, i32* %8
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds i8, i8* %98, i64 %100
%102 = load i8, i8* %101
%103 = sext i8 %102 to i32
%104 = icmp eq i32 %103, 13
br label %105
105: ; preds = %93, %81
%106 = phi i1 [ true, %81 ], [ %104, %93 ]
br label %107
107: ; preds = %105, %78
%108 = phi i1 [ false, %78 ], [ %106, %105 ]
br i1 %108, label %109, label %113
109: ; preds = %107
br label %110
110: ; preds = %109
%111 = load i32, i32* %8
%112 = add nsw i32 %111, -1
store i32 %112, i32* %8
br label %78
113: ; preds = %107
%114 = load i8**, i8*** %5
%115 = load i32, i32* %7
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds i8*, i8** %114, i64 %116
%118 = load i8*, i8** %117
%119 = load i32, i32* %8
%120 = add nsw i32 %119, 1
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds i8, i8* %118, i64 %121
store i8 0, i8* %122
br label %123
123: ; preds = %113
%124 = load i32, i32* %7
%125 = add nsw i32 %124, 1
store i32 %125, i32* %7
br label %20
126: ; preds = %69, %20
%127 = load i8**, i8*** %5
%128 = load i8***, i8**** %3
store i8** %127, i8*** %128
%129 = load i32, i32* %7
ret i32 %129
}

LLVM IR (-O2):
@.str = [6 x i8] c"words\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [21 x i8] c"Error opening file.\0A\00"
@.str.3 = [16 x i8] c"Out of memory.\0A\00"
define i32 @readFile(i8*** nocapture %0, i32 %1) {
%3 = load i8**, i8*** %0
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @exit(i32 2)
unreachable
10: ; preds = %2, %58
%11 = phi i64 [ %62, %58 ], [ 0, %2 ]
%12 = phi i8** [ %28, %58 ], [ %3, %2 ]
%13 = phi i32 [ %29, %58 ], [ %1, %2 ]
%14 = sext i32 %13 to i64
%15 = icmp slt i64 %11, %14
br i1 %15, label %27, label %16
16: ; preds = %10
%17 = shl i32 %13, 4
%18 = tail call i64 @realloc(i8** %12, i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%23 = tail call i32 @exit(i32 3)
unreachable
24: ; preds = %16
%25 = inttoptr i64 %18 to i8**
%26 = shl nsw i32 %13, 1
br label %27
27: ; preds = %24, %10
%28 = phi i8** [ %25, %24 ], [ %12, %10 ]
%29 = phi i32 [ %26, %24 ], [ %13, %10 ]
%30 = tail call i64 @malloc(i32 30)
%31 = inttoptr i64 %30 to i8*
%32 = getelementptr inbounds i8*, i8** %28, i64 %11
store i8* %31, i8** %32
%33 = icmp eq i64 %30, 0
br i1 %33, label %34, label %38
34: ; preds = %27
%35 = load i32, i32* @stderr
%36 = tail call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%37 = tail call i32 @exit(i32 4)
unreachable
38: ; preds = %27
%39 = tail call i32* @fgets(i8* %31, i32 29, i32* %4)
%40 = icmp eq i32* %39, null
br i1 %40, label %63, label %41
41: ; preds = %38
%42 = load i8*, i8** %32
%43 = tail call i32 @strlen(i8* %42)
%44 = icmp sgt i32 %43, 0
%45 = load i8*, i8** %32
br i1 %44, label %46, label %58
46: ; preds = %41
%47 = zext i32 %43 to i64
br label %48
48: ; preds = %46, %54
%49 = phi i64 [ %47, %46 ], [ %50, %54 ]
%50 = add nsw i64 %49, -1
%51 = and i64 %50, 4294967295
%52 = getelementptr inbounds i8, i8* %45, i64 %51
%53 = load i8, i8* %52
switch i8 %53, label %56 [
i8 10, label %54
i8 13, label %54
]
54: ; preds = %48, %48
%55 = icmp ugt i64 %49, 1
br i1 %55, label %48, label %58
56: ; preds = %48
%57 = trunc i64 %49 to i32
br label %58
58: ; preds = %54, %56, %41
%59 = phi i32 [ %43, %41 ], [ %57, %56 ], [ 0, %54 ]
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %45, i64 %60
store i8 0, i8* %61
%62 = add nuw i64 %11, 1
br label %10
63: ; preds = %38
%64 = trunc i64 %11 to i32
store i8** %28, i8*** %0
ret i32 %64
}