#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);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ report_error(char *);
char **read_datafile(char *filename) {
  FILE *fp;
  int i, j;
  char **buffer;
  fp = NULL;
  i = 0;
  j = 0;
  buffer = NULL;
  fp = fopen(filename, "r");
  if (!fp) {
    report_error("Cannot open data file for reading.");
    exit(1);
  }
  buffer = (char **)malloc(sizeof(char *) * 200);
  if (buffer == NULL) {
    report_error("Failed to allocate memory.");
    exit(1);
  }
  for (i = 0; i < 200; i++) {
    buffer[i] = (char *)malloc(sizeof(char) * 80);
    memset(buffer[i], '\0', 80);
    if (buffer[i] == NULL) {
      report_error("Failed to allocate memory.");
      exit(1);
    }
  }
  for (i = 0; (i < 200) || (!feof(fp)); i++) {
    for (j = 0; (j < 80) || (!feof(fp)); j++) {
      fscanf(fp, "%c", &buffer[i][j]);
      if (buffer[i][j] == '\0') {
        break;
      }
      if (buffer[i][j] == '\n') {
        break;
      }
    }
  }
  if (fp) {
    if (fclose(fp) != 0) {
      report_error("Failed to close data file.");
      exit(1);
    }
  }
  return buffer;
}


