#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*/ line;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int socketpair(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
               int *);
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ wait(int *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
main() {
  int fds[2], i;
  char line[4];
  int pid;
  char *m1 = "to";
  char *m2 = "fro";
  i = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
  if (i < 0)
    exit(1);
  printf("pipe\n");
  if ((pid = fork()) < 0)
    exit(1);
  if (pid == 0) {
    printf("child\n");
    if (write(fds[0], m1, strlen(m1)) < 0)
      exit(1);
    printf("child write\n");
    i = read(fds[0], line, sizeof(line));
    if (i < 0)
      exit(1);
    line[i] = 0;
    if (strcmp(line, m2))
      exit(1);
    printf("child read OK\n");
    fflush(stdout);
    exit(0);
  } else {
    printf("mother\n");
    i = read(fds[1], line, sizeof(line));
    if (i < 0)
      exit(1);
    line[i] = 0;
    if (strcmp(line, m1))
      exit(1);
    printf("mother read\n");
    if (write(fds[1], m2, strlen(m2)) < 0)
      exit(1);
    printf("mother write OK\n");
    wait(&i);
    printf("child exit %d\n", i);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe4a(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe42(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
mov    0x2e03(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rcx
xor    %edx,%edx
call   1080 <socketpair@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11f9 <main+0x59>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1224 <main+0x84>
mov    $0x1,%edi
call   10a0 <exit@plt>
cmpl   $0x0,-0x18(%rbp)
jne    12f8 <main+0x158>
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1275 <main+0xd5>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    12ab <main+0x10b>
mov    $0x1,%edi
call   10a0 <exit@plt>
movslq -0x10(%rbp),%rax
movb   $0x0,-0x14(%rbp,%rax,1)
lea    -0x14(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     12d5 <main+0x135>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xd45(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0xd31(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    132e <main+0x18e>
mov    $0x1,%edi
call   10a0 <exit@plt>
movslq -0x10(%rbp),%rax
movb   $0x0,-0x14(%rbp,%rax,1)
lea    -0x14(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1358 <main+0x1b8>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xcd9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    139f <main+0x1ff>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xc9f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x10(%rbp),%rdi
call   10b0 <wait@plt>
mov    -0x10(%rbp),%esi
lea    0xc96(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rcx
xor    %edx,%edx
call   1090 <socketpair@plt>
test   %eax,%eax
js     130f <main+0x15f>
lea    0xe32(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %eax,%eax
js     130f <main+0x15f>
jne    129b <main+0xeb>
lea    0xe39(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%rsp),%ebx
lea    0xdeb(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %rax,%rax
js     130f <main+0x15f>
lea    0xe0b(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%rsp),%edi
lea    0x8(%rsp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
test   %eax,%eax
js     130f <main+0x15f>
mov    %eax,%eax
movb   $0x0,0x8(%rsp,%rax,1)
lea    0xd9c(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    130f <main+0x15f>
lea    0xdcf(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xd79(%rip),%rdi
call   1030 <puts@plt>
mov    0x14(%rsp),%edi
lea    0x8(%rsp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    %eax,0xc(%rsp)
test   %eax,%eax
js     130f <main+0x15f>
mov    %eax,%eax
movb   $0x0,0x8(%rsp,%rax,1)
lea    0xd30(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    130f <main+0x15f>
lea    0xd3c(%rip),%rdi
call   1030 <puts@plt>
mov    0x14(%rsp),%ebx
lea    0xd0d(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %rax,%rax
jns    1319 <main+0x169>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xd0e(%rip),%rdi
call   1030 <puts@plt>
lea    0xc(%rsp),%rdi
call   10c0 <wait@plt>
mov    0xc(%rsp),%esi
lea    0xccd(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"to\00"
@.str.1 = [4 x i8] c"fro\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [6 x i8] c"pipe\0A\00"
@.str.3 = [7 x i8] c"child\0A\00"
@.str.4 = [13 x i8] c"child write\0A\00"
@.str.5 = [15 x i8] c"child read OK\0A\00"
@stdout = global i32 0
@.str.6 = [8 x i8] c"mother\0A\00"
@.str.7 = [13 x i8] c"mother read\0A\00"
@.str.8 = [17 x i8] c"mother write OK\0A\00"
@.str.9 = [15 x i8] c"child exit %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = alloca [4 x i8]
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %7
%8 = load i32, i32* @AF_UNIX
%9 = load i32, i32* @SOCK_STREAM
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%11 = call i32 @socketpair(i32 %8, i32 %9, i32 0, i32* %10)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 (...) @fork()
store i32 %18, i32* %5
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %16
%23 = load i32, i32* %5
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %61
25: ; preds = %22
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%28 = load i32, i32* %27
%29 = load i8*, i8** %6
%30 = load i8*, i8** %6
%31 = call i32 @strlen(i8* %30)
%32 = call i64 @write(i32 %28, i8* %29, i32 %31)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %25
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %25
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%39 = load i32, i32* %38
%40 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%41 = call i32 @read(i32 %39, i8* %40, i32 4)
store i32 %41, i32* %3
%42 = load i32, i32* %3
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %36
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %36
%47 = load i32, i32* %3
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 %48
store i8 0, i8* %49
%50 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%51 = load i8*, i8** %7
%52 = call i64 @strcmp(i8* %50, i8* %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %46
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %46
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%58 = load i32, i32* @stdout
%59 = call i32 @fflush(i32 %58)
%60 = call i32 @exit(i32 0)
unreachable
61: ; preds = %22
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%63 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%64 = load i32, i32* %63
%65 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%66 = call i32 @read(i32 %64, i8* %65, i32 4)
store i32 %66, i32* %3
%67 = load i32, i32* %3
%68 = icmp slt i32 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %61
%70 = call i32 @exit(i32 1)
unreachable
71: ; preds = %61
%72 = load i32, i32* %3
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 %73
store i8 0, i8* %74
%75 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%76 = load i8*, i8** %6
%77 = call i64 @strcmp(i8* %75, i8* %76)
%78 = icmp ne i64 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %71
%80 = call i32 @exit(i32 1)
unreachable
81: ; preds = %71
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%83 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%84 = load i32, i32* %83
%85 = load i8*, i8** %7
%86 = load i8*, i8** %7
%87 = call i32 @strlen(i8* %86)
%88 = call i64 @write(i32 %84, i8* %85, i32 %87)
%89 = icmp slt i64 %88, 0
br i1 %89, label %90, label %92
90: ; preds = %81
%91 = call i32 @exit(i32 1)
unreachable
92: ; preds = %81
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%94 = call i32 @wait(i32* %3)
%95 = load i32, i32* %3
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i32 %95)
br label %97
97: ; preds = %92
%98 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"to\00"
@.str.1 = [4 x i8] c"fro\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@stdout = global i32 0
@.str.9 = [15 x i8] c"child exit %d\0A\00"
@str = [5 x i8] c"pipe\00"
@str.10 = [7 x i8] c"mother\00"
@str.11 = [12 x i8] c"mother read\00"
@str.12 = [16 x i8] c"mother write OK\00"
@str.13 = [6 x i8] c"child\00"
@str.14 = [12 x i8] c"child write\00"
@str.15 = [14 x i8] c"child read OK\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca i32
%3 = alloca [4 x i8]
%4 = bitcast [2 x i32]* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @AF_UNIX
%8 = load i32, i32* @SOCK_STREAM
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%10 = call i32 @socketpair(i32 %7, i32 %8, i32 0, i32* %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%16 = call i32 (...) @fork()
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %14
%21 = icmp eq i32 %16, 0
br i1 %21, label %22, label %49
22: ; preds = %20
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.13, i64 0, i64 0))
%24 = load i32, i32* %9
%25 = call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%26 = call i64 @write(i32 %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %22
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.14, i64 0, i64 0))
%32 = load i32, i32* %9
%33 = call i32 @read(i32 %32, i8* %6, i32 4)
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %30
%38 = zext i32 %33 to i64
%39 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 %38
store i8 0, i8* %39
%40 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %44, label %42
42: ; preds = %37
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %37
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.15, i64 0, i64 0))
%46 = load i32, i32* @stdout
%47 = call i32 @fflush(i32 %46)
%48 = call i32 @exit(i32 0)
unreachable
49: ; preds = %20
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.10, i64 0, i64 0))
%51 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%52 = load i32, i32* %51
%53 = call i32 @read(i32 %52, i8* %6, i32 4)
store i32 %53, i32* %2
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %49
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %49
%58 = zext i32 %53 to i64
%59 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 %58
store i8 0, i8* %59
%60 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%61 = icmp eq i64 %60, 0
br i1 %61, label %64, label %62
62: ; preds = %57
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %57
%65 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.11, i64 0, i64 0))
%66 = load i32, i32* %51
%67 = call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%68 = call i64 @write(i32 %66, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %67)
%69 = icmp slt i64 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %64
%71 = call i32 @exit(i32 1)
unreachable
72: ; preds = %64
%73 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.12, i64 0, i64 0))
%74 = call i32 @wait(i32* %2)
%75 = load i32, i32* %2
%76 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i32 %75)
%77 = call i32 @exit(i32 0)
unreachable
}