#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_CUR;
int /*<<< orphan*/ SEEK_END;
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *fp1 = NULL, *fp2 = NULL;
  char c;
  if (argc < 3) {
    printf("\nEnter file names\n");
    return -1;
  }
  fp1 = fopen(argv[1], "r");
  fp2 = fopen(argv[2], "r");
  if (NULL == fp1 || NULL == fp2) {
    printf("\nERROR: file open failed\n");
    return -1;
  }
  fseek(fp1, -2, SEEK_END);
  c = fgetc(fp1);
  while (ftell(fp1) != 1) {
    printf(" %c ", c);
    fseek(fp1, -2, SEEK_CUR);
    c = fgetc(fp1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    119a <main+0x4a>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1272 <main+0x122>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe52(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
je     11e2 <main+0x92>
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    11fc <main+0xac>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1272 <main+0x122>
mov    -0x18(%rbp),%rdi
mov    0x2de1(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffe,%esi
call   1060 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x21(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <ftell@plt>
cmp    $0x1,%eax
je     126b <main+0x11b>
movsbl -0x21(%rbp),%esi
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d92(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffe,%esi
call   1060 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x21(%rbp)
jmp    121f <main+0xcf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x3,%edi
jge    1179 <main+0x19>
lea    0xeac(%rip),%rdi
jmp    1237 <main+0xd7>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe79(%rip),%rbp
mov    %rbp,%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
mov    0x10(%rbx),%rdi
mov    %rbp,%rsi
call   1080 <fopen@plt>
lea    0xe62(%rip),%rdi
test   %r15,%r15
je     1237 <main+0xd7>
test   %rax,%rax
je     1237 <main+0xd7>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    $0xfffffffe,%esi
call   1070 <fseek@plt>
mov    %r15,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1060 <ftell@plt>
xor    %ebp,%ebp
cmp    $0x1,%eax
je     1241 <main+0xe1>
lea    0xe15(%rip),%r14
mov    0x2dec(%rip),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
movsbl %bl,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r12),%edx
mov    %r15,%rdi
mov    $0xfffffffe,%esi
call   1070 <fseek@plt>
mov    %r15,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1060 <ftell@plt>
cmp    $0x1,%eax
jne    1200 <main+0xa0>
jmp    1241 <main+0xe1>
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"\0AEnter file names\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"\0AERROR: file open failed\0A\00"
@SEEK_END = global i32 0
@.str.3 = [5 x i8] c" %c \00"
@SEEK_CUR = 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 i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i32* null, i32** %7
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %49
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %6
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %7
%22 = load i32*, i32** %6
%23 = icmp eq i32* null, %22
br i1 %23, label %27, label %24
24: ; preds = %13
%25 = load i32*, i32** %7
%26 = icmp eq i32* null, %25
br i1 %26, label %27, label %29
27: ; preds = %24, %13
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %49
29: ; preds = %24
%30 = load i32*, i32** %6
%31 = load i32, i32* @SEEK_END
%32 = call i32 @fseek(i32* %30, i32 -2, i32 %31)
%33 = load i32*, i32** %6
%34 = call signext i8 @fgetc(i32* %33)
store i8 %34, i8* %8
br label %35
35: ; preds = %39, %29
%36 = load i32*, i32** %6
%37 = call i32 @ftell(i32* %36)
%38 = icmp ne i32 %37, 1
br i1 %38, label %39, label %48
39: ; preds = %35
%40 = load i8, i8* %8
%41 = sext i8 %40 to i32
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %41)
%43 = load i32*, i32** %6
%44 = load i32, i32* @SEEK_CUR
%45 = call i32 @fseek(i32* %43, i32 -2, i32 %44)
%46 = load i32*, i32** %6
%47 = call signext i8 @fgetc(i32* %46)
store i8 %47, i8* %8
br label %35
48: ; preds = %35
store i32 0, i32* %3
br label %49
49: ; preds = %48, %27, %11
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@.str.3 = [5 x i8] c" %c \00"
@SEEK_CUR = global i32 0
@str = [25 x i8] c"\0AERROR: file open failed\00"
@str.4 = [18 x i8] c"\0AEnter file names\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %29, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %7, null
%12 = icmp eq i32* %10, null
%13 = or i1 %11, %12
br i1 %13, label %29, label %14
14: ; preds = %4
%15 = load i32, i32* @SEEK_END
%16 = tail call i32 @fseek(i32* %7, i32 -2, i32 %15)
%17 = tail call signext i8 @fgetc(i32* %7)
%18 = tail call i32 @ftell(i32* %7)
%19 = icmp eq i32 %18, 1
br i1 %19, label %32, label %20
20: ; preds = %14, %20
%21 = phi i8 [ %26, %20 ], [ %17, %14 ]
%22 = sext i8 %21 to i32
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = load i32, i32* @SEEK_CUR
%25 = tail call i32 @fseek(i32* %7, i32 -2, i32 %24)
%26 = tail call signext i8 @fgetc(i32* %7)
%27 = tail call i32 @ftell(i32* %7)
%28 = icmp eq i32 %27, 1
br i1 %28, label %32, label %20
29: ; preds = %4, %2
%30 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @str.4, i64 0, i64 0), %2 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0), %4 ]
%31 = tail call i32 @puts(i8* dereferenceable(1) %30)
br label %32
32: ; preds = %20, %29, %14
%33 = phi i32 [ 0, %14 ], [ -1, %29 ], [ 0, %20 ]
ret i32 %33
}