#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *, int *);
int /*<<< orphan*/ printf(char *, char *);
int Load_Mem(char *InputFileName, int IntArray[]) {
  int N, Addr, Value, NumVals;
  FILE *FP;
  FP = fopen(InputFileName, "r");
  if (FP == NULL) {
    printf("%s could not be opened; check the filename\n", InputFileName);
    return 0;
  } else {
    for (N = 0; N < 1728; N++) {
      NumVals = fscanf(FP, "%d: %d", &Addr, &Value);
      if (NumVals == 2)
        IntArray[N] = Value;
      else
        break;
    }
    fclose(FP);
    return N;
  }
}


x86 assembly (clang, -O0):
<Load_Mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    118b <Load_Mem+0x4b>
mov    -0x10(%rbp),%rsi
lea    0xe88(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11fe <Load_Mem+0xbe>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x6c0,-0x1c(%rbp)
jge    11ef <Load_Mem+0xaf>
mov    -0x30(%rbp),%rdi
lea    0xe84(%rip),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
call   1050 <fscanf@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x2,-0x28(%rbp)
jne    11d7 <Load_Mem+0x97>
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    11dc <Load_Mem+0x9c>
jmp    11ef <Load_Mem+0xaf>
jmp    11e1 <Load_Mem+0xa1>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1192 <Load_Mem+0x52>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Load_Mem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xea8(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b9 <Load_Mem+0x79>
mov    %rax,%r14
xor    %ebx,%ebx
lea    0xec0(%rip),%r12
lea    0x4(%rsp),%r13
mov    %rsp,%rbp
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %rbp,%rcx
call   1050 <fscanf@plt>
cmp    $0x2,%eax
jne    11af <Load_Mem+0x6f>
mov    (%rsp),%eax
mov    %eax,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    $0x6c0,%rbx
jne    1180 <Load_Mem+0x40>
mov    $0x6c0,%ebx
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    11ca <Load_Mem+0x8a>
lea    0xe42(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%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 = [44 x i8] c"%s could not be opened; check the filename\0A\00"
@.str.2 = [7 x i8] c"%d: %d\00"
define i32 @Load_Mem(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %5
%11 = load i8*, i8** %4
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %10
%13 = load i32*, i32** %10
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %16)
store i32 0, i32* %3
br label %42
18: ; preds = %2
store i32 0, i32* %6
br label %19
19: ; preds = %35, %18
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 1728
br i1 %21, label %22, label %38
22: ; preds = %19
%23 = load i32*, i32** %10
%24 = call i32 @fscanf(i32* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32* %7, i32* %8)
store i32 %24, i32* %9
%25 = load i32, i32* %9
%26 = icmp eq i32 %25, 2
br i1 %26, label %27, label %33
27: ; preds = %22
%28 = load i32, i32* %8
%29 = load i32*, i32** %5
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
store i32 %28, i32* %32
br label %34
33: ; preds = %22
br label %38
34: ; preds = %27
br label %35
35: ; preds = %34
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %19
38: ; preds = %33, %19
%39 = load i32*, i32** %10
%40 = call i32 @fclose(i32* %39)
%41 = load i32, i32* %6
store i32 %41, i32* %3
br label %42
42: ; preds = %38, %15
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [44 x i8] c"%s could not be opened; check the filename\0A\00"
@.str.2 = [7 x i8] c"%d: %d\00"
define i32 @Load_Mem(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %25
11: ; preds = %2, %15
%12 = phi i64 [ %18, %15 ], [ 0, %2 ]
%13 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32* %3, i32* %4)
%14 = icmp eq i32 %13, 2
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i32, i32* %4
%17 = getelementptr inbounds i32, i32* %1, i64 %12
store i32 %16, i32* %17
%18 = add nuw nsw i64 %12, 1
%19 = icmp eq i64 %18, 1728
br i1 %19, label %22, label %11
20: ; preds = %11
%21 = trunc i64 %12 to i32
br label %22
22: ; preds = %15, %20
%23 = phi i32 [ %21, %20 ], [ 1728, %15 ]
%24 = call i32 @fclose(i32* %7)
br label %25
25: ; preds = %22, %9
%26 = phi i32 [ 0, %9 ], [ %23, %22 ]
ret i32 %26
}