#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*/ O_WRONLY;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
int main(int argc, char *argv[]) {
  char buf[101];
  buf[100] = '\0';
  int fd1 = open("2.9.text", O_RDONLY);
  lseek(fd1, 100, SEEK_END);
  if (read(fd1, buf, 100) == 100) {
    printf(
        "Read it successfully from 100 bytes away of EOF, no error happend.\n");
  } else {
    fprintf(stderr,
            "Boooooooom! You failed to read it from 100 bytes away of EOF.\n");
    perror("2.9.text");
  }
  close(fd1);
  int fd2 = open("2.9.text", O_WRONLY);
  lseek(fd2, 100, SEEK_END);
  if (write(fd2, "hello", 5) == 5) {
    printf("Write it successfully from 100 bytes away of EOF, no error "
           "happend.\n");
  } else {
    fprintf(stderr,
            "Boooooooom! You failed to write it from 100 bytes away of EOF.\n");
    perror("2.9.text");
  }
  close(fd2);
  int fd3 = open("2.9.text", O_WRONLY);
  lseek(fd3, 20000, SEEK_END);
  if (write(fd3, "hello", 5) == 5) {
    printf("Write it successfully from 20000 bytes away of EOF, no error "
           "happend.\n");
  } else {
    fprintf(
        stderr,
        "Boooooooom! You failed to write it from 20000 bytes away of EOF.\n");
    perror("2.9.text");
  }
  close(fd3);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x1c(%rbp)
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
lea    0xe53(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%edi
mov    0x2e23(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1050 <lseek@plt>
mov    -0x84(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
call   1070 <read@plt>
cmp    $0x64,%eax
jne    11ff <main+0x7f>
lea    0xe14(%rip),%rdi
call   1040 <printf@plt>
jmp    1220 <main+0xa0>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xde5(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x84(%rbp),%edi
call   1060 <close@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%esi
lea    0xdc5(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x88(%rbp)
mov    -0x88(%rbp),%edi
mov    0x2d95(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1050 <lseek@plt>
mov    -0x88(%rbp),%edi
lea    0xe20(%rip),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
cmp    $0x5,%eax
jne    1290 <main+0x110>
lea    0xe0c(%rip),%rdi
call   1040 <printf@plt>
jmp    12b1 <main+0x131>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
lea    0xe37(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xd54(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x88(%rbp),%edi
call   1060 <close@plt>
mov    0x2cfd(%rip),%rax
mov    (%rax),%esi
lea    0xd34(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x8c(%rbp)
mov    -0x8c(%rbp),%edi
mov    0x2d04(%rip),%rax
mov    (%rax),%edx
mov    $0x4e20,%esi
call   1050 <lseek@plt>
mov    -0x8c(%rbp),%edi
lea    0xd8f(%rip),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
cmp    $0x5,%eax
jne    1321 <main+0x1a1>
lea    0xe00(%rip),%rdi
call   1040 <printf@plt>
jmp    1342 <main+0x1c2>
mov    0x2ca8(%rip),%rax
mov    (%rax),%edi
lea    0xe2d(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xcc3(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x8c(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x70,%rsp
movb   $0x0,0x64(%rsp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
lea    0xe62(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebx
mov    0x2e3c(%rip),%r14
mov    (%r14),%edx
mov    %eax,%edi
mov    $0x64,%esi
call   1050 <lseek@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x64,%edx
call   1070 <read@plt>
cmp    $0x64,%eax
jne    1293 <main+0x113>
lea    0xf80(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    0x2dd3(%rip),%r15
mov    (%r15),%esi
lea    0xe09(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebx
mov    (%r14),%edx
mov    %eax,%edi
mov    $0x64,%esi
call   1050 <lseek@plt>
lea    0xe34(%rip),%rsi
mov    %ebx,%edi
mov    $0x5,%edx
call   1040 <write@plt>
cmp    $0x5,%eax
jne    12b9 <main+0x139>
lea    0xee6(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    (%r15),%esi
lea    0xdba(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebx
mov    (%r14),%edx
mov    %eax,%edi
mov    $0x4e20,%esi
call   1050 <lseek@plt>
lea    0xde5(%rip),%rsi
mov    %ebx,%edi
mov    $0x5,%edx
call   1040 <write@plt>
cmp    $0x5,%eax
jne    12df <main+0x15f>
lea    0xe55(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
lea    0xd66(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xd51(%rip),%rdi
call   10a0 <perror@plt>
jmp    11df <main+0x5f>
mov    0x2d10(%rip),%rax
mov    (%rax),%edi
lea    0xd85(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xd2b(%rip),%rdi
call   10a0 <perror@plt>
jmp    1235 <main+0xb5>
mov    0x2cea(%rip),%rax
mov    (%rax),%edi
lea    0xd9f(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xd05(%rip),%rdi
call   10a0 <perror@plt>
jmp    1280 <main+0x100>

LLVM IR (-O0):
@.str = [9 x i8] c"2.9.text\00"
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
@.str.1 = [68 x i8] c"Read it successfully from 100 bytes away of EOF, no error happend.\0A\00"
@stderr = global i32 0
@.str.2 = [63 x i8] c"Boooooooom! You failed to read it from 100 bytes away of EOF.\0A\00"
@O_WRONLY = global i32 0
@.str.3 = [6 x i8] c"hello\00"
@.str.4 = [69 x i8] c"Write it successfully from 100 bytes away of EOF, no error happend.\0A\00"
@.str.5 = [64 x i8] c"Boooooooom! You failed to write it from 100 bytes away of EOF.\0A\00"
@.str.6 = [71 x i8] c"Write it successfully from 20000 bytes away of EOF, no error happend.\0A\00"
@.str.7 = [66 x i8] c"Boooooooom! You failed to write it from 20000 bytes away of EOF.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [101 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = getelementptr inbounds [101 x i8], [101 x i8]* %6, i64 0, i64 100
store i8 0, i8* %10
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = load i32, i32* @SEEK_END
%15 = call i32 @lseek(i32 %13, i32 100, i32 %14)
%16 = load i32, i32* %7
%17 = getelementptr inbounds [101 x i8], [101 x i8]* %6, i64 0, i64 0
%18 = call i32 @read(i32 %16, i8* %17, i32 100)
%19 = icmp eq i32 %18, 100
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0))
br label %26
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %22, %20
%27 = load i32, i32* %7
%28 = call i32 @close(i32 %27)
%29 = load i32, i32* @O_WRONLY
%30 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %29)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = load i32, i32* @SEEK_END
%33 = call i32 @lseek(i32 %31, i32 100, i32 %32)
%34 = load i32, i32* %8
%35 = call i32 @write(i32 %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
%36 = icmp eq i32 %35, 5
br i1 %36, label %37, label %39
37: ; preds = %26
%38 = call i32 @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.4, i64 0, i64 0))
br label %43
39: ; preds = %26
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.5, i64 0, i64 0))
%42 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %43
43: ; preds = %39, %37
%44 = load i32, i32* %8
%45 = call i32 @close(i32 %44)
%46 = load i32, i32* @O_WRONLY
%47 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %46)
store i32 %47, i32* %9
%48 = load i32, i32* %9
%49 = load i32, i32* @SEEK_END
%50 = call i32 @lseek(i32 %48, i32 20000, i32 %49)
%51 = load i32, i32* %9
%52 = call i32 @write(i32 %51, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
%53 = icmp eq i32 %52, 5
br i1 %53, label %54, label %56
54: ; preds = %43
%55 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.6, i64 0, i64 0))
br label %60
56: ; preds = %43
%57 = load i32, i32* @stderr
%58 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.7, i64 0, i64 0))
%59 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %60
60: ; preds = %56, %54
%61 = load i32, i32* %9
%62 = call i32 @close(i32 %61)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"2.9.text\00"
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
@stderr = global i32 0
@.str.2 = [63 x i8] c"Boooooooom! You failed to read it from 100 bytes away of EOF.\0A\00"
@O_WRONLY = global i32 0
@.str.3 = [6 x i8] c"hello\00"
@.str.5 = [64 x i8] c"Boooooooom! You failed to write it from 100 bytes away of EOF.\0A\00"
@.str.7 = [66 x i8] c"Boooooooom! You failed to write it from 20000 bytes away of EOF.\0A\00"
@str = [70 x i8] c"Write it successfully from 20000 bytes away of EOF, no error happend.\00"
@str.8 = [68 x i8] c"Write it successfully from 100 bytes away of EOF, no error happend.\00"
@str.9 = [67 x i8] c"Read it successfully from 100 bytes away of EOF, no error happend.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [101 x i8]
%4 = getelementptr inbounds [101 x i8], [101 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds [101 x i8], [101 x i8]* %3, i64 0, i64 100
store i8 0, i8* %5
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load i32, i32* @SEEK_END
%9 = tail call i32 @lseek(i32 %7, i32 100, i32 %8)
%10 = call i32 @read(i32 %7, i8* %4, i32 100)
%11 = icmp eq i32 %10, 100
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str.9, i64 0, i64 0))
br label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0))
%17 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %14, %12
%19 = tail call i32 @close(i32 %7)
%20 = load i32, i32* @O_WRONLY
%21 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = load i32, i32* @SEEK_END
%23 = tail call i32 @lseek(i32 %21, i32 100, i32 %22)
%24 = tail call i32 @write(i32 %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
%25 = icmp eq i32 %24, 5
br i1 %25, label %26, label %28
26: ; preds = %18
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @str.8, i64 0, i64 0))
br label %32
28: ; preds = %18
%29 = load i32, i32* @stderr
%30 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.5, i64 0, i64 0))
%31 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %32
32: ; preds = %28, %26
%33 = tail call i32 @close(i32 %21)
%34 = load i32, i32* @O_WRONLY
%35 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %34)
%36 = load i32, i32* @SEEK_END
%37 = tail call i32 @lseek(i32 %35, i32 20000, i32 %36)
%38 = tail call i32 @write(i32 %35, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
%39 = icmp eq i32 %38, 5
br i1 %39, label %40, label %42
40: ; preds = %32
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str, i64 0, i64 0))
br label %46
42: ; preds = %32
%43 = load i32, i32* @stderr
%44 = tail call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.7, i64 0, i64 0))
%45 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %46
46: ; preds = %42, %40
%47 = tail call i32 @close(i32 %35)
ret i32 0
}