#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;

/* Variables and functions */
int /*<<< orphan*/ be_bc(int *, int *);
int /*<<< orphan*/ be_dc(int *, int *);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int todc[2], fromdc[2];
  pid_t pid;
  if (pipe(todc) == -1 || pipe(fromdc) == -1) {
    perror("pipe() failed");
    exit(1);
  }
  if ((pid = fork()) == -1) {
    perror("fork() failed");
    exit(1);
  }
  if (pid == 0) {
    be_dc(todc, fromdc);
  } else {
    be_bc(todc, fromdc);
    wait(NULL);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1040 <pipe@plt>
cmp    $0xffffffff,%eax
je     11aa <main+0x3a>
lea    -0x20(%rbp),%rdi
call   1040 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11c0 <main+0x50>
lea    0xe4f(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    11e9 <main+0x79>
lea    0xe34(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x24(%rbp)
jne    1205 <main+0x95>
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <be_dc@plt>
jmp    121b <main+0xab>
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <be_bc@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <wait@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0x10(%rsp),%rdi
call   1040 <pipe@plt>
cmp    $0xffffffff,%eax
je     11d0 <main+0x60>
lea    0x8(%rsp),%rdi
call   1040 <pipe@plt>
cmp    $0xffffffff,%eax
je     11d0 <main+0x60>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     11ba <main+0x4a>
cmp    $0xffffffff,%eax
je     11d9 <main+0x69>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <be_bc@plt>
xor    %edi,%edi
call   1080 <wait@plt>
jmp    11c9 <main+0x59>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1060 <be_dc@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
lea    0xe29(%rip),%rdi
jmp    11e0 <main+0x70>
lea    0xe2e(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"pipe() failed\00"
@.str.1 = [14 x i8] c"fork() failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca [2 x i32]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%10 = call i32 @pipe(i32* %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%14 = call i32 @pipe(i32* %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %12, %2
%17 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %12
%20 = call i32 (...) @fork()
store i32 %20, i32* %8
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %19
%26 = load i32, i32* %8
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%31 = call i32 @be_dc(i32* %29, i32* %30)
br label %37
32: ; preds = %25
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%35 = call i32 @be_bc(i32* %33, i32* %34)
%36 = call i32 @wait(i32* null)
br label %37
37: ; preds = %32, %28
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [14 x i8] c"pipe() failed\00"
@.str.1 = [14 x i8] c"fork() failed\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = alloca [2 x i32]
%5 = bitcast [2 x i32]* %3 to i8*
%6 = bitcast [2 x i32]* %4 to i8*
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%8 = call i32 @pipe(i32* %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%12 = call i32 @pipe(i32* %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %10, %2
%15 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %10
%18 = call i32 (...) @fork()
switch i32 %18, label %24 [
i32 -1, label %19
i32 0, label %22
]
19: ; preds = %17
%20 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %17
%23 = call i32 @be_dc(i32* %7, i32* %11)
br label %27
24: ; preds = %17
%25 = call i32 @be_bc(i32* %7, i32* %11)
%26 = call i32 @wait(i32* null)
br label %27
27: ; preds = %24, %22
ret i32 0
}