#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 chdir(char *);
int /*<<< orphan*/ executeCommandWithoutWait(char **);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ runFile(char **);
scalar_t__ strcmp(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, scalar_t__);
char *strtok(char *, char *);
char **tokenize(char *);
int /*<<< orphan*/ waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
void executeInParallel(char *input) {
  char *inputCommands;
  inputCommands = (char *)malloc(1000 * sizeof(char));
  strncpy(inputCommands, input + 9, strlen(input) - 9);
  char *commands;
  commands = strtok(inputCommands, ":");
  char **lolTokens;
  int n = 0;
  while (commands != NULL) {
    n++;
    lolTokens = tokenize(commands);
    if ((strcmp(lolTokens[0], "cd") == 0) ||
        (strcmp(lolTokens[0], " cd") == 0)) {
      if (lolTokens[1] == NULL)
        chdir(getenv("HOME"));
      else if (chdir(lolTokens[1]) == -1)
        perror("Error in parallel chdir");
    } else if (strcmp(lolTokens[0], "run") == 0) {
      runFile(lolTokens);
    } else
      executeCommandWithoutWait(lolTokens);
    commands = strtok(NULL, ":");
  }
  int count = 0;
  while (count != n) {
    waitpid(-1, NULL, 0);
    count++;
  }
  free(inputCommands);
}


x86 assembly (clang, -O0):
<executeInParallel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x3e8,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
add    $0x9,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
sub    $0x9,%rdx
call   1050 <strncpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xdda(%rip),%rsi
call   10e0 <strtok@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1337 <executeInParallel+0x167>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   10b0 <tokenize@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xd9e(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     1291 <executeInParallel+0xc1>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xd80(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    12e5 <executeInParallel+0x115>
mov    -0x20(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    12b9 <executeInParallel+0xe9>
lea    0xd5f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1080 <chdir@plt>
jmp    12e0 <executeInParallel+0x110>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <chdir@plt>
cmp    $0xffffffff,%eax
jne    12db <executeInParallel+0x10b>
lea    0xd35(%rip),%rdi
call   10d0 <perror@plt>
jmp    12e0 <executeInParallel+0x110>
jmp    131e <executeInParallel+0x14e>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xd30(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1310 <executeInParallel+0x140>
mov    -0x20(%rbp),%rdi
call   10f0 <runFile@plt>
jmp    1319 <executeInParallel+0x149>
mov    -0x20(%rbp),%rdi
call   1060 <executeCommandWithoutWait@plt>
jmp    131e <executeInParallel+0x14e>
xor    %eax,%eax
mov    %eax,%edi
lea    0xcd7(%rip),%rsi
call   10e0 <strtok@plt>
mov    %rax,-0x18(%rbp)
jmp    1236 <executeInParallel+0x66>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
je     1368 <executeInParallel+0x198>
mov    $0xffffffff,%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10c0 <waitpid@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    133e <executeInParallel+0x16e>
mov    -0x10(%rbp),%rdi
call   1040 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<executeInParallel>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x3e8,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbp
lea    0x9(%rbx),%r14
mov    %rbx,%rdi
call   1070 <strlen@plt>
lea    -0x9(%rax),%rdx
mov    %rbp,%rdi
mov    %r14,%rsi
call   1050 <strncpy@plt>
lea    0xdf3(%rip),%rsi
mov    %rbp,%rdi
call   10e0 <strtok@plt>
test   %rax,%rax
je     1304 <executeInParallel+0x134>
mov    %rbp,(%rsp)
xor    %r14d,%r14d
lea    0xdd7(%rip),%r13
lea    0xdcd(%rip),%rbx
lea    0xdc8(%rip),%rbp
lea    0xde2(%rip),%r12
jmp    1277 <executeInParallel+0xa7>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xdaf(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1080 <chdir@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   10e0 <strtok@plt>
add    $0x1,%r14d
test   %rax,%rax
je     12eb <executeInParallel+0x11b>
mov    %rax,%rdi
call   10b0 <tokenize@plt>
mov    %rax,%r15
mov    (%rax),%rdi
mov    %r13,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     12c0 <executeInParallel+0xf0>
mov    (%r15),%rdi
mov    %rbp,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     12c0 <executeInParallel+0xf0>
mov    (%r15),%rdi
mov    %r12,%rsi
call   1090 <strcmp@plt>
mov    %r15,%rdi
test   %rax,%rax
je     12e1 <executeInParallel+0x111>
call   1060 <executeCommandWithoutWait@plt>
jmp    1264 <executeInParallel+0x94>
nopl   0x0(%rax)
mov    0x8(%r15),%rdi
test   %rdi,%rdi
je     1250 <executeInParallel+0x80>
call   1080 <chdir@plt>
cmp    $0xffffffff,%eax
jne    1264 <executeInParallel+0x94>
lea    0xd31(%rip),%rdi
call   10d0 <perror@plt>
jmp    1264 <executeInParallel+0x94>
call   10f0 <runFile@plt>
jmp    1264 <executeInParallel+0x94>
mov    (%rsp),%rbp
nop
mov    $0xffffffff,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10c0 <waitpid@plt>
add    $0xffffffff,%r14d
jne    12f0 <executeInParallel+0x120>
mov    %rbp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <free@plt>

LLVM IR (-O0):
@.str = [2 x i8] c":\00"
@.str.1 = [3 x i8] c"cd\00"
@.str.2 = [4 x i8] c" cd\00"
@.str.3 = [5 x i8] c"HOME\00"
@.str.4 = [24 x i8] c"Error in parallel chdir\00"
@.str.5 = [4 x i8] c"run\00"
define void @executeInParallel(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
%8 = call i64 @malloc(i32 1000)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i64 9
%13 = load i8*, i8** %2
%14 = call i64 @strlen(i8* %13)
%15 = sub nsw i64 %14, 9
%16 = call i32 @strncpy(i8* %10, i8* %12, i64 %15)
%17 = load i8*, i8** %3
%18 = call i8* @strtok(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %18, i8** %4
store i32 0, i32* %6
br label %19
19: ; preds = %69, %1
%20 = load i8*, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %71
22: ; preds = %19
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
%25 = load i8*, i8** %4
%26 = call i8** @tokenize(i8* %25)
store i8** %26, i8*** %5
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %38, label %32
32: ; preds = %22
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %56
38: ; preds = %32, %22
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %46
43: ; preds = %38
%44 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%45 = call i32 @chdir(i8* %44)
br label %55
46: ; preds = %38
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = call i32 @chdir(i8* %49)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %54
52: ; preds = %46
%53 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %54
54: ; preds = %52, %46
br label %55
55: ; preds = %54, %43
br label %69
56: ; preds = %32
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 0
%59 = load i8*, i8** %58
%60 = call i64 @strcmp(i8* %59, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %56
%63 = load i8**, i8*** %5
%64 = call i32 @runFile(i8** %63)
br label %68
65: ; preds = %56
%66 = load i8**, i8*** %5
%67 = call i32 @executeCommandWithoutWait(i8** %66)
br label %68
68: ; preds = %65, %62
br label %69
69: ; preds = %68, %55
%70 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %70, i8** %4
br label %19
71: ; preds = %19
store i32 0, i32* %7
br label %72
72: ; preds = %76, %71
%73 = load i32, i32* %7
%74 = load i32, i32* %6
%75 = icmp ne i32 %73, %74
br i1 %75, label %76, label %80
76: ; preds = %72
%77 = call i32 @waitpid(i32 -1, i32* null, i32 0)
%78 = load i32, i32* %7
%79 = add nsw i32 %78, 1
store i32 %79, i32* %7
br label %72
80: ; preds = %72
%81 = load i8*, i8** %3
%82 = call i32 @free(i8* %81)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c":\00"
@.str.1 = [3 x i8] c"cd\00"
@.str.2 = [4 x i8] c" cd\00"
@.str.3 = [5 x i8] c"HOME\00"
@.str.4 = [24 x i8] c"Error in parallel chdir\00"
@.str.5 = [4 x i8] c"run\00"
define void @executeInParallel(i8* %0) {
%2 = tail call i64 @malloc(i32 1000)
%3 = inttoptr i64 %2 to i8*
%4 = getelementptr inbounds i8, i8* %0, i64 9
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = add nsw i64 %5, -9
%7 = tail call i32 @strncpy(i8* %3, i8* %4, i64 %6)
%8 = tail call i8* @strtok(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %50, label %10
10: ; preds = %1, %42
%11 = phi i32 [ %13, %42 ], [ 0, %1 ]
%12 = phi i8* [ %43, %42 ], [ %8, %1 ]
%13 = add nuw nsw i32 %11, 1
%14 = tail call i8** @tokenize(i8* %12)
%15 = load i8*, i8** %14
%16 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %10
%19 = load i8*, i8** %14
%20 = tail call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %34
22: ; preds = %18, %10
%23 = getelementptr inbounds i8*, i8** %14, i64 1
%24 = load i8*, i8** %23
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%28 = tail call i32 @chdir(i8* %27)
br label %42
29: ; preds = %22
%30 = tail call i32 @chdir(i8* %24)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %42
32: ; preds = %29
%33 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %42
34: ; preds = %18
%35 = load i8*, i8** %14
%36 = tail call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = tail call i32 @runFile(i8** %14)
br label %42
40: ; preds = %34
%41 = tail call i32 @executeCommandWithoutWait(i8** %14)
br label %42
42: ; preds = %38, %40, %26, %32, %29
%43 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %10
45: ; preds = %42, %45
%46 = phi i32 [ %48, %45 ], [ 0, %42 ]
%47 = tail call i32 @waitpid(i32 -1, i32* null, i32 0)
%48 = add nuw nsw i32 %46, 1
%49 = icmp eq i32 %46, %11
br i1 %49, label %50, label %45
50: ; preds = %45, %1
%51 = tail call i32 @free(i8* %3)
ret void
}