#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*/ exit(int);
int /*<<< orphan*/ fclose(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*/ gets(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puts(char *);
int main(void) {
  char file[50];
  char ch;
  FILE *fp;
  long count, last;
  puts("Enter the name of the file to be processed: ");
  gets(file);
  if ((fp = fopen(file, "rb")) == NULL) {
    printf("reverse can't open %s\n", file);
    exit(1);
  }
  fseek(fp, 0L, SEEK_END);
  last = ftell(fp);
  for (count = 1L; count <= last; count++) {
    fseek(fp, -count, SEEK_END);
    ch = getc(fp);
    if (ch != '\032' && ch != '\r')
      putchar(ch);
  }
  putchar('\n');
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe4a(%rip),%rdi
call   1040 <puts@plt>
lea    -0x40(%rbp),%rdi
call   1080 <gets@plt>
lea    -0x40(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
jne    11fc <main+0x5c>
lea    -0x40(%rbp),%rsi
lea    0xe43(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x50(%rbp),%rdi
mov    0x2de1(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1090 <fseek@plt>
mov    -0x50(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x60(%rbp)
movq   $0x1,-0x58(%rbp)
mov    -0x58(%rbp),%rax
cmp    -0x60(%rbp),%rax
jg     1294 <main+0xf4>
mov    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
sub    -0x58(%rbp),%rsi
mov    0x2da0(%rip),%rax
mov    (%rax),%edx
call   1090 <fseek@plt>
mov    -0x50(%rbp),%rdi
call   10c0 <getc@plt>
mov    %al,-0x41(%rbp)
movsbl -0x41(%rbp),%eax
cmp    $0x1a,%eax
je     127e <main+0xde>
movsbl -0x41(%rbp),%eax
cmp    $0xd,%eax
je     127e <main+0xde>
movsbl -0x41(%rbp),%edi
call   1030 <putchar@plt>
jmp    1283 <main+0xe3>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    1227 <main+0x87>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x50(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xe4e(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1080 <gets@plt>
lea    0xe64(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     126b <main+0xcb>
mov    %rax,%r15
mov    0x2e04(%rip),%r12
mov    (%r12),%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r15,%rdi
call   1070 <ftell@plt>
test   %rax,%rax
jle    124b <main+0xab>
mov    %rax,%r14
mov    $0xffffffffffffffff,%rbx
jmp    1222 <main+0x82>
nopl   0x0(%rax,%rax,1)
lea    (%r14,%rbx,1),%rax
add    $0xffffffffffffffff,%rax
add    $0xffffffffffffffff,%rbx
cmp    $0xffffffffffffffff,%rax
je     124b <main+0xab>
mov    (%r12),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <fseek@plt>
mov    %r15,%rdi
call   10c0 <getc@plt>
cmp    $0xd,%al
je     1210 <main+0x70>
cmp    $0x1a,%al
je     1210 <main+0x70>
movsbl %al,%edi
call   1030 <putchar@plt>
jmp    1210 <main+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdbe(%rip),%rdi
mov    %rsp,%rsi
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [45 x i8] c"Enter the name of the file to be processed: \00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [23 x i8] c"reverse can't open %s\0A\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 @puts(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%9 = call i32 @gets(i8* %8)
%10 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %4
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %0
%14 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%15 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = load i32*, i32** %4
%19 = load i32, i32* @SEEK_END
%20 = call i32 @fseek(i32* %18, i64 0, i32 %19)
%21 = load i32*, i32** %4
%22 = call i64 @ftell(i32* %21)
store i64 %22, i64* %6
store i64 1, i64* %5
br label %23
23: ; preds = %46, %17
%24 = load i64, i64* %5
%25 = load i64, i64* %6
%26 = icmp sle i64 %24, %25
br i1 %26, label %27, label %49
27: ; preds = %23
%28 = load i32*, i32** %4
%29 = load i64, i64* %5
%30 = sub nsw i64 0, %29
%31 = load i32, i32* @SEEK_END
%32 = call i32 @fseek(i32* %28, i64 %30, i32 %31)
%33 = load i32*, i32** %4
%34 = call signext i8 @getc(i32* %33)
store i8 %34, i8* %3
%35 = load i8, i8* %3
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 26
br i1 %37, label %38, label %45
38: ; preds = %27
%39 = load i8, i8* %3
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 13
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = load i8, i8* %3
%44 = call i32 @putchar(i8 signext %43)
br label %45
45: ; preds = %42, %38, %27
br label %46
46: ; preds = %45
%47 = load i64, i64* %5
%48 = add nsw i64 %47, 1
store i64 %48, i64* %5
br label %23
49: ; preds = %23
%50 = call i32 @putchar(i8 signext 10)
%51 = load i32*, i32** %4
%52 = call i32 @fclose(i32* %51)
ret i32 0
}

LLVM IR (-O2):
@.str = [45 x i8] c"Enter the name of the file to be processed: \00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [23 x i8] c"reverse can't open %s\0A\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 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @gets(i8* %2)
%5 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = load i32, i32* @SEEK_END
%12 = call i32 @fseek(i32* %5, i64 0, i32 %11)
%13 = call i64 @ftell(i32* %5)
%14 = icmp slt i64 %13, 1
br i1 %14, label %26, label %15
15: ; preds = %10, %23
%16 = phi i64 [ %24, %23 ], [ 1, %10 ]
%17 = sub nsw i64 0, %16
%18 = load i32, i32* @SEEK_END
%19 = call i32 @fseek(i32* %5, i64 %17, i32 %18)
%20 = call signext i8 @getc(i32* %5)
switch i8 %20, label %21 [
i8 26, label %23
i8 13, label %23
]
21: ; preds = %15
%22 = call i32 @putchar(i8 signext %20)
br label %23
23: ; preds = %15, %15, %21
%24 = add nuw i64 %16, 1
%25 = icmp eq i64 %16, %13
br i1 %25, label %26, label %15
26: ; preds = %23, %10
%27 = call i32 @putchar(i8 signext 10)
%28 = call i32 @fclose(i32* %5)
ret i32 0
}