#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ exit(int);
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int read(int, char *, int);
int main(int argc, char **argv) {
  if (argc < 1) {
    printf("USAGE: %s <fichier>\n", argv[0]);
    exit(1);
  }
  int fd = open(argv[1], O_RDONLY);
  int taille = lseek(fd, 0, SEEK_END);
  printf("Taille fichier: %i\n", taille);
  int i, nbLu;
  char c = 0;
  for (i = 0; i < taille; i++) {
    lseek(fd, -i, SEEK_END);
    nbLu = read(fd, &c, 1);
    putchar(c);
  }
  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)
cmpl   $0x1,-0x8(%rbp)
jge    119f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e26(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movb   $0x0,-0x21(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1237 <main+0xd7>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
sub    -0x1c(%rbp),%esi
mov    0x2de3(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
mov    -0x14(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %eax,-0x20(%rbp)
movsbl -0x21(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ea <main+0x8a>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %edi,%edi
jle    120d <main+0xad>
mov    0x8(%rsi),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,%ebx
mov    0x2e59(%rip),%r12
mov    (%r12),%edx
xor    %ebp,%ebp
mov    %eax,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,%r14d
lea    0xe6d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movb   $0x0,0xf(%rsp)
test   %r14d,%r14d
jle    11fe <main+0x9e>
neg    %r14d
lea    0xf(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r12),%edx
mov    %ebx,%edi
mov    %ebp,%esi
call   1050 <lseek@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
movsbl 0xf(%rsp),%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
cmp    %ebp,%r14d
jne    11d0 <main+0x70>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rsi),%rsi
lea    0xde9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"USAGE: %s <fichier>\0A\00"
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
@.str.1 = [20 x i8] c"Taille fichier: %i\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = load i32, i32* @SEEK_END
%27 = call i32 @lseek(i32 %25, i32 0, i32 %26)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %28)
store i8 0, i8* %10
store i32 0, i32* %8
br label %30
30: ; preds = %44, %19
%31 = load i32, i32* %8
%32 = load i32, i32* %7
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %47
34: ; preds = %30
%35 = load i32, i32* %6
%36 = load i32, i32* %8
%37 = sub nsw i32 0, %36
%38 = load i32, i32* @SEEK_END
%39 = call i32 @lseek(i32 %35, i32 %37, i32 %38)
%40 = load i32, i32* %6
%41 = call i32 @read(i32 %40, i8* %10, i32 1)
store i32 %41, i32* %9
%42 = load i8, i8* %10
%43 = call i32 @putchar(i8 signext %42)
br label %44
44: ; preds = %34
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
br label %30
47: ; preds = %30
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"USAGE: %s <fichier>\0A\00"
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
@.str.1 = [20 x i8] c"Taille fichier: %i\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = icmp slt i32 %0, 1
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 @open(i8* %11, i32 %12)
%14 = load i32, i32* @SEEK_END
%15 = tail call i32 @lseek(i32 %13, i32 0, i32 %14)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %15)
store i8 0, i8* %3
%17 = icmp sgt i32 %15, 0
br i1 %17, label %18, label %28
18: ; preds = %9, %18
%19 = phi i32 [ %26, %18 ], [ 0, %9 ]
%20 = sub nsw i32 0, %19
%21 = load i32, i32* @SEEK_END
%22 = tail call i32 @lseek(i32 %13, i32 %20, i32 %21)
%23 = call i32 @read(i32 %13, i8* %3, i32 1)
%24 = load i8, i8* %3
%25 = tail call i32 @putchar(i8 signext %24)
%26 = add nuw nsw i32 %19, 1
%27 = icmp eq i32 %26, %15
br i1 %27, label %28, label %18
28: ; preds = %18, %9
ret i32 0
}