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

/* 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 pid, todc[2], fromdc[2];
  if (pipe(todc) == -1 || pipe(fromdc) == -1) {
    perror("pipe failed");
    exit(1);
  };
  if ((pid = fork()) == -1) {
    perror("Can`t fork");
    exit(2);
  };
  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    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
call   1040 <pipe@plt>
cmp    $0xffffffff,%eax
je     11a3 <main+0x33>
lea    -0x18(%rbp),%rdi
call   1040 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11b9 <main+0x49>
lea    0xe56(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    11e2 <main+0x72>
lea    0xe39(%rip),%rdi
call   1050 <perror@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x8(%rbp)
jne    11fe <main+0x8e>
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <be_dc@plt>
jmp    1214 <main+0xa4>
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <be_bc@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <wait@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%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     11e6 <main+0x76>
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
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe1f(%rip),%rdi
call   1050 <perror@plt>
mov    $0x2,%edi
call   1070 <exit@plt>

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

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