#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*/ close(int);
int /*<<< orphan*/ exit(int);
int lseek(int, long, int);
int open(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int write(int, char *, int);
main(int argc, char *argv[]) {
  int fd, l;
  char buf[80];
  if ((fd = open(argv[1], O_RDONLY, 0666)) == -1) {
    perror("open");
    exit(1);
  };
  ;
  if (lseek(fd, -10L, 2) == -1) {
    perror("lseek");
    exit(1);
  };
  ;
  if ((l = read(fd, buf, 10)) != 10) {
    perror("read");
    exit(1);
  };
  ;
  if (write(1, buf, l) != l) {
    perror("write");
    exit(1);
  };
  ;
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
mov    $0x1b6,%edx
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11bc <main+0x4c>
lea    0xe53(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0xfffffffffffffff6,%rsi
mov    $0x2,%edx
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
jne    11ef <main+0x7f>
lea    0xe25(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0xa,%edx
call   1060 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xa,%eax
je     1222 <main+0xb2>
lea    0xdf8(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x70(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
cmp    -0x18(%rbp),%eax
je     1252 <main+0xe2>
lea    0xdcd(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x50,%rsp
mov    0x8(%rsi),%rdi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
mov    $0x1b6,%edx
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11e5 <main+0x75>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0xfffffffffffffff6,%rsi
mov    $0x2,%edx
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
je     11ee <main+0x7e>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xa,%edx
call   1060 <read@plt>
cmp    $0xa,%eax
jne    11f7 <main+0x87>
mov    %rsp,%rsi
mov    $0x1,%edi
mov    $0xa,%edx
call   1030 <write@plt>
cmp    $0xa,%eax
jne    1200 <main+0x90>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
ret
lea    0xe14(%rip),%rdi
jmp    1207 <main+0x97>
lea    0xe10(%rip),%rdi
jmp    1207 <main+0x97>
lea    0xe0d(%rip),%rdi
jmp    1207 <main+0x97>
lea    0xe09(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [5 x i8] c"open\00"
@.str.1 = [6 x i8] c"lseek\00"
@.str.2 = [5 x i8] c"read\00"
@.str.3 = [6 x i8] c"write\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca [80 x i8]
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = load i8**, i8*** %4
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* %10, i32 %11, i32 438)
store i32 %12, i32* %5
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i32, i32* %5
%19 = call i32 @lseek(i32 %18, i64 -10, i32 2)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %17
%25 = load i32, i32* %5
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%27 = call i32 @read(i32 %25, i8* %26, i32 10)
store i32 %27, i32* %6
%28 = icmp ne i32 %27, 10
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %24
%33 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%34 = load i32, i32* %6
%35 = call i32 @write(i32 1, i8* %33, i32 %34)
%36 = load i32, i32* %6
%37 = icmp ne i32 %35, %36
br i1 %37, label %38, label %41
38: ; preds = %32
%39 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %32
%42 = load i32, i32* %5
%43 = call i32 @close(i32 %42)
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [5 x i8] c"open\00"
@.str.1 = [6 x i8] c"lseek\00"
@.str.2 = [5 x i8] c"read\00"
@.str.3 = [6 x i8] c"write\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* %6, i32 %7, i32 438)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = tail call i32 @lseek(i32 %8, i64 -10, i32 2)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %13
%20 = call i32 @read(i32 %8, i8* %4, i32 10)
%21 = icmp eq i32 %20, 10
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %19
%26 = call i32 @write(i32 1, i8* %4, i32 10)
%27 = icmp eq i32 %26, 10
br i1 %27, label %31, label %28
28: ; preds = %25
%29 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %25
%32 = tail call i32 @close(i32 %8)
ret i32 0
}