#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*/ ssize_t;
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void main() {
  int i, infd = open("/etc/passwd", O_RDONLY);
  int fp = lseek(infd, 0, SEEK_END);
  char buf;
  lseek(infd, 0, SEEK_SET);
  for (i = fp - 1; i >= 0; i--) {
    lseek(infd, (off_t)i, SEEK_SET);
    ssize_t fileread = read(infd, &buf, 1);
    write(1, &buf, fileread);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e7e(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e50(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     11e3 <main+0xa3>
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
mov    -0x8(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edx
mov    $0x1,%edi
lea    -0xd(%rbp),%rsi
call   1030 <write@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    1192 <main+0x52>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
lea    0xea9(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebp
mov    0x2e83(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %eax,%ebx
mov    0x2e57(%rip),%r15
mov    (%r15),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
test   %ebx,%ebx
jle    11d3 <main+0x93>
add    $0x1,%ebx
lea    0x7(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    -0x2(%rbx),%esi
mov    (%r15),%edx
mov    %ebp,%edi
call   1040 <lseek@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     11a0 <main+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/etc/passwd\00"
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = load i32, i32* @SEEK_END
%10 = call i32 @lseek(i32 %8, i32 0, i32 %9)
store i32 %10, i32* %3
%11 = load i32, i32* %2
%12 = load i32, i32* @SEEK_SET
%13 = call i32 @lseek(i32 %11, i32 0, i32 %12)
%14 = load i32, i32* %3
%15 = sub nsw i32 %14, 1
store i32 %15, i32* %1
br label %16
16: ; preds = %28, %0
%17 = load i32, i32* %1
%18 = icmp sge i32 %17, 0
br i1 %18, label %19, label %31
19: ; preds = %16
%20 = load i32, i32* %2
%21 = load i32, i32* %1
%22 = load i32, i32* @SEEK_SET
%23 = call i32 @lseek(i32 %20, i32 %21, i32 %22)
%24 = load i32, i32* %2
%25 = call i32 @read(i32 %24, i8* %4, i32 1)
store i32 %25, i32* %5
%26 = load i32, i32* %5
%27 = call i32 @write(i32 1, i8* %4, i32 %26)
br label %28
28: ; preds = %19
%29 = load i32, i32* %1
%30 = add nsw i32 %29, -1
store i32 %30, i32* %1
br label %16
31: ; preds = %16
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"/etc/passwd\00"
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define void @main() {
%1 = alloca i8
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = load i32, i32* @SEEK_END
%5 = tail call i32 @lseek(i32 %3, i32 0, i32 %4)
%6 = load i32, i32* @SEEK_SET
%7 = tail call i32 @lseek(i32 %3, i32 0, i32 %6)
%8 = icmp sgt i32 %5, 0
br i1 %8, label %9, label %17
9: ; preds = %0, %9
%10 = phi i32 [ %11, %9 ], [ %5, %0 ]
%11 = add nsw i32 %10, -1
%12 = load i32, i32* @SEEK_SET
%13 = tail call i32 @lseek(i32 %3, i32 %11, i32 %12)
%14 = call i32 @read(i32 %3, i8* %1, i32 1)
%15 = call i32 @write(i32 1, i8* %1, i32 %14)
%16 = icmp ugt i32 %10, 1
br i1 %16, label %9, label %17
17: ; preds = %9, %0
ret void
}