#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 EXIT_SUCCESS;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
unsigned long ftell(int /*<<< orphan*/ *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ putchar(int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  FILE *fp;
  int ch;
  unsigned long last;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if ((fp = fopen(argv[1], "rb")) == NULL) {
    fprintf(stderr, "Err. fopen(), %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (fseek(fp, 0, SEEK_END) != -1)
    last = ftell(fp);
  for (long i = 1; i < last; i++)
    if (fseek(fp, -i, SEEK_END) != -1)
      putchar(ch = getc(fp));
  fclose(fp);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11da <main+0x4a>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe39(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1236 <main+0xa6>
mov    0x2dd5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xdf6(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    0x2da7(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1070 <fseek@plt>
cmp    $0xffffffff,%eax
je     1262 <main+0xd2>
mov    -0x18(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x28(%rbp)
movq   $0x1,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    12c4 <main+0x134>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
sub    -0x30(%rbp),%rsi
mov    0x2d5d(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
cmp    $0xffffffff,%eax
je     12ae <main+0x11e>
mov    -0x18(%rbp),%rdi
call   10b0 <getc@plt>
mov    %eax,%edi
mov    %edi,-0x1c(%rbp)
call   1030 <putchar@plt>
jmp    12b3 <main+0x123>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    126a <main+0xda>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2cec(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    124b <main+0xbb>
mov    0x8(%rsi),%rdi
lea    0xe6a(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1260 <main+0xd0>
mov    %rax,%r15
mov    0x2e24(%rip),%r12
mov    (%r12),%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
cmp    $0xffffffff,%eax
je     122e <main+0x9e>
mov    %r15,%rdi
call   1060 <ftell@plt>
cmp    $0x2,%rax
jb     122e <main+0x9e>
mov    %rax,%r14
neg    %r14
mov    $0xffffffffffffffff,%rbx
jmp    1209 <main+0x79>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0xffffffffffffffff,%rbx
cmp    %rbx,%r14
je     122e <main+0x9e>
mov    (%r12),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <fseek@plt>
cmp    $0xffffffff,%eax
je     1200 <main+0x70>
mov    %r15,%rdi
call   10b0 <getc@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    1200 <main+0x70>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    0x2d83(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xda2(%rip),%rsi
jmp    1283 <main+0xf3>
mov    0x2d71(%rip),%rax
mov    (%rax),%ebx
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd9b(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"Usage: %s <filename>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [18 x i8] c"Err. fopen(), %s\0A\00"
@errno = global i32 0
@SEEK_END = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %20
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %6
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %33
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %20
%34 = load i32*, i32** %6
%35 = load i32, i32* @SEEK_END
%36 = call i32 @fseek(i32* %34, i64 0, i32 %35)
%37 = icmp ne i32 %36, -1
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = load i32*, i32** %6
%40 = call i64 @ftell(i32* %39)
store i64 %40, i64* %8
br label %41
41: ; preds = %38, %33
store i64 1, i64* %9
br label %42
42: ; preds = %58, %41
%43 = load i64, i64* %9
%44 = load i64, i64* %8
%45 = icmp ult i64 %43, %44
br i1 %45, label %46, label %61
46: ; preds = %42
%47 = load i32*, i32** %6
%48 = load i64, i64* %9
%49 = sub nsw i64 0, %48
%50 = load i32, i32* @SEEK_END
%51 = call i32 @fseek(i32* %47, i64 %49, i32 %50)
%52 = icmp ne i32 %51, -1
br i1 %52, label %53, label %57
53: ; preds = %46
%54 = load i32*, i32** %6
%55 = call i32 @getc(i32* %54)
store i32 %55, i32* %7
%56 = call i32 @putchar(i32 %55)
br label %57
57: ; preds = %53, %46
br label %58
58: ; preds = %57
%59 = load i64, i64* %9
%60 = add nsw i64 %59, 1
store i64 %60, i64* %9
br label %42
61: ; preds = %42
%62 = load i32*, i32** %6
%63 = call i32 @fclose(i32* %62)
%64 = load i32, i32* @EXIT_SUCCESS
ret i32 %64
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"Usage: %s <filename>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [18 x i8] c"Err. fopen(), %s\0A\00"
@errno = global i32 0
@SEEK_END = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %22
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %10
%23 = load i32, i32* @SEEK_END
%24 = tail call i32 @fseek(i32* %13, i64 0, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %29, label %26
26: ; preds = %22
%27 = tail call i64 @ftell(i32* %13)
%28 = icmp ugt i64 %27, 1
br i1 %28, label %32, label %29
29: ; preds = %41, %22, %26
%30 = tail call i32 @fclose(i32* %13)
%31 = load i32, i32* @EXIT_SUCCESS
ret i32 %31
32: ; preds = %26, %41
%33 = phi i64 [ %42, %41 ], [ 1, %26 ]
%34 = sub nsw i64 0, %33
%35 = load i32, i32* @SEEK_END
%36 = tail call i32 @fseek(i32* %13, i64 %34, i32 %35)
%37 = icmp eq i32 %36, -1
br i1 %37, label %41, label %38
38: ; preds = %32
%39 = tail call i32 @getc(i32* %13)
%40 = tail call i32 @putchar(i32 %39)
br label %41
41: ; preds = %32, %38
%42 = add nuw i64 %33, 1
%43 = icmp eq i64 %42, %27
br i1 %43, label %29, label %32
}