#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int *malloc(int);
int *parse_input(char *file_name, int n) {
  int *array = malloc(sizeof(int) * n);
  FILE *file = fopen(file_name, "r");
  int i;
  for (i = 0; i < n; i++) {
    fscanf(file, "%d", &array[i]);
  }
  return (array);
}


x86 assembly (clang, -O0):
<parse_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea3(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a6 <parse_input+0x76>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe6f(%rip),%rsi
call   1030 <fscanf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116d <parse_input+0x3d>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_input>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %rdi,%rbx
lea    0x0(,%r15,4),%edi
call   1040 <malloc@plt>
mov    %rax,%r14
lea    0xeaa(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %r15d,%r15d
jle    1198 <parse_input+0x68>
mov    %rax,%r12
mov    %r15d,%r13d
lea    0xe92(%rip),%r15
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1030 <fscanf@plt>
add    $0x4,%rbx
add    $0xffffffffffffffff,%r13
jne    1180 <parse_input+0x50>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
define i32* @parse_input(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = sext i32 %8 to i64
%10 = mul i64 4, %9
%11 = trunc i64 %10 to i32
%12 = call i32* @malloc(i32 %11)
store i32* %12, i32** %5
%13 = load i8*, i8** %3
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %6
store i32 0, i32* %7
br label %15
15: ; preds = %26, %2
%16 = load i32, i32* %7
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %29
19: ; preds = %15
%20 = load i32*, i32** %6
%21 = load i32*, i32** %5
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = call i32 @fscanf(i32* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %24)
br label %26
26: ; preds = %19
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %15
29: ; preds = %15
%30 = load i32*, i32** %5
ret i32* %30
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
define i32* @parse_input(i8* nocapture %0, i32 %1) {
%3 = shl i32 %1, 2
%4 = tail call i32* @malloc(i32 %3)
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %15
7: ; preds = %2
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %13, %9 ]
%11 = getelementptr inbounds i32, i32* %4, i64 %10
%12 = tail call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %11)
%13 = add nuw nsw i64 %10, 1
%14 = icmp eq i64 %13, %8
br i1 %14, label %15, label %9
15: ; preds = %9, %2
ret i32* %4
}