#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*/ close(int);
int dup2(int, int);
int /*<<< orphan*/ execlp(char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
void be_dc(int in[2], int out[2]) {
  if (dup2(in[0], 0) == -1) {
    perror("dc: cannot redirect stdin");
    exit(1);
  }
  close(in[0]);
  close(in[1]);
  if (dup2(out[1], 1) == -1) {
    perror("dc: cannot redirect stdout");
    exit(1);
  }
  execlp("dc", "dc", "-", NULL);
  perror("dc: execlp() failed");
  exit(1);
}


x86 assembly (clang, -O0):
<be_dc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
cmp    $0xffffffff,%eax
jne    118c <be_dc+0x3c>
lea    0xe83(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
cmp    $0xffffffff,%eax
jne    11d3 <be_dc+0x83>
lea    0xe56(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    0xe5b(%rip),%rsi
lea    0xe57(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   1070 <execlp@plt>
lea    0xe46(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<be_dc>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
cmp    $0xffffffff,%eax
jne    1171 <be_dc+0x21>
lea    0xe91(%rip),%rdi
jmp    11bb <be_dc+0x6b>
mov    (%rbx),%edi
call   1040 <close@plt>
mov    0x4(%rbx),%edi
call   1040 <close@plt>
mov    0x4(%r14),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
cmp    $0xffffffff,%eax
jne    119c <be_dc+0x4c>
lea    0xe80(%rip),%rdi
jmp    11bb <be_dc+0x6b>
lea    0xe92(%rip),%rdi
lea    0xe8e(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   1070 <execlp@plt>
lea    0xe7f(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
@.str = [26 x i8] c"dc: cannot redirect stdin\00"
@.str.1 = [27 x i8] c"dc: cannot redirect stdout\00"
@.str.2 = [3 x i8] c"dc\00"
@.str.3 = [2 x i8] c"-\00"
@.str.4 = [20 x i8] c"dc: execlp() failed\00"
define void @be_dc(i32* nocapture %0, i32* nocapture %1) {
%3 = load i32, i32* %0
%4 = tail call i32 @dup2(i32 %3, i32 0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = load i32, i32* %0
%11 = tail call i32 @close(i32 %10)
%12 = getelementptr inbounds i32, i32* %0, i64 1
%13 = load i32, i32* %12
%14 = tail call i32 @close(i32 %13)
%15 = getelementptr inbounds i32, i32* %1, i64 1
%16 = load i32, i32* %15
%17 = tail call i32 @dup2(i32 %16, i32 1)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %9
%20 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %9
%23 = tail call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32* null)
%24 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
}