#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char **);
char *malloc(int);
int /*<<< orphan*/ stderr;
int strlen(char *);
char **fileAsArray(char *filename) {
  int lines = 16;
  int line_len = 100;
  char **words = (char **)malloc(sizeof(char *) * lines);
  if (words == NULL) {
    fprintf(stderr, "Error: Out of memory!\n");
    free(words);
    exit(1);
  }
  FILE *fp = fopen(filename, "r");
  if (fp == NULL) {
    fprintf(stderr, "Error: File not found!\n");
    exit(2);
  }
  int i;
  for (i = 0; 1; i++) {
    int j;
    words[i] = malloc(line_len);
    if (fgets(words[i], line_len - 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';
  }
  fclose(fp);
  return (words);
}


x86 assembly (clang, -O0):
<fileAsArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x10,-0xc(%rbp)
movl   $0x64,-0x10(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e0 <fileAsArray+0x60>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    121e <fileAsArray+0x9e>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x24(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    1234 <fileAsArray+0xb4>
jmp    132a <fileAsArray+0x1aa>
mov    -0x10(%rbp),%edi
call   1080 <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
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%esi
sub    $0x1,%esi
mov    -0x20(%rbp),%rdx
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    1275 <fileAsArray+0xf5>
jmp    132a <fileAsArray+0x1aa>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x28(%rbp)
mov    %al,-0x29(%rbp)
jl     12e0 <fileAsArray+0x160>
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,-0x2a(%rbp)
je     12da <fileAsArray+0x15a>
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,-0x2a(%rbp)
mov    -0x2a(%rbp),%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    12f0 <fileAsArray+0x170>
jmp    1303 <fileAsArray+0x183>
jmp    12f5 <fileAsArray+0x175>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    128c <fileAsArray+0x10c>
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    1225 <fileAsArray+0xa5>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fileAsArray>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%rbx
mov    $0x80,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1278 <fileAsArray+0xf8>
mov    %rax,%r14
lea    0xe6e(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     129e <fileAsArray+0x11e>
mov    %rax,%r15
mov    $0x64,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,(%r14)
mov    %rax,%rdi
mov    $0x63,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1263 <fileAsArray+0xe3>
xor    %r12d,%r12d
jmp    1227 <fileAsArray+0xa7>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
cltq
movb   $0x0,(%rbx,%rax,1)
lea    0x1(%r12),%r13
mov    $0x64,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,0x8(%r14,%r12,8)
mov    %rax,%rdi
mov    $0x63,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
mov    %r13,%r12
test   %rax,%rax
je     1263 <fileAsArray+0xe3>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    11f2 <fileAsArray+0x72>
mov    %eax,%eax
jmp    124d <fileAsArray+0xcd>
nopw   0x0(%rax,%rax,1)
lea    0x1(%rcx),%rdx
mov    %rcx,%rax
cmp    $0x1,%rdx
jbe    11f0 <fileAsArray+0x70>
lea    -0x1(%rax),%rcx
mov    %ecx,%edx
movzbl (%rbx,%rdx,1),%edx
cmp    $0xd,%dl
je     1240 <fileAsArray+0xc0>
cmp    $0xa,%dl
je     1240 <fileAsArray+0xc0>
jmp    11f2 <fileAsArray+0x72>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
lea    0xd78(%rip),%rsi
call   1070 <fprintf@plt>
xor    %edi,%edi
call   1030 <free@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
lea    0xd6b(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"Error: Out of memory!\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"Error: File not found!\0A\00"
define noalias i8** @fileAsArray(i8* nocapture %0) {
%2 = tail call dereferenceable_or_null(128) i8* @malloc(i32 128)
%3 = bitcast i8* %2 to i8**
%4 = icmp eq i8* %2, null
br i1 %4, label %5, label %10
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @free(i8** null)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %1
%11 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
store i8* %14, i8** %3
%15 = tail call i32* @fgets(i8* %14, i32 99, i32* %11)
%16 = icmp eq i32* %15, null
br i1 %16, label %47, label %21
17: ; preds = %10
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call i32 @exit(i32 2)
unreachable
21: ; preds = %13, %38
%22 = phi i64 [ %42, %38 ], [ 0, %13 ]
%23 = phi i8* [ %43, %38 ], [ %14, %13 ]
%24 = tail call i32 @strlen(i8* %23)
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %38
26: ; preds = %21
%27 = zext i32 %24 to i64
br label %28
28: ; preds = %26, %34
%29 = phi i64 [ %27, %26 ], [ %30, %34 ]
%30 = add nsw i64 %29, -1
%31 = and i64 %30, 4294967295
%32 = getelementptr inbounds i8, i8* %23, i64 %31
%33 = load i8, i8* %32
switch i8 %33, label %36 [
i8 10, label %34
i8 13, label %34
]
34: ; preds = %28, %28
%35 = icmp ugt i64 %29, 1
br i1 %35, label %28, label %38
36: ; preds = %28
%37 = trunc i64 %29 to i32
br label %38
38: ; preds = %34, %36, %21
%39 = phi i32 [ %24, %21 ], [ %37, %36 ], [ 0, %34 ]
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %23, i64 %40
store i8 0, i8* %41
%42 = add nuw i64 %22, 1
%43 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
%44 = getelementptr inbounds i8*, i8** %3, i64 %42
store i8* %43, i8** %44
%45 = tail call i32* @fgets(i8* %43, i32 99, i32* %11)
%46 = icmp eq i32* %45, null
br i1 %46, label %47, label %21
47: ; preds = %38, %13
%48 = tail call i32 @fclose(i32* %11)
ret i8** %3
}