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

/* Variables and functions */
int /*<<< orphan*/ _PC_PIPE_BUF;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err_sys(char *, ...);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ getpid();
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int, int);
int pathconf(char *, int /*<<< orphan*/);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int ret = 0, i = 0, j = 0;
  int fd[2] = {0};
  if (pipe(fd) < 0)
    err_sys("pipe");
  printf("parent %lu start\n", getpid());
  int pipe_buf = pathconf(".", _PC_PIPE_BUF);
  printf("PIPE_BUF = %d\n", pipe_buf);
  char *buf = (char *)malloc(pipe_buf * 3);
  for (i = 0; i < 10; ++i) {
    pid_t pid = fork();
    if (pid == 0) {
      close(fd[0]);
      memset(buf, 'a' + i, pipe_buf * 3);
      for (j = 0; j < 10; ++j) {
        ret = write(fd[1], buf, pipe_buf * 3);
        printf("child %ld write %d with %c in turn %d\n", getpid(), ret,
               'a' + i, j);
      }
      sleep(i);
      printf("child %ld exit\n", getpid());
      return 0;
    } else if (pid > 0) {
      printf("start child %lu\n", pid);
    } else
      err_sys("fork");
  }
  close(fd[1]);
  while (1) {
    ret = read(fd[0], buf, pipe_buf * 3);
    if (ret == 0) {
      printf("reach end\n");
      break;
    }
    char tmp = buf[0];
    printf("parent read %d of %c\n", ret, tmp);
    for (j = 0; j < ret; j++) {
      if (buf[j] != tmp)
        err_sys("find different character %c at %d\n", buf[j], j);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x24(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1080 <memset@plt>
lea    -0x24(%rbp),%rdi
call   10a0 <pipe@plt>
cmp    $0x0,%rax
jge    121c <main+0x5c>
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1030 <err_sys@plt>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,%esi
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2dae(%rip),%rax
mov    (%rax),%esi
lea    0xdd4(%rip),%rdi
call   1060 <pathconf@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
imul   $0x3,-0x28(%rbp),%edi
call   10c0 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0xa,-0x18(%rbp)
jge    1370 <main+0x1b0>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    132a <main+0x16a>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%esi
add    $0x61,%esi
imul   $0x3,-0x28(%rbp),%edx
call   1080 <memset@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    12ff <main+0x13f>
mov    -0x20(%rbp),%edi
mov    -0x30(%rbp),%rsi
imul   $0x3,-0x28(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
add    $0x61,%ecx
mov    -0x1c(%rbp),%r8d
lea    0xd3e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12b0 <main+0xf0>
mov    -0x18(%rbp),%edi
call   10d0 <sleep@plt>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,%esi
lea    0xd38(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    142d <main+0x26d>
cmpl   $0x0,-0x34(%rbp)
jle    134a <main+0x18a>
mov    -0x34(%rbp),%esi
lea    0xd21(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1358 <main+0x198>
lea    0xd1f(%rip),%rdi
mov    $0x0,%al
call   1030 <err_sys@plt>
jmp    135d <main+0x19d>
jmp    1362 <main+0x1a2>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1270 <main+0xb0>
mov    -0x20(%rbp),%edi
call   1090 <close@plt>
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%rsi
imul   $0x3,-0x28(%rbp),%edx
call   10b0 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    13a8 <main+0x1e8>
lea    0xcd9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1426 <main+0x266>
mov    -0x30(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x35(%rbp)
mov    -0x14(%rbp),%esi
movsbl -0x35(%rbp),%edx
lea    0xcc1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1421 <main+0x261>
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x35(%rbp),%ecx
cmp    %ecx,%eax
je     140e <main+0x24e>
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
mov    -0x1c(%rbp),%edx
lea    0xc8f(%rip),%rdi
mov    $0x0,%al
call   1030 <err_sys@plt>
jmp    1413 <main+0x253>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    13cd <main+0x20d>
jmp    1378 <main+0x1b8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movq   $0x0,(%rsp)
mov    %rsp,%rdi
call   10b0 <pipe@plt>
test   %rax,%rax
jns    11fe <main+0x2e>
lea    0xe09(%rip),%rdi
xor    %eax,%eax
call   1040 <err_sys@plt>
xor    %r14d,%r14d
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xdf6(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%esi
lea    0xdef(%rip),%rdi
call   1070 <pathconf@plt>
mov    %eax,%ebx
lea    0xde3(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    (%rbx,%rbx,2),%r15d
mov    %r15d,%edi
call   10d0 <malloc@plt>
mov    %rax,%r12
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     1465 <main+0x295>
jle    1271 <main+0xa1>
lea    0xdf9(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    127f <main+0xaf>
lea    0xdf8(%rip),%rdi
xor    %eax,%eax
call   1040 <err_sys@plt>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     129e <main+0xce>
jle    12a9 <main+0xd9>
lea    0xdcc(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    12b7 <main+0xe7>
mov    $0x1,%r14d
jmp    1465 <main+0x295>
lea    0xdc0(%rip),%rdi
xor    %eax,%eax
call   1040 <err_sys@plt>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     12d6 <main+0x106>
jle    12e1 <main+0x111>
lea    0xd94(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    12ef <main+0x11f>
mov    $0x2,%r14d
jmp    1465 <main+0x295>
lea    0xd88(%rip),%rdi
xor    %eax,%eax
call   1040 <err_sys@plt>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     130e <main+0x13e>
jle    1319 <main+0x149>
lea    0xd5c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    1327 <main+0x157>
mov    $0x3,%r14d
jmp    1465 <main+0x295>
lea    0xd50(%rip),%rdi
xor    %eax,%eax
call   1040 <err_sys@plt>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     1346 <main+0x176>
jle    1351 <main+0x181>
lea    0xd24(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    135f <main+0x18f>
mov    $0x4,%r14d
jmp    1465 <main+0x295>
lea    0xd18(%rip),%rdi
xor    %eax,%eax
call   1040 <err_sys@plt>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     137e <main+0x1ae>
jle    1389 <main+0x1b9>
lea    0xcec(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    1397 <main+0x1c7>
mov    $0x5,%r14d
jmp    1465 <main+0x295>
lea    0xce0(%rip),%rdi
xor    %eax,%eax
call   1040 <err_sys@plt>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     13b6 <main+0x1e6>
jle    13c1 <main+0x1f1>
lea    0xcb4(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    13cf <main+0x1ff>
mov    $0x6,%r14d
jmp    1465 <main+0x295>
lea    0xca8(%rip),%rdi
xor    %eax,%eax
call   1040 <err_sys@plt>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     13ee <main+0x21e>
jle    13f6 <main+0x226>
lea    0xc7c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    1404 <main+0x234>
mov    $0x7,%r14d
jmp    1465 <main+0x295>
lea    0xc73(%rip),%rdi
xor    %eax,%eax
call   1040 <err_sys@plt>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     1423 <main+0x253>
jle    142b <main+0x25b>
lea    0xc47(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    1439 <main+0x269>
mov    $0x8,%r14d
jmp    1465 <main+0x295>
lea    0xc3e(%rip),%rdi
xor    %eax,%eax
call   1040 <err_sys@plt>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     145f <main+0x28f>
jle    167e <main+0x4ae>
lea    0xc0e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    168c <main+0x4bc>
mov    $0x9,%r14d
mov    (%rsp),%edi
call   10a0 <close@plt>
lea    0x61(%r14),%ebp
mov    %r12,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
call   1090 <memset@plt>
mov    0x4(%rsp),%edi
mov    %r12,%rsi
mov    %r15d,%edx
call   1050 <write@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xb8b(%rip),%r13
mov    %r13,%rdi
mov    %eax,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
xor    %r8d,%r8d
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x4(%rsp),%edi
mov    %r12,%rsi
mov    %r15d,%edx
call   1050 <write@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getpid@plt>
mov    %r13,%rdi
mov    %eax,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    $0x1,%r8d
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x4(%rsp),%edi
mov    %r12,%rsi
mov    %r15d,%edx
call   1050 <write@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getpid@plt>
mov    %r13,%rdi
mov    %eax,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    $0x2,%r8d
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x4(%rsp),%edi
mov    %r12,%rsi
mov    %r15d,%edx
call   1050 <write@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getpid@plt>
mov    %r13,%rdi
mov    %eax,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    $0x3,%r8d
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x4(%rsp),%edi
mov    %r12,%rsi
mov    %r15d,%edx
call   1050 <write@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getpid@plt>
mov    %r13,%rdi
mov    %eax,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    $0x4,%r8d
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x4(%rsp),%edi
mov    %r12,%rsi
mov    %r15d,%edx
call   1050 <write@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getpid@plt>
mov    %r13,%rdi
mov    %eax,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    $0x5,%r8d
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x4(%rsp),%edi
mov    %r12,%rsi
mov    %r15d,%edx
call   1050 <write@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getpid@plt>
mov    %r13,%rdi
mov    %eax,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    $0x6,%r8d
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x4(%rsp),%edi
mov    %r12,%rsi
mov    %r15d,%edx
call   1050 <write@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getpid@plt>
mov    %r13,%rdi
mov    %eax,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    $0x7,%r8d
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x4(%rsp),%edi
mov    %r12,%rsi
mov    %r15d,%edx
call   1050 <write@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getpid@plt>
mov    %r13,%rdi
mov    %eax,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    $0x8,%r8d
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x4(%rsp),%edi
mov    %r12,%rsi
mov    %r15d,%edx
call   1050 <write@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getpid@plt>
mov    %r13,%rdi
mov    %eax,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    $0x9,%r8d
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r14d,%edi
call   10e0 <sleep@plt>
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0x9eb(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x9eb(%rip),%rdi
xor    %eax,%eax
call   1040 <err_sys@plt>
mov    0x4(%rsp),%edi
call   10a0 <close@plt>
mov    (%rsp),%edi
mov    %r12,%rsi
mov    %r15d,%edx
call   10c0 <read@plt>
test   %eax,%eax
je     1711 <main+0x541>
mov    %eax,%ebx
lea    0x9db(%rip),%rbp
jmp    16c6 <main+0x4f6>
mov    (%rsp),%edi
mov    %r12,%rsi
mov    %r15d,%edx
call   10c0 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
je     1711 <main+0x541>
mov    (%r12),%r13b
movsbl %r13b,%edx
lea    0x9a0(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1080 <printf@plt>
test   %ebx,%ebx
jle    16b2 <main+0x4e2>
mov    %ebx,%r14d
xor    %ebx,%ebx
jmp    16f9 <main+0x529>
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %rbx,%r14
je     16b2 <main+0x4e2>
movsbl (%r12,%rbx,1),%esi
cmp    %r13b,%sil
je     16f0 <main+0x520>
mov    %rbp,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <err_sys@plt>
jmp    16f0 <main+0x520>
lea    0x996(%rip),%rdi
call   1030 <puts@plt>
jmp    166d <main+0x49d>

LLVM IR (-O0):
@.str = [5 x i8] c"pipe\00"
@.str.1 = [18 x i8] c"parent %lu start\0A\00"
@.str.2 = [2 x i8] c".\00"
@_PC_PIPE_BUF = global i32 0
@.str.3 = [15 x i8] c"PIPE_BUF = %d\0A\00"
@.str.4 = [39 x i8] c"child %ld write %d with %c in turn %d\0A\00"
@.str.5 = [16 x i8] c"child %ld exit\0A\00"
@.str.6 = [17 x i8] c"start child %lu\0A\00"
@.str.7 = [5 x i8] c"fork\00"
@.str.8 = [11 x i8] c"reach end\0A\00"
@.str.9 = [22 x i8] c"parent read %d of %c\0A\00"
@.str.10 = [35 x i8] c"find different character %c at %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [2 x i32]
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%14 = bitcast [2 x i32]* %9 to i8*
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%16 = call i64 @pipe(i32* %15)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %2
%21 = call i32 (...) @getpid()
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = load i32, i32* @_PC_PIPE_BUF
%24 = call i32 @pathconf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %23)
store i32 %24, i32* %10
%25 = load i32, i32* %10
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %10
%28 = mul nsw i32 %27, 3
%29 = call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %11
store i32 0, i32* %7
br label %31
31: ; preds = %82, %20
%32 = load i32, i32* %7
%33 = icmp slt i32 %32, 10
br i1 %33, label %34, label %85
34: ; preds = %31
%35 = call i32 (...) @fork()
store i32 %35, i32* %12
%36 = load i32, i32* %12
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %72
38: ; preds = %34
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%40 = load i32, i32* %39
%41 = call i32 @close(i32 %40)
%42 = load i8*, i8** %11
%43 = load i32, i32* %7
%44 = add nsw i32 97, %43
%45 = load i32, i32* %10
%46 = mul nsw i32 %45, 3
%47 = call i32 @memset(i8* %42, i32 %44, i32 %46)
store i32 0, i32* %8
br label %48
48: ; preds = %64, %38
%49 = load i32, i32* %8
%50 = icmp slt i32 %49, 10
br i1 %50, label %51, label %67
51: ; preds = %48
%52 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%53 = load i32, i32* %52
%54 = load i8*, i8** %11
%55 = load i32, i32* %10
%56 = mul nsw i32 %55, 3
%57 = call i32 @write(i32 %53, i8* %54, i32 %56)
store i32 %57, i32* %6
%58 = call i32 (...) @getpid()
%59 = load i32, i32* %6
%60 = load i32, i32* %7
%61 = add nsw i32 97, %60
%62 = load i32, i32* %8
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %58, i32 %59, i32 %61, i32 %62)
br label %64
64: ; preds = %51
%65 = load i32, i32* %8
%66 = add nsw i32 %65, 1
store i32 %66, i32* %8
br label %48
67: ; preds = %48
%68 = load i32, i32* %7
%69 = call i32 @sleep(i32 %68)
%70 = call i32 (...) @getpid()
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %70)
store i32 0, i32* %3
br label %137
72: ; preds = %34
%73 = load i32, i32* %12
%74 = icmp sgt i32 %73, 0
br i1 %74, label %75, label %78
75: ; preds = %72
%76 = load i32, i32* %12
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %76)
br label %80
78: ; preds = %72
%79 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %80
80: ; preds = %78, %75
br label %81
81: ; preds = %80
br label %82
82: ; preds = %81
%83 = load i32, i32* %7
%84 = add nsw i32 %83, 1
store i32 %84, i32* %7
br label %31
85: ; preds = %31
%86 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%87 = load i32, i32* %86
%88 = call i32 @close(i32 %87)
br label %89
89: ; preds = %85, %135
%90 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%91 = load i32, i32* %90
%92 = load i8*, i8** %11
%93 = load i32, i32* %10
%94 = mul nsw i32 %93, 3
%95 = call i32 @read(i32 %91, i8* %92, i32 %94)
store i32 %95, i32* %6
%96 = load i32, i32* %6
%97 = icmp eq i32 %96, 0
br i1 %97, label %98, label %100
98: ; preds = %89
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
br label %136
100: ; preds = %89
%101 = load i8*, i8** %11
%102 = getelementptr inbounds i8, i8* %101, i64 0
%103 = load i8, i8* %102
store i8 %103, i8* %13
%104 = load i32, i32* %6
%105 = load i8, i8* %13
%106 = sext i8 %105 to i32
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i32 %104, i32 %106)
store i32 0, i32* %8
br label %108
108: ; preds = %132, %100
%109 = load i32, i32* %8
%110 = load i32, i32* %6
%111 = icmp slt i32 %109, %110
br i1 %111, label %112, label %135
112: ; preds = %108
%113 = load i8*, i8** %11
%114 = load i32, i32* %8
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds i8, i8* %113, i64 %115
%117 = load i8, i8* %116
%118 = sext i8 %117 to i32
%119 = load i8, i8* %13
%120 = sext i8 %119 to i32
%121 = icmp ne i32 %118, %120
br i1 %121, label %122, label %131
122: ; preds = %112
%123 = load i8*, i8** %11
%124 = load i32, i32* %8
%125 = sext i32 %124 to i64
%126 = getelementptr inbounds i8, i8* %123, i64 %125
%127 = load i8, i8* %126
%128 = sext i8 %127 to i32
%129 = load i32, i32* %8
%130 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.10, i64 0, i64 0), i32 %128, i32 %129)
br label %131
131: ; preds = %122, %112
br label %132
132: ; preds = %131
%133 = load i32, i32* %8
%134 = add nsw i32 %133, 1
store i32 %134, i32* %8
br label %108
135: ; preds = %108
br label %89
136: ; preds = %98
store i32 0, i32* %3
br label %137
137: ; preds = %136, %67
%138 = load i32, i32* %3
ret i32 %138
}

LLVM IR (-O2):
@.str = [5 x i8] c"pipe\00"
@.str.1 = [18 x i8] c"parent %lu start\0A\00"
@.str.2 = [2 x i8] c".\00"
@_PC_PIPE_BUF = global i32 0
@.str.3 = [15 x i8] c"PIPE_BUF = %d\0A\00"
@.str.4 = [39 x i8] c"child %ld write %d with %c in turn %d\0A\00"
@.str.5 = [16 x i8] c"child %ld exit\0A\00"
@.str.6 = [17 x i8] c"start child %lu\0A\00"
@.str.7 = [5 x i8] c"fork\00"
@.str.9 = [22 x i8] c"parent read %d of %c\0A\00"
@.str.10 = [35 x i8] c"find different character %c at %d\0A\00"
@str = [10 x i8] c"reach end\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to [2 x i32]*
%5 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%6 = bitcast i64* %3 to i32*
%7 = call i64 @pipe(i32* %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %2
%12 = call i32 (...) @getpid()
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = load i32, i32* @_PC_PIPE_BUF
%15 = call i32 @pathconf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%17 = mul nsw i32 %15, 3
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8*
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%21 = call i32 (...) @fork()
%22 = icmp eq i32 %21, 0
br i1 %22, label %142, label %23
23: ; preds = %11
%24 = icmp sgt i32 %21, 0
br i1 %24, label %25, label %27
25: ; preds = %23
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %21)
br label %29
27: ; preds = %23
%28 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %29
29: ; preds = %25, %27
%30 = call i32 (...) @fork()
%31 = icmp eq i32 %30, 0
br i1 %31, label %142, label %32
32: ; preds = %29
%33 = icmp sgt i32 %30, 0
br i1 %33, label %36, label %34
34: ; preds = %32
%35 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %38
36: ; preds = %32
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %30)
br label %38
38: ; preds = %36, %34
%39 = call i32 (...) @fork()
%40 = icmp eq i32 %39, 0
br i1 %40, label %142, label %41
41: ; preds = %38
%42 = icmp sgt i32 %39, 0
br i1 %42, label %45, label %43
43: ; preds = %41
%44 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %47
45: ; preds = %41
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %39)
br label %47
47: ; preds = %45, %43
%48 = call i32 (...) @fork()
%49 = icmp eq i32 %48, 0
br i1 %49, label %142, label %50
50: ; preds = %47
%51 = icmp sgt i32 %48, 0
br i1 %51, label %54, label %52
52: ; preds = %50
%53 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %56
54: ; preds = %50
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %48)
br label %56
56: ; preds = %54, %52
%57 = call i32 (...) @fork()
%58 = icmp eq i32 %57, 0
br i1 %58, label %142, label %59
59: ; preds = %56
%60 = icmp sgt i32 %57, 0
br i1 %60, label %63, label %61
61: ; preds = %59
%62 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %65
63: ; preds = %59
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %57)
br label %65
65: ; preds = %63, %61
%66 = call i32 (...) @fork()
%67 = icmp eq i32 %66, 0
br i1 %67, label %142, label %68
68: ; preds = %65
%69 = icmp sgt i32 %66, 0
br i1 %69, label %72, label %70
70: ; preds = %68
%71 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %74
72: ; preds = %68
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %66)
br label %74
74: ; preds = %72, %70
%75 = call i32 (...) @fork()
%76 = icmp eq i32 %75, 0
br i1 %76, label %142, label %77
77: ; preds = %74
%78 = icmp sgt i32 %75, 0
br i1 %78, label %81, label %79
79: ; preds = %77
%80 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %83
81: ; preds = %77
%82 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %75)
br label %83
83: ; preds = %81, %79
%84 = call i32 (...) @fork()
%85 = icmp eq i32 %84, 0
br i1 %85, label %142, label %86
86: ; preds = %83
%87 = icmp sgt i32 %84, 0
br i1 %87, label %90, label %88
88: ; preds = %86
%89 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %92
90: ; preds = %86
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %84)
br label %92
92: ; preds = %90, %88
%93 = call i32 (...) @fork()
%94 = icmp eq i32 %93, 0
br i1 %94, label %142, label %95
95: ; preds = %92
%96 = icmp sgt i32 %93, 0
br i1 %96, label %99, label %97
97: ; preds = %95
%98 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %101
99: ; preds = %95
%100 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %93)
br label %101
101: ; preds = %99, %97
%102 = call i32 (...) @fork()
%103 = icmp eq i32 %102, 0
br i1 %103, label %142, label %104
104: ; preds = %101
%105 = icmp sgt i32 %102, 0
br i1 %105, label %108, label %106
106: ; preds = %104
%107 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %110
108: ; preds = %104
%109 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %102)
br label %110
110: ; preds = %108, %106
%111 = load i32, i32* %20
%112 = call i32 @close(i32 %111)
%113 = load i32, i32* %6
%114 = call i32 @read(i32 %113, i8* %19, i32 %17)
%115 = icmp eq i32 %114, 0
br i1 %115, label %120, label %122
116: ; preds = %139, %122
%117 = load i32, i32* %6
%118 = call i32 @read(i32 %117, i8* %19, i32 %17)
%119 = icmp eq i32 %118, 0
br i1 %119, label %120, label %122
120: ; preds = %116, %110
%121 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %191
122: ; preds = %110, %116
%123 = phi i32 [ %118, %116 ], [ %114, %110 ]
%124 = load i8, i8* %19
%125 = sext i8 %124 to i32
%126 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i32 %123, i32 %125)
%127 = icmp sgt i32 %123, 0
br i1 %127, label %128, label %116
128: ; preds = %122
%129 = zext i32 %123 to i64
br label %130
130: ; preds = %128, %139
%131 = phi i64 [ 0, %128 ], [ %140, %139 ]
%132 = getelementptr inbounds i8, i8* %19, i64 %131
%133 = load i8, i8* %132
%134 = icmp eq i8 %133, %124
br i1 %134, label %139, label %135
135: ; preds = %130
%136 = sext i8 %133 to i32
%137 = trunc i64 %131 to i32
%138 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.10, i64 0, i64 0), i32 %136, i32 %137)
br label %139
139: ; preds = %130, %135
%140 = add nuw nsw i64 %131, 1
%141 = icmp eq i64 %140, %129
br i1 %141, label %116, label %130
142: ; preds = %101, %92, %83, %74, %65, %56, %47, %38, %29, %11
%143 = phi i32 [ 0, %11 ], [ 1, %29 ], [ 2, %38 ], [ 3, %47 ], [ 4, %56 ], [ 5, %65 ], [ 6, %74 ], [ 7, %83 ], [ 8, %92 ], [ 9, %101 ]
%144 = load i32, i32* %6
%145 = call i32 @close(i32 %144)
%146 = add nuw nsw i32 %143, 97
%147 = call i32 @memset(i8* %19, i32 %146, i32 %17)
%148 = load i32, i32* %20
%149 = call i32 @write(i32 %148, i8* %19, i32 %17)
%150 = call i32 (...) @getpid()
%151 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %150, i32 %149, i32 %146, i32 0)
%152 = load i32, i32* %20
%153 = call i32 @write(i32 %152, i8* %19, i32 %17)
%154 = call i32 (...) @getpid()
%155 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %154, i32 %153, i32 %146, i32 1)
%156 = load i32, i32* %20
%157 = call i32 @write(i32 %156, i8* %19, i32 %17)
%158 = call i32 (...) @getpid()
%159 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %158, i32 %157, i32 %146, i32 2)
%160 = load i32, i32* %20
%161 = call i32 @write(i32 %160, i8* %19, i32 %17)
%162 = call i32 (...) @getpid()
%163 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %162, i32 %161, i32 %146, i32 3)
%164 = load i32, i32* %20
%165 = call i32 @write(i32 %164, i8* %19, i32 %17)
%166 = call i32 (...) @getpid()
%167 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %166, i32 %165, i32 %146, i32 4)
%168 = load i32, i32* %20
%169 = call i32 @write(i32 %168, i8* %19, i32 %17)
%170 = call i32 (...) @getpid()
%171 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %170, i32 %169, i32 %146, i32 5)
%172 = load i32, i32* %20
%173 = call i32 @write(i32 %172, i8* %19, i32 %17)
%174 = call i32 (...) @getpid()
%175 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %174, i32 %173, i32 %146, i32 6)
%176 = load i32, i32* %20
%177 = call i32 @write(i32 %176, i8* %19, i32 %17)
%178 = call i32 (...) @getpid()
%179 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %178, i32 %177, i32 %146, i32 7)
%180 = load i32, i32* %20
%181 = call i32 @write(i32 %180, i8* %19, i32 %17)
%182 = call i32 (...) @getpid()
%183 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %182, i32 %181, i32 %146, i32 8)
%184 = load i32, i32* %20
%185 = call i32 @write(i32 %184, i8* %19, i32 %17)
%186 = call i32 (...) @getpid()
%187 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %186, i32 %185, i32 %146, i32 9)
%188 = call i32 @sleep(i32 %143)
%189 = call i32 (...) @getpid()
%190 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %189)
br label %191
191: ; preds = %142, %120
ret i32 0
}