x86 assembly (clang, -O0):
<read_datafile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe4b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11df <read_datafile+0x5f>
lea    0xe32(%rip),%rdi
call   1080 <report_error@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    $0x640,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    120e <read_datafile+0x8e>
lea    0xe26(%rip),%rdi
call   1080 <report_error@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xc8,-0x14(%rbp)
jge    128f <read_datafile+0x10f>
mov    $0x50,%edi
call   1070 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1040 <memset@plt>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    127c <read_datafile+0xfc>
lea    0xdb8(%rip),%rdi
call   1080 <report_error@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1281 <read_datafile+0x101>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1215 <read_datafile+0x95>
movl   $0x0,-0x14(%rbp)
mov    $0x1,%al
cmpl   $0xc8,-0x14(%rbp)
mov    %al,-0x21(%rbp)
jl     12bc <read_datafile+0x13c>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    12cc <read_datafile+0x14c>
jmp    1393 <read_datafile+0x213>
movl   $0x0,-0x18(%rbp)
mov    $0x1,%al
cmpl   $0x50,-0x18(%rbp)
mov    %al,-0x22(%rbp)
jl     12f6 <read_datafile+0x176>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    1306 <read_datafile+0x186>
jmp    1380 <read_datafile+0x200>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
movslq -0x18(%rbp),%rax
add    %rax,%rdx
lea    0xd1c(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    134b <read_datafile+0x1cb>
jmp    1380 <read_datafile+0x200>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    136d <read_datafile+0x1ed>
jmp    1380 <read_datafile+0x200>
jmp    1372 <read_datafile+0x1f2>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12d3 <read_datafile+0x153>
jmp    1385 <read_datafile+0x205>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1296 <read_datafile+0x116>
cmpq   $0x0,-0x10(%rbp)
je     13cc <read_datafile+0x24c>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     13c7 <read_datafile+0x247>
lea    0xc8b(%rip),%rdi
call   1080 <report_error@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    13cc <read_datafile+0x24c>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_datafile>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
lea    0xe70(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12aa <read_datafile+0x12a>
mov    %rax,%r14
mov    $0x640,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1294 <read_datafile+0x114>
mov    %rax,%r12
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    $0x50,%edi
call   1070 <malloc@plt>
mov    %rax,(%r12,%rbx,8)
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1040 <memset@plt>
cmpq   $0x0,(%r12,%rbx,8)
je     1294 <read_datafile+0x114>
add    $0x1,%rbx
cmp    $0xc8,%rbx
jne    11c0 <read_datafile+0x40>
xor    %r13d,%r13d
lea    0xe41(%rip),%r15
jmp    1214 <read_datafile+0x94>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13
cmp    $0xc8,%r13
jb     1229 <read_datafile+0xa9>
mov    %r14,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    127a <read_datafile+0xfa>
xor    %ebx,%ebx
cmp    $0x50,%rbx
jb     124c <read_datafile+0xcc>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    1210 <read_datafile+0x90>
mov    (%r12,%r13,8),%rdx
add    %rbx,%rdx
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <fscanf@plt>
mov    (%r12,%r13,8),%rax
movzbl (%rax,%rbx,1),%eax
test   %al,%al
je     1210 <read_datafile+0x90>
cmp    $0xa,%al
je     1210 <read_datafile+0x90>
add    $0x1,%rbx
cmp    $0x50,%rbx
jae    1240 <read_datafile+0xc0>
jmp    124c <read_datafile+0xcc>
mov    %r14,%rdi
call   1030 <fclose@plt>
test   %rax,%rax
jne    12b3 <read_datafile+0x133>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xd8a(%rip),%rdi
call   1080 <report_error@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xd51(%rip),%rdi
jmp    129b <read_datafile+0x11b>
lea    0xd89(%rip),%rdi
jmp    129b <read_datafile+0x11b>

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [35 x i8] c"Cannot open data file for reading.\00"
@.str.2 = [27 x i8] c"Failed to allocate memory.\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [27 x i8] c"Failed to close data file.\00"
define i8** @read_datafile(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 @report_error(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %1
%8 = tail call i64 @malloc(i32 1600)
%9 = inttoptr i64 %8 to i8**
%10 = icmp eq i64 %8, 0
br i1 %10, label %11, label %17
11: ; preds = %7
%12 = tail call i32 @report_error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %17
%15 = add nuw nsw i64 %18, 1
%16 = icmp eq i64 %15, 200
br i1 %16, label %28, label %17
17: ; preds = %7, %14
%18 = phi i64 [ %15, %14 ], [ 0, %7 ]
%19 = tail call i64 @malloc(i32 80)
%20 = inttoptr i64 %19 to i8*
%21 = getelementptr inbounds i8*, i8** %9, i64 %18
store i8* %20, i8** %21
%22 = tail call i32 @memset(i8* %20, i8 signext 0, i32 80)
%23 = load i8*, i8** %21
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %14
25: ; preds = %17
%26 = tail call i32 @report_error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %14, %51
%29 = phi i64 [ %52, %51 ], [ 0, %14 ]
%30 = icmp ult i64 %29, 200
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = tail call i32 @feof(i32* %2)
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %53
34: ; preds = %28, %31
%35 = getelementptr inbounds i8*, i8** %9, i64 %29
br label %36
36: ; preds = %49, %34
%37 = phi i64 [ %50, %49 ], [ 0, %34 ]
%38 = icmp ult i64 %37, 80
br i1 %38, label %42, label %39
39: ; preds = %36
%40 = tail call i32 @feof(i32* %2)
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %51
42: ; preds = %36, %39
%43 = load i8*, i8** %35
%44 = getelementptr inbounds i8, i8* %43, i64 %37
%45 = tail call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %44)
%46 = load i8*, i8** %35
%47 = getelementptr inbounds i8, i8* %46, i64 %37
%48 = load i8, i8* %47
switch i8 %48, label %49 [
i8 0, label %51
i8 10, label %51
]
49: ; preds = %42
%50 = add nuw i64 %37, 1
br label %36
51: ; preds = %42, %42, %39
%52 = add nuw i64 %29, 1
br label %28
53: ; preds = %31
%54 = tail call i64 @fclose(i32* %2)
%55 = icmp eq i64 %54, 0
br i1 %55, label %59, label %56
56: ; preds = %53
%57 = tail call i32 @report_error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%58 = tail call i32 @exit(i32 1)
unreachable
59: ; preds = %53
ret i8** %9
}