#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_CUR;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int main(int argc, char *argv[]) {
  int fd;
  char buf[100];
  if ((fd = open(argv[1], O_RDONLY)) < 0) {
    perror("open");
    exit(-1);
  }
  read(fd, buf, 1);
  write(STDOUT_FILENO, buf, 1);
  lseek(fd, 2, SEEK_CUR);
  read(fd, buf, 1);
  write(STDOUT_FILENO, buf, 1);
  lseek(fd, -1, SEEK_END);
  read(fd, buf, 1);
  write(STDOUT_FILENO, buf, 1);
  lseek(fd, 0, SEEK_SET);
  read(fd, buf, 1);
  write(STDOUT_FILENO, buf, 1);
  close(fd);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11d1 <main+0x51>
lea    0xe3e(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
mov    0x2dd5(%rip),%rax
mov    (%rax),%edx
mov    $0x2,%esi
call   1050 <lseek@plt>
mov    -0x14(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
mov    0x2d9f(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%esi
call   1050 <lseek@plt>
mov    -0x14(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
mov    0x2d41(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    -0x14(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
lea    0xd46(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    0x8(%rsi),%rdi
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     1284 <main+0x104>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    0x2e32(%rip),%r15
mov    (%r15),%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0x2,%esi
call   1050 <lseek@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    (%r15),%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0xffffffff,%esi
call   1050 <lseek@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    (%r15),%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    0x2d83(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    (%r15),%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xd75(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [5 x i8] c"open\00"
@STDOUT_FILENO = global i32 0
@SEEK_CUR = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [100 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%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)
store i32 %12, i32* %6
%13 = icmp slt i32 %12, 0
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* %6
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%20 = call i32 @read(i32 %18, i8* %19, i32 1)
%21 = load i32, i32* @STDOUT_FILENO
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%23 = call i32 @write(i32 %21, i8* %22, i32 1)
%24 = load i32, i32* %6
%25 = load i32, i32* @SEEK_CUR
%26 = call i32 @lseek(i32 %24, i32 2, i32 %25)
%27 = load i32, i32* %6
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%29 = call i32 @read(i32 %27, i8* %28, i32 1)
%30 = load i32, i32* @STDOUT_FILENO
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%32 = call i32 @write(i32 %30, i8* %31, i32 1)
%33 = load i32, i32* %6
%34 = load i32, i32* @SEEK_END
%35 = call i32 @lseek(i32 %33, i32 -1, i32 %34)
%36 = load i32, i32* %6
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%38 = call i32 @read(i32 %36, i8* %37, i32 1)
%39 = load i32, i32* @STDOUT_FILENO
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%41 = call i32 @write(i32 %39, i8* %40, i32 1)
%42 = load i32, i32* %6
%43 = load i32, i32* @SEEK_SET
%44 = call i32 @lseek(i32 %42, i32 0, i32 %43)
%45 = load i32, i32* %6
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%47 = call i32 @read(i32 %45, i8* %46, i32 1)
%48 = load i32, i32* @STDOUT_FILENO
%49 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%50 = call i32 @write(i32 %48, i8* %49, i32 1)
%51 = load i32, i32* %6
%52 = call i32 @close(i32 %51)
%53 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [5 x i8] c"open\00"
@STDOUT_FILENO = global i32 0
@SEEK_CUR = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 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)
%9 = icmp slt i32 %8, 0
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 = call i32 @read(i32 %8, i8* %4, i32 1)
%15 = load i32, i32* @STDOUT_FILENO
%16 = call i32 @write(i32 %15, i8* %4, i32 1)
%17 = load i32, i32* @SEEK_CUR
%18 = tail call i32 @lseek(i32 %8, i32 2, i32 %17)
%19 = call i32 @read(i32 %8, i8* %4, i32 1)
%20 = load i32, i32* @STDOUT_FILENO
%21 = call i32 @write(i32 %20, i8* %4, i32 1)
%22 = load i32, i32* @SEEK_END
%23 = tail call i32 @lseek(i32 %8, i32 -1, i32 %22)
%24 = call i32 @read(i32 %8, i8* %4, i32 1)
%25 = load i32, i32* @STDOUT_FILENO
%26 = call i32 @write(i32 %25, i8* %4, i32 1)
%27 = load i32, i32* @SEEK_SET
%28 = tail call i32 @lseek(i32 %8, i32 0, i32 %27)
%29 = call i32 @read(i32 %8, i8* %4, i32 1)
%30 = load i32, i32* @STDOUT_FILENO
%31 = call i32 @write(i32 %30, i8* %4, i32 1)
%32 = tail call i32 @close(i32 %8)
%33 = tail call i32 @putchar(i32 10)
ret i32 0
}