#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int *read_file(char *filename, int *size) {
  FILE *fp;
  int *vett;
  int i = 0, v, N;
  if ((fp = fopen(filename, "r")) == NULL) {
    fprintf(stderr, "Errore apertura file in lettura.\n");
    exit(-1);
  }
  fscanf(fp, "%d", &N);
  vett = (int *)malloc(N * sizeof(int));
  while (fscanf(fp, "%d", &v) > 0) {
    vett[i] = v;
    i++;
  }
  *size = N;
  fclose(fp);
  return vett;
}


x86 assembly (clang, -O0):
<read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11b4 <read_file+0x54>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xe65(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1040 <fscanf@plt>
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe3e(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x0,%rax
jle    1215 <read_file+0xb5>
mov    -0x28(%rbp),%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11db <read_file+0x7b>
mov    -0x2c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     120e <read_file+0xae>
mov    %rax,%rbx
lea    0xe97(%rip),%r12
mov    %rsp,%rdx
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <fscanf@plt>
mov    (%rsp),%edi
shl    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <fscanf@plt>
test   %rax,%rax
jle    11ee <read_file+0x8e>
lea    0xe5f(%rip),%r12
lea    0x4(%rsp),%r13
mov    %r15,%rbp
nopl   (%rax)
mov    0x4(%rsp),%eax
mov    %eax,0x0(%rbp)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1040 <fscanf@plt>
add    $0x4,%rbp
test   %rax,%rax
jg     11d0 <read_file+0x70>
mov    (%rsp),%eax
mov    %eax,(%r14)
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
lea    0xde4(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [34 x i8] c"Errore apertura file in lettura.\0A\00"
@.str.2 = [3 x i8] c"%d\00"
define i32* @read_file(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32 0, i32* %7
%10 = load i8*, i8** %3
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %5
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %2
%18 = load i32*, i32** %5
%19 = call i64 @fscanf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %9)
%20 = load i32, i32* %9
%21 = sext i32 %20 to i64
%22 = mul i64 %21, 4
%23 = trunc i64 %22 to i32
%24 = call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to i32*
store i32* %25, i32** %6
br label %26
26: ; preds = %30, %17
%27 = load i32*, i32** %5
%28 = call i64 @fscanf(i32* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
%29 = icmp sgt i64 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %26
%31 = load i32, i32* %8
%32 = load i32*, i32** %6
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
store i32 %31, i32* %35
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 1
store i32 %37, i32* %7
br label %26
38: ; preds = %26
%39 = load i32, i32* %9
%40 = load i32*, i32** %4
store i32 %39, i32* %40
%41 = load i32*, i32** %5
%42 = call i32 @fclose(i32* %41)
%43 = load i32*, i32** %6
ret i32* %43
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [34 x i8] c"Errore apertura file in lettura.\0A\00"
@.str.2 = [3 x i8] c"%d\00"
define i32* @read_file(i8* nocapture %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 %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @exit(i32 -1)
unreachable
13: ; preds = %2
%14 = call i64 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%15 = load i32, i32* %4
%16 = shl i32 %15, 2
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i32*
%19 = call i64 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%20 = icmp sgt i64 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %13, %21
%22 = phi i64 [ %25, %21 ], [ 0, %13 ]
%23 = load i32, i32* %3
%24 = getelementptr inbounds i32, i32* %18, i64 %22
store i32 %23, i32* %24
%25 = add nuw i64 %22, 1
%26 = call i64 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%27 = icmp sgt i64 %26, 0
br i1 %27, label %21, label %28
28: ; preds = %21, %13
%29 = load i32, i32* %4
store i32 %29, i32* %1
%30 = call i32 @fclose(i32* %7)
ret i32* %18
}