#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*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(long *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
long *malloc(int);
int /*<<< orphan*/ stderr;
long *Load_File(char *Filename, int *Size) {
  FILE *fptr = NULL;
  fptr = fopen(Filename, "r");
  if (fptr == NULL)
    return NULL;
  int N;
  int i;
  int temp;
  long *array;
  fscanf(fptr, "%d", &N);
  array = malloc(sizeof(long) * N);
  for (i = 0; i < N; i++) {
    if (feof(fptr)) {
      fprintf(stderr, "Empty file encountered, closing file!\n");
      free(array);
      *Size = i;
      fclose(fptr);
      return NULL;
    }
    fscanf(fptr, "%d", &temp);
    array[i] = temp;
  }
  *Size = N;
  fclose(fptr);
  return array;
}


x86 assembly (clang, -O0):
<Load_File>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b4 <Load_File+0x44>
movq   $0x0,-0x8(%rbp)
jmp    128a <Load_File+0x11a>
mov    -0x20(%rbp),%rdi
lea    0xe43(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1050 <fscanf@plt>
movslq -0x24(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1270 <Load_File+0x100>
mov    -0x20(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     123e <Load_File+0xce>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
lea    0xdf4(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    128a <Load_File+0x11a>
mov    -0x20(%rbp),%rdi
lea    0xdb9(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1050 <fscanf@plt>
movslq -0x2c(%rbp),%rdx
mov    -0x38(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11e2 <Load_File+0x72>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Load_File>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xe7b(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1205 <Load_File+0x95>
mov    %rax,%rbx
lea    0xe69(%rip),%rsi
mov    %rsp,%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    (%rsp),%ebp
lea    0x0(,%rbp,8),%edi
call   1080 <malloc@plt>
mov    %rax,%r15
test   %ebp,%ebp
jle    122a <Load_File+0xba>
xor    %ebp,%ebp
lea    0xe3f(%rip),%r12
lea    0x4(%rsp),%r13
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %rax,%rax
jne    120a <Load_File+0x9a>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1050 <fscanf@plt>
movslq 0x4(%rsp),%rax
mov    %rax,(%r15,%rbp,8)
add    $0x1,%rbp
movslq (%rsp),%rax
cmp    %rax,%rbp
jl     11d0 <Load_File+0x60>
mov    %eax,%ebp
jmp    122a <Load_File+0xba>
xor    %r15d,%r15d
jmp    1235 <Load_File+0xc5>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
lea    0xdeb(%rip),%rsi
call   1060 <fprintf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %r15d,%r15d
mov    %ebp,(%r14)
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r15,%rax
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 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [39 x i8] c"Empty file encountered, closing file!\0A\00"
define i64* @Load_File(i8* %0, i32* %1) {
%3 = alloca i64*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* null, i32** %6
%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** %6
%13 = load i32*, i32** %6
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %2
store i64* null, i64** %3
br label %59
16: ; preds = %2
%17 = load i32*, i32** %6
%18 = call i32 @fscanf(i32* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = mul i64 8, %20
%22 = trunc i64 %21 to i32
%23 = call i64* @malloc(i32 %22)
store i64* %23, i64** %10
store i32 0, i32* %8
br label %24
24: ; preds = %50, %16
%25 = load i32, i32* %8
%26 = load i32, i32* %7
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %53
28: ; preds = %24
%29 = load i32*, i32** %6
%30 = call i64 @feof(i32* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %41
32: ; preds = %28
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%35 = load i64*, i64** %10
%36 = call i32 @free(i64* %35)
%37 = load i32, i32* %8
%38 = load i32*, i32** %5
store i32 %37, i32* %38
%39 = load i32*, i32** %6
%40 = call i32 @fclose(i32* %39)
store i64* null, i64** %3
br label %59
41: ; preds = %28
%42 = load i32*, i32** %6
%43 = call i32 @fscanf(i32* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %9)
%44 = load i32, i32* %9
%45 = sext i32 %44 to i64
%46 = load i64*, i64** %10
%47 = load i32, i32* %8
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i64, i64* %46, i64 %48
store i64 %45, i64* %49
br label %50
50: ; preds = %41
%51 = load i32, i32* %8
%52 = add nsw i32 %51, 1
store i32 %52, i32* %8
br label %24
53: ; preds = %24
%54 = load i32, i32* %7
%55 = load i32*, i32** %5
store i32 %54, i32* %55
%56 = load i32*, i32** %6
%57 = call i32 @fclose(i32* %56)
%58 = load i64*, i64** %10
store i64* %58, i64** %3
br label %59
59: ; preds = %53, %32, %15
%60 = load i64*, i64** %3
ret i64* %60
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [39 x i8] c"Empty file encountered, closing file!\0A\00"
define noalias i64* @Load_File(i8* nocapture %0, i32* nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca i32
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %37, label %7
7: ; preds = %2
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%11 = load i32, i32* %3
%12 = shl i32 %11, 3
%13 = call i64* @malloc(i32 %12)
%14 = icmp sgt i32 %11, 0
br i1 %14, label %15, label %33
15: ; preds = %7, %24
%16 = phi i64 [ %29, %24 ], [ 0, %7 ]
%17 = call i64 @feof(i32* %5)
%18 = icmp eq i64 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %15
%20 = trunc i64 %16 to i32
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @free(i64* %13)
br label %33
24: ; preds = %15
%25 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i64, i64* %13, i64 %16
store i64 %27, i64* %28
%29 = add nuw nsw i64 %16, 1
%30 = load i32, i32* %3
%31 = sext i32 %30 to i64
%32 = icmp slt i64 %29, %31
br i1 %32, label %15, label %33
33: ; preds = %24, %7, %19
%34 = phi i32 [ %20, %19 ], [ %11, %7 ], [ %30, %24 ]
%35 = phi i64* [ null, %19 ], [ %13, %7 ], [ %13, %24 ]
store i32 %34, i32* %1
%36 = call i32 @fclose(i32* %5)
br label %37
37: ; preds = %2, %33
%38 = phi i64* [ %35, %33 ], [ null, %2 ]
ret i64* %38
}