#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*/ O_WRONLY;
char *_PATH_BSHELL;
int /*<<< orphan*/ _PATH_DEVNULL;
int /*<<< orphan*/ __environ;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execve(char *, char *const *, int /*<<< orphan*/);
int open(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ unsetenv(char *);
void exec_comm_child(char *comm, int *fildes, int showerr, int noexec) {
  const char *args[4] = {_PATH_BSHELL, "-c", comm, NULL};
  if (noexec)
    args[1] = "-nc";
  dup2(fildes[1], 1);
  close(fildes[1]);
  if (showerr == 0) {
    int fd;
    close(2);
    fd = open(_PATH_DEVNULL, O_WRONLY);
    if (fd >= 0 && fd != 2) {
      dup2(fd, 2);
      close(fd);
    }
  }
  unsetenv("IFS");
  close(fildes[0]);
  execve(_PATH_BSHELL, (char *const *)args, __environ);
  abort();
}


x86 assembly (clang, -O0):
<exec_comm_child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
lea    0xe75(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11b4 <exec_comm_child+0x54>
lea    0xe53(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
mov    $0x1,%esi
call   1040 <dup2@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1050 <close@plt>
cmpl   $0x0,-0x14(%rbp)
jne    122d <exec_comm_child+0xcd>
mov    $0x2,%edi
call   1050 <close@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jl     1228 <exec_comm_child+0xc8>
cmpl   $0x2,-0x44(%rbp)
je     1228 <exec_comm_child+0xc8>
mov    -0x44(%rbp),%edi
mov    $0x2,%esi
call   1040 <dup2@plt>
mov    -0x44(%rbp),%edi
call   1050 <close@plt>
jmp    122d <exec_comm_child+0xcd>
lea    0xdd3(%rip),%rdi
call   1080 <unsetenv@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1050 <close@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%rdi
lea    -0x40(%rbp),%rsi
mov    0x2d9f(%rip),%rax
mov    (%rax),%edx
call   1060 <execve@plt>
mov    $0x0,%al
call   1030 <abort@plt>

x86 assembly (clang, -O2):
<exec_comm_child>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    0x2e6c(%rip),%r14
mov    (%r14),%rax
mov    %rax,(%rsp)
lea    0xe7e(%rip),%rax
mov    %rax,0x8(%rsp)
mov    %rdi,0x10(%rsp)
movq   $0x0,0x18(%rsp)
test   %ecx,%ecx
je     11a5 <exec_comm_child+0x45>
lea    0xe63(%rip),%rax
mov    %rax,0x8(%rsp)
mov    0x4(%rbx),%edi
mov    $0x1,%esi
call   1040 <dup2@plt>
mov    0x4(%rbx),%edi
call   1050 <close@plt>
test   %ebp,%ebp
jne    11fd <exec_comm_child+0x9d>
mov    $0x2,%edi
call   1050 <close@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
js     11fd <exec_comm_child+0x9d>
mov    %eax,%ebp
cmp    $0x2,%eax
je     11fd <exec_comm_child+0x9d>
mov    %ebp,%edi
mov    $0x2,%esi
call   1040 <dup2@plt>
mov    %ebp,%edi
call   1050 <close@plt>
lea    0xe03(%rip),%rdi
call   1080 <unsetenv@plt>
mov    (%rbx),%edi
call   1050 <close@plt>
mov    (%r14),%rdi
mov    0x2dde(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rsi
call   1060 <execve@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@_PATH_BSHELL = global i8* null
@.str = [3 x i8] c"-c\00"
@.str.1 = [4 x i8] c"-nc\00"
@_PATH_DEVNULL = global i32 0
@O_WRONLY = global i32 0
@.str.2 = [4 x i8] c"IFS\00"
@__environ = global i32 0
define void @exec_comm_child(i8* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [4 x i8*]
%10 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = getelementptr inbounds [4 x i8*], [4 x i8*]* %9, i64 0, i64 0
%12 = load i8*, i8** @_PATH_BSHELL
store i8* %12, i8** %11
%13 = getelementptr inbounds i8*, i8** %11, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %13
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %5
store i8* %15, i8** %14
%16 = getelementptr inbounds i8*, i8** %14, i64 1
store i8* null, i8** %16
%17 = load i32, i32* %8
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %4
%20 = getelementptr inbounds [4 x i8*], [4 x i8*]* %9, i64 0, i64 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %20
br label %21
21: ; preds = %19, %4
%22 = load i32*, i32** %6
%23 = getelementptr inbounds i32, i32* %22, i64 1
%24 = load i32, i32* %23
%25 = call i32 @dup2(i32 %24, i32 1)
%26 = load i32*, i32** %6
%27 = getelementptr inbounds i32, i32* %26, i64 1
%28 = load i32, i32* %27
%29 = call i32 @close(i32 %28)
%30 = load i32, i32* %7
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %48
32: ; preds = %21
%33 = call i32 @close(i32 2)
%34 = load i32, i32* @_PATH_DEVNULL
%35 = load i32, i32* @O_WRONLY
%36 = call i32 @open(i32 %34, i32 %35)
store i32 %36, i32* %10
%37 = load i32, i32* %10
%38 = icmp sge i32 %37, 0
br i1 %38, label %39, label %47
39: ; preds = %32
%40 = load i32, i32* %10
%41 = icmp ne i32 %40, 2
br i1 %41, label %42, label %47
42: ; preds = %39
%43 = load i32, i32* %10
%44 = call i32 @dup2(i32 %43, i32 2)
%45 = load i32, i32* %10
%46 = call i32 @close(i32 %45)
br label %47
47: ; preds = %42, %39, %32
br label %48
48: ; preds = %47, %21
%49 = call i32 @unsetenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%50 = load i32*, i32** %6
%51 = getelementptr inbounds i32, i32* %50, i64 0
%52 = load i32, i32* %51
%53 = call i32 @close(i32 %52)
%54 = load i8*, i8** @_PATH_BSHELL
%55 = getelementptr inbounds [4 x i8*], [4 x i8*]* %9, i64 0, i64 0
%56 = load i32, i32* @__environ
%57 = call i32 @execve(i8* %54, i8** %55, i32 %56)
%58 = call i32 (...) @abort()
unreachable
}

LLVM IR (-O2):
@_PATH_BSHELL = global i8* null
@.str = [3 x i8] c"-c\00"
@.str.1 = [4 x i8] c"-nc\00"
@_PATH_DEVNULL = global i32 0
@O_WRONLY = global i32 0
@.str.2 = [4 x i8] c"IFS\00"
@__environ = global i32 0
define void @exec_comm_child(i8* %0, i32* nocapture %1, i32 %2, i32 %3) {
%5 = alloca [4 x i8*]
%6 = bitcast [4 x i8*]* %5 to i8*
%7 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 0
%8 = load i8*, i8** @_PATH_BSHELL
store i8* %8, i8** %7
%9 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 2
store i8* %0, i8** %10
%11 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 3
store i8* null, i8** %11
%12 = icmp eq i32 %3, 0
br i1 %12, label %14, label %13
13: ; preds = %4
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %9
br label %14
14: ; preds = %13, %4
%15 = getelementptr inbounds i32, i32* %1, i64 1
%16 = load i32, i32* %15
%17 = tail call i32 @dup2(i32 %16, i32 1)
%18 = load i32, i32* %15
%19 = tail call i32 @close(i32 %18)
%20 = icmp eq i32 %2, 0
br i1 %20, label %21, label %32
21: ; preds = %14
%22 = tail call i32 @close(i32 2)
%23 = load i32, i32* @_PATH_DEVNULL
%24 = load i32, i32* @O_WRONLY
%25 = tail call i32 @open(i32 %23, i32 %24)
%26 = icmp sgt i32 %25, -1
%27 = icmp ne i32 %25, 2
%28 = and i1 %26, %27
br i1 %28, label %29, label %32
29: ; preds = %21
%30 = tail call i32 @dup2(i32 %25, i32 2)
%31 = tail call i32 @close(i32 %25)
br label %32
32: ; preds = %21, %29, %14
%33 = tail call i32 @unsetenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%34 = load i32, i32* %1
%35 = tail call i32 @close(i32 %34)
%36 = load i8*, i8** @_PATH_BSHELL
%37 = load i32, i32* @__environ
%38 = call i32 @execve(i8* %36, i8** %7, i32 %37)
%39 = call i32 (...) @abort()
unreachable
}