#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 */
scalar_t__ fgets(char *, int, 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(101);
  while (fgets(code, 100, file)) {
    printf("%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    11fd <main+0x9d>
mov    -0x10(%rbp),%rdi
call   1050 <genera_mensaje@plt>
mov    $0x65,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x64,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     11ed <main+0x8d>
mov    -0x18(%rbp),%rsi
lea    0xe2a(%rip),%rdi
call   1040 <printf@plt>
jmp    11bc <main+0x5c>
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   %rbx
lea    0xe94(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11ec <main+0x8c>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <genera_mensaje@plt>
mov    $0x65,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11e0 <main+0x80>
lea    0xe5c(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11c0 <main+0x60>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    11f1 <main+0x91>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"datos.dat\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [4 x i8] c"%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 %25
10: ; preds = %0
%11 = load i32*, i32** %2
%12 = call i32 @genera_mensaje(i32* %11)
%13 = call i8* @malloc(i32 101)
store i8* %13, i8** %3
br label %14
14: ; preds = %19, %10
%15 = load i8*, i8** %3
%16 = load i32*, i32** %2
%17 = call i64 @fgets(i8* %15, i32 100, i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i8*, i8** %3
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %14
22: ; preds = %14
%23 = load i8*, i8** %3
%24 = call i32 @free(i8* %23)
store i32 0, i32* %1
br label %25
25: ; preds = %22, %9
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str = [10 x i8] c"datos.dat\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [4 x i8] c"%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 %14, label %3
3: ; preds = %0
%4 = tail call i32 @genera_mensaje(i32* %1)
%5 = tail call dereferenceable_or_null(101) i8* @malloc(i32 101)
%6 = tail call i64 @fgets(i8* %5, i32 100, i32* %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %3, %8
%9 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%10 = tail call i64 @fgets(i8* %5, i32 100, i32* %1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %8
12: ; preds = %8, %3
%13 = tail call i32 @free(i8* %5)
br label %14
14: ; preds = %0, %12
%15 = phi i32 [ 0, %12 ], [ -1, %0 ]
ret i32 %15
}