#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_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main(void) {
  char nombre[50], c;
  FILE *archivo;
  long int cont, ultimo;
  printf("Nombre del archivo: ");
  fgets(nombre, 50 - 2, stdin);
  if (*(nombre + strlen(nombre) - 1) != '\n') {
    printf("El nombre es demaciado largo");
    return -1;
  } else
    *(nombre + strlen(nombre) - 1) = '\0';
  archivo = fopen(nombre, "rb");
  if (archivo == NULL) {
    printf("Error al abrir \"%s\"", nombre);
    return -1;
  }
  fseek(archivo, 0L, SEEK_END);
  ultimo = ftell(archivo);
  for (cont = 1L; cont <= ultimo; cont++) {
    fseek(archivo, -cont, SEEK_END);
    c = getc(archivo);
    if (c != '\r')
      putchar(c);
  }
  putchar('\n');
  fclose(archivo);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    0x2e28(%rip),%rax
mov    (%rax),%edx
mov    $0x30,%esi
call   1070 <fgets@plt>
lea    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
cltq
movsbl -0x41(%rbp,%rax,1),%eax
cmp    $0xa,%eax
je     11f7 <main+0x67>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e9 <main+0x159>
lea    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x41(%rbp,%rax,1)
lea    -0x40(%rbp),%rdi
lea    0xe20(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    1244 <main+0xb4>
lea    -0x40(%rbp),%rsi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e9 <main+0x159>
mov    -0x50(%rbp),%rdi
mov    0x2d99(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1090 <fseek@plt>
mov    -0x50(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x60(%rbp)
movq   $0x1,-0x58(%rbp)
mov    -0x58(%rbp),%rax
cmp    -0x60(%rbp),%rax
jg     12cf <main+0x13f>
mov    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
sub    -0x58(%rbp),%rsi
mov    0x2d58(%rip),%rax
mov    (%rax),%edx
call   1090 <fseek@plt>
mov    -0x50(%rbp),%rdi
call   10b0 <getc@plt>
mov    %al,-0x41(%rbp)
movsbl -0x41(%rbp),%eax
cmp    $0xd,%eax
je     12b9 <main+0x129>
movsbl -0x41(%rbp),%edi
call   1030 <putchar@plt>
jmp    12be <main+0x12e>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    126f <main+0xdf>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x50(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40,%rsp
lea    0xe5c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x30,%esi
call   1070 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rsp,%rax,1)
jne    1277 <main+0xe7>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rsp,%rax,1)
lea    0xe40(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     129b <main+0x10b>
mov    %rax,%r12
mov    0x2ddb(%rip),%r13
mov    0x0(%r13),%edx
xor    %r14d,%r14d
mov    %rax,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r12,%rdi
call   1080 <ftell@plt>
test   %rax,%rax
jle    1287 <main+0xf7>
mov    %rax,%r15
mov    $0xffffffffffffffff,%rbx
jmp    1252 <main+0xc2>
nopw   0x0(%rax,%rax,1)
lea    (%r15,%rbx,1),%rax
add    $0xffffffffffffffff,%rax
add    $0xffffffffffffffff,%rbx
cmp    $0xffffffffffffffff,%rax
je     1287 <main+0xf7>
mov    0x0(%r13),%edx
mov    %r12,%rdi
mov    %rbx,%rsi
call   1090 <fseek@plt>
mov    %r12,%rdi
call   10b0 <getc@plt>
cmp    $0xd,%al
je     1240 <main+0xb0>
movsbl %al,%edi
call   1030 <putchar@plt>
jmp    1240 <main+0xb0>
lea    0xd97(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12ac <main+0x11c>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
jmp    12b2 <main+0x122>
lea    0xd93(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Nombre del archivo: \00"
@stdin = global i32 0
@.str.1 = [29 x i8] c"El nombre es demaciado largo\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [20 x i8] c"Error al abrir \22%s\22\00"
@SEEK_END = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [50 x i8]
%3 = alloca i8
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i64
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %8, i32 48, i32 %9)
%11 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%12 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
%16 = getelementptr inbounds i8, i8* %15, i64 -1
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 10
br i1 %19, label %20, label %22
20: ; preds = %0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %69
22: ; preds = %0
%23 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%24 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
%28 = getelementptr inbounds i8, i8* %27, i64 -1
store i8 0, i8* %28
br label %29
29: ; preds = %22
%30 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %31, i32** %4
%32 = load i32*, i32** %4
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %35)
store i32 -1, i32* %1
br label %69
37: ; preds = %29
%38 = load i32*, i32** %4
%39 = load i32, i32* @SEEK_END
%40 = call i32 @fseek(i32* %38, i64 0, i32 %39)
%41 = load i32*, i32** %4
%42 = call i64 @ftell(i32* %41)
store i64 %42, i64* %6
store i64 1, i64* %5
br label %43
43: ; preds = %62, %37
%44 = load i64, i64* %5
%45 = load i64, i64* %6
%46 = icmp sle i64 %44, %45
br i1 %46, label %47, label %65
47: ; preds = %43
%48 = load i32*, i32** %4
%49 = load i64, i64* %5
%50 = sub nsw i64 0, %49
%51 = load i32, i32* @SEEK_END
%52 = call i32 @fseek(i32* %48, i64 %50, i32 %51)
%53 = load i32*, i32** %4
%54 = call signext i8 @getc(i32* %53)
store i8 %54, i8* %3
%55 = load i8, i8* %3
%56 = sext i8 %55 to i32
%57 = icmp ne i32 %56, 13
br i1 %57, label %58, label %61
58: ; preds = %47
%59 = load i8, i8* %3
%60 = call i32 @putchar(i8 signext %59)
br label %61
61: ; preds = %58, %47
br label %62
62: ; preds = %61
%63 = load i64, i64* %5
%64 = add nsw i64 %63, 1
store i64 %64, i64* %5
br label %43
65: ; preds = %43
%66 = call i32 @putchar(i8 signext 10)
%67 = load i32*, i32** %4
%68 = call i32 @fclose(i32* %67)
store i32 0, i32* %1
br label %69
69: ; preds = %65, %34, %20
%70 = load i32, i32* %1
ret i32 %70
}

LLVM IR (-O2):
@.str = [21 x i8] c"Nombre del archivo: \00"
@stdin = global i32 0
@.str.1 = [29 x i8] c"El nombre es demaciado largo\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [20 x i8] c"Error al abrir \22%s\22\00"
@SEEK_END = global i32 0
define i32 @main() {
%1 = alloca [50 x i8]
%2 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @stdin
%5 = call i32 @fgets(i8* %2, i32 48, i32 %4)
%6 = call i32 @strlen(i8* %2)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %7
%9 = getelementptr inbounds i8, i8* %8, i64 -1
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 10
br i1 %11, label %14, label %12
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %43
14: ; preds = %0
%15 = call i32 @strlen(i8* %2)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %16
%18 = getelementptr inbounds i8, i8* %17, i64 -1
store i8 0, i8* %18
%19 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %2)
br label %43
23: ; preds = %14
%24 = load i32, i32* @SEEK_END
%25 = call i32 @fseek(i32* %19, i64 0, i32 %24)
%26 = call i64 @ftell(i32* %19)
%27 = icmp slt i64 %26, 1
br i1 %27, label %40, label %28
28: ; preds = %23, %37
%29 = phi i64 [ %38, %37 ], [ 1, %23 ]
%30 = sub nsw i64 0, %29
%31 = load i32, i32* @SEEK_END
%32 = call i32 @fseek(i32* %19, i64 %30, i32 %31)
%33 = call signext i8 @getc(i32* %19)
%34 = icmp eq i8 %33, 13
br i1 %34, label %37, label %35
35: ; preds = %28
%36 = call i32 @putchar(i8 signext %33)
br label %37
37: ; preds = %28, %35
%38 = add nuw i64 %29, 1
%39 = icmp eq i64 %29, %26
br i1 %39, label %40, label %28
40: ; preds = %37, %23
%41 = call i32 @putchar(i8 signext 10)
%42 = call i32 @fclose(i32* %19)
br label %43
43: ; preds = %40, %21, %12
%44 = phi i32 [ -1, %12 ], [ -1, %21 ], [ 0, %40 ]
ret i32 %44
}