#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*/ SIGINT;
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ execvp(char *, char **);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
unsigned long getTimestamp();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ quit(int);
int /*<<< orphan*/ resetSignal(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
void runCommand(char *command, char *args[]) {
  int background = 0;
  int i;
  unsigned long startTime;
  pid_t pid = fork();
  if (pid == -1) {
    fprintf(stderr, "Unable to fork.\n");
    quit(1);
  }
  for (i = (5); i >= 0; i--) {
    if (args[i] != NULL) {
      if (strcmp(args[i], "&") == 0) {
        background = 1;
        args[i] = NULL;
      }
      break;
    }
  }
  if (pid == 0) {
    resetSignal(SIGINT);
    resetSignal(SIGTERM);
    execvp(command, args);
    fprintf(stderr, "Unable to start command: %s\n", command);
    quit(1);
  } else if (pid > 0) {
    startTime = getTimestamp();
    printf("Started %s process with pid %d\n",
           background ? "background" : "foreground", pid);
    if (background) {
      return;
    }
    while (waitpid(pid, NULL, 0) == -1)
      ;
    printf("Foreground process %d ended\n", pid);
    printf("Wallclock time: %.3f\n", (getTimestamp() - startTime) / 1000.0);
  }
}


x86 assembly (clang, -O0):
<runCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11dc <runCommand+0x4c>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1060 <quit@plt>
movl   $0x5,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     1251 <runCommand+0xc1>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     123e <runCommand+0xae>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe2e(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1239 <runCommand+0xa9>
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
jmp    1251 <runCommand+0xc1>
jmp    1243 <runCommand+0xb3>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    11e3 <runCommand+0x53>
cmpl   $0x0,-0x24(%rbp)
jne    12ae <runCommand+0x11e>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
call   1040 <resetSignal@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
call   1040 <resetSignal@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <execvp@plt>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdab(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1060 <quit@plt>
jmp    1385 <runCommand+0x1f5>
cmpl   $0x0,-0x24(%rbp)
jle    1380 <runCommand+0x1f0>
mov    $0x0,%al
call   1030 <getTimestamp@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%ecx
lea    0xdbe(%rip),%rsi
lea    0xdac(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
mov    -0x24(%rbp),%edx
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
je     12fb <runCommand+0x16b>
jmp    1385 <runCommand+0x1f5>
jmp    1300 <runCommand+0x170>
mov    -0x24(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1090 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    131c <runCommand+0x18c>
jmp    1300 <runCommand+0x170>
mov    -0x24(%rbp),%esi
lea    0xd70(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x25(%rbp)
call   1050 <printf@plt>
mov    -0x25(%rbp),%al
call   1030 <getTimestamp@plt>
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm0
movaps 0xcc5(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xcc9(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xc92(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xd3a(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
jmp    1385 <runCommand+0x1f5>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runCommand>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
xor    %eax,%eax
call   10b0 <fork@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11cd <runCommand+0x3d>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1060 <quit@plt>
mov    0x28(%r15),%rdi
mov    $0x5,%r12d
test   %rdi,%rdi
jne    1227 <runCommand+0x97>
mov    0x20(%r15),%rdi
mov    $0x4,%r12d
test   %rdi,%rdi
jne    1227 <runCommand+0x97>
mov    0x18(%r15),%rdi
mov    $0x3,%r12d
test   %rdi,%rdi
jne    1227 <runCommand+0x97>
mov    0x10(%r15),%rdi
mov    $0x2,%r12d
test   %rdi,%rdi
jne    1227 <runCommand+0x97>
mov    0x8(%r15),%rdi
mov    $0x1,%r12d
test   %rdi,%rdi
jne    1227 <runCommand+0x97>
mov    (%r15),%rdi
test   %rdi,%rdi
je     1302 <runCommand+0x172>
xor    %r12d,%r12d
lea    0xe0b(%rip),%rsi
call   1070 <strcmp@plt>
mov    $0x1,%bpl
test   %rax,%rax
jne    1245 <runCommand+0xb5>
movq   $0x0,(%r15,%r12,8)
xor    %ebp,%ebp
test   %ebx,%ebx
je     130d <runCommand+0x17d>
jle    12f9 <runCommand+0x169>
xor    %eax,%eax
call   1030 <getTimestamp@plt>
mov    %rax,%r14
lea    0xe1f(%rip),%rax
lea    0xe0d(%rip),%rsi
test   %bpl,%bpl
cmovne %rax,%rsi
lea    0xddf(%rip),%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
test   %bpl,%bpl
je     12f9 <runCommand+0x169>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <waitpid@plt>
cmp    $0xffffffff,%eax
je     1290 <runCommand+0x100>
lea    0xde7(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <getTimestamp@plt>
sub    %r14,%rax
movq   %rax,%xmm1
punpckldq 0xd39(%rip),%xmm1
subpd  0xd41(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
divsd  0xd3d(%rip),%xmm0
lea    0xdc1(%rip),%rdi
mov    $0x1,%al
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%bpl
test   %ebx,%ebx
jne    124d <runCommand+0xbd>
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
call   1040 <resetSignal@plt>
mov    0x2cbe(%rip),%rax
mov    (%rax),%edi
call   1040 <resetSignal@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   10a0 <execvp@plt>
mov    0x2c95(%rip),%rax
mov    (%rax),%edi
lea    0xcf7(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <quit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [17 x i8] c"Unable to fork.\0A\00"
@.str.1 = [2 x i8] c"&\00"
@SIGINT = global i32 0
@SIGTERM = global i32 0
@.str.2 = [29 x i8] c"Unable to start command: %s\0A\00"
@.str.3 = [32 x i8] c"Started %s process with pid %d\0A\00"
@.str.4 = [11 x i8] c"background\00"
@.str.5 = [11 x i8] c"foreground\00"
@.str.6 = [29 x i8] c"Foreground process %d ended\0A\00"
@.str.7 = [22 x i8] c"Wallclock time: %.3f\0A\00"
define void @runCommand(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %3
store i8** %1, i8*** %4
store i32 0, i32* %5
%9 = call i32 (...) @fork()
store i32 %9, i32* %8
%10 = load i32, i32* %8
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @quit(i32 1)
br label %16
16: ; preds = %12, %2
store i32 5, i32* %6
br label %17
17: ; preds = %42, %16
%18 = load i32, i32* %6
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %45
20: ; preds = %17
%21 = load i8**, i8*** %4
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
%25 = load i8*, i8** %24
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %41
27: ; preds = %20
%28 = load i8**, i8*** %4
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
%32 = load i8*, i8** %31
%33 = call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %27
store i32 1, i32* %5
%36 = load i8**, i8*** %4
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
store i8* null, i8** %39
br label %40
40: ; preds = %35, %27
br label %45
41: ; preds = %20
br label %42
42: ; preds = %41
%43 = load i32, i32* %6
%44 = add nsw i32 %43, -1
store i32 %44, i32* %6
br label %17
45: ; preds = %40, %17
%46 = load i32, i32* %8
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %60
48: ; preds = %45
%49 = load i32, i32* @SIGINT
%50 = call i32 @resetSignal(i32 %49)
%51 = load i32, i32* @SIGTERM
%52 = call i32 @resetSignal(i32 %51)
%53 = load i8*, i8** %3
%54 = load i8**, i8*** %4
%55 = call i32 @execvp(i8* %53, i8** %54)
%56 = load i32, i32* @stderr
%57 = load i8*, i8** %3
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %57)
%59 = call i32 @quit(i32 1)
br label %90
60: ; preds = %45
%61 = load i32, i32* %8
%62 = icmp sgt i32 %61, 0
br i1 %62, label %63, label %89
63: ; preds = %60
%64 = call i64 (...) @getTimestamp()
store i64 %64, i64* %7
%65 = load i32, i32* %5
%66 = icmp ne i32 %65, 0
%67 = zext i1 %66 to i64
%68 = select i1 %66, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0)
%69 = load i32, i32* %8
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %68, i32 %69)
%71 = load i32, i32* %5
%72 = icmp ne i32 %71, 0
br i1 %72, label %73, label %74
73: ; preds = %63
br label %90
74: ; preds = %63
br label %75
75: ; preds = %79, %74
%76 = load i32, i32* %8
%77 = call i32 @waitpid(i32 %76, i32* null, i32 0)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %80
79: ; preds = %75
br label %75
80: ; preds = %75
%81 = load i32, i32* %8
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i32 %81)
%83 = call i64 (...) @getTimestamp()
%84 = load i64, i64* %7
%85 = sub i64 %83, %84
%86 = uitofp i64 %85 to double
%87 = fdiv double %86, 1.000000e+03
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), double %87)
br label %89
89: ; preds = %80, %60
br label %90
90: ; preds = %73, %89, %48
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [17 x i8] c"Unable to fork.\0A\00"
@.str.1 = [2 x i8] c"&\00"
@SIGINT = global i32 0
@SIGTERM = global i32 0
@.str.2 = [29 x i8] c"Unable to start command: %s\0A\00"
@.str.3 = [32 x i8] c"Started %s process with pid %d\0A\00"
@.str.4 = [11 x i8] c"background\00"
@.str.5 = [11 x i8] c"foreground\00"
@.str.6 = [29 x i8] c"Foreground process %d ended\0A\00"
@.str.7 = [22 x i8] c"Wallclock time: %.3f\0A\00"
define void @runCommand(i8* %0, i8** %1) {
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @quit(i32 1)
br label %9
9: ; preds = %5, %2
%10 = getelementptr inbounds i8*, i8** %1, i64 5
%11 = load i8*, i8** %10
%12 = icmp eq i8* %11, null
br i1 %12, label %20, label %13
13: ; preds = %36, %32, %28, %24, %20, %9
%14 = phi i64 [ 5, %9 ], [ 4, %20 ], [ 3, %24 ], [ 2, %28 ], [ 1, %32 ], [ 0, %36 ]
%15 = phi i8* [ %11, %9 ], [ %22, %20 ], [ %26, %24 ], [ %30, %28 ], [ %34, %32 ], [ %37, %36 ]
%16 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %39
18: ; preds = %13
%19 = getelementptr inbounds i8*, i8** %1, i64 %14
store i8* null, i8** %19
br label %39
20: ; preds = %9
%21 = getelementptr inbounds i8*, i8** %1, i64 4
%22 = load i8*, i8** %21
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %13
24: ; preds = %20
%25 = getelementptr inbounds i8*, i8** %1, i64 3
%26 = load i8*, i8** %25
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %13
28: ; preds = %24
%29 = getelementptr inbounds i8*, i8** %1, i64 2
%30 = load i8*, i8** %29
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %13
32: ; preds = %28
%33 = getelementptr inbounds i8*, i8** %1, i64 1
%34 = load i8*, i8** %33
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %13
36: ; preds = %32
%37 = load i8*, i8** %1
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %13
39: ; preds = %36, %13, %18
%40 = phi i1 [ true, %13 ], [ false, %18 ], [ true, %36 ]
%41 = icmp eq i32 %3, 0
br i1 %41, label %42, label %51
42: ; preds = %39
%43 = load i32, i32* @SIGINT
%44 = tail call i32 @resetSignal(i32 %43)
%45 = load i32, i32* @SIGTERM
%46 = tail call i32 @resetSignal(i32 %45)
%47 = tail call i32 @execvp(i8* %0, i8** %1)
%48 = load i32, i32* @stderr
%49 = tail call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%50 = tail call i32 @quit(i32 1)
br label %67
51: ; preds = %39
%52 = icmp sgt i32 %3, 0
br i1 %52, label %53, label %67
53: ; preds = %51
%54 = tail call i64 (...) @getTimestamp()
%55 = select i1 %40, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0)
%56 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %55, i32 %3)
br i1 %40, label %57, label %67
57: ; preds = %53, %57
%58 = tail call i32 @waitpid(i32 %3, i32* null, i32 0)
%59 = icmp eq i32 %58, -1
br i1 %59, label %57, label %60
60: ; preds = %57
%61 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i32 %3)
%62 = tail call i64 (...) @getTimestamp()
%63 = sub i64 %62, %54
%64 = uitofp i64 %63 to double
%65 = fdiv double %64, 1.000000e+03
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), double %65)
br label %67
67: ; preds = %42, %60, %51, %53
ret void
}