#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: Can`t redirect stdin");
    exit(3);
  };
  close(in[0]);
  close(in[1]);
  if (dup2(out[1], 1) == -1) {
    perror("dc: Can`t redirect stdout");
    exit(4);
  };
  close(out[1]);
  close(out[0]);
  execlp("dc", "dc", "-", NULL);
  {
    perror("Can`t run dc");
    exit(5);
  };
}


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    $0x3,%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    0xe55(%rip),%rdi
call   1050 <perror@plt>
mov    $0x4,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1040 <close@plt>
lea    0xe4e(%rip),%rsi
lea    0xe3b(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   1070 <execlp@plt>
lea    0xe2a(%rip),%rdi
call   1050 <perror@plt>
mov    $0x5,%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    117e <be_dc+0x2e>
lea    0xe91(%rip),%rdi
call   1050 <perror@plt>
mov    $0x3,%edi
call   1060 <exit@plt>
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    11b6 <be_dc+0x66>
lea    0xe72(%rip),%rdi
call   1050 <perror@plt>
mov    $0x4,%edi
call   1060 <exit@plt>
mov    0x4(%r14),%edi
call   1040 <close@plt>
mov    (%r14),%edi
call   1040 <close@plt>
lea    0xe71(%rip),%rdi
lea    0xe5e(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   1070 <execlp@plt>
lea    0xe4f(%rip),%rdi
call   1050 <perror@plt>
mov    $0x5,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"dc: Can`t redirect stdin\00"
@.str.1 = [26 x i8] c"dc: Can`t redirect stdout\00"
@.str.2 = [3 x i8] c"dc\00"
@.str.3 = [2 x i8] c"-\00"
@.str.4 = [13 x i8] c"Can`t run dc\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 ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 3)
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 ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 4)
unreachable
30: ; preds = %13
%31 = load i32*, i32** %4
%32 = getelementptr inbounds i32, i32* %31, i64 1
%33 = load i32, i32* %32
%34 = call i32 @close(i32 %33)
%35 = load i32*, i32** %4
%36 = getelementptr inbounds i32, i32* %35, i64 0
%37 = load i32, i32* %36
%38 = call i32 @close(i32 %37)
%39 = 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)
%40 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%41 = call i32 @exit(i32 5)
unreachable
}

LLVM IR (-O2):
@.str = [25 x i8] c"dc: Can`t redirect stdin\00"
@.str.1 = [26 x i8] c"dc: Can`t redirect stdout\00"
@.str.2 = [3 x i8] c"dc\00"
@.str.3 = [2 x i8] c"-\00"
@.str.4 = [13 x i8] c"Can`t run dc\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 ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 3)
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 ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @exit(i32 4)
unreachable
22: ; preds = %9
%23 = load i32, i32* %15
%24 = tail call i32 @close(i32 %23)
%25 = load i32, i32* %1
%26 = tail call i32 @close(i32 %25)
%27 = 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)
%28 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%29 = tail call i32 @exit(i32 5)
unreachable
}