#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 */
struct stat {
  int st_size;
};
typedef int /*<<< orphan*/ rbuf;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int O_APPEND;
int O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fstat(int, struct stat *);
int lseek(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pread(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ sleep(int);
size_t strlen(char *);
size_t write(int, char *, size_t);
int main(int argc, char *argv[]) {
  int fd = open(argv[1], O_RDWR | O_APPEND);
  if (fd < 0) {
    perror("fopen");
    exit(EXIT_FAILURE);
  }
  printf("file content: \n");
  char rbuf[1024] = {0};
  while (read(fd, rbuf, sizeof(rbuf)) > 0) {
    write(STDOUT_FILENO, rbuf, strlen(rbuf));
    printf("11111\n");
    sleep(1);
  }
  struct stat fst;
  if (fstat(fd, &fst)) {
    perror("fstat");
    exit(EXIT_FAILURE);
  }
  if (-1 == lseek(fd, fst.st_size / 2, SEEK_SET)) {
    perror("lseek");
    exit(EXIT_FAILURE);
  }
  char wbuf[512] = "12345678";
  if (write(fd, wbuf, strlen(wbuf)) != strlen(wbuf)) {
    perror("write");
    char buf[512];
    if (read(fd, buf, sizeof(buf)) < 0) {
      perror("read");
    } else {
      printf("%s\n", buf);
    }
    exit(EXIT_FAILURE);
  }
  printf("write %s from %d\n", wbuf, fst.st_size / 2);
  memset(rbuf, 0, sizeof(rbuf));
  pread(fd, rbuf, sizeof(rbuf), 0);
  sleep(1);
  printf("22222\n");
  write(STDOUT_FILENO, rbuf, strlen(rbuf));
  size_t ws = write(fd, wbuf, strlen(wbuf));
  printf("write size: %lu\n", ws);
  lseek(fd, 0, SEEK_SET);
  memset(rbuf, 0, sizeof(rbuf));
  size_t rs = read(fd, rbuf, sizeof(rbuf));
  printf("read size: %lu\n", rs);
  printf("read content: %s\n", rbuf);
  close(fd);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x890,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dd8(%rip),%rax
mov    (%rax),%esi
mov    0x2d9f(%rip),%rax
or     (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    123f <main+0x5f>
lea    0xdd4(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1090 <read@plt>
cmp    $0x0,%rax
jle    12d9 <main+0xf9>
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84c(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x848(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x84c(%rbp),%edi
mov    -0x848(%rbp),%rsi
mov    %rax,%rdx
call   1030 <write@plt>
lea    0xd53(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10f0 <sleep@plt>
jmp    1260 <main+0x80>
mov    -0x14(%rbp),%edi
lea    -0x428(%rbp),%rsi
call   1100 <fstat@plt>
cmp    $0x0,%rax
je     130c <main+0x12c>
lea    0xd24(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2cc3(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x428(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    0x2caa(%rip),%rax
mov    (%rax),%edx
call   1060 <lseek@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1356 <main+0x176>
lea    0xce0(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c79(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    -0x630(%rbp),%rdi
lea    0xd1c(%rip),%rsi
mov    $0x200,%edx
call   10a0 <memcpy@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x864(%rbp)
lea    -0x630(%rbp),%rax
mov    %rax,-0x860(%rbp)
lea    -0x630(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x864(%rbp),%edi
mov    -0x860(%rbp),%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,-0x858(%rbp)
lea    -0x630(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x858(%rbp),%rax
cmp    %rcx,%rax
je     142a <main+0x24a>
lea    0xc56(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x14(%rbp),%edi
lea    -0x830(%rbp),%rsi
mov    $0x200,%edx
call   1090 <read@plt>
cmp    $0x0,%rax
jge    1407 <main+0x227>
lea    0xc32(%rip),%rdi
call   10c0 <perror@plt>
jmp    141c <main+0x23c>
lea    -0x830(%rbp),%rsi
lea    0xc67(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2ba5(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    -0x630(%rbp),%rsi
mov    -0x428(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
lea    0xbec(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   10d0 <pread@plt>
mov    $0x1,%edi
call   10f0 <sleep@plt>
lea    0xbbd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2b59(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x884(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x880(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x884(%rbp),%edi
mov    -0x880(%rbp),%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x874(%rbp)
lea    -0x630(%rbp),%rax
mov    %rax,-0x870(%rbp)
lea    -0x630(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x874(%rbp),%edi
mov    -0x870(%rbp),%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,-0x838(%rbp)
mov    -0x838(%rbp),%rsi
lea    0xb32(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
mov    0x2aa4(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1090 <read@plt>
mov    %rax,-0x840(%rbp)
mov    -0x840(%rbp),%rsi
lea    0xaed(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x420(%rbp),%rsi
lea    0xae8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    0x2a24(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    0x8(%rsi),%rdi
mov    0x2dd4(%rip),%rax
mov    0x2d9d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   10c0 <open@plt>
test   %eax,%eax
js     1383 <main+0x193>
mov    %eax,%r12d
lea    0xe34(%rip),%rdi
call   1030 <puts@plt>
lea    0x410(%rsp),%rbx
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   10a0 <read@plt>
test   %rax,%rax
jle    12bf <main+0xcf>
mov    0x2d8a(%rip),%r15
lea    0x410(%rsp),%rbp
lea    0xe02(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15),%ebx
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1040 <write@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1100 <sleep@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
call   10a0 <read@plt>
test   %rax,%rax
jg     1280 <main+0x90>
lea    0x8(%rsp),%rsi
mov    %r12d,%edi
call   1110 <fstat@plt>
test   %rax,%rax
jne    138c <main+0x19c>
mov    0x8(%rsp),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    0x2ce7(%rip),%r13
mov    0x0(%r13),%edx
mov    %r12d,%edi
mov    %ebp,%esi
call   1070 <lseek@plt>
cmp    $0xffffffff,%eax
je     1395 <main+0x1a5>
lea    0xd79(%rip),%rsi
lea    0x210(%rsp),%r14
mov    $0x200,%edx
mov    %r14,%rdi
call   10b0 <memcpy@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %r12d,%edi
mov    %r14,%rsi
mov    %rax,%rdx
call   1040 <write@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
cmp    %rax,%rbx
je     139e <main+0x1ae>
lea    0xcc9(%rip),%rdi
call   10d0 <perror@plt>
lea    0x10(%rsp),%rsi
mov    %r12d,%edi
mov    $0x200,%edx
call   10a0 <read@plt>
test   %rax,%rax
jns    14a2 <main+0x2b2>
lea    0xca8(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c4c(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
lea    0xc76(%rip),%rdi
jmp    1370 <main+0x180>
lea    0xc73(%rip),%rdi
jmp    1370 <main+0x180>
lea    0xc70(%rip),%rdi
jmp    1370 <main+0x180>
lea    0xc78(%rip),%rdi
lea    0x210(%rsp),%r15
mov    %r15,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x410(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   10e0 <pread@plt>
mov    $0x1,%edi
call   1100 <sleep@plt>
lea    0xc7e(%rip),%rdi
call   1030 <puts@plt>
mov    0x2bf1(%rip),%rax
mov    (%rax),%ebx
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %rax,%rdx
call   1040 <write@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %r12d,%edi
mov    %r15,%rsi
mov    %rax,%rdx
call   1040 <write@plt>
lea    0xbfc(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x0(%r13),%edx
mov    %r12d,%edi
xor    %esi,%esi
call   1070 <lseek@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   10a0 <read@plt>
lea    0xbcf(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xbce(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12d,%edi
call   1090 <close@plt>
mov    0x2b25(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
lea    0x10(%rsp),%rdi
call   1030 <puts@plt>
jmp    1375 <main+0x185>

LLVM IR (-O0):
%struct.stat = type { i32 }
@O_RDWR = global i32 0
@O_APPEND = global i32 0
@.str = [6 x i8] c"fopen\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [16 x i8] c"file content: \0A\00"
@STDOUT_FILENO = global i32 0
@.str.2 = [7 x i8] c"11111\0A\00"
@.str.3 = [6 x i8] c"fstat\00"
@SEEK_SET = global i32 0
@.str.4 = [6 x i8] c"lseek\00"
@__const.main.wbuf = [512 x i8] c"12345678\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.5 = [6 x i8] c"write\00"
@.str.6 = [5 x i8] c"read\00"
@.str.7 = [4 x i8] c"%s\0A\00"
@.str.8 = [18 x i8] c"write %s from %d\0A\00"
@.str.9 = [7 x i8] c"22222\0A\00"
@.str.10 = [17 x i8] c"write size: %lu\0A\00"
@.str.11 = [16 x i8] c"read size: %lu\0A\00"
@.str.12 = [18 x i8] c"read content: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca %struct.stat
%9 = alloca [512 x i8]
%10 = alloca [512 x i8]
%11 = alloca i64
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_RDWR
%17 = load i32, i32* @O_APPEND
%18 = or i32 %16, %17
%19 = call i32 @open(i8* %15, i32 %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %2
%23 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %2
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%28 = bitcast [1024 x i8]* %7 to i8*
br label %29
29: ; preds = %34, %26
%30 = load i32, i32* %6
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%32 = call i64 @read(i32 %30, i8* %31, i32 1024)
%33 = icmp sgt i64 %32, 0
br i1 %33, label %34, label %42
34: ; preds = %29
%35 = load i32, i32* @STDOUT_FILENO
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%38 = call i64 @strlen(i8* %37)
%39 = call i64 @write(i32 %35, i8* %36, i64 %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 @sleep(i32 1)
br label %29
42: ; preds = %29
%43 = load i32, i32* %6
%44 = call i64 @fstat(i32 %43, %struct.stat* %8)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %42
%47 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %42
%51 = load i32, i32* %6
%52 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%53 = load i32, i32* %52
%54 = sdiv i32 %53, 2
%55 = load i32, i32* @SEEK_SET
%56 = call i32 @lseek(i32 %51, i32 %54, i32 %55)
%57 = icmp eq i32 -1, %56
br i1 %57, label %58, label %62
58: ; preds = %50
%59 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%60 = load i32, i32* @EXIT_FAILURE
%61 = call i32 @exit(i32 %60)
unreachable
62: ; preds = %50
%63 = bitcast [512 x i8]* %9 to i8*
%64 = load i32, i32* %6
%65 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%66 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%67 = call i64 @strlen(i8* %66)
%68 = call i64 @write(i32 %64, i8* %65, i64 %67)
%69 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%70 = call i64 @strlen(i8* %69)
%71 = icmp ne i64 %68, %70
br i1 %71, label %72, label %86
72: ; preds = %62
%73 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%74 = load i32, i32* %6
%75 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%76 = call i64 @read(i32 %74, i8* %75, i32 512)
%77 = icmp slt i64 %76, 0
br i1 %77, label %78, label %80
78: ; preds = %72
%79 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %83
80: ; preds = %72
%81 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %81)
br label %83
83: ; preds = %80, %78
%84 = load i32, i32* @EXIT_FAILURE
%85 = call i32 @exit(i32 %84)
unreachable
86: ; preds = %62
%87 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%88 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%89 = load i32, i32* %88
%90 = sdiv i32 %89, 2
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0), i8* %87, i32 %90)
%92 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%93 = call i32 @memset(i8* %92, i32 0, i32 1024)
%94 = load i32, i32* %6
%95 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%96 = call i32 @pread(i32 %94, i8* %95, i32 1024, i32 0)
%97 = call i32 @sleep(i32 1)
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%99 = load i32, i32* @STDOUT_FILENO
%100 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%101 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%102 = call i64 @strlen(i8* %101)
%103 = call i64 @write(i32 %99, i8* %100, i64 %102)
%104 = load i32, i32* %6
%105 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%106 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%107 = call i64 @strlen(i8* %106)
%108 = call i64 @write(i32 %104, i8* %105, i64 %107)
store i64 %108, i64* %11
%109 = load i64, i64* %11
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0), i64 %109)
%111 = load i32, i32* %6
%112 = load i32, i32* @SEEK_SET
%113 = call i32 @lseek(i32 %111, i32 0, i32 %112)
%114 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%115 = call i32 @memset(i8* %114, i32 0, i32 1024)
%116 = load i32, i32* %6
%117 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%118 = call i64 @read(i32 %116, i8* %117, i32 1024)
store i64 %118, i64* %12
%119 = load i64, i64* %12
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0), i64 %119)
%121 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0), i8* %121)
%123 = load i32, i32* %6
%124 = call i32 @close(i32 %123)
%125 = load i32, i32* @EXIT_SUCCESS
%126 = call i32 @exit(i32 %125)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@O_RDWR = global i32 0
@O_APPEND = global i32 0
@.str = [6 x i8] c"fopen\00"
@EXIT_FAILURE = global i32 0
@STDOUT_FILENO = global i32 0
@.str.3 = [6 x i8] c"fstat\00"
@SEEK_SET = global i32 0
@.str.4 = [6 x i8] c"lseek\00"
@__const.main.wbuf = [512 x i8] c"12345678\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.5 = [6 x i8] c"write\00"
@.str.6 = [5 x i8] c"read\00"
@.str.8 = [18 x i8] c"write %s from %d\0A\00"
@.str.10 = [17 x i8] c"write size: %lu\0A\00"
@.str.11 = [16 x i8] c"read size: %lu\0A\00"
@.str.12 = [18 x i8] c"read content: %s\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [15 x i8] c"file content: \00"
@str.13 = [6 x i8] c"22222\00"
@str.14 = [6 x i8] c"11111\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca %struct.stat
%5 = alloca [512 x i8]
%6 = alloca [512 x i8]
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = load i32, i32* @O_RDWR
%10 = load i32, i32* @O_APPEND
%11 = or i32 %10, %9
%12 = tail call i32 @open(i8* %8, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%21 = call i64 @read(i32 %12, i8* %20, i32 1024)
%22 = icmp sgt i64 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %18, %23
%24 = load i32, i32* @STDOUT_FILENO
%25 = call i64 @strlen(i8* %20)
%26 = call i64 @write(i32 %24, i8* %20, i64 %25)
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.14, i64 0, i64 0))
%28 = tail call i32 @sleep(i32 1)
%29 = call i64 @read(i32 %12, i8* %20, i32 1024)
%30 = icmp sgt i64 %29, 0
br i1 %30, label %23, label %31
31: ; preds = %23, %18
%32 = bitcast %struct.stat* %4 to i8*
%33 = call i64 @fstat(i32 %12, %struct.stat* %4)
%34 = icmp eq i64 %33, 0
br i1 %34, label %39, label %35
35: ; preds = %31
%36 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
%38 = tail call i32 @exit(i32 %37)
unreachable
39: ; preds = %31
%40 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%41 = load i32, i32* %40
%42 = sdiv i32 %41, 2
%43 = load i32, i32* @SEEK_SET
%44 = tail call i32 @lseek(i32 %12, i32 %42, i32 %43)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %50
46: ; preds = %39
%47 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%48 = load i32, i32* @EXIT_FAILURE
%49 = tail call i32 @exit(i32 %48)
unreachable
50: ; preds = %39
%51 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%52 = call i64 @strlen(i8* %51)
%53 = call i64 @write(i32 %12, i8* %51, i64 %52)
%54 = call i64 @strlen(i8* %51)
%55 = icmp eq i64 %53, %54
br i1 %55, label %68, label %56
56: ; preds = %50
%57 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%58 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%59 = call i64 @read(i32 %12, i8* %58, i32 512)
%60 = icmp slt i64 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %56
%62 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %65
63: ; preds = %56
%64 = call i32 @puts(i8* %58)
br label %65
65: ; preds = %63, %61
%66 = load i32, i32* @EXIT_FAILURE
%67 = tail call i32 @exit(i32 %66)
unreachable
68: ; preds = %50
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0), i8* %51, i32 %42)
%70 = call i32 @memset(i8* %20, i32 0, i32 1024)
%71 = call i32 @pread(i32 %12, i8* %20, i32 1024, i32 0)
%72 = call i32 @sleep(i32 1)
%73 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.13, i64 0, i64 0))
%74 = load i32, i32* @STDOUT_FILENO
%75 = call i64 @strlen(i8* %20)
%76 = call i64 @write(i32 %74, i8* %20, i64 %75)
%77 = call i64 @strlen(i8* %51)
%78 = call i64 @write(i32 %12, i8* %51, i64 %77)
%79 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0), i64 %78)
%80 = load i32, i32* @SEEK_SET
%81 = call i32 @lseek(i32 %12, i32 0, i32 %80)
%82 = call i32 @memset(i8* %20, i32 0, i32 1024)
%83 = call i64 @read(i32 %12, i8* %20, i32 1024)
%84 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0), i64 %83)
%85 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0), i8* %20)
%86 = call i32 @close(i32 %12)
%87 = load i32, i32* @EXIT_SUCCESS
%88 = call i32 @exit(i32 %87)
unreachable
}