#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 **createStringArray(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int growStringArray(char ***, int, int);
int /*<<< orphan*/ isComment(char *);
int /*<<< orphan*/ isEmpty(char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char *);
char **readNodeNames(char *machineFN) {
  FILE *f = fopen(machineFN, "r");
  int arraySize = 64;
  char **nameArray = createStringArray(arraySize, 1024);
  int numNames = 0;
  char line[1024];
  char *ret = fgets(line, 1024, f);
  char *name;
  while (ret != NULL && !isComment(line) && !isEmpty(line)) {
    name = strtok(line, " \n");
    strcpy(nameArray[numNames], name);
    numNames++;
    if (numNames > arraySize)
      arraySize = growStringArray(&nameArray, arraySize, 1024);
    ret = fgets(line, 1024, f);
  }
  fclose(f);
  return nameArray;
}


x86 assembly (clang, -O0):
<readNodeNames>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe56(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x40,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x400,%esi
call   1080 <createStringArray@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
mov    %rax,-0x438(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x438(%rbp)
mov    %al,-0x441(%rbp)
je     123d <readNodeNames+0xad>
lea    -0x430(%rbp),%rdi
call   1050 <isComment@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x441(%rbp)
jne    123d <readNodeNames+0xad>
lea    -0x430(%rbp),%rdi
call   1070 <isEmpty@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x441(%rbp)
mov    -0x441(%rbp),%al
test   $0x1,%al
jne    1250 <readNodeNames+0xc0>
jmp    12cc <readNodeNames+0x13c>
lea    -0x430(%rbp),%rdi
lea    0xda4(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x440(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x440(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    12ab <readNodeNames+0x11b>
mov    -0x14(%rbp),%esi
lea    -0x20(%rbp),%rdi
mov    $0x400,%edx
call   10b0 <growStringArray@plt>
mov    %eax,-0x14(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
mov    %rax,-0x438(%rbp)
jmp    11ee <readNodeNames+0x5e>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readNodeNames>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
lea    0xe58(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r14
mov    $0x40,%r13d
mov    $0x40,%edi
mov    $0x400,%esi
call   1080 <createStringArray@plt>
mov    %rax,0x8(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     126a <readNodeNames+0xda>
xor    %ebp,%ebp
lea    0x10(%rsp),%rbx
lea    0xe0f(%rip),%r15
lea    0x8(%rsp),%r12
jmp    1219 <readNodeNames+0x89>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
add    $0x1,%rbp
test   %rax,%rax
je     126a <readNodeNames+0xda>
mov    %rbx,%rdi
call   1050 <isComment@plt>
test   %eax,%eax
jne    126a <readNodeNames+0xda>
mov    %rbx,%rdi
call   1070 <isEmpty@plt>
test   %eax,%eax
jne    126a <readNodeNames+0xda>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10a0 <strtok@plt>
mov    0x8(%rsp),%rcx
mov    (%rcx,%rbp,8),%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
movslq %r13d,%rax
cmp    %rax,%rbp
jl     1200 <readNodeNames+0x70>
mov    %r12,%rdi
mov    %r13d,%esi
mov    $0x400,%edx
call   10b0 <growStringArray@plt>
mov    %eax,%r13d
jmp    1200 <readNodeNames+0x70>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%rax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c" \0A\00"
define i8** @readNodeNames(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %2
%10 = load i8*, i8** %2
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %3
store i32 64, i32* %4
%12 = load i32, i32* %4
%13 = call i8** @createStringArray(i32 %12, i32 1024)
store i8** %13, i8*** %5
store i32 0, i32* %6
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%15 = load i32*, i32** %3
%16 = call i8* @fgets(i8* %14, i32 1024, i32* %15)
store i8* %16, i8** %8
br label %17
17: ; preds = %49, %1
%18 = load i8*, i8** %8
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %29
20: ; preds = %17
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%22 = call i32 @isComment(i8* %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %20
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%26 = call i32 @isEmpty(i8* %25)
%27 = icmp ne i32 %26, 0
%28 = xor i1 %27, true
br label %29
29: ; preds = %24, %20, %17
%30 = phi i1 [ false, %20 ], [ false, %17 ], [ %28, %24 ]
br i1 %30, label %31, label %53
31: ; preds = %29
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%33 = call i8* @strtok(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %33, i8** %9
%34 = load i8**, i8*** %5
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
%38 = load i8*, i8** %37
%39 = load i8*, i8** %9
%40 = call i32 @strcpy(i8* %38, i8* %39)
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
%43 = load i32, i32* %6
%44 = load i32, i32* %4
%45 = icmp sgt i32 %43, %44
br i1 %45, label %46, label %49
46: ; preds = %31
%47 = load i32, i32* %4
%48 = call i32 @growStringArray(i8*** %5, i32 %47, i32 1024)
store i32 %48, i32* %4
br label %49
49: ; preds = %46, %31
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%51 = load i32*, i32** %3
%52 = call i8* @fgets(i8* %50, i32 1024, i32* %51)
store i8* %52, i8** %8
br label %17
53: ; preds = %29
%54 = load i32*, i32** %3
%55 = call i32 @fclose(i32* %54)
%56 = load i8**, i8*** %5
ret i8** %56
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c" \0A\00"
define i8** @readNodeNames(i8* nocapture %0) {
%2 = alloca i8**
%3 = alloca [1024 x i8]
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = bitcast i8*** %2 to i8*
%6 = tail call i8** @createStringArray(i32 64, i32 1024)
store i8** %6, i8*** %2
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = call i8* @fgets(i8* %7, i32 1024, i32* %4)
%9 = icmp eq i8* %8, null
br i1 %9, label %33, label %10
10: ; preds = %1, %29
%11 = phi i64 [ %24, %29 ], [ 0, %1 ]
%12 = phi i32 [ %30, %29 ], [ 64, %1 ]
%13 = call i32 @isComment(i8* %7)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %33
15: ; preds = %10
%16 = call i32 @isEmpty(i8* %7)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %33
18: ; preds = %15
%19 = call i8* @strtok(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = load i8**, i8*** %2
%21 = getelementptr inbounds i8*, i8** %20, i64 %11
%22 = load i8*, i8** %21
%23 = call i32 @strcpy(i8* %22, i8* %19)
%24 = add nuw i64 %11, 1
%25 = sext i32 %12 to i64
%26 = icmp slt i64 %11, %25
br i1 %26, label %29, label %27
27: ; preds = %18
%28 = call i32 @growStringArray(i8*** %2, i32 %12, i32 1024)
br label %29
29: ; preds = %27, %18
%30 = phi i32 [ %28, %27 ], [ %12, %18 ]
%31 = call i8* @fgets(i8* %7, i32 1024, i32* %4)
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %10
33: ; preds = %15, %10, %29, %1
%34 = call i32 @fclose(i32* %4)
%35 = load i8**, i8*** %2
ret i8** %35
}