#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*/ asprintf(char **, char *, char const *);
int /*<<< orphan*/ err(int, char *, ...);
int /*<<< orphan*/ execvp(char *, char **);
int fork();
void run_command(const char *command) {
  char *argv[4];
  switch (fork()) {
  case -1:
    err(1, "fork");
  case 0:
    argv[0] = "/bin/sh";
    argv[1] = "-c";
    argv[3] = NULL;
    if (asprintf(&argv[2], "exec %s", command) < 0)
      err(1, NULL);
    if (execvp(argv[0], argv) < 0)
      err(1, "failed to execute %s %s '%s'", argv[0], argv[1], argv[2]);
  }
}


x86 assembly (clang, -O0):
<run_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
call   1060 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x34(%rbp)
sub    $0xffffffff,%eax
je     1176 <run_command+0x36>
jmp    1166 <run_command+0x26>
mov    -0x34(%rbp),%eax
test   %eax,%eax
je     1189 <run_command+0x49>
jmp    1212 <run_command+0xd2>
mov    $0x1,%edi
lea    0xe7e(%rip),%rsi
mov    $0x0,%al
call   1030 <err@plt>
lea    0xe75(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe72(%rip),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
add    $0x10,%rdi
mov    -0x8(%rbp),%rdx
lea    0xe56(%rip),%rsi
call   1040 <asprintf@plt>
cmp    $0x0,%eax
jge    11d8 <run_command+0x98>
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x0,%al
call   1030 <err@plt>
mov    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <execvp@plt>
cmp    $0x0,%eax
jge    120d <run_command+0xcd>
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    $0x1,%edi
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   1030 <err@plt>
jmp    1212 <run_command+0xd2>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_command>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     116f <run_command+0x2f>
cmp    $0xffffffff,%eax
jne    11e6 <run_command+0xa6>
lea    0xe9d(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1030 <err@plt>
lea    0xe8f(%rip),%rax
mov    %rax,(%rsp)
lea    0xe8c(%rip),%rax
mov    %rax,0x8(%rsp)
movq   $0x0,0x18(%rsp)
lea    0x10(%rsp),%rdi
lea    0xe75(%rip),%rsi
mov    %rbx,%rdx
call   1040 <asprintf@plt>
test   %eax,%eax
jns    11b5 <run_command+0x75>
mov    $0x1,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1030 <err@plt>
mov    (%rsp),%rdi
mov    %rsp,%rsi
call   1050 <execvp@plt>
test   %eax,%eax
jns    11e6 <run_command+0xa6>
mov    (%rsp),%rdx
mov    0x8(%rsp),%rcx
mov    0x10(%rsp),%r8
lea    0xe3e(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1030 <err@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@.str.1 = [8 x i8] c"/bin/sh\00"
@.str.2 = [3 x i8] c"-c\00"
@.str.3 = [8 x i8] c"exec %s\00"
@.str.4 = [29 x i8] c"failed to execute %s %s '%s'\00"
define void @run_command(i8* %0) {
%2 = alloca i8*
%3 = alloca [4 x i8*]
store i8* %0, i8** %2
%4 = call i32 (...) @fork()
switch i32 %4, label %32 [
i32 -1, label %5
i32 0, label %7
]
5: ; preds = %1
%6 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %1, %5
%8 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 3
store i8* null, i8** %10
%11 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 2
%12 = load i8*, i8** %2
%13 = call i32 @asprintf(i8** %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %7
%16 = call i32 (i32, i8*, ...) @err(i32 1, i8* null)
br label %17
17: ; preds = %15, %7
%18 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 0
%19 = load i8*, i8** %18
%20 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 0
%21 = call i32 @execvp(i8* %19, i8** %20)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %17
%24 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 0
%25 = load i8*, i8** %24
%26 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 1
%27 = load i8*, i8** %26
%28 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 2
%29 = load i8*, i8** %28
%30 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %25, i8* %27, i8* %29)
br label %31
31: ; preds = %23, %17
br label %32
32: ; preds = %31, %1
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@.str.1 = [8 x i8] c"/bin/sh\00"
@.str.2 = [3 x i8] c"-c\00"
@.str.3 = [8 x i8] c"exec %s\00"
@.str.4 = [29 x i8] c"failed to execute %s %s '%s'\00"
define void @run_command(i8* %0) {
%2 = alloca [4 x i8*]
%3 = bitcast [4 x i8*]* %2 to i8*
%4 = tail call i32 (...) @fork()
switch i32 %4, label %25 [
i32 -1, label %5
i32 0, label %7
]
5: ; preds = %1
%6 = tail call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %1, %5
%8 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 3
store i8* null, i8** %10
%11 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 2
%12 = call i32 @asprintf(i8** %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %7
%15 = call i32 (i32, i8*, ...) @err(i32 1, i8* null)
br label %16
16: ; preds = %14, %7
%17 = load i8*, i8** %8
%18 = call i32 @execvp(i8* %17, i8** %8)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i8*, i8** %8
%22 = load i8*, i8** %9
%23 = load i8*, i8** %11
%24 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %21, i8* %22, i8* %23)
br label %25
25: ; preds = %16, %20, %1
ret void
}