#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 *);
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");
    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   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c7 <fileAsArray+0x57>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1205 <fileAsArray+0x95>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe23(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
movl   $0x0,-0x24(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    121b <fileAsArray+0xab>
jmp    1311 <fileAsArray+0x1a1>
mov    -0x10(%rbp),%edi
call   1070 <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   1050 <fgets@plt>
cmp    $0x0,%rax
jne    125c <fileAsArray+0xec>
jmp    1311 <fileAsArray+0x1a1>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x28(%rbp)
mov    %al,-0x29(%rbp)
jl     12c7 <fileAsArray+0x157>
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     12c1 <fileAsArray+0x151>
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    12d7 <fileAsArray+0x167>
jmp    12ea <fileAsArray+0x17a>
jmp    12dc <fileAsArray+0x16c>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    1273 <fileAsArray+0x103>
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    120c <fileAsArray+0x9c>
mov    -0x20(%rbp),%rdi
call   1030 <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   1070 <malloc@plt>
test   %rax,%rax
je     1268 <fileAsArray+0xf8>
mov    %rax,%r14
lea    0xe7e(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1287 <fileAsArray+0x117>
mov    %rax,%r15
mov    $0x64,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,(%r14)
mov    %rax,%rdi
mov    $0x63,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1253 <fileAsArray+0xe3>
xor    %r12d,%r12d
jmp    1217 <fileAsArray+0xa7>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
cltq
movb   $0x0,(%rbx,%rax,1)
lea    0x1(%r12),%r13
mov    $0x64,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,0x8(%r14,%r12,8)
mov    %rax,%rdi
mov    $0x63,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
mov    %r13,%r12
test   %rax,%rax
je     1253 <fileAsArray+0xe3>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11e2 <fileAsArray+0x72>
mov    %eax,%eax
jmp    123d <fileAsArray+0xcd>
nopw   0x0(%rax,%rax,1)
lea    0x1(%rcx),%rdx
mov    %rcx,%rax
cmp    $0x1,%rdx
jbe    11e0 <fileAsArray+0x70>
lea    -0x1(%rax),%rcx
mov    %ecx,%edx
movzbl (%rbx,%rdx,1),%edx
cmp    $0xd,%dl
je     1230 <fileAsArray+0xc0>
cmp    $0xa,%dl
je     1230 <fileAsArray+0xc0>
jmp    11e2 <fileAsArray+0x72>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
lea    0xd88(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
lea    0xd82(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1090 <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 %21
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 = call i32 @exit(i32 1)
unreachable
21: ; preds = %1
%22 = load i8*, i8** %2
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %6
%24 = load i32*, i32** %6
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @exit(i32 2)
unreachable
30: ; preds = %21
store i32 0, i32* %7
br label %31
31: ; preds = %103, %30
br i1 true, label %32, label %106
32: ; preds = %31
%33 = load i32, i32* %4
%34 = call i8* @malloc(i32 %33)
%35 = load i8**, i8*** %5
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %35, i64 %37
store i8* %34, i8** %38
%39 = load i8**, i8*** %5
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8*, i8** %39, i64 %41
%43 = load i8*, i8** %42
%44 = load i32, i32* %4
%45 = sub nsw i32 %44, 1
%46 = load i32*, i32** %6
%47 = call i32* @fgets(i8* %43, i32 %45, i32* %46)
%48 = icmp eq i32* %47, null
br i1 %48, label %49, label %50
49: ; preds = %32
br label %106
50: ; preds = %32
%51 = load i8**, i8*** %5
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %51, i64 %53
%55 = load i8*, i8** %54
%56 = call i32 @strlen(i8* %55)
%57 = sub nsw i32 %56, 1
store i32 %57, i32* %8
br label %58
58: ; preds = %90, %50
%59 = load i32, i32* %8
%60 = icmp sge i32 %59, 0
br i1 %60, label %61, label %87
61: ; preds = %58
%62 = load i8**, i8*** %5
%63 = load i32, i32* %7
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8*, i8** %62, i64 %64
%66 = load i8*, i8** %65
%67 = load i32, i32* %8
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %66, i64 %68
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = icmp eq i32 %71, 10
br i1 %72, label %85, label %73
73: ; preds = %61
%74 = load i8**, i8*** %5
%75 = load i32, i32* %7
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8*, i8** %74, i64 %76
%78 = load i8*, i8** %77
%79 = load i32, i32* %8
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8, i8* %78, i64 %80
%82 = load i8, i8* %81
%83 = sext i8 %82 to i32
%84 = icmp eq i32 %83, 13
br label %85
85: ; preds = %73, %61
%86 = phi i1 [ true, %61 ], [ %84, %73 ]
br label %87
87: ; preds = %85, %58
%88 = phi i1 [ false, %58 ], [ %86, %85 ]
br i1 %88, label %89, label %93
89: ; preds = %87
br label %90
90: ; preds = %89
%91 = load i32, i32* %8
%92 = add nsw i32 %91, -1
store i32 %92, i32* %8
br label %58
93: ; preds = %87
%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 = add nsw i32 %99, 1
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds i8, i8* %98, i64 %101
store i8 0, i8* %102
br label %103
103: ; preds = %93
%104 = load i32, i32* %7
%105 = add nsw i32 %104, 1
store i32 %105, i32* %7
br label %31
106: ; preds = %49, %31
%107 = load i32*, i32** %6
%108 = call i32 @fclose(i32* %107)
%109 = load i8**, i8*** %5
ret i8** %109
}

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 %9
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 @exit(i32 1)
unreachable
9: ; preds = %1
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
store i8* %13, i8** %3
%14 = tail call i32* @fgets(i8* %13, i32 99, i32* %10)
%15 = icmp eq i32* %14, null
br i1 %15, label %46, label %20
16: ; preds = %9
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%19 = tail call i32 @exit(i32 2)
unreachable
20: ; preds = %12, %37
%21 = phi i64 [ %41, %37 ], [ 0, %12 ]
%22 = phi i8* [ %42, %37 ], [ %13, %12 ]
%23 = tail call i32 @strlen(i8* %22)
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %37
25: ; preds = %20
%26 = zext i32 %23 to i64
br label %27
27: ; preds = %25, %33
%28 = phi i64 [ %26, %25 ], [ %29, %33 ]
%29 = add nsw i64 %28, -1
%30 = and i64 %29, 4294967295
%31 = getelementptr inbounds i8, i8* %22, i64 %30
%32 = load i8, i8* %31
switch i8 %32, label %35 [
i8 10, label %33
i8 13, label %33
]
33: ; preds = %27, %27
%34 = icmp ugt i64 %28, 1
br i1 %34, label %27, label %37
35: ; preds = %27
%36 = trunc i64 %28 to i32
br label %37
37: ; preds = %33, %35, %20
%38 = phi i32 [ %23, %20 ], [ %36, %35 ], [ 0, %33 ]
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %22, i64 %39
store i8 0, i8* %40
%41 = add nuw i64 %21, 1
%42 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
%43 = getelementptr inbounds i8*, i8** %3, i64 %41
store i8* %42, i8** %43
%44 = tail call i32* @fgets(i8* %42, i32 99, i32* %10)
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %20
46: ; preds = %37, %12
%47 = tail call i32 @fclose(i32* %10)
ret i8** %3
}