#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 */
scalar_t__ EOF;
int atoi(char *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
scalar_t__ strcmp(char *, char *);
char *strtok(char *, char *);
int *load_entity_map(char *fname, int D) {
  FILE *f;
  int *map;
  char *line = (char *)malloc(1024 * sizeof(char));
  int n;
  size_t nbytes = 1024 * sizeof(char);
  map = (int *)malloc(D * sizeof(int));
  if (strcmp(fname, "NONE") == 0) {
    for (n = 0; n < D; n++) {
      map[n] = -1;
    }
    return map;
  }
  n = 0;
  f = fopen(fname, "r");
  while (getline(&line, &nbytes, f) != EOF) {
    line = strtok(line, "\n");
    map[n] = atoi(line);
    n += 1;
  }
  return map;
}


x86 assembly (clang, -O0):
<load_entity_map>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0x400,%edi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
movq   $0x400,-0x40(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11ef <load_entity_map+0x8f>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e2 <load_entity_map+0x82>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11b9 <load_entity_map+0x59>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    126b <load_entity_map+0x10b>
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe04(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdx
lea    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1080 <getline@plt>
mov    0x2dc6(%rip),%rcx
cmp    (%rcx),%rax
je     1263 <load_entity_map+0x103>
mov    -0x30(%rbp),%rdi
lea    0xdd1(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%edx
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    120a <load_entity_map+0xaa>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_entity_map>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r15d
mov    %rdi,%rbx
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,(%rsp)
movq   $0x400,0x10(%rsp)
lea    0x0(,%r15,4),%edi
call   1050 <malloc@plt>
mov    %rax,0x8(%rsp)
lea    0xe4c(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1245 <load_entity_map+0xd5>
lea    0xe39(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
call   1090 <getline@plt>
mov    0x2dfa(%rip),%rbp
cmp    0x0(%rbp),%rax
je     1260 <load_entity_map+0xf0>
lea    0xe0c(%rip),%r15
mov    %rsp,%r12
lea    0x10(%rsp),%r13
mov    0x8(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    (%rsp),%rdi
mov    %r15,%rsi
call   1070 <strtok@plt>
mov    %rax,(%rsp)
mov    %rax,%rdi
call   1080 <atoi@plt>
mov    %eax,(%r14)
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1090 <getline@plt>
add    $0x4,%r14
cmp    0x0(%rbp),%rax
jne    1210 <load_entity_map+0xa0>
jmp    1260 <load_entity_map+0xf0>
test   %r15d,%r15d
jle    1260 <load_entity_map+0xf0>
mov    %r15d,%edx
shl    $0x2,%rdx
mov    0x8(%rsp),%rdi
mov    $0xff,%esi
call   1030 <memset@plt>
mov    0x8(%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"NONE\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i64 0
@.str.2 = [2 x i8] c"\0A\00"
define i32* @load_entity_map(i8* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
%11 = call i64 @malloc(i32 1024)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %8
store i64 1024, i64* %10
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 4
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i32*
store i32* %18, i32** %7
%19 = load i8*, i8** %4
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %37
22: ; preds = %2
store i32 0, i32* %9
br label %23
23: ; preds = %32, %22
%24 = load i32, i32* %9
%25 = load i32, i32* %5
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %35
27: ; preds = %23
%28 = load i32*, i32** %7
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
store i32 -1, i32* %31
br label %32
32: ; preds = %27
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
br label %23
35: ; preds = %23
%36 = load i32*, i32** %7
store i32* %36, i32** %3
br label %58
37: ; preds = %2
store i32 0, i32* %9
%38 = load i8*, i8** %4
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %39, i32** %6
br label %40
40: ; preds = %45, %37
%41 = load i32*, i32** %6
%42 = call i64 @getline(i8** %8, i64* %10, i32* %41)
%43 = load i64, i64* @EOF
%44 = icmp ne i64 %42, %43
br i1 %44, label %45, label %56
45: ; preds = %40
%46 = load i8*, i8** %8
%47 = call i8* @strtok(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %47, i8** %8
%48 = load i8*, i8** %8
%49 = call i32 @atoi(i8* %48)
%50 = load i32*, i32** %7
%51 = load i32, i32* %9
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %50, i64 %52
store i32 %49, i32* %53
%54 = load i32, i32* %9
%55 = add nsw i32 %54, 1
store i32 %55, i32* %9
br label %40
56: ; preds = %40
%57 = load i32*, i32** %7
store i32* %57, i32** %3
br label %58
58: ; preds = %56, %35
%59 = load i32*, i32** %3
ret i32* %59
}

LLVM IR (-O2):
@.str = [5 x i8] c"NONE\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i64 0
@.str.2 = [2 x i8] c"\0A\00"
define i32* @load_entity_map(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
%6 = tail call i64 @malloc(i32 1024)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %3
%8 = bitcast i64* %4 to i8*
store i64 1024, i64* %4
%9 = shl i32 %1, 2
%10 = tail call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i32*
%12 = inttoptr i64 %10 to i8*
%13 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = icmp sgt i32 %1, 0
br i1 %16, label %17, label %35
17: ; preds = %15
%18 = zext i32 %1 to i64
%19 = shl nuw nsw i64 %18, 2
br label %35
20: ; preds = %2
%21 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%22 = call i64 @getline(i8** %3, i64* %4, i32* %21)
%23 = load i64, i64* @EOF
%24 = icmp eq i64 %22, %23
br i1 %24, label %35, label %25
25: ; preds = %20, %25
%26 = phi i64 [ %31, %25 ], [ 0, %20 ]
%27 = load i8*, i8** %3
%28 = call i8* @strtok(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %28, i8** %3
%29 = call i32 @atoi(i8* %28)
%30 = getelementptr inbounds i32, i32* %11, i64 %26
store i32 %29, i32* %30
%31 = add nuw i64 %26, 1
%32 = call i64 @getline(i8** %3, i64* %4, i32* %21)
%33 = load i64, i64* @EOF
%34 = icmp eq i64 %32, %33
br i1 %34, label %35, label %25
35: ; preds = %25, %17, %20, %15
ret i32* %11
}