#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 */
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ build_args_array(char *, char **);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int waitpid(int, int *, int /*<<< orphan*/);
void run_command(char *command) {
  char *args[256 + 1];
  pid_t child;
  int child_stat;
  child = fork();
  if (child == 0) {
    build_args_array(command, args);
    execvp(*args, args);
    fprintf(stderr, "Execvp failed!\n%s\n", strerror(errno));
    exit(EXIT_FAILURE);
  } else if (child == -1) {
    fprintf(stderr, "Fork failed!\n%s\n", strerror(errno));
  }
  if (waitpid(child, &child_stat, 0) == -1) {
    fprintf(stderr, "Error running command!\n%s\n", strerror(errno));
  }
}


x86 assembly (clang, -O0):
<run_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x814(%rbp)
cmpl   $0x0,-0x814(%rbp)
jne    11fc <run_command+0x8c>
mov    -0x8(%rbp),%rdi
lea    -0x810(%rbp),%rsi
call   1040 <build_args_array@plt>
mov    -0x810(%rbp),%rdi
lea    -0x810(%rbp),%rsi
call   1060 <execvp@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x81c(%rbp)
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x81c(%rbp),%edi
mov    %rax,%rdx
lea    0xe17(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
cmpl   $0xffffffff,-0x814(%rbp)
jne    123b <run_command+0xcb>
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x820(%rbp)
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x820(%rbp),%edi
mov    %rax,%rdx
lea    0xddd(%rip),%rsi
call   1030 <fprintf@plt>
jmp    1240 <run_command+0xd0>
mov    -0x814(%rbp),%edi
lea    -0x818(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    128f <run_command+0x11f>
mov    0x2d7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x824(%rbp)
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x824(%rbp),%edi
mov    %rax,%rdx
lea    0xd9a(%rip),%rsi
call   1030 <fprintf@plt>
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_command>:
push   %rbp
push   %r14
push   %rbx
sub    $0x810,%rsp
mov    %rdi,%r14
xor    %eax,%eax
call   1090 <fork@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     11e0 <run_command+0x70>
test   %ebx,%ebx
jne    1208 <run_command+0x98>
mov    %rsp,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <build_args_array@plt>
mov    (%rsp),%rdi
mov    %rbx,%rsi
call   1060 <execvp@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%ebx
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe38(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1030 <fprintf@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%ebp
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe15(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1030 <fprintf@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    1241 <run_command+0xd1>
mov    0x2dc0(%rip),%rax
mov    (%rax),%ebx
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xded(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1030 <fprintf@plt>
add    $0x810,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"Execvp failed!\0A%s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [17 x i8] c"Fork failed!\0A%s\0A\00"
@.str.2 = [27 x i8] c"Error running command!\0A%s\0A\00"
define void @run_command(i8* %0) {
%2 = alloca i8*
%3 = alloca [257 x i8*]
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = call i32 (...) @fork()
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %23
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = getelementptr inbounds [257 x i8*], [257 x i8*]* %3, i64 0, i64 0
%12 = call i32 @build_args_array(i8* %10, i8** %11)
%13 = getelementptr inbounds [257 x i8*], [257 x i8*]* %3, i64 0, i64 0
%14 = load i8*, i8** %13
%15 = getelementptr inbounds [257 x i8*], [257 x i8*]* %3, i64 0, i64 0
%16 = call i32 @execvp(i8* %14, i8** %15)
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %1
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %26, %23
br label %32
32: ; preds = %31
%33 = load i32, i32* %4
%34 = call i32 @waitpid(i32 %33, i32* %5, i32 0)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %41
36: ; preds = %32
%37 = load i32, i32* @stderr
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %36, %32
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"Execvp failed!\0A%s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [17 x i8] c"Fork failed!\0A%s\0A\00"
@.str.2 = [27 x i8] c"Error running command!\0A%s\0A\00"
define void @run_command(i8* %0) {
%2 = alloca [257 x i8*]
%3 = alloca i32
%4 = bitcast [257 x i8*]* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = tail call i32 (...) @fork()
switch i32 %6, label %23 [
i32 0, label %7
i32 -1, label %18
]
7: ; preds = %1
%8 = getelementptr inbounds [257 x i8*], [257 x i8*]* %2, i64 0, i64 0
%9 = call i32 @build_args_array(i8* %0, i8** %8)
%10 = load i8*, i8** %8
%11 = call i32 @execvp(i8* %10, i8** %8)
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %1
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = tail call i8* @strerror(i32 %20)
%22 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %1, %18
%24 = call i32 @waitpid(i32 %6, i32* %3, i32 0)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %26, %23
ret void
}