#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 fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, int);
int main() {
  int c;
  FILE *f;
  f = fopen("abcd.txt", "r");
  fseek(f, -1, SEEK_END);
  c = fgetc(f);
  printf("Last character = [%c/%d]\n", c, (int)c);
  fseek(f, -2, SEEK_END);
  c = fgetc(f);
  printf("Second to last character = [%c/%d]\n", c, (int)c);
  fseek(f, -3, SEEK_END);
  c = fgetc(f);
  printf("Third to last character = [%c/%d]\n", c, (int)c);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e67(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%esi
call   1060 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe65(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e32(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffe,%esi
call   1060 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe4a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2dfd(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffd,%esi
call   1060 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe39(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    0x2e77(%rip),%r14
mov    (%r14),%edx
mov    %rax,%rdi
mov    $0xffffffff,%esi
call   1060 <fseek@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
lea    0xe7b(%rip),%rdi
mov    %eax,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0xfffffffe,%esi
call   1060 <fseek@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
lea    0xe6d(%rip),%rdi
mov    %eax,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0xfffffffd,%esi
call   1060 <fseek@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
lea    0xe69(%rip),%rdi
mov    %eax,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [9 x i8] c"abcd.txt\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@.str.2 = [26 x i8] c"Last character = [%c/%d]\0A\00"
@.str.3 = [36 x i8] c"Second to last character = [%c/%d]\0A\00"
@.str.4 = [35 x i8] c"Third to last character = [%c/%d]\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %3
%5 = load i32*, i32** %3
%6 = load i32, i32* @SEEK_END
%7 = call i32 @fseek(i32* %5, i32 -1, i32 %6)
%8 = load i32*, i32** %3
%9 = call i32 @fgetc(i32* %8)
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = load i32, i32* %2
%12 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %10, i32 %11)
%13 = load i32*, i32** %3
%14 = load i32, i32* @SEEK_END
%15 = call i32 @fseek(i32* %13, i32 -2, i32 %14)
%16 = load i32*, i32** %3
%17 = call i32 @fgetc(i32* %16)
store i32 %17, i32* %2
%18 = load i32, i32* %2
%19 = load i32, i32* %2
%20 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %18, i32 %19)
%21 = load i32*, i32** %3
%22 = load i32, i32* @SEEK_END
%23 = call i32 @fseek(i32* %21, i32 -3, i32 %22)
%24 = load i32*, i32** %3
%25 = call i32 @fgetc(i32* %24)
store i32 %25, i32* %2
%26 = load i32, i32* %2
%27 = load i32, i32* %2
%28 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i32 %26, i32 %27)
%29 = load i32*, i32** %3
%30 = call i32 @fclose(i32* %29)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"abcd.txt\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@.str.2 = [26 x i8] c"Last character = [%c/%d]\0A\00"
@.str.3 = [36 x i8] c"Second to last character = [%c/%d]\0A\00"
@.str.4 = [35 x i8] c"Third to last character = [%c/%d]\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = load i32, i32* @SEEK_END
%3 = tail call i32 @fseek(i32* %1, i32 -1, i32 %2)
%4 = tail call i32 @fgetc(i32* %1)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %4, i32 %4)
%6 = load i32, i32* @SEEK_END
%7 = tail call i32 @fseek(i32* %1, i32 -2, i32 %6)
%8 = tail call i32 @fgetc(i32* %1)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %8, i32 %8)
%10 = load i32, i32* @SEEK_END
%11 = tail call i32 @fseek(i32* %1, i32 -3, i32 %10)
%12 = tail call i32 @fgetc(i32* %1)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i32 %12, i32 %12)
%14 = tail call i32 @fclose(i32* %1)
ret i32 0
}