#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*/ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
leerFichero(char *nombreFichero, int nEle) {
  FILE *fichero;
  int i = 0, vector[nEle];
  if ((fichero = fopen(nombreFichero, "rb")) != NULL) {
    printf("\nEl fichero %s ha sido abierto correctamente\n", nombreFichero);
  } else {
    printf("\nError. El fichero %s no se ha podido abrir\n", nombreFichero);
    exit(-1);
  }
  fread(vector, sizeof(int), nEle, fichero);
  printf("\nLos elementos del vector son: ");
  for (i = 0; i < nEle; i++) {
    printf(" %i", vector[i]);
  }
  printf("\n");
  fclose(fichero);
}


x86 assembly (clang, -O0):
<leerFichero>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11c2 <leerFichero+0x72>
mov    -0x10(%rbp),%rsi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11de <leerFichero+0x8e>
mov    -0x10(%rbp),%rsi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
call   1030 <fread@plt>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    123b <leerFichero+0xeb>
mov    -0x40(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1208 <leerFichero+0xb8>
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<leerFichero>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r12
mov    %esi,%r13d
mov    %rsp,%r14
lea    0xf(,%r13,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
lea    0xe6d(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1227 <leerFichero+0xc7>
mov    %rax,%rbx
lea    0xe58(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
mov    $0x4,%esi
mov    %r15d,%edx
mov    %rbx,%r12
mov    %rbx,%rcx
call   1040 <fread@plt>
lea    0xe8c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
test   %r15d,%r15d
jle    1207 <leerFichero+0xa7>
lea    0xe99(%rip),%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r14,%rbx,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    11f0 <leerFichero+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r12,%rdi
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fclose@plt>
lea    0xe03(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [46 x i8] c"\0AEl fichero %s ha sido abierto correctamente\0A\00"
@.str.2 = [45 x i8] c"\0AError. El fichero %s no se ha podido abrir\0A\00"
@.str.3 = [32 x i8] c"\0ALos elementos del vector son: \00"
@.str.4 = [4 x i8] c" %i\00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @leerFichero(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %7
%10 = load i32, i32* %5
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %8
%13 = alloca i32, i64 %11
store i64 %11, i64* %9
%14 = load i8*, i8** %4
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %6
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load i8*, i8** %4
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %24
20: ; preds = %2
%21 = load i8*, i8** %4
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %17
%25 = load i32, i32* %5
%26 = load i32*, i32** %6
%27 = call i32 @fread(i32* %13, i32 4, i32 %25, i32* %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %7
br label %29
29: ; preds = %39, %24
%30 = load i32, i32* %7
%31 = load i32, i32* %5
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %42
33: ; preds = %29
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %13, i64 %35
%37 = load i32, i32* %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %33
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
br label %29
42: ; preds = %29
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%44 = load i32*, i32** %6
%45 = call i32 @fclose(i32* %44)
%46 = load i8*, i8** %8
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [46 x i8] c"\0AEl fichero %s ha sido abierto correctamente\0A\00"
@.str.2 = [45 x i8] c"\0AError. El fichero %s no se ha podido abrir\0A\00"
@.str.3 = [32 x i8] c"\0ALos elementos del vector son: \00"
@.str.4 = [4 x i8] c" %i\00"
define i32 @leerFichero(i8* %0, i32 %1) {
%3 = zext i32 %1 to i64
%4 = alloca i32, i64 %3
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%9 = call i32 @fread(i32* %4, i32 4, i32 %1, i32* %5)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%11 = icmp sgt i32 %1, 0
br i1 %11, label %15, label %22
12: ; preds = %2
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %7, %15
%16 = phi i64 [ %20, %15 ], [ 0, %7 ]
%17 = getelementptr inbounds i32, i32* %4, i64 %16
%18 = load i32, i32* %17
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %18)
%20 = add nuw nsw i64 %16, 1
%21 = icmp eq i64 %20, %3
br i1 %21, label %22, label %15
22: ; preds = %15, %7
%23 = tail call i32 @putchar(i32 10)
%24 = tail call i32 @fclose(i32* %5)
ret i32 undef
}