#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*/ STDERR_FILENO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ execl(char *, char *, char *, char *, int /*<<< orphan*/ *);
void child_exec(int in[2], int out[2], int err[2], char *cmd) {
  close(in[1]);
  close(out[0]);
  close(err[0]);
  dup2(in[0], STDIN_FILENO);
  dup2(out[1], STDOUT_FILENO);
  dup2(err[1], STDERR_FILENO);
  execl("/bin/sh", "/bin/sh", "-c", cmd, NULL);
}


x86 assembly (clang, -O0):
<child_exec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0x20(%rbp),%rcx
lea    0xe4d(%rip),%rsi
lea    0xe4e(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rsi,%rdi
call   1050 <execl@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<child_exec>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
mov    0x4(%rdi),%edi
call   1040 <close@plt>
mov    (%r12),%edi
call   1040 <close@plt>
mov    (%r15),%edi
call   1040 <close@plt>
mov    (%rbx),%edi
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    0x4(%r12),%edi
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    0x4(%r15),%edi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
lea    0xe67(%rip),%rdi
lea    0xe68(%rip),%rdx
mov    %rdi,%rsi
mov    %r14,%rcx
xor    %r8d,%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <execl@plt>

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str = [8 x i8] c"/bin/sh\00"
@.str.1 = [3 x i8] c"-c\00"
define void @child_exec(i32* %0, i32* %1, i32* %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i8* %3, i8** %8
%9 = load i32*, i32** %5
%10 = getelementptr inbounds i32, i32* %9, i64 1
%11 = load i32, i32* %10
%12 = call i32 @close(i32 %11)
%13 = load i32*, i32** %6
%14 = getelementptr inbounds i32, i32* %13, i64 0
%15 = load i32, i32* %14
%16 = call i32 @close(i32 %15)
%17 = load i32*, i32** %7
%18 = getelementptr inbounds i32, i32* %17, i64 0
%19 = load i32, i32* %18
%20 = call i32 @close(i32 %19)
%21 = load i32*, i32** %5
%22 = getelementptr inbounds i32, i32* %21, i64 0
%23 = load i32, i32* %22
%24 = load i32, i32* @STDIN_FILENO
%25 = call i32 @dup2(i32 %23, i32 %24)
%26 = load i32*, i32** %6
%27 = getelementptr inbounds i32, i32* %26, i64 1
%28 = load i32, i32* %27
%29 = load i32, i32* @STDOUT_FILENO
%30 = call i32 @dup2(i32 %28, i32 %29)
%31 = load i32*, i32** %7
%32 = getelementptr inbounds i32, i32* %31, i64 1
%33 = load i32, i32* %32
%34 = load i32, i32* @STDERR_FILENO
%35 = call i32 @dup2(i32 %33, i32 %34)
%36 = load i8*, i8** %8
%37 = call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %36, i32* null)
ret void
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str = [8 x i8] c"/bin/sh\00"
@.str.1 = [3 x i8] c"-c\00"
define void @child_exec(i32* nocapture %0, i32* nocapture %1, i32* nocapture %2, i8* %3) {
%5 = getelementptr inbounds i32, i32* %0, i64 1
%6 = load i32, i32* %5
%7 = tail call i32 @close(i32 %6)
%8 = load i32, i32* %1
%9 = tail call i32 @close(i32 %8)
%10 = load i32, i32* %2
%11 = tail call i32 @close(i32 %10)
%12 = load i32, i32* %0
%13 = load i32, i32* @STDIN_FILENO
%14 = tail call i32 @dup2(i32 %12, i32 %13)
%15 = getelementptr inbounds i32, i32* %1, i64 1
%16 = load i32, i32* %15
%17 = load i32, i32* @STDOUT_FILENO
%18 = tail call i32 @dup2(i32 %16, i32 %17)
%19 = getelementptr inbounds i32, i32* %2, i64 1
%20 = load i32, i32* %19
%21 = load i32, i32* @STDERR_FILENO
%22 = tail call i32 @dup2(i32 %20, i32 %21)
%23 = tail call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3, i32* null)
ret void
}