#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
char *leeArchivo(char *nombreArchivo) {
  FILE *archivo = fopen(nombreArchivo, "r");
  char *contenido = (char *)malloc(sizeof(char) * 1000000);
  if (archivo) {
    int caracter, i = 0;
    while ((caracter = getc(archivo)) != EOF) {
      contenido[i] = caracter;
      i++;
    }
    contenido[i + 1] = '\0';
    fclose(archivo);
  } else {
    contenido = NULL;
  }
  return contenido;
}


x86 assembly (clang, -O0):
<leeArchivo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    $0xf4240,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d8 <leeArchivo+0x98>
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <getc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e55(%rip),%rcx
cmp    (%rcx),%eax
je     11b9 <leeArchivo+0x79>
mov    -0x1c(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1180 <leeArchivo+0x40>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11e0 <leeArchivo+0xa0>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<leeArchivo>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xeb1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r12
mov    $0xf4240,%edi
call   1040 <malloc@plt>
test   %r12,%r12
je     11b7 <leeArchivo+0x77>
mov    %rax,%r14
mov    %r12,%rdi
call   1060 <getc@plt>
mov    0x2e70(%rip),%r15
mov    $0x1,%ecx
cmp    (%r15),%eax
je     11a8 <leeArchivo+0x68>
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
mov    %al,-0x1(%r14,%rbx,1)
mov    %r12,%rdi
call   1060 <getc@plt>
add    $0x1,%rbx
cmp    (%r15),%eax
jne    1190 <leeArchivo+0x50>
mov    %ebx,%ecx
movb   $0x0,(%r14,%rcx,1)
mov    %r12,%rdi
call   1030 <fclose@plt>
jmp    11ba <leeArchivo+0x7a>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
define i8* @leeArchivo(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %3
%9 = call i64 @malloc(i32 1000000)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %4
%11 = load i32*, i32** %3
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %36
13: ; preds = %1
store i32 0, i32* %6
br label %14
14: ; preds = %19, %13
%15 = load i32*, i32** %3
%16 = call i32 @getc(i32* %15)
store i32 %16, i32* %5
%17 = load i32, i32* @EOF
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %28
19: ; preds = %14
%20 = load i32, i32* %5
%21 = trunc i32 %20 to i8
%22 = load i8*, i8** %4
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8 %21, i8* %25
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %14
28: ; preds = %14
%29 = load i8*, i8** %4
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
store i8 0, i8* %33
%34 = load i32*, i32** %3
%35 = call i32 @fclose(i32* %34)
br label %37
36: ; preds = %1
store i8* null, i8** %4
br label %37
37: ; preds = %36, %28
%38 = load i8*, i8** %4
ret i8* %38
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
define i8* @leeArchivo(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = tail call i64 @malloc(i32 1000000)
%4 = inttoptr i64 %3 to i8*
%5 = icmp eq i32* %2, null
br i1 %5, label %26, label %6
6: ; preds = %1
%7 = tail call i32 @getc(i32* %2)
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %22, label %10
10: ; preds = %6, %10
%11 = phi i64 [ %15, %10 ], [ 0, %6 ]
%12 = phi i32 [ %16, %10 ], [ %7, %6 ]
%13 = trunc i32 %12 to i8
%14 = getelementptr inbounds i8, i8* %4, i64 %11
store i8 %13, i8* %14
%15 = add nuw i64 %11, 1
%16 = tail call i32 @getc(i32* %2)
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %10
19: ; preds = %10
%20 = add i64 %11, 2
%21 = and i64 %20, 4294967295
br label %22
22: ; preds = %19, %6
%23 = phi i64 [ 1, %6 ], [ %21, %19 ]
%24 = getelementptr inbounds i8, i8* %4, i64 %23
store i8 0, i8* %24
%25 = tail call i32 @fclose(i32* %2)
br label %26
26: ; preds = %1, %22
%27 = phi i8* [ %4, %22 ], [ null, %1 ]
ret i8* %27
}