#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 */
char **calloc(int, int);
int /*<<< orphan*/ *fopen(char const *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char *);
char **read(const char *fname) {
  char **lines = calloc(13, sizeof(char[256]));
  if (lines == NULL) {
    puts("Calloc failure of lines");
    return NULL;
  }
  FILE *file;
  file = fopen(fname, "r");
  if (file) {
    char *buff = malloc(1024);
    if (buff == NULL) {
      puts("Buffer allocation error");
      return NULL;
    }
    size_t nread;
    size_t idx = 0;
    while ((nread = fread(buff, 1, 1024, file)) > 0) {
      char tmp[1024];
      strcpy(tmp, buff);
      char *token = strtok(tmp, "\n");
      while (token) {
        lines[idx] = token;
        idx++;
        if (idx > 13) {
          puts("FILE TOO LONG; ABORTING");
          return NULL;
        }
        token = strtok(NULL, "\n");
      }
    }
    free(buff);
  } else {
    puts("File opening error or file does not exist");
    return NULL;
  }
  return lines;
}


x86 assembly (clang, -O0):
<read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0xd,%edi
mov    $0x100,%esi
call   1070 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c6 <read+0x46>
lea    0xe4c(%rip),%rdi
call   1050 <puts@plt>
movq   $0x0,-0x8(%rbp)
jmp    130f <read+0x18f>
mov    -0x10(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12ee <read+0x16e>
mov    $0x400,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1217 <read+0x97>
lea    0xe13(%rip),%rdi
call   1050 <puts@plt>
movq   $0x0,-0x8(%rbp)
jmp    130f <read+0x18f>
movq   $0x0,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1060 <fread@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jbe    12e0 <read+0x160>
lea    -0x440(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x440(%rbp),%rdi
lea    0xdce(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x448(%rbp)
cmpq   $0x0,-0x448(%rbp)
je     12db <read+0x15b>
mov    -0x448(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
cmpq   $0xd,-0x38(%rbp)
jbe    12bf <read+0x13f>
lea    0xd85(%rip),%rdi
call   1050 <puts@plt>
movq   $0x0,-0x8(%rbp)
jmp    130f <read+0x18f>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd66(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x448(%rbp)
jmp    126e <read+0xee>
jmp    121f <read+0x9f>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    1307 <read+0x187>
lea    0xd55(%rip),%rdi
call   1050 <puts@plt>
movq   $0x0,-0x8(%rbp)
jmp    130f <read+0x18f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%r14
mov    $0xd,%edi
mov    $0x100,%esi
call   1070 <calloc@plt>
test   %rax,%rax
je     1208 <read+0x88>
mov    %rax,%rbx
lea    0xe7c(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     126f <read+0xef>
mov    %rax,%r14
mov    $0x400,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1278 <read+0xf8>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r14,%rcx
call   1060 <fread@plt>
test   %rax,%rax
je     12a4 <read+0x124>
xor    %ebp,%ebp
mov    %rsp,%r12
lea    0xe2a(%rip),%r13
jmp    123a <read+0xba>
lea    0xdf1(%rip),%rdi
jmp    1288 <read+0x108>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r14,%rcx
call   1060 <fread@plt>
test   %rax,%rax
je     12a4 <read+0x124>
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r12,%rdi
nopl   0x0(%rax,%rax,1)
mov    %r13,%rsi
call   10a0 <strtok@plt>
test   %rax,%rax
je     1220 <read+0xa0>
mov    %rax,(%rbx,%rbp,8)
add    $0x1,%rbp
cmp    $0xe,%rbp
jae    1281 <read+0x101>
xor    %edi,%edi
jmp    1250 <read+0xd0>
lea    0xdd4(%rip),%rdi
jmp    1288 <read+0x108>
lea    0xd99(%rip),%rdi
jmp    1288 <read+0x108>
lea    0xdaa(%rip),%rdi
call   1050 <puts@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
call   1030 <free@plt>
jmp    128f <read+0x10f>

LLVM IR (-O0):
@.str = [24 x i8] c"Calloc failure of lines\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"Buffer allocation error\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [24 x i8] c"FILE TOO LONG; ABORTING\00"
@.str.5 = [42 x i8] c"File opening error or file does not exist\00"
define i8** @read(i8* %0) {
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca [1024 x i8]
%10 = alloca i8*
store i8* %0, i8** %3
%11 = call i8** @calloc(i32 13, i32 256)
store i8** %11, i8*** %4
%12 = load i8**, i8*** %4
%13 = icmp eq i8** %12, null
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i8** null, i8*** %2
br label %63
16: ; preds = %1
%17 = load i8*, i8** %3
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %5
%19 = load i32*, i32** %5
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %59
21: ; preds = %16
%22 = call i8* @malloc(i32 1024)
store i8* %22, i8** %6
%23 = load i8*, i8** %6
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i8** null, i8*** %2
br label %63
27: ; preds = %21
store i64 0, i64* %8
br label %28
28: ; preds = %55, %27
%29 = load i8*, i8** %6
%30 = load i32*, i32** %5
%31 = call i64 @fread(i8* %29, i32 1, i32 1024, i32* %30)
store i64 %31, i64* %7
%32 = icmp ugt i64 %31, 0
br i1 %32, label %33, label %56
33: ; preds = %28
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%35 = load i8*, i8** %6
%36 = call i32 @strcpy(i8* %34, i8* %35)
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%38 = call i8* @strtok(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %38, i8** %10
br label %39
39: ; preds = %53, %33
%40 = load i8*, i8** %10
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %55
42: ; preds = %39
%43 = load i8*, i8** %10
%44 = load i8**, i8*** %4
%45 = load i64, i64* %8
%46 = getelementptr inbounds i8*, i8** %44, i64 %45
store i8* %43, i8** %46
%47 = load i64, i64* %8
%48 = add i64 %47, 1
store i64 %48, i64* %8
%49 = load i64, i64* %8
%50 = icmp ugt i64 %49, 13
br i1 %50, label %51, label %53
51: ; preds = %42
%52 = call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
store i8** null, i8*** %2
br label %63
53: ; preds = %42
%54 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %54, i8** %10
br label %39
55: ; preds = %39
br label %28
56: ; preds = %28
%57 = load i8*, i8** %6
%58 = call i32 @free(i8* %57)
br label %61
59: ; preds = %16
%60 = call i32 @puts(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0))
store i8** null, i8*** %2
br label %63
61: ; preds = %56
%62 = load i8**, i8*** %4
store i8** %62, i8*** %2
br label %63
63: ; preds = %61, %59, %51, %25, %14
%64 = load i8**, i8*** %2
ret i8** %64
}

LLVM IR (-O2):
@.str = [24 x i8] c"Calloc failure of lines\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"Buffer allocation error\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [24 x i8] c"FILE TOO LONG; ABORTING\00"
@.str.5 = [42 x i8] c"File opening error or file does not exist\00"
define noalias i8** @read(i8* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = tail call i8** @calloc(i32 13, i32 256)
%4 = icmp eq i8** %3, null
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %44
7: ; preds = %1
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %42, label %10
10: ; preds = %7
%11 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%12 = icmp eq i8* %11, null
br i1 %12, label %18, label %13
13: ; preds = %10
%14 = call i64 @fread(i8* %11, i32 1, i32 1024, i32* %8)
%15 = icmp eq i64 %14, 0
br i1 %15, label %40, label %16
16: ; preds = %13
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
br label %20
18: ; preds = %10
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %44
20: ; preds = %16, %36
%21 = phi i64 [ 0, %16 ], [ %37, %36 ]
%22 = call i32 @strcpy(i8* %17, i8* %11)
%23 = call i8* @strtok(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i8* %23, null
br i1 %24, label %36, label %25
25: ; preds = %20, %33
%26 = phi i8* [ %34, %33 ], [ %23, %20 ]
%27 = phi i64 [ %29, %33 ], [ %21, %20 ]
%28 = getelementptr inbounds i8*, i8** %3, i64 %27
store i8* %26, i8** %28
%29 = add i64 %27, 1
%30 = icmp ugt i64 %29, 13
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %44
33: ; preds = %25
%34 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %25
36: ; preds = %33, %20
%37 = phi i64 [ %21, %20 ], [ %29, %33 ]
%38 = call i64 @fread(i8* %11, i32 1, i32 1024, i32* %8)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %20
40: ; preds = %36, %13
%41 = call i32 @free(i8* %11)
br label %44
42: ; preds = %7
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0))
br label %44
44: ; preds = %31, %18, %40, %42, %5
%45 = phi i8** [ null, %5 ], [ null, %42 ], [ %3, %40 ], [ null, %18 ], [ null, %31 ]
ret i8** %45
}