#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 **readNodes() {
  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("NODES", "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):
<readNodes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x10,-0x4(%rbp)
movl   $0x64,-0x8(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c3 <readNodes+0x53>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xe4d(%rip),%rdi
lea    0xe4c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1204 <readNodes+0x94>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
movl   $0x0,-0x1c(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    121a <readNodes+0xaa>
jmp    1310 <readNodes+0x1a0>
mov    -0x8(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
mov    -0x18(%rbp),%rdx
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    125b <readNodes+0xeb>
jmp    1310 <readNodes+0x1a0>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x20(%rbp)
mov    %al,-0x21(%rbp)
jl     12c6 <readNodes+0x156>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0x22(%rbp)
je     12c0 <readNodes+0x150>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
sete   %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    12d6 <readNodes+0x166>
jmp    12e9 <readNodes+0x179>
jmp    12db <readNodes+0x16b>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    1272 <readNodes+0x102>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    120b <readNodes+0x9b>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readNodes>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    $0x80,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1268 <readNodes+0xf8>
mov    %rax,%r14
lea    0xe81(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1287 <readNodes+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 <readNodes+0xe3>
xor    %r12d,%r12d
jmp    1217 <readNodes+0xa7>
nopl   0x0(%rax)
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 <readNodes+0xe3>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11e2 <readNodes+0x72>
mov    %eax,%eax
jmp    123d <readNodes+0xcd>
nopw   0x0(%rax,%rax,1)
lea    0x1(%rcx),%rdx
mov    %rcx,%rax
cmp    $0x1,%rdx
jbe    11e0 <readNodes+0x70>
lea    -0x1(%rax),%rcx
mov    %ecx,%edx
movzbl (%rbx,%rdx,1),%edx
cmp    $0xd,%dl
je     1230 <readNodes+0xc0>
cmp    $0xa,%dl
je     1230 <readNodes+0xc0>
jmp    11e2 <readNodes+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    0xd88(%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 = [6 x i8] c"NODES\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [24 x i8] c"Error: File not found!\0A\00"
define i8** @readNodes() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32 16, i32* %1
store i32 100, i32* %2
%7 = load i32, i32* %1
%8 = sext i32 %7 to i64
%9 = mul i64 8, %8
%10 = trunc i64 %9 to i32
%11 = call i8* @malloc(i32 %10)
%12 = bitcast i8* %11 to i8**
store i8** %12, i8*** %3
%13 = load i8**, i8*** %3
%14 = icmp eq i8** %13, null
br i1 %14, label %15, label %19
15: ; preds = %0
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %0
%20 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %20, i32** %4
%21 = load i32*, i32** %4
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%26 = call i32 @exit(i32 2)
unreachable
27: ; preds = %19
store i32 0, i32* %5
br label %28
28: ; preds = %100, %27
br i1 true, label %29, label %103
29: ; preds = %28
%30 = load i32, i32* %2
%31 = call i8* @malloc(i32 %30)
%32 = load i8**, i8*** %3
%33 = load i32, i32* %5
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8*, i8** %32, i64 %34
store i8* %31, i8** %35
%36 = load i8**, i8*** %3
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
%40 = load i8*, i8** %39
%41 = load i32, i32* %2
%42 = sub nsw i32 %41, 1
%43 = load i32*, i32** %4
%44 = call i32* @fgets(i8* %40, i32 %42, i32* %43)
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %47
46: ; preds = %29
br label %103
47: ; preds = %29
%48 = load i8**, i8*** %3
%49 = load i32, i32* %5
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
%52 = load i8*, i8** %51
%53 = call i32 @strlen(i8* %52)
%54 = sub nsw i32 %53, 1
store i32 %54, i32* %6
br label %55
55: ; preds = %87, %47
%56 = load i32, i32* %6
%57 = icmp sge i32 %56, 0
br i1 %57, label %58, label %84
58: ; preds = %55
%59 = load i8**, i8*** %3
%60 = load i32, i32* %5
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8*, i8** %59, i64 %61
%63 = load i8*, i8** %62
%64 = load i32, i32* %6
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = icmp eq i32 %68, 10
br i1 %69, label %82, label %70
70: ; preds = %58
%71 = load i8**, i8*** %3
%72 = load i32, i32* %5
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8*, i8** %71, i64 %73
%75 = load i8*, i8** %74
%76 = load i32, i32* %6
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8, i8* %75, i64 %77
%79 = load i8, i8* %78
%80 = sext i8 %79 to i32
%81 = icmp eq i32 %80, 13
br label %82
82: ; preds = %70, %58
%83 = phi i1 [ true, %58 ], [ %81, %70 ]
br label %84
84: ; preds = %82, %55
%85 = phi i1 [ false, %55 ], [ %83, %82 ]
br i1 %85, label %86, label %90
86: ; preds = %84
br label %87
87: ; preds = %86
%88 = load i32, i32* %6
%89 = add nsw i32 %88, -1
store i32 %89, i32* %6
br label %55
90: ; preds = %84
%91 = load i8**, i8*** %3
%92 = load i32, i32* %5
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i8*, i8** %91, i64 %93
%95 = load i8*, i8** %94
%96 = load i32, i32* %6
%97 = add nsw i32 %96, 1
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i8, i8* %95, i64 %98
store i8 0, i8* %99
br label %100
100: ; preds = %90
%101 = load i32, i32* %5
%102 = add nsw i32 %101, 1
store i32 %102, i32* %5
br label %28
103: ; preds = %46, %28
%104 = load i32*, i32** %4
%105 = call i32 @fclose(i32* %104)
%106 = load i8**, i8*** %3
ret i8** %106
}

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