#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ execvp(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
scalar_t__ wait(int *);
void runCommand(char *command, char **args) {
  pid_t childPid;
  int status;
  if ((childPid = fork()) < 0) {
    fprintf(stderr, "Not possible to create child process\n");
    exit(EXIT_FAILURE);
  } else if (childPid == 0) {
    if (execvp(command, args) < 0) {
      fprintf(stderr, "Not possible to execute %s\n", command);
      perror("[ERROR]");
      exit(EXIT_FAILURE);
    }
  } else if (childPid < 0) {
    fprintf(stderr, "Not possible to fork\n");
  } else {
    while (wait(&status) != childPid)
      ;
  }
}


x86 assembly (clang, -O0):
<runCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    11aa <runCommand+0x4a>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1206 <runCommand+0xa6>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <execvp@plt>
cmp    $0x0,%rax
jge    1201 <runCommand+0xa1>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe46(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
lea    0xe54(%rip),%rdi
call   1040 <perror@plt>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
jmp    1254 <runCommand+0xf4>
cmpq   $0x0,-0x18(%rbp)
jge    122d <runCommand+0xcd>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    124f <runCommand+0xef>
jmp    1232 <runCommand+0xd2>
lea    -0x1c(%rbp),%rdi
call   1070 <wait@plt>
cmp    -0x18(%rbp),%rax
je     124a <runCommand+0xea>
jmp    1232 <runCommand+0xd2>
jmp    124f <runCommand+0xef>
jmp    1254 <runCommand+0xf4>
jmp    1259 <runCommand+0xf9>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runCommand>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
js     11b9 <runCommand+0x59>
je     119f <runCommand+0x3f>
mov    %rax,%rbx
lea    0xc(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1070 <wait@plt>
cmp    %rbx,%rax
jne    1190 <runCommand+0x30>
jmp    11af <runCommand+0x4f>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <execvp@plt>
test   %rax,%rax
js     11d2 <runCommand+0x72>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe37(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11f8 <runCommand+0x98>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0xe4f(%rip),%rdi
call   1040 <perror@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [38 x i8] c"Not possible to create child process\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [28 x i8] c"Not possible to execute %s\0A\00"
@.str.2 = [8 x i8] c"[ERROR]\00"
@.str.3 = [22 x i8] c"Not possible to fork\0A\00"
define void @runCommand(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %3
store i8** %1, i8*** %4
%7 = call i64 (...) @fork()
store i64 %7, i64* %5
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = load i64, i64* %5
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %30
17: ; preds = %14
%18 = load i8*, i8** %3
%19 = load i8**, i8*** %4
%20 = call i64 @execvp(i8* %18, i8** %19)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %3
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %17
br label %44
30: ; preds = %14
%31 = load i64, i64* %5
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %43
36: ; preds = %30
br label %37
37: ; preds = %41, %36
%38 = call i64 @wait(i32* %6)
%39 = load i64, i64* %5
%40 = icmp ne i64 %38, %39
br i1 %40, label %41, label %42
41: ; preds = %37
br label %37
42: ; preds = %37
br label %43
43: ; preds = %42, %33
br label %44
44: ; preds = %43, %29
br label %45
45: ; preds = %44
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [38 x i8] c"Not possible to create child process\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [28 x i8] c"Not possible to execute %s\0A\00"
@.str.2 = [8 x i8] c"[ERROR]\00"
define void @runCommand(i8* %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i64 (...) @fork()
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = icmp eq i64 %5, 0
br i1 %13, label %14, label %23
14: ; preds = %12
%15 = tail call i64 @execvp(i8* %0, i8** %1)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%20 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %12, %23
%24 = call i64 @wait(i32* %3)
%25 = icmp eq i64 %24, %5
br i1 %25, label %26, label %23
26: ; preds = %23, %14
ret void
}