#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*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int main(void) {
  FILE *fichero;
  int x = 0, y = 0;
  fichero = fopen("datos.txt", "w+");
  if (fichero == NULL) {
    printf("Error");
  } else {
    printf("Se procederá a guardar en un fichero los números del 1 al mil.");
    sleep(1);
    while ((!feof(fichero)) && (x < 1000)) {
      x++;
      fprintf(fichero, "%d\n", x);
    }
    printf("\n\nProceso concluido.\n");
    printf("Se procederá a enseñar dichos números.");
    fseek(fichero, 0, SEEK_SET);
    while (!feof(fichero)) {
      fscanf(fichero, "%d\n", &y);
      printf("%d\n", y);
    }
  }
  fclose(fichero);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe5c(%rip),%rdi
lea    0xe5f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d2 <main+0x52>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12be <main+0x13e>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
jne    1210 <main+0x90>
cmpl   $0x3e8,-0x14(%rbp)
setl   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1220 <main+0xa0>
jmp    1241 <main+0xc1>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe1d(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11ea <main+0x6a>
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2d78(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    128f <main+0x10f>
jmp    12b9 <main+0x139>
mov    -0x10(%rbp),%rdi
lea    0xdba(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x18(%rbp),%esi
lea    0xda7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1271 <main+0xf1>
jmp    12be <main+0x13e>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
lea    0xe5a(%rip),%rdi
lea    0xe5d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
je     128a <main+0xfa>
lea    0xe4e(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    %r15,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    1216 <main+0x86>
lea    0xe69(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %ebp,%ebx
lea    0x1(%rbx),%ebp
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1070 <fprintf@plt>
mov    %r15,%rdi
call   1080 <feof@plt>
cmp    $0x3e6,%ebx
ja     1216 <main+0x86>
test   %eax,%eax
je     11f0 <main+0x60>
lea    0xe65(%rip),%rdi
call   1030 <puts@plt>
lea    0xe2f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r15,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    1298 <main+0x108>
lea    0xdfe(%rip),%rbp
lea    0x4(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1060 <fscanf@plt>
mov    0x4(%rsp),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     1260 <main+0xd0>
jmp    1298 <main+0x108>
lea    0xd7c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"datos.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [6 x i8] c"Error\00"
@.str.3 = [65 x i8] c"Se proceder\C3\A1 a guardar en un fichero los n\C3\BAmeros del 1 al mil.\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@.str.5 = [22 x i8] c"\0A\0AProceso concluido.\0A\00"
@.str.6 = [42 x i8] c"Se proceder\C3\A1 a ense\C3\B1ar dichos n\C3\BAmeros.\00"
@SEEK_SET = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
%5 = 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* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %45
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 @sleep(i32 1)
br label %13
13: ; preds = %22, %10
%14 = load i32*, i32** %2
%15 = call i32 @feof(i32* %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = load i32, i32* %3
%19 = icmp slt i32 %18, 1000
br label %20
20: ; preds = %17, %13
%21 = phi i1 [ false, %13 ], [ %19, %17 ]
br i1 %21, label %22, label %28
22: ; preds = %20
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
%25 = load i32*, i32** %2
%26 = load i32, i32* %3
%27 = call i32 @fprintf(i32* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %26)
br label %13
28: ; preds = %20
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
%31 = load i32*, i32** %2
%32 = load i32, i32* @SEEK_SET
%33 = call i32 @fseek(i32* %31, i32 0, i32 %32)
br label %34
34: ; preds = %39, %28
%35 = load i32*, i32** %2
%36 = call i32 @feof(i32* %35)
%37 = icmp ne i32 %36, 0
%38 = xor i1 %37, true
br i1 %38, label %39, label %44
39: ; preds = %34
%40 = load i32*, i32** %2
%41 = call i32 @fscanf(i32* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %4)
%42 = load i32, i32* %4
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %42)
br label %34
44: ; preds = %34
br label %45
45: ; preds = %44, %8
%46 = load i32*, i32** %2
%47 = call i32 @fclose(i32* %46)
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
@.str = [10 x i8] c"datos.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [6 x i8] c"Error\00"
@.str.3 = [65 x i8] c"Se proceder\C3\A1 a guardar en un fichero los n\C3\BAmeros del 1 al mil.\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@.str.6 = [42 x i8] c"Se proceder\C3\A1 a ense\C3\B1ar dichos n\C3\BAmeros.\00"
@SEEK_SET = global i32 0
@str = [21 x i8] c"\0A\0AProceso concluido.\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = 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))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %33
7: ; preds = %0
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str.3, i64 0, i64 0))
%9 = tail call i32 @sleep(i32 1)
%10 = tail call i32 @feof(i32* %3)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %7, %12
%13 = phi i32 [ %14, %12 ], [ 0, %7 ]
%14 = add nuw nsw i32 %13, 1
%15 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %14)
%16 = tail call i32 @feof(i32* %3)
%17 = icmp eq i32 %16, 0
%18 = icmp ult i32 %13, 999
%19 = and i1 %18, %17
br i1 %19, label %12, label %20
20: ; preds = %12, %7
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
%23 = load i32, i32* @SEEK_SET
%24 = tail call i32 @fseek(i32* %3, i32 0, i32 %23)
%25 = call i32 @feof(i32* %3)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %20, %27
%28 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%29 = load i32, i32* %1
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %29)
%31 = call i32 @feof(i32* %3)
%32 = icmp eq i32 %31, 0
br i1 %32, label %27, label %33
33: ; preds = %27, %20, %5
%34 = call i32 @fclose(i32* %3)
ret i32 0
}