#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 */
scalar_t__ add_argv(char **, char *);
int /*<<< orphan*/ err_handler(char *);
scalar_t__ malloc(int);
char **create_argv_for_execution_using_shell(char *command) {
  char *shell;
  char **argv;
  shell = "/bin/bash";
  if ((argv = (char **)malloc(sizeof(char *) * 4)) == NULL) {
    err_handler("malloc failed");
    return NULL;
  }
  argv[0] = NULL;
  argv[1] = NULL;
  argv[2] = NULL;
  argv[3] = NULL;
  if (add_argv(&(argv[0]), shell) == 0)
    return NULL;
  if (add_argv(&(argv[1]), "-c") == 0)
    return NULL;
  if (add_argv(&(argv[2]), command) == 0)
    return NULL;
  return argv;
}


x86 assembly (clang, -O0):
<create_argv_for_execution_using_shell>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xebd(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    $0x20,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1178 <create_argv_for_execution_using_shell+0x48>
lea    0xea4(%rip),%rdi
call   1030 <err_handler@plt>
movq   $0x0,-0x8(%rbp)
jmp    1226 <create_argv_for_execution_using_shell+0xf6>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,0x10(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,0x18(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <add_argv@plt>
cmp    $0x0,%rax
jne    11cb <create_argv_for_execution_using_shell+0x9b>
movq   $0x0,-0x8(%rbp)
jmp    1226 <create_argv_for_execution_using_shell+0xf6>
mov    -0x20(%rbp),%rdi
add    $0x8,%rdi
lea    0xe3e(%rip),%rsi
call   1040 <add_argv@plt>
cmp    $0x0,%rax
jne    11f6 <create_argv_for_execution_using_shell+0xc6>
movq   $0x0,-0x8(%rbp)
jmp    1226 <create_argv_for_execution_using_shell+0xf6>
mov    -0x20(%rbp),%rdi
add    $0x10,%rdi
mov    -0x10(%rbp),%rsi
call   1040 <add_argv@plt>
cmp    $0x0,%rax
jne    121e <create_argv_for_execution_using_shell+0xee>
movq   $0x0,-0x8(%rbp)
jmp    1226 <create_argv_for_execution_using_shell+0xf6>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_argv_for_execution_using_shell>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x20,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1191 <create_argv_for_execution_using_shell+0x61>
mov    %rax,%rbx
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rax)
movups %xmm0,(%rax)
lea    0xea6(%rip),%rsi
mov    %rax,%rdi
call   1040 <add_argv@plt>
test   %rax,%rax
je     119d <create_argv_for_execution_using_shell+0x6d>
lea    0x8(%rbx),%rdi
lea    0xea6(%rip),%rsi
call   1040 <add_argv@plt>
test   %rax,%rax
je     119d <create_argv_for_execution_using_shell+0x6d>
lea    0x10(%rbx),%rdi
mov    %r14,%rsi
call   1040 <add_argv@plt>
test   %rax,%rax
cmove  %rax,%rbx
jmp    119f <create_argv_for_execution_using_shell+0x6f>
lea    0xe72(%rip),%rdi
call   1030 <err_handler@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/bin/bash\00"
@.str.1 = [14 x i8] c"malloc failed\00"
@.str.2 = [3 x i8] c"-c\00"
define i8** @create_argv_for_execution_using_shell(i8* %0) {
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8**
store i8* %0, i8** %3
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %4
%6 = call i64 @malloc(i32 32)
%7 = inttoptr i64 %6 to i8**
store i8** %7, i8*** %5
%8 = icmp eq i8** %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @err_handler(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i8** null, i8*** %2
br label %41
11: ; preds = %1
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
store i8* null, i8** %13
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
store i8* null, i8** %15
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 2
store i8* null, i8** %17
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 3
store i8* null, i8** %19
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %4
%23 = call i64 @add_argv(i8** %21, i8* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %11
store i8** null, i8*** %2
br label %41
26: ; preds = %11
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = call i64 @add_argv(i8** %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
store i8** null, i8*** %2
br label %41
32: ; preds = %26
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %3
%36 = call i64 @add_argv(i8** %34, i8* %35)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %32
store i8** null, i8*** %2
br label %41
39: ; preds = %32
%40 = load i8**, i8*** %5
store i8** %40, i8*** %2
br label %41
41: ; preds = %39, %38, %31, %25, %9
%42 = load i8**, i8*** %2
ret i8** %42
}

LLVM IR (-O2):
@.str = [10 x i8] c"/bin/bash\00"
@.str.1 = [14 x i8] c"malloc failed\00"
@.str.2 = [3 x i8] c"-c\00"
define i8** @create_argv_for_execution_using_shell(i8* %0) {
%2 = tail call i64 @malloc(i32 32)
%3 = inttoptr i64 %2 to i8**
%4 = icmp eq i64 %2, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @err_handler(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %20
7: ; preds = %1
%8 = getelementptr inbounds i8*, i8** %3, i64 2
%9 = inttoptr i64 %2 to i8*
%10 = tail call i64 @add_argv(i8** %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %20, label %12
12: ; preds = %7
%13 = getelementptr inbounds i8*, i8** %3, i64 1
%14 = tail call i64 @add_argv(i8** %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = tail call i64 @add_argv(i8** %8, i8* %0)
%18 = icmp eq i64 %17, 0
%19 = select i1 %18, i8** null, i8** %3
br label %20
20: ; preds = %16, %12, %7, %5
%21 = phi i8** [ null, %5 ], [ null, %7 ], [ null, %12 ], [ %19, %16 ]
ret i8** %21
}