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

/* Variables and functions */
int TEMP_FAILURE_RETRY(int /*<<< orphan*/);
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ close(int);
int getpid();
int pipe(int *);
int /*<<< orphan*/ printf(char *, long, long);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ read(int, int *, int);
int vfork();
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, int *, int);
int do_test(void) {
  int result = 0;
  int fd[2];
  if (pipe(fd) == -1) {
    puts("pipe failed");
    return 1;
  }
  pid_t p1;
  if ((p1 = vfork()) == 0) {
    pid_t p = getpid();
    _exit(TEMP_FAILURE_RETRY(write(fd[1], &p, sizeof(p))) != sizeof(p));
  } else if (p1 == -1) {
    puts("1st vfork failed");
    result = 1;
  }
  pid_t p2 = 0;
  if (TEMP_FAILURE_RETRY(read(fd[0], &p2, sizeof(pid_t))) != sizeof(pid_t)) {
    puts("1st read failed");
    result = 1;
  }
  int r;
  if (TEMP_FAILURE_RETRY(waitpid(p1, &r, 0)) != p1) {
    puts("1st waitpid failed");
    result = 1;
  } else if (r != 0) {
    puts("write in 1st child failed");
    result = 1;
  }
  pid_t p0 = getpid();
  pid_t p3;
  if ((p3 = vfork()) == 0) {
    pid_t p = getpid();
    _exit(TEMP_FAILURE_RETRY(write(fd[1], &p, sizeof(p))) != sizeof(p));
  } else if (p1 == -1) {
    puts("2nd vfork failed");
    result = 1;
  }
  pid_t p4;
  if (TEMP_FAILURE_RETRY(read(fd[0], &p4, sizeof(pid_t))) != sizeof(pid_t)) {
    puts("2nd read failed");
    result = 1;
  }
  if (TEMP_FAILURE_RETRY(waitpid(p3, &r, 0)) != p3) {
    puts("2nd waitpid failed");
    result = 1;
  } else if (r != 0) {
    puts("write in 2nd child failed");
    result = 1;
  }
  pid_t p5 = getpid();
  if (p0 != p5) {
    printf("p0(%ld) != p5(%ld)\n", (long int)p0, (long int)p5);
    result = 1;
  }
  if (p0 == p1) {
    printf("p0(%ld) == p1(%ld)\n", (long int)p0, (long int)p1);
    result = 1;
  }
  if (p1 != p2) {
    printf("p1(%ld) != p2(%ld)\n", (long int)p1, (long int)p2);
    result = 1;
  }
  if (p0 == p3) {
    printf("p0(%ld) == p3(%ld)\n", (long int)p0, (long int)p3);
    result = 1;
  }
  if (p3 != p4) {
    printf("p3(%ld) != p4(%ld)\n", (long int)p3, (long int)p4);
    result = 1;
  }
  close(fd[0]);
  close(fd[1]);
  if (result == 0)
    puts("All OK");
  return result;
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
call   1090 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11e9 <do_test+0x39>
lea    0xe28(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    14e1 <do_test+0x331>
call   10c0 <vfork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    122f <do_test+0x7f>
mov    $0x0,%al
call   1060 <getpid@plt>
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1050 <write@plt>
mov    %eax,%edi
call   10d0 <TEMP_FAILURE_RETRY@plt>
cltq
cmp    $0x4,%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <_exit@plt>
cmpl   $0xffffffff,-0x14(%rbp)
jne    124c <do_test+0x9c>
lea    0xdcc(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x8(%rbp)
jmp    1251 <do_test+0xa1>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   10a0 <read@plt>
mov    %eax,%edi
call   10d0 <TEMP_FAILURE_RETRY@plt>
cltq
cmp    $0x4,%rax
je     128f <do_test+0xdf>
lea    0xd9a(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   10b0 <waitpid@plt>
mov    %eax,%edi
call   10d0 <TEMP_FAILURE_RETRY@plt>
cmp    -0x14(%rbp),%eax
je     12c5 <do_test+0x115>
lea    0xd79(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x8(%rbp)
jmp    12e7 <do_test+0x137>
cmpl   $0x0,-0x20(%rbp)
je     12e2 <do_test+0x132>
lea    0xd6a(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x8(%rbp)
jmp    12e7 <do_test+0x137>
mov    $0x0,%al
call   1060 <getpid@plt>
mov    %eax,-0x24(%rbp)
call   10c0 <vfork@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jne    1337 <do_test+0x187>
mov    $0x0,%al
call   1060 <getpid@plt>
mov    %eax,-0x2c(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x2c(%rbp),%rsi
mov    $0x4,%edx
call   1050 <write@plt>
mov    %eax,%edi
call   10d0 <TEMP_FAILURE_RETRY@plt>
cltq
cmp    $0x4,%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <_exit@plt>
cmpl   $0xffffffff,-0x14(%rbp)
jne    1354 <do_test+0x1a4>
lea    0xd12(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x8(%rbp)
jmp    1359 <do_test+0x1a9>
mov    -0x10(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x4,%edx
call   10a0 <read@plt>
mov    %eax,%edi
call   10d0 <TEMP_FAILURE_RETRY@plt>
cltq
cmp    $0x4,%rax
je     1390 <do_test+0x1e0>
lea    0xce7(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   10b0 <waitpid@plt>
mov    %eax,%edi
call   10d0 <TEMP_FAILURE_RETRY@plt>
cmp    -0x28(%rbp),%eax
je     13c6 <do_test+0x216>
lea    0xcc6(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x8(%rbp)
jmp    13e8 <do_test+0x238>
cmpl   $0x0,-0x20(%rbp)
je     13e3 <do_test+0x233>
lea    0xcb7(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x8(%rbp)
jmp    13e8 <do_test+0x238>
mov    $0x0,%al
call   1060 <getpid@plt>
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x34(%rbp),%eax
je     1419 <do_test+0x269>
movslq -0x24(%rbp),%rsi
movslq -0x34(%rbp),%rdx
lea    0xc9b(%rip),%rdi
call   1070 <printf@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1440 <do_test+0x290>
movslq -0x24(%rbp),%rsi
movslq -0x14(%rbp),%rdx
lea    0xc88(%rip),%rdi
call   1070 <printf@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     1467 <do_test+0x2b7>
movslq -0x14(%rbp),%rsi
movslq -0x1c(%rbp),%rdx
lea    0xc75(%rip),%rdi
call   1070 <printf@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jne    148e <do_test+0x2de>
movslq -0x24(%rbp),%rsi
movslq -0x28(%rbp),%rdx
lea    0xc62(%rip),%rdi
call   1070 <printf@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x30(%rbp),%eax
je     14b5 <do_test+0x305>
movslq -0x28(%rbp),%rsi
movslq -0x30(%rbp),%rdx
lea    0xc4f(%rip),%rdi
call   1070 <printf@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x10(%rbp),%edi
call   1080 <close@plt>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
cmpl   $0x0,-0x8(%rbp)
jne    14db <do_test+0x32b>
lea    0xc36(%rip),%rdi
call   1040 <puts@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
lea    0x18(%rsp),%rdi
call   1090 <pipe@plt>
cmp    $0xffffffff,%eax
je     125d <do_test+0xad>
call   10c0 <vfork@plt>
test   %eax,%eax
je     13f9 <do_test+0x249>
mov    %eax,%ebx
xor    %eax,%eax
cmp    $0xffffffff,%ebx
jne    11f6 <do_test+0x46>
lea    0xe20(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
mov    %eax,%ebp
mov    %ebx,%r14d
movl   $0x0,0xc(%rsp)
mov    0x18(%rsp),%edi
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
call   10a0 <read@plt>
mov    %eax,%edi
call   10d0 <TEMP_FAILURE_RETRY@plt>
cmp    $0x4,%eax
je     1233 <do_test+0x83>
lea    0xdf4(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
lea    0x14(%rsp),%rsi
xor    %edx,%edx
mov    %r14d,%edi
call   10b0 <waitpid@plt>
mov    %eax,%edi
call   10d0 <TEMP_FAILURE_RETRY@plt>
cmp    %ebx,%eax
jne    1273 <do_test+0xc3>
cmpl   $0x0,0x14(%rsp)
je     1284 <do_test+0xd4>
lea    0xde5(%rip),%rdi
jmp    127a <do_test+0xca>
lea    0xd9c(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    13ec <do_test+0x23c>
lea    0xdb3(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
xor    %eax,%eax
call   1060 <getpid@plt>
mov    %eax,%r14d
call   10c0 <vfork@plt>
test   %eax,%eax
je     140f <do_test+0x25f>
mov    %eax,%r15d
cmp    $0xffffffff,%ebx
jne    12b4 <do_test+0x104>
lea    0xdb0(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
mov    %ebp,%r12d
mov    %r15d,%ebp
mov    0x18(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x4,%edx
call   10a0 <read@plt>
mov    %eax,%edi
call   10d0 <TEMP_FAILURE_RETRY@plt>
cmp    $0x4,%eax
je     12eb <do_test+0x13b>
lea    0xd8b(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r12d
lea    0x14(%rsp),%rsi
xor    %edx,%edx
mov    %ebp,%edi
call   10b0 <waitpid@plt>
mov    %eax,%edi
call   10d0 <TEMP_FAILURE_RETRY@plt>
cmp    %r15d,%eax
jne    1315 <do_test+0x165>
cmpl   $0x0,0x14(%rsp)
je     1327 <do_test+0x177>
lea    0xd7b(%rip),%rdi
jmp    131c <do_test+0x16c>
lea    0xd5f(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r12d
xor    %eax,%eax
call   1060 <getpid@plt>
mov    %r12d,%ecx
cmp    %eax,%r14d
je     134d <do_test+0x19d>
movslq %r14d,%rsi
movslq %eax,%rdx
lea    0xd65(%rip),%rdi
call   1070 <printf@plt>
mov    $0x1,%ecx
mov    %ecx,%eax
cmp    %ebx,%r14d
jne    136b <do_test+0x1bb>
movslq %ebx,%rdx
lea    0xd5e(%rip),%rdi
mov    %rdx,%rsi
call   1070 <printf@plt>
mov    $0x1,%eax
movslq 0xc(%rsp),%rdx
mov    %edx,%ecx
cmp    %edx,%ebx
je     138a <do_test+0x1da>
movslq %ebx,%rsi
lea    0xd50(%rip),%rdi
call   1070 <printf@plt>
mov    $0x1,%eax
cmp    %r15d,%r14d
jne    13a6 <do_test+0x1f6>
movslq %r14d,%rdx
lea    0xd4b(%rip),%rdi
mov    %rdx,%rsi
call   1070 <printf@plt>
mov    $0x1,%eax
movslq 0x10(%rsp),%rdx
mov    %edx,%ecx
mov    %eax,%ebx
cmp    %edx,%r15d
je     13c8 <do_test+0x218>
movslq %r15d,%rsi
lea    0xd3a(%rip),%rdi
call   1070 <printf@plt>
mov    $0x1,%ebx
mov    0x18(%rsp),%edi
call   1080 <close@plt>
mov    0x1c(%rsp),%edi
call   1080 <close@plt>
test   %ebx,%ebx
jne    13ea <do_test+0x23a>
lea    0xd27(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1060 <getpid@plt>
mov    %eax,0xc(%rsp)
mov    0x1c(%rsp),%edi
lea    0xc(%rsp),%rsi
jmp    1423 <do_test+0x273>
xor    %eax,%eax
call   1060 <getpid@plt>
mov    %eax,0x10(%rsp)
mov    0x1c(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x4,%edx
call   1050 <write@plt>
mov    %eax,%edi
call   10d0 <TEMP_FAILURE_RETRY@plt>
xor    %edi,%edi
cmp    $0x4,%eax
setne  %al
mov    %al,%dil
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"pipe failed\00"
@.str.1 = [17 x i8] c"1st vfork failed\00"
@.str.2 = [16 x i8] c"1st read failed\00"
@.str.3 = [19 x i8] c"1st waitpid failed\00"
@.str.4 = [26 x i8] c"write in 1st child failed\00"
@.str.5 = [17 x i8] c"2nd vfork failed\00"
@.str.6 = [16 x i8] c"2nd read failed\00"
@.str.7 = [19 x i8] c"2nd waitpid failed\00"
@.str.8 = [26 x i8] c"write in 2nd child failed\00"
@.str.9 = [20 x i8] c"p0(%ld) != p5(%ld)\0A\00"
@.str.10 = [20 x i8] c"p0(%ld) == p1(%ld)\0A\00"
@.str.11 = [20 x i8] c"p1(%ld) != p2(%ld)\0A\00"
@.str.12 = [20 x i8] c"p0(%ld) == p3(%ld)\0A\00"
@.str.13 = [20 x i8] c"p3(%ld) != p4(%ld)\0A\00"
@.str.14 = [7 x i8] c"All OK\00"
define i32 @do_test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [2 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %2
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%14 = call i32 @pipe(i32* %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %167
18: ; preds = %0
%19 = call i32 @vfork()
store i32 %19, i32* %4
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = call i32 (...) @getpid()
store i32 %22, i32* %5
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%24 = load i32, i32* %23
%25 = call i32 @write(i32 %24, i32* %5, i32 4)
%26 = call i32 @TEMP_FAILURE_RETRY(i32 %25)
%27 = sext i32 %26 to i64
%28 = icmp ne i64 %27, 4
%29 = zext i1 %28 to i32
%30 = call i32 @_exit(i32 %29)
unreachable
31: ; preds = %18
%32 = load i32, i32* %4
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
br label %36
36: ; preds = %34, %31
br label %37
37: ; preds = %36
store i32 0, i32* %6
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%39 = load i32, i32* %38
%40 = call i32 @read(i32 %39, i32* %6, i32 4)
%41 = call i32 @TEMP_FAILURE_RETRY(i32 %40)
%42 = sext i32 %41 to i64
%43 = icmp ne i64 %42, 4
br i1 %43, label %44, label %46
44: ; preds = %37
%45 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %2
br label %46
46: ; preds = %44, %37
%47 = load i32, i32* %4
%48 = call i32 @waitpid(i32 %47, i32* %7, i32 0)
%49 = call i32 @TEMP_FAILURE_RETRY(i32 %48)
%50 = load i32, i32* %4
%51 = icmp ne i32 %49, %50
br i1 %51, label %52, label %54
52: ; preds = %46
%53 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %2
br label %60
54: ; preds = %46
%55 = load i32, i32* %7
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %54
%58 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %2
br label %59
59: ; preds = %57, %54
br label %60
60: ; preds = %59, %52
%61 = call i32 (...) @getpid()
store i32 %61, i32* %8
%62 = call i32 @vfork()
store i32 %62, i32* %9
%63 = icmp eq i32 %62, 0
br i1 %63, label %64, label %74
64: ; preds = %60
%65 = call i32 (...) @getpid()
store i32 %65, i32* %10
%66 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%67 = load i32, i32* %66
%68 = call i32 @write(i32 %67, i32* %10, i32 4)
%69 = call i32 @TEMP_FAILURE_RETRY(i32 %68)
%70 = sext i32 %69 to i64
%71 = icmp ne i64 %70, 4
%72 = zext i1 %71 to i32
%73 = call i32 @_exit(i32 %72)
unreachable
74: ; preds = %60
%75 = load i32, i32* %4
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %79
77: ; preds = %74
%78 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %2
br label %79
79: ; preds = %77, %74
br label %80
80: ; preds = %79
%81 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%82 = load i32, i32* %81
%83 = call i32 @read(i32 %82, i32* %11, i32 4)
%84 = call i32 @TEMP_FAILURE_RETRY(i32 %83)
%85 = sext i32 %84 to i64
%86 = icmp ne i64 %85, 4
br i1 %86, label %87, label %89
87: ; preds = %80
%88 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %2
br label %89
89: ; preds = %87, %80
%90 = load i32, i32* %9
%91 = call i32 @waitpid(i32 %90, i32* %7, i32 0)
%92 = call i32 @TEMP_FAILURE_RETRY(i32 %91)
%93 = load i32, i32* %9
%94 = icmp ne i32 %92, %93
br i1 %94, label %95, label %97
95: ; preds = %89
%96 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %2
br label %103
97: ; preds = %89
%98 = load i32, i32* %7
%99 = icmp ne i32 %98, 0
br i1 %99, label %100, label %102
100: ; preds = %97
%101 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %2
br label %102
102: ; preds = %100, %97
br label %103
103: ; preds = %102, %95
%104 = call i32 (...) @getpid()
store i32 %104, i32* %12
%105 = load i32, i32* %8
%106 = load i32, i32* %12
%107 = icmp ne i32 %105, %106
br i1 %107, label %108, label %114
108: ; preds = %103
%109 = load i32, i32* %8
%110 = sext i32 %109 to i64
%111 = load i32, i32* %12
%112 = sext i32 %111 to i64
%113 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i64 %110, i64 %112)
store i32 1, i32* %2
br label %114
114: ; preds = %108, %103
%115 = load i32, i32* %8
%116 = load i32, i32* %4
%117 = icmp eq i32 %115, %116
br i1 %117, label %118, label %124
118: ; preds = %114
%119 = load i32, i32* %8
%120 = sext i32 %119 to i64
%121 = load i32, i32* %4
%122 = sext i32 %121 to i64
%123 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0), i64 %120, i64 %122)
store i32 1, i32* %2
br label %124
124: ; preds = %118, %114
%125 = load i32, i32* %4
%126 = load i32, i32* %6
%127 = icmp ne i32 %125, %126
br i1 %127, label %128, label %134
128: ; preds = %124
%129 = load i32, i32* %4
%130 = sext i32 %129 to i64
%131 = load i32, i32* %6
%132 = sext i32 %131 to i64
%133 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.11, i64 0, i64 0), i64 %130, i64 %132)
store i32 1, i32* %2
br label %134
134: ; preds = %128, %124
%135 = load i32, i32* %8
%136 = load i32, i32* %9
%137 = icmp eq i32 %135, %136
br i1 %137, label %138, label %144
138: ; preds = %134
%139 = load i32, i32* %8
%140 = sext i32 %139 to i64
%141 = load i32, i32* %9
%142 = sext i32 %141 to i64
%143 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0), i64 %140, i64 %142)
store i32 1, i32* %2
br label %144
144: ; preds = %138, %134
%145 = load i32, i32* %9
%146 = load i32, i32* %11
%147 = icmp ne i32 %145, %146
br i1 %147, label %148, label %154
148: ; preds = %144
%149 = load i32, i32* %9
%150 = sext i32 %149 to i64
%151 = load i32, i32* %11
%152 = sext i32 %151 to i64
%153 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.13, i64 0, i64 0), i64 %150, i64 %152)
store i32 1, i32* %2
br label %154
154: ; preds = %148, %144
%155 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%156 = load i32, i32* %155
%157 = call i32 @close(i32 %156)
%158 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%159 = load i32, i32* %158
%160 = call i32 @close(i32 %159)
%161 = load i32, i32* %2
%162 = icmp eq i32 %161, 0
br i1 %162, label %163, label %165
163: ; preds = %154
%164 = call i32 @puts(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.14, i64 0, i64 0))
br label %165
165: ; preds = %163, %154
%166 = load i32, i32* %2
store i32 %166, i32* %1
br label %167
167: ; preds = %165, %16
%168 = load i32, i32* %1
ret i32 %168
}

LLVM IR (-O2):
@.str = [12 x i8] c"pipe failed\00"
@.str.1 = [17 x i8] c"1st vfork failed\00"
@.str.2 = [16 x i8] c"1st read failed\00"
@.str.3 = [19 x i8] c"1st waitpid failed\00"
@.str.4 = [26 x i8] c"write in 1st child failed\00"
@.str.5 = [17 x i8] c"2nd vfork failed\00"
@.str.6 = [16 x i8] c"2nd read failed\00"
@.str.7 = [19 x i8] c"2nd waitpid failed\00"
@.str.8 = [26 x i8] c"write in 2nd child failed\00"
@.str.9 = [20 x i8] c"p0(%ld) != p5(%ld)\0A\00"
@.str.10 = [20 x i8] c"p0(%ld) == p1(%ld)\0A\00"
@.str.11 = [20 x i8] c"p1(%ld) != p2(%ld)\0A\00"
@.str.12 = [20 x i8] c"p0(%ld) == p3(%ld)\0A\00"
@.str.13 = [20 x i8] c"p3(%ld) != p4(%ld)\0A\00"
@.str.14 = [7 x i8] c"All OK\00"
define i32 @do_test() {
%1 = alloca [2 x i32]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast [2 x i32]* %1 to i8*
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%9 = call i32 @pipe(i32* %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %136
13: ; preds = %0
%14 = call i32 @vfork()
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = bitcast i32* %2 to i8*
%18 = call i32 (...) @getpid()
store i32 %18, i32* %2
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%20 = load i32, i32* %19
%21 = call i32 @write(i32 %20, i32* %2, i32 4)
%22 = call i32 @TEMP_FAILURE_RETRY(i32 %21)
%23 = icmp ne i32 %22, 4
%24 = zext i1 %23 to i32
%25 = call i32 @_exit(i32 %24)
unreachable
26: ; preds = %13
%27 = icmp eq i32 %14, -1
br i1 %27, label %28, label %30
28: ; preds = %26
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %26, %28
%31 = phi i32 [ 1, %28 ], [ 0, %26 ]
%32 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%33 = load i32, i32* %8
%34 = call i32 @read(i32 %33, i32* %3, i32 4)
%35 = call i32 @TEMP_FAILURE_RETRY(i32 %34)
%36 = icmp eq i32 %35, 4
br i1 %36, label %39, label %37
37: ; preds = %30
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %37, %30
%40 = phi i32 [ 1, %37 ], [ %31, %30 ]
%41 = bitcast i32* %4 to i8*
%42 = call i32 @waitpid(i32 %14, i32* %4, i32 0)
%43 = call i32 @TEMP_FAILURE_RETRY(i32 %42)
%44 = icmp eq i32 %43, %14
br i1 %44, label %45, label %48
45: ; preds = %39
%46 = load i32, i32* %4
%47 = icmp eq i32 %46, 0
br i1 %47, label %51, label %48
48: ; preds = %45, %39
%49 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), %39 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), %45 ]
%50 = call i32 @puts(i8* dereferenceable(1) %49)
br label %51
51: ; preds = %48, %45
%52 = phi i32 [ %40, %45 ], [ 1, %48 ]
%53 = call i32 (...) @getpid()
%54 = call i32 @vfork()
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %66
56: ; preds = %51
%57 = bitcast i32* %5 to i8*
%58 = call i32 (...) @getpid()
store i32 %58, i32* %5
%59 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%60 = load i32, i32* %59
%61 = call i32 @write(i32 %60, i32* %5, i32 4)
%62 = call i32 @TEMP_FAILURE_RETRY(i32 %61)
%63 = icmp ne i32 %62, 4
%64 = zext i1 %63 to i32
%65 = call i32 @_exit(i32 %64)
unreachable
66: ; preds = %51
br i1 %27, label %67, label %69
67: ; preds = %66
%68 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %69
69: ; preds = %66, %67
%70 = phi i32 [ 1, %67 ], [ %52, %66 ]
%71 = bitcast i32* %6 to i8*
%72 = load i32, i32* %8
%73 = call i32 @read(i32 %72, i32* %6, i32 4)
%74 = call i32 @TEMP_FAILURE_RETRY(i32 %73)
%75 = icmp eq i32 %74, 4
br i1 %75, label %78, label %76
76: ; preds = %69
%77 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
br label %78
78: ; preds = %76, %69
%79 = phi i32 [ 1, %76 ], [ %70, %69 ]
%80 = call i32 @waitpid(i32 %54, i32* %4, i32 0)
%81 = call i32 @TEMP_FAILURE_RETRY(i32 %80)
%82 = icmp eq i32 %81, %54
br i1 %82, label %83, label %86
83: ; preds = %78
%84 = load i32, i32* %4
%85 = icmp eq i32 %84, 0
br i1 %85, label %89, label %86
86: ; preds = %83, %78
%87 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), %78 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), %83 ]
%88 = call i32 @puts(i8* dereferenceable(1) %87)
br label %89
89: ; preds = %86, %83
%90 = phi i32 [ %79, %83 ], [ 1, %86 ]
%91 = call i32 (...) @getpid()
%92 = icmp eq i32 %53, %91
br i1 %92, label %97, label %93
93: ; preds = %89
%94 = sext i32 %53 to i64
%95 = sext i32 %91 to i64
%96 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i64 %94, i64 %95)
br label %97
97: ; preds = %93, %89
%98 = phi i32 [ 1, %93 ], [ %90, %89 ]
%99 = icmp eq i32 %53, %14
br i1 %99, label %100, label %103
100: ; preds = %97
%101 = sext i32 %14 to i64
%102 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0), i64 %101, i64 %101)
br label %103
103: ; preds = %100, %97
%104 = phi i32 [ 1, %100 ], [ %98, %97 ]
%105 = load i32, i32* %3
%106 = icmp eq i32 %14, %105
br i1 %106, label %111, label %107
107: ; preds = %103
%108 = sext i32 %14 to i64
%109 = sext i32 %105 to i64
%110 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.11, i64 0, i64 0), i64 %108, i64 %109)
br label %111
111: ; preds = %107, %103
%112 = phi i32 [ 1, %107 ], [ %104, %103 ]
%113 = icmp eq i32 %53, %54
br i1 %113, label %114, label %117
114: ; preds = %111
%115 = sext i32 %53 to i64
%116 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0), i64 %115, i64 %115)
br label %117
117: ; preds = %114, %111
%118 = phi i32 [ 1, %114 ], [ %112, %111 ]
%119 = load i32, i32* %6
%120 = icmp eq i32 %54, %119
br i1 %120, label %125, label %121
121: ; preds = %117
%122 = sext i32 %54 to i64
%123 = sext i32 %119 to i64
%124 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.13, i64 0, i64 0), i64 %122, i64 %123)
br label %125
125: ; preds = %121, %117
%126 = phi i32 [ 1, %121 ], [ %118, %117 ]
%127 = load i32, i32* %8
%128 = call i32 @close(i32 %127)
%129 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%130 = load i32, i32* %129
%131 = call i32 @close(i32 %130)
%132 = icmp eq i32 %126, 0
br i1 %132, label %133, label %135
133: ; preds = %125
%134 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.14, i64 0, i64 0))
br label %135
135: ; preds = %133, %125
br label %136
136: ; preds = %135, %11
%137 = phi i32 [ 1, %11 ], [ %126, %135 ]
ret i32 %137
}