#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 */
char EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ system(char *);
int main() {
  char aux = "";
  char aux2[100];
  FILE *f;
  f = fopen("Ejemplo.txt", "r");
  if (f == NULL) {
    printf("No se ha podido abrir el fichero");
    exit(1);
  }
  while (aux != EOF) {
    aux = fgetc(f);
    printf("%c", aux);
  }
  printf("\n");
  fclose(f);
  f = fopen("Ejemplo.txt", "r");
  if (f == NULL) {
    printf("No se ha podido abrir el fichero");
    exit(1);
  }
  while (!feof(f)) {
    fgets(aux2, 100, f);
    printf("%s", aux2);
  }
  printf("\n");
  fclose(f);
  system("pause");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rax
mov    %al,-0x5(%rbp)
lea    0xe5d(%rip),%rdi
lea    0xe62(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    11d6 <main+0x56>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    11db <main+0x5b>
movsbl -0x5(%rbp),%eax
mov    0x2e02(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1214 <main+0x94>
mov    -0x78(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%esi
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11db <main+0x5b>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x78(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xdce(%rip),%rdi
lea    0xdd3(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    1265 <main+0xe5>
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    126a <main+0xea>
mov    -0x78(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1288 <main+0x108>
jmp    12b1 <main+0x131>
lea    -0x70(%rbp),%rdi
mov    -0x78(%rbp),%rdx
mov    $0x64,%esi
call   1070 <fgets@plt>
lea    -0x70(%rbp),%rsi
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    126a <main+0xea>
lea    0xd7a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x78(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xd68(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
lea    0xe5f(%rip),%rdi
lea    0xe64(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1284 <main+0xf4>
mov    %rax,%rbx
mov    0x2e28(%rip),%r14
lea    0xe70(%rip),%rax
cmp    %al,(%r14)
je     11e7 <main+0x57>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1070 <fgetc@plt>
movsbl %al,%ebp
mov    %ebp,%edi
call   1030 <putchar@plt>
cmp    (%r14),%bpl
jne    11d0 <main+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe00(%rip),%rdi
lea    0xe05(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1284 <main+0xf4>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    1259 <main+0xc9>
mov    %rsp,%r14
lea    0xe05(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x64,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     1230 <main+0xa0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xdc0(%rip),%rdi
call   1050 <system@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd83(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [12 x i8] c"Ejemplo.txt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [33 x i8] c"No se ha podido abrir el fichero\00"
@EOF = global i8 0
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [6 x i8] c"pause\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca [100 x i8]
%4 = alloca i32*
store i32 0, i32* %1
store i8 ptrtoint ([1 x i8]* @.str to i8), i8* %2
%5 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %5, i32** %4
%6 = load i32*, i32** %4
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
br label %12
12: ; preds = %18, %11
%13 = load i8, i8* %2
%14 = sext i8 %13 to i32
%15 = load i8, i8* @EOF
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %14, %16
br i1 %17, label %18, label %24
18: ; preds = %12
%19 = load i32*, i32** %4
%20 = call signext i8 @fgetc(i32* %19)
store i8 %20, i8* %2
%21 = load i8, i8* %2
%22 = sext i8 %21 to i32
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %22)
br label %12
24: ; preds = %12
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%26 = load i32*, i32** %4
%27 = call i32 @fclose(i32* %26)
%28 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %28, i32** %4
%29 = load i32*, i32** %4
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %34
31: ; preds = %24
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %24
br label %35
35: ; preds = %40, %34
%36 = load i32*, i32** %4
%37 = call i32 @feof(i32* %36)
%38 = icmp ne i32 %37, 0
%39 = xor i1 %38, true
br i1 %39, label %40, label %46
40: ; preds = %35
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%42 = load i32*, i32** %4
%43 = call i32 @fgets(i8* %41, i32 100, i32* %42)
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %44)
br label %35
46: ; preds = %35
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%48 = load i32*, i32** %4
%49 = call i32 @fclose(i32* %48)
%50 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [12 x i8] c"Ejemplo.txt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [33 x i8] c"No se ha podido abrir el fichero\00"
@EOF = global i8 0
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [6 x i8] c"pause\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = load i8, i8* @EOF
%7 = icmp eq i8 %6, ptrtoint ([1 x i8]* @.str to i8)
br i1 %7, label %17, label %11
8: ; preds = %0
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %5, %11
%12 = tail call signext i8 @fgetc(i32* %3)
%13 = sext i8 %12 to i32
%14 = tail call i32 @putchar(i32 %13)
%15 = load i8, i8* @EOF
%16 = icmp eq i8 %12, %15
br i1 %16, label %17, label %11
17: ; preds = %11, %5
%18 = tail call i32 @putchar(i32 10)
%19 = tail call i32 @fclose(i32* %3)
%20 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %25, label %22
22: ; preds = %17
%23 = call i32 @feof(i32* %20)
%24 = icmp eq i32 %23, 0
br i1 %24, label %28, label %33
25: ; preds = %17
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %22, %28
%29 = call i32 @fgets(i8* %2, i32 100, i32* %20)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %2)
%31 = call i32 @feof(i32* %20)
%32 = icmp eq i32 %31, 0
br i1 %32, label %28, label %33
33: ; preds = %28, %22
%34 = call i32 @putchar(i32 10)
%35 = call i32 @fclose(i32* %20)
%36 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}