#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 scalar_t__ pid_t;
typedef int /*<<< orphan*/ num;

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int S_IRWXG;
int S_IRWXO;
int S_IRWXU;
int /*<<< orphan*/ TELL_CHILD(scalar_t__);
int /*<<< orphan*/ TELL_PARENT(int /*<<< orphan*/);
int /*<<< orphan*/ TELL_WAIT();
int /*<<< orphan*/ WAIT_CHILD();
int /*<<< orphan*/ WAIT_PARENT();
int /*<<< orphan*/ close(int);
int errno;
scalar_t__ fork();
int /*<<< orphan*/ getppid();
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, int *, int);
char *strerror(int);
int /*<<< orphan*/ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int write(int, int *, int);
int main(int argc, char *argv[]) {
  char filename[] = "ipc.txt";
  int num = 0;
  int fd = -1;
  pid_t pid;
  fd = open(filename, O_RDWR | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
  if (fd == -1) {
    printf("open %s failed[%d][%s]\n", filename, errno, strerror(errno));
    return -1;
  }
  if (sizeof(num) != write(fd, &num, sizeof(int))) {
    printf("write error[%d][%s]\n", errno, strerror(errno));
    return -1;
  }
  TELL_WAIT();
  pid = fork();
  if (pid < 0) {
    printf("fork error[%d][%s]\n", errno, strerror(errno));
    return -1;
  } else if (pid == 0) {
    int i = 0;
    while (i++ < 10) {
      WAIT_PARENT();
      lseek(fd, 0, SEEK_SET);
      if (read(fd, &num, sizeof(int)) <= 0) {
        printf("child: read error[%d][%s]\n", errno, strerror(errno));
        return -1;
      }
      num += 1;
      lseek(fd, 0, SEEK_SET);
      if (write(fd, &num, sizeof(int)) <= 0) {
        printf("child:write error[%d][%s]\n", errno, strerror(errno));
        return -1;
      }
      printf("child:write num = %08d success.\n", num);
      TELL_PARENT(getppid());
    }
  } else {
    int i = 0;
    int status;
    while (i++ < 10) {
      lseek(fd, 0, SEEK_SET);
      if (read(fd, &num, sizeof(int)) <= 0) {
        printf("parent:read error[%d][%s]\n", errno, strerror(errno));
        return -1;
      }
      num += 1;
      lseek(fd, 0, SEEK_SET);
      if (write(fd, &num, sizeof(int)) <= 0) {
        printf("parent:write error[%d][%s]\n", errno, strerror(errno));
        return -1;
      }
      printf("parent:write num = %08d success.\n", num);
      TELL_CHILD(pid);
      WAIT_CHILD();
    }
    waitpid(pid, &status, 0);
  }
  if (fd != -1)
    close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xdf3(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
lea    -0x18(%rbp),%rdi
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
mov    0x2dc5(%rip),%rax
or     (%rax),%esi
mov    0x2d9c(%rip),%rax
mov    (%rax),%edx
mov    0x2d83(%rip),%rax
or     (%rax),%edx
mov    0x2d9a(%rip),%rax
or     (%rax),%edx
call   10d0 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    12a8 <main+0xb8>
lea    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2d47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%edx
mov    %rax,%rcx
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15cf <main+0x3df>
mov    -0x20(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
movslq %eax,%rcx
mov    $0x4,%eax
cmp    %rcx,%rax
je     1304 <main+0x114>
mov    0x2ce7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x44(%rbp),%esi
mov    %rax,%rdx
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15cf <main+0x3df>
mov    $0x0,%al
call   1080 <TELL_WAIT@plt>
mov    $0x0,%al
call   1110 <fork@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    135b <main+0x16b>
mov    0x2c90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2c84(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x48(%rbp),%esi
mov    %rax,%rdx
lea    0xcd8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15cf <main+0x3df>
cmpq   $0x0,-0x28(%rbp)
jne    1489 <main+0x299>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x2c(%rbp)
cmp    $0xa,%eax
jge    1484 <main+0x294>
mov    $0x0,%al
call   10f0 <WAIT_PARENT@plt>
mov    -0x20(%rbp),%edi
mov    0x2c1e(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <lseek@plt>
mov    -0x20(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   10b0 <read@plt>
cmp    $0x0,%rax
jg     13f0 <main+0x200>
mov    0x2bfb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2bef(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x4c(%rbp),%esi
mov    %rax,%rdx
lea    0xc57(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15cf <main+0x3df>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
mov    0x2bad(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <lseek@plt>
mov    -0x20(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
cmp    $0x0,%eax
jg     1460 <main+0x270>
mov    0x2b8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    0x2b7f(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x50(%rbp),%esi
mov    %rax,%rdx
lea    0xc02(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15cf <main+0x3df>
mov    -0x1c(%rbp),%esi
lea    0xc00(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   10e0 <getppid@plt>
mov    %eax,%edi
call   1060 <TELL_PARENT@plt>
jmp    136d <main+0x17d>
jmp    15b1 <main+0x3c1>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x30(%rbp)
cmp    $0xa,%eax
jge    15a2 <main+0x3b2>
mov    -0x20(%rbp),%edi
mov    0x2b02(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <lseek@plt>
mov    -0x20(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   10b0 <read@plt>
cmp    $0x0,%rax
jg     150c <main+0x31c>
mov    0x2adf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    0x2ad3(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x54(%rbp),%esi
mov    %rax,%rdx
lea    0xb92(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15cf <main+0x3df>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
mov    0x2a91(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <lseek@plt>
mov    -0x20(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
cmp    $0x0,%eax
jg     157c <main+0x38c>
mov    0x2a6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    0x2a63(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x58(%rbp),%esi
mov    %rax,%rdx
lea    0xb3d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15cf <main+0x3df>
mov    -0x1c(%rbp),%esi
lea    0xb3c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <TELL_CHILD@plt>
mov    $0x0,%al
call   1030 <WAIT_CHILD@plt>
jmp    1490 <main+0x2a0>
mov    -0x28(%rbp),%rdi
lea    -0x34(%rbp),%rsi
xor    %edx,%edx
call   10c0 <waitpid@plt>
jmp    15b6 <main+0x3c6>
cmpl   $0xffffffff,-0x20(%rbp)
je     15c8 <main+0x3d8>
mov    -0x20(%rbp),%edi
call   10a0 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movabs $0x7478742e637069,%rax
mov    %rax,0x8(%rsp)
mov    0x2dbc(%rip),%rax
mov    0x2ddd(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2db2(%rip),%rax
mov    0x2d9b(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
movl   $0x0,0x4(%rsp)
mov    0x2da8(%rip),%rax
or     (%rax),%edx
lea    0x8(%rsp),%rdi
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     1340 <main+0x150>
mov    %eax,%r13d
lea    0x4(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1040 <write@plt>
cmp    $0x4,%eax
jne    136d <main+0x17d>
xor    %eax,%eax
call   1080 <TELL_WAIT@plt>
xor    %eax,%eax
call   1110 <fork@plt>
test   %rax,%rax
js     1389 <main+0x199>
je     13a5 <main+0x1b5>
mov    %rax,%r14
mov    $0xa,%ebx
mov    0x2d12(%rip),%r12
lea    0x4(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r12),%edx
mov    %r13d,%edi
xor    %esi,%esi
call   1090 <lseek@plt>
mov    %r13d,%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   10b0 <read@plt>
test   %rax,%rax
jle    1443 <main+0x253>
mov    0x4(%rsp),%ebp
add    $0x1,%ebp
mov    %ebp,0x4(%rsp)
mov    (%r12),%edx
mov    %r13d,%edi
xor    %esi,%esi
call   1090 <lseek@plt>
mov    %r13d,%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
test   %eax,%eax
jle    145c <main+0x26c>
lea    0xdab(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14,%rdi
call   1050 <TELL_CHILD@plt>
xor    %eax,%eax
call   1030 <WAIT_CHILD@plt>
add    $0xffffffff,%ebx
jne    12b0 <main+0xc0>
lea    0x14(%rsp),%rsi
mov    %r14,%rdi
xor    %edx,%edx
call   10c0 <waitpid@plt>
jmp    1437 <main+0x247>
mov    0x2c71(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1100 <strerror@plt>
lea    0xca9(%rip),%rdi
lea    0x8(%rsp),%rsi
mov    %ebx,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <printf@plt>
jmp    14b1 <main+0x2c1>
mov    0x2c44(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1100 <strerror@plt>
lea    0xcc9(%rip),%rdi
jmp    14a5 <main+0x2b5>
mov    0x2c28(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1100 <strerror@plt>
lea    0xc78(%rip),%rdi
jmp    14a5 <main+0x2b5>
mov    $0xa,%r12d
mov    0x2bfe(%rip),%rbx
lea    0x4(%rsp),%r14
lea    0xca4(%rip),%r15
xchg   %ax,%ax
xor    %eax,%eax
call   10f0 <WAIT_PARENT@plt>
mov    (%rbx),%edx
mov    %r13d,%edi
xor    %esi,%esi
call   1090 <lseek@plt>
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   10b0 <read@plt>
test   %rax,%rax
jle    1475 <main+0x285>
mov    0x4(%rsp),%ebp
add    $0x1,%ebp
mov    %ebp,0x4(%rsp)
mov    (%rbx),%edx
mov    %r13d,%edi
xor    %esi,%esi
call   1090 <lseek@plt>
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
test   %eax,%eax
jle    148e <main+0x29e>
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   10e0 <getppid@plt>
mov    %eax,%edi
call   1060 <TELL_PARENT@plt>
add    $0xffffffff,%r12d
jne    13c0 <main+0x1d0>
mov    %r13d,%edi
call   10a0 <close@plt>
xor    %eax,%eax
jmp    14b6 <main+0x2c6>
mov    0x2b6e(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1100 <strerror@plt>
lea    0xc29(%rip),%rdi
jmp    14a5 <main+0x2b5>
mov    0x2b55(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1100 <strerror@plt>
lea    0xc2b(%rip),%rdi
jmp    14a5 <main+0x2b5>
mov    0x2b3c(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1100 <strerror@plt>
lea    0xba0(%rip),%rdi
jmp    14a5 <main+0x2b5>
mov    0x2b23(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1100 <strerror@plt>
lea    0xba2(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.filename = [8 x i8] c"ipc.txt\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@.str = [24 x i8] c"open %s failed[%d][%s]\0A\00"
@errno = global i32 0
@.str.1 = [21 x i8] c"write error[%d][%s]\0A\00"
@.str.2 = [20 x i8] c"fork error[%d][%s]\0A\00"
@SEEK_SET = global i32 0
@.str.3 = [27 x i8] c"child: read error[%d][%s]\0A\00"
@.str.4 = [27 x i8] c"child:write error[%d][%s]\0A\00"
@.str.5 = [33 x i8] c"child:write num = %08d success.\0A\00"
@.str.6 = [27 x i8] c"parent:read error[%d][%s]\0A\00"
@.str.7 = [28 x i8] c"parent:write error[%d][%s]\0A\00"
@.str.8 = [34 x i8] c"parent:write num = %08d success.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [8 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = bitcast [8 x i8]* %6 to i8*
store i32 0, i32* %7
store i32 -1, i32* %8
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%15 = load i32, i32* @O_RDWR
%16 = load i32, i32* @O_CREAT
%17 = or i32 %15, %16
%18 = load i32, i32* @S_IRWXU
%19 = load i32, i32* @S_IRWXG
%20 = or i32 %18, %19
%21 = load i32, i32* @S_IRWXO
%22 = or i32 %20, %21
%23 = call i32 @open(i8* %14, i32 %17, i32 %22)
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %32
26: ; preds = %2
%27 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%28 = load i32, i32* @errno
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %27, i32 %28, i8* %30)
store i32 -1, i32* %3
br label %141
32: ; preds = %2
%33 = load i32, i32* %8
%34 = call i32 @write(i32 %33, i32* %7, i32 4)
%35 = sext i32 %34 to i64
%36 = icmp ne i64 4, %35
br i1 %36, label %37, label %42
37: ; preds = %32
%38 = load i32, i32* @errno
%39 = load i32, i32* @errno
%40 = call i8* @strerror(i32 %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %38, i8* %40)
store i32 -1, i32* %3
br label %141
42: ; preds = %32
%43 = call i32 (...) @TELL_WAIT()
%44 = call i64 (...) @fork()
store i64 %44, i64* %9
%45 = load i64, i64* %9
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %42
%48 = load i32, i32* @errno
%49 = load i32, i32* @errno
%50 = call i8* @strerror(i32 %49)
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %48, i8* %50)
store i32 -1, i32* %3
br label %141
52: ; preds = %42
%53 = load i64, i64* %9
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %93
55: ; preds = %52
store i32 0, i32* %10
br label %56
56: ; preds = %87, %55
%57 = load i32, i32* %10
%58 = add nsw i32 %57, 1
store i32 %58, i32* %10
%59 = icmp slt i32 %57, 10
br i1 %59, label %60, label %92
60: ; preds = %56
%61 = call i32 (...) @WAIT_PARENT()
%62 = load i32, i32* %8
%63 = load i32, i32* @SEEK_SET
%64 = call i32 @lseek(i32 %62, i32 0, i32 %63)
%65 = load i32, i32* %8
%66 = call i64 @read(i32 %65, i32* %7, i32 4)
%67 = icmp sle i64 %66, 0
br i1 %67, label %68, label %73
68: ; preds = %60
%69 = load i32, i32* @errno
%70 = load i32, i32* @errno
%71 = call i8* @strerror(i32 %70)
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %69, i8* %71)
store i32 -1, i32* %3
br label %141
73: ; preds = %60
%74 = load i32, i32* %7
%75 = add nsw i32 %74, 1
store i32 %75, i32* %7
%76 = load i32, i32* %8
%77 = load i32, i32* @SEEK_SET
%78 = call i32 @lseek(i32 %76, i32 0, i32 %77)
%79 = load i32, i32* %8
%80 = call i32 @write(i32 %79, i32* %7, i32 4)
%81 = icmp sle i32 %80, 0
br i1 %81, label %82, label %87
82: ; preds = %73
%83 = load i32, i32* @errno
%84 = load i32, i32* @errno
%85 = call i8* @strerror(i32 %84)
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %83, i8* %85)
store i32 -1, i32* %3
br label %141
87: ; preds = %73
%88 = load i32, i32* %7
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i32 %88)
%90 = call i32 (...) @getppid()
%91 = call i32 @TELL_PARENT(i32 %90)
br label %56
92: ; preds = %56
br label %133
93: ; preds = %52
store i32 0, i32* %11
br label %94
94: ; preds = %124, %93
%95 = load i32, i32* %11
%96 = add nsw i32 %95, 1
store i32 %96, i32* %11
%97 = icmp slt i32 %95, 10
br i1 %97, label %98, label %130
98: ; preds = %94
%99 = load i32, i32* %8
%100 = load i32, i32* @SEEK_SET
%101 = call i32 @lseek(i32 %99, i32 0, i32 %100)
%102 = load i32, i32* %8
%103 = call i64 @read(i32 %102, i32* %7, i32 4)
%104 = icmp sle i64 %103, 0
br i1 %104, label %105, label %110
105: ; preds = %98
%106 = load i32, i32* @errno
%107 = load i32, i32* @errno
%108 = call i8* @strerror(i32 %107)
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i32 %106, i8* %108)
store i32 -1, i32* %3
br label %141
110: ; preds = %98
%111 = load i32, i32* %7
%112 = add nsw i32 %111, 1
store i32 %112, i32* %7
%113 = load i32, i32* %8
%114 = load i32, i32* @SEEK_SET
%115 = call i32 @lseek(i32 %113, i32 0, i32 %114)
%116 = load i32, i32* %8
%117 = call i32 @write(i32 %116, i32* %7, i32 4)
%118 = icmp sle i32 %117, 0
br i1 %118, label %119, label %124
119: ; preds = %110
%120 = load i32, i32* @errno
%121 = load i32, i32* @errno
%122 = call i8* @strerror(i32 %121)
%123 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i32 %120, i8* %122)
store i32 -1, i32* %3
br label %141
124: ; preds = %110
%125 = load i32, i32* %7
%126 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i32 %125)
%127 = load i64, i64* %9
%128 = call i32 @TELL_CHILD(i64 %127)
%129 = call i32 (...) @WAIT_CHILD()
br label %94
130: ; preds = %94
%131 = load i64, i64* %9
%132 = call i32 @waitpid(i64 %131, i32* %12, i32 0)
br label %133
133: ; preds = %130, %92
br label %134
134: ; preds = %133
%135 = load i32, i32* %8
%136 = icmp ne i32 %135, -1
br i1 %136, label %137, label %140
137: ; preds = %134
%138 = load i32, i32* %8
%139 = call i32 @close(i32 %138)
br label %140
140: ; preds = %137, %134
store i32 0, i32* %3
br label %141
141: ; preds = %140, %119, %105, %82, %68, %47, %37, %26
%142 = load i32, i32* %3
ret i32 %142
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@.str = [24 x i8] c"open %s failed[%d][%s]\0A\00"
@errno = global i32 0
@.str.1 = [21 x i8] c"write error[%d][%s]\0A\00"
@.str.2 = [20 x i8] c"fork error[%d][%s]\0A\00"
@SEEK_SET = global i32 0
@.str.3 = [27 x i8] c"child: read error[%d][%s]\0A\00"
@.str.4 = [27 x i8] c"child:write error[%d][%s]\0A\00"
@.str.5 = [33 x i8] c"child:write num = %08d success.\0A\00"
@.str.6 = [27 x i8] c"parent:read error[%d][%s]\0A\00"
@.str.7 = [28 x i8] c"parent:write error[%d][%s]\0A\00"
@.str.8 = [34 x i8] c"parent:write num = %08d success.\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i64* %3 to i8*
store i64 32783537688244329, i64* %3
%7 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_CREAT
%10 = or i32 %9, %8
%11 = load i32, i32* @S_IRWXU
%12 = load i32, i32* @S_IRWXG
%13 = or i32 %12, %11
%14 = load i32, i32* @S_IRWXO
%15 = or i32 %13, %14
%16 = call i32 @open(i8* %6, i32 %10, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64* %3, i32 %19, i8* %20)
br label %101
22: ; preds = %2
%23 = call i32 @write(i32 %16, i32* %4, i32 4)
%24 = icmp eq i32 %23, 4
br i1 %24, label %29, label %25
25: ; preds = %22
%26 = load i32, i32* @errno
%27 = tail call i8* @strerror(i32 %26)
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %26, i8* %27)
br label %101
29: ; preds = %22
%30 = tail call i32 (...) @TELL_WAIT()
%31 = tail call i64 (...) @fork()
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load i32, i32* @errno
%35 = tail call i8* @strerror(i32 %34)
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %34, i8* %35)
br label %101
37: ; preds = %29
%38 = icmp eq i64 %31, 0
br i1 %38, label %39, label %67
39: ; preds = %37, %61
%40 = phi i32 [ %65, %61 ], [ 1, %37 ]
%41 = tail call i32 (...) @WAIT_PARENT()
%42 = load i32, i32* @SEEK_SET
%43 = tail call i32 @lseek(i32 %16, i32 0, i32 %42)
%44 = call i64 @read(i32 %16, i32* %4, i32 4)
%45 = icmp slt i64 %44, 1
br i1 %45, label %46, label %50
46: ; preds = %39
%47 = load i32, i32* @errno
%48 = tail call i8* @strerror(i32 %47)
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %47, i8* %48)
br label %101
50: ; preds = %39
%51 = load i32, i32* %4
%52 = add nsw i32 %51, 1
store i32 %52, i32* %4
%53 = load i32, i32* @SEEK_SET
%54 = tail call i32 @lseek(i32 %16, i32 0, i32 %53)
%55 = call i32 @write(i32 %16, i32* %4, i32 4)
%56 = icmp slt i32 %55, 1
br i1 %56, label %57, label %61
57: ; preds = %50
%58 = load i32, i32* @errno
%59 = tail call i8* @strerror(i32 %58)
%60 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %58, i8* %59)
br label %101
61: ; preds = %50
%62 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i32 %52)
%63 = tail call i32 (...) @getppid()
%64 = tail call i32 @TELL_PARENT(i32 %63)
%65 = add nuw nsw i32 %40, 1
%66 = icmp eq i32 %65, 11
br i1 %66, label %99, label %39
67: ; preds = %37
%68 = bitcast i32* %5 to i8*
br label %69
69: ; preds = %67, %90
%70 = phi i32 [ 1, %67 ], [ %94, %90 ]
%71 = load i32, i32* @SEEK_SET
%72 = tail call i32 @lseek(i32 %16, i32 0, i32 %71)
%73 = call i64 @read(i32 %16, i32* %4, i32 4)
%74 = icmp slt i64 %73, 1
br i1 %74, label %75, label %79
75: ; preds = %69
%76 = load i32, i32* @errno
%77 = tail call i8* @strerror(i32 %76)
%78 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i32 %76, i8* %77)
br label %96
79: ; preds = %69
%80 = load i32, i32* %4
%81 = add nsw i32 %80, 1
store i32 %81, i32* %4
%82 = load i32, i32* @SEEK_SET
%83 = tail call i32 @lseek(i32 %16, i32 0, i32 %82)
%84 = call i32 @write(i32 %16, i32* %4, i32 4)
%85 = icmp slt i32 %84, 1
br i1 %85, label %86, label %90
86: ; preds = %79
%87 = load i32, i32* @errno
%88 = tail call i8* @strerror(i32 %87)
%89 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i32 %87, i8* %88)
br label %96
90: ; preds = %79
%91 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i32 %81)
%92 = tail call i32 @TELL_CHILD(i64 %31)
%93 = tail call i32 (...) @WAIT_CHILD()
%94 = add nuw nsw i32 %70, 1
%95 = icmp eq i32 %94, 11
br i1 %95, label %97, label %69
96: ; preds = %75, %86
br label %101
97: ; preds = %90
%98 = call i32 @waitpid(i64 %31, i32* %5, i32 0)
br label %99
99: ; preds = %61, %97
%100 = call i32 @close(i32 %16)
br label %101
101: ; preds = %57, %46, %96, %99, %33, %25, %18
%102 = phi i32 [ -1, %18 ], [ -1, %25 ], [ -1, %33 ], [ 0, %99 ], [ -1, %96 ], [ -1, %46 ], [ -1, %57 ]
ret i32 %102
}