#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*/ EXIT_FAILURE;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
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*/ printf(char *, char *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, char *);
int main(void) {
  char file[81];
  char ch;
  FILE *fp;
  long count, last;
  puts("Enter the name of the file to be processed:");
  scanf("%80s", file);
  if ((fp = fopen(file, "rb")) == NULL) {
    printf("reverse can't open %s\n", file);
    exit(EXIT_FAILURE);
  }
  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    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe47(%rip),%rdi
call   1040 <puts@plt>
lea    -0x60(%rbp),%rsi
lea    0xe63(%rip),%rdi
call   1090 <scanf@plt>
lea    -0x60(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x70(%rbp)
cmp    $0x0,%rax
jne    120a <main+0x6a>
lea    -0x60(%rbp),%rsi
lea    0xe3d(%rip),%rdi
call   1060 <printf@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x70(%rbp),%rdi
mov    0x2dd3(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
mov    -0x70(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x80(%rbp)
movq   $0x1,-0x78(%rbp)
mov    -0x78(%rbp),%rax
cmp    -0x80(%rbp),%rax
jg     12a2 <main+0x102>
mov    -0x70(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
sub    -0x78(%rbp),%rsi
mov    0x2d92(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
mov    -0x70(%rbp),%rdi
call   10c0 <getc@plt>
mov    %al,-0x61(%rbp)
movsbl -0x61(%rbp),%eax
cmp    $0x1a,%eax
je     128c <main+0xec>
movsbl -0x61(%rbp),%eax
cmp    $0xd,%eax
je     128c <main+0xec>
movsbl -0x61(%rbp),%edi
call   1030 <putchar@plt>
jmp    1291 <main+0xf1>
mov    -0x78(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x78(%rbp)
jmp    1235 <main+0x95>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x70(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0xe4e(%rip),%rdi
call   1040 <puts@plt>
lea    0xe6e(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1090 <scanf@plt>
lea    0xe61(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     127b <main+0xdb>
mov    %rax,%r15
mov    0x2dfd(%rip),%r12
mov    (%r12),%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r15,%rdi
call   1070 <ftell@plt>
test   %rax,%rax
jle    125b <main+0xbb>
mov    %rax,%r14
mov    $0xffffffffffffffff,%rbx
jmp    1232 <main+0x92>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    (%r14,%rbx,1),%rax
add    $0xffffffffffffffff,%rax
add    $0xffffffffffffffff,%rbx
cmp    $0xffffffffffffffff,%rax
je     125b <main+0xbb>
mov    (%r12),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <fseek@plt>
mov    %r15,%rdi
call   10c0 <getc@plt>
cmp    $0xd,%al
je     1220 <main+0x80>
cmp    $0x1a,%al
je     1220 <main+0x80>
movsbl %al,%edi
call   1030 <putchar@plt>
jmp    1220 <main+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdb2(%rip),%rdi
mov    %rsp,%rsi
call   1060 <printf@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

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

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