#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 fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ genera_mensaje(int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int main(void) {
  FILE *file = fopen("datos.dat", "a+");
  char *code;
  size_t n = 0;
  int c;
  if (file == NULL)
    return -1;
  genera_mensaje(file);
  code = malloc(1000);
  while ((c = fgetc(file)) != EOF) {
    code[n++] = (char)c;
  }
  code[n] = '\0';
  printf("El texto leido es %s\n", code);
  free(code);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a5 <main+0x45>
movl   $0xffffffff,-0x4(%rbp)
jmp    1223 <main+0xc3>
mov    -0x10(%rbp),%rdi
call   1060 <genera_mensaje@plt>
mov    $0x3e8,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e19(%rip),%rcx
cmp    (%rcx),%eax
je     11f7 <main+0x97>
mov    -0x24(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x20(%rbp)
mov    %dl,(%rax,%rcx,1)
jmp    11bc <main+0x5c>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rsi
lea    0xdff(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
lea    0xe90(%rip),%rdi
lea    0xe93(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11b5 <main+0x55>
mov    %rax,%r13
mov    %rax,%rdi
call   1060 <genera_mensaje@plt>
mov    $0x3e8,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %r13,%rdi
call   1050 <fgetc@plt>
mov    0x2e40(%rip),%r12
xor    %r14d,%r14d
cmp    (%r12),%eax
jne    11bd <main+0x5d>
xor    %ebx,%ebx
jmp    11d6 <main+0x76>
mov    $0xffffffff,%r14d
jmp    11f2 <main+0x92>
xor    %ebx,%ebx
nop
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
mov    %r13,%rdi
call   1050 <fgetc@plt>
cmp    (%r12),%eax
jne    11c0 <main+0x60>
movb   $0x0,(%r15,%rbx,1)
lea    0xe2b(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"datos.dat\00"
@.str.1 = [3 x i8] c"a+\00"
@EOF = global i32 0
@.str.2 = [22 x i8] c"El texto leido es %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
store i64 0, i64* %4
%7 = load i32*, i32** %2
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %10
9: ; preds = %0
store i32 -1, i32* %1
br label %34
10: ; preds = %0
%11 = load i32*, i32** %2
%12 = call i32 @genera_mensaje(i32* %11)
%13 = call i8* @malloc(i32 1000)
store i8* %13, i8** %3
br label %14
14: ; preds = %19, %10
%15 = load i32*, i32** %2
%16 = call i32 @fgetc(i32* %15)
store i32 %16, i32* %5
%17 = load i32, i32* @EOF
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %26
19: ; preds = %14
%20 = load i32, i32* %5
%21 = trunc i32 %20 to i8
%22 = load i8*, i8** %3
%23 = load i64, i64* %4
%24 = add i64 %23, 1
store i64 %24, i64* %4
%25 = getelementptr inbounds i8, i8* %22, i64 %23
store i8 %21, i8* %25
br label %14
26: ; preds = %14
%27 = load i8*, i8** %3
%28 = load i64, i64* %4
%29 = getelementptr inbounds i8, i8* %27, i64 %28
store i8 0, i8* %29
%30 = load i8*, i8** %3
%31 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = load i8*, i8** %3
%33 = call i32 @free(i8* %32)
store i32 0, i32* %1
br label %34
34: ; preds = %26, %9
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str = [10 x i8] c"datos.dat\00"
@.str.1 = [3 x i8] c"a+\00"
@EOF = global i32 0
@.str.2 = [22 x i8] c"El texto leido es %s\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %23, label %3
3: ; preds = %0
%4 = tail call i32 @genera_mensaje(i32* %1)
%5 = tail call dereferenceable_or_null(1000) i8* @malloc(i32 1000)
%6 = tail call i32 @fgetc(i32* %1)
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %6, %7
br i1 %8, label %18, label %9
9: ; preds = %3, %9
%10 = phi i32 [ %15, %9 ], [ %6, %3 ]
%11 = phi i64 [ %13, %9 ], [ 0, %3 ]
%12 = trunc i32 %10 to i8
%13 = add i64 %11, 1
%14 = getelementptr inbounds i8, i8* %5, i64 %11
store i8 %12, i8* %14
%15 = tail call i32 @fgetc(i32* %1)
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %9
18: ; preds = %9, %3
%19 = phi i64 [ 0, %3 ], [ %13, %9 ]
%20 = getelementptr inbounds i8, i8* %5, i64 %19
store i8 0, i8* %20
%21 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%22 = tail call i32 @free(i8* %5)
br label %23
23: ; preds = %0, %18
%24 = phi i32 [ 0, %18 ], [ -1, %0 ]
ret i32 %24
}