#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 fork();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main() {
  char command1[] = "java -cp \".:./JLex\" JLex.Main "
                    "/Users/javon/Desktop/School/Language_Processors/"
                    "assignment_2/hpl-eval-pset/src/hpl/lang/HPLLexer";
  char command2[] = "java -jar java_cup.jar -parser HPLParser "
                    "/Users/javon/Desktop/School/Language_Processors/"
                    "assignment_2/hpl-eval-pset/src/hpl/lang/HPLParser.cup";
  char command3[] = "mv *.java hpl/lang";
  char command4[] = "find . -name \"*.java\" > sources.txt";
  char command5[] = "javac -cp \"java_cup.runtime.jar:.\" @sources.txt";
  char command6[] = "java -cp \"java_cup.runtime.jar:.\" hpl/sys/HPLRepl";
  int pid, pid2, pid3, pid4;
  pid = fork();
  if (pid == 0) {
    system(command1);
    printf("Lexer ran successfully\n");
    pid2 = fork();
    if (pid2 == 0) {
      system(command2);
      printf("Parser ran successfully\n");
    } else {
      wait(NULL);
      pid3 = fork();
      if (pid3 == 0) {
        system(command3);
        printf("Moved HPLParser.java and sym.java\n");
      } else {
        wait(NULL);
        pid4 = fork();
        if (pid4 == 0) {
          system(command4);
          printf("Generated location to java files\n");
        } else {
          wait(NULL);
          system(command5);
          printf("Compiled all classes successfully\n");
        }
      }
    }
  } else if (pid > 0) {
    wait(NULL);
    system(command6);
    printf("Program ran successfully\n");
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x90(%rbp),%rdi
lea    0xe90(%rip),%rsi
mov    $0x7f,%edx
call   1050 <memcpy@plt>
lea    -0x120(%rbp),%rdi
lea    0xef8(%rip),%rsi
mov    $0x8f,%edx
call   1050 <memcpy@plt>
mov    0xf77(%rip),%rax
mov    %rax,-0x140(%rbp)
mov    0xf71(%rip),%rax
mov    %rax,-0x138(%rbp)
mov    0xf6b(%rip),%ax
mov    %ax,-0x130(%rbp)
mov    0xf60(%rip),%al
mov    %al,-0x12e(%rbp)
lea    -0x170(%rbp),%rdi
lea    0xf5a(%rip),%rsi
mov    $0x24,%edx
call   1050 <memcpy@plt>
lea    -0x1a0(%rbp),%rdi
lea    0xf72(%rip),%rsi
mov    $0x30,%edx
call   1050 <memcpy@plt>
lea    -0x1e0(%rbp),%rdi
lea    0xf8a(%rip),%rsi
mov    $0x32,%edx
call   1050 <memcpy@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x1e4(%rbp)
cmpl   $0x0,-0x1e4(%rbp)
jne    1329 <main+0x1d9>
lea    -0x90(%rbp),%rdi
call   1030 <system@plt>
lea    0xf85(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x1e8(%rbp)
cmpl   $0x0,-0x1e8(%rbp)
jne    1279 <main+0x129>
lea    -0x120(%rbp),%rdi
call   1030 <system@plt>
lea    0xf6b(%rip),%rdi
call   1040 <printf@plt>
jmp    1324 <main+0x1d4>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x1ec(%rbp)
cmpl   $0x0,-0x1ec(%rbp)
jne    12b9 <main+0x169>
lea    -0x140(%rbp),%rdi
call   1030 <system@plt>
lea    0xf44(%rip),%rdi
call   1040 <printf@plt>
jmp    131f <main+0x1cf>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x1f0(%rbp)
cmpl   $0x0,-0x1f0(%rbp)
jne    12f9 <main+0x1a9>
lea    -0x170(%rbp),%rdi
call   1030 <system@plt>
lea    0xf27(%rip),%rdi
call   1040 <printf@plt>
jmp    131a <main+0x1ca>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
lea    -0x1a0(%rbp),%rdi
call   1030 <system@plt>
lea    0xf23(%rip),%rdi
call   1040 <printf@plt>
jmp    131f <main+0x1cf>
jmp    1324 <main+0x1d4>
jmp    135c <main+0x20c>
cmpl   $0x0,-0x1e4(%rbp)
jle    1357 <main+0x207>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
lea    -0x1e0(%rbp),%rdi
call   1030 <system@plt>
lea    0xf09(%rip),%rdi
call   1040 <printf@plt>
jmp    135c <main+0x20c>
xor    %eax,%eax
add    $0x1f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x1d8,%rsp
movups 0xf0e(%rip),%xmm0
movups %xmm0,0x12f(%rsp)
movaps 0xef0(%rip),%xmm0
movaps %xmm0,0x120(%rsp)
movaps 0xed1(%rip),%xmm0
movaps %xmm0,0x110(%rsp)
movaps 0xeb2(%rip),%xmm0
movaps %xmm0,0x100(%rsp)
movaps 0xe93(%rip),%xmm0
movaps %xmm0,0xf0(%rsp)
movaps 0xe74(%rip),%xmm0
movaps %xmm0,0xe0(%rsp)
movaps 0xe55(%rip),%xmm0
movaps %xmm0,0xd0(%rsp)
movaps 0xe36(%rip),%xmm0
movaps %xmm0,0xc0(%rsp)
lea    0xea7(%rip),%rsi
lea    0x140(%rsp),%rbx
mov    $0x8f,%edx
mov    %rbx,%rdi
call   1050 <memcpy@plt>
movaps 0xf1b(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x676e61,0xf(%rsp)
movaps 0xf38(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xf1c(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movl   $0x747874,0x40(%rsp)
movaps 0xf58(%rip),%xmm0
movaps %xmm0,0xb0(%rsp)
movaps 0xf39(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
movaps 0xf1a(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xf5b(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xf3f(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xf23(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movw   $0x6c,0x80(%rsp)
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     12a2 <main+0x152>
jle    132c <main+0x1dc>
lea    0x50(%rsp),%rbx
lea    0xf29(%rip),%r14
xor    %edi,%edi
call   1060 <wait@plt>
jmp    131c <main+0x1cc>
lea    0xc0(%rsp),%rdi
call   1040 <system@plt>
lea    0xf25(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     12fb <main+0x1ab>
xor    %edi,%edi
call   1060 <wait@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     1304 <main+0x1b4>
xor    %edi,%edi
call   1060 <wait@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     1310 <main+0x1c0>
lea    0x90(%rsp),%rbx
lea    0xef9(%rip),%r14
jmp    1299 <main+0x149>
lea    0xf55(%rip),%r14
jmp    131c <main+0x1cc>
mov    %rsp,%rbx
lea    0xf27(%rip),%r14
jmp    131c <main+0x1cc>
lea    0x20(%rsp),%rbx
lea    0xef8(%rip),%r14
mov    %rbx,%rdi
call   1040 <system@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x1d8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.command1 = [127 x i8] c"java -cp \22.:./JLex\22 JLex.Main /Users/javon/Desktop/School/Language_Processors/assignment_2/hpl-eval-pset/src/hpl/lang/HPLLexer\00"
@__const.main.command2 = [143 x i8] c"java -jar java_cup.jar -parser HPLParser /Users/javon/Desktop/School/Language_Processors/assignment_2/hpl-eval-pset/src/hpl/lang/HPLParser.cup\00"
@__const.main.command3 = [19 x i8] c"mv *.java hpl/lang\00"
@__const.main.command4 = [36 x i8] c"find . -name \22*.java\22 > sources.txt\00"
@__const.main.command5 = [48 x i8] c"javac -cp \22java_cup.runtime.jar:.\22 @sources.txt\00"
@__const.main.command6 = [50 x i8] c"java -cp \22java_cup.runtime.jar:.\22 hpl/sys/HPLRepl\00"
@.str = [24 x i8] c"Lexer ran successfully\0A\00"
@.str.1 = [25 x i8] c"Parser ran successfully\0A\00"
@.str.2 = [35 x i8] c"Moved HPLParser.java and sym.java\0A\00"
@.str.3 = [34 x i8] c"Generated location to java files\0A\00"
@.str.4 = [35 x i8] c"Compiled all classes successfully\0A\00"
@.str.5 = [26 x i8] c"Program ran successfully\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [127 x i8]
%3 = alloca [143 x i8]
%4 = alloca [19 x i8]
%5 = alloca [36 x i8]
%6 = alloca [48 x i8]
%7 = alloca [50 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %1
%12 = bitcast [127 x i8]* %2 to i8*
%13 = bitcast [143 x i8]* %3 to i8*
%14 = bitcast [19 x i8]* %4 to i8*
%15 = bitcast [36 x i8]* %5 to i8*
%16 = bitcast [48 x i8]* %6 to i8*
%17 = bitcast [50 x i8]* %7 to i8*
%18 = call i32 (...) @fork()
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %58
21: ; preds = %0
%22 = getelementptr inbounds [127 x i8], [127 x i8]* %2, i64 0, i64 0
%23 = call i32 @system(i8* %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%25 = call i32 (...) @fork()
store i32 %25, i32* %9
%26 = load i32, i32* %9
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %21
%29 = getelementptr inbounds [143 x i8], [143 x i8]* %3, i64 0, i64 0
%30 = call i32 @system(i8* %29)
%31 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %57
32: ; preds = %21
%33 = call i32 @wait(i32* null)
%34 = call i32 (...) @fork()
store i32 %34, i32* %10
%35 = load i32, i32* %10
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %32
%38 = getelementptr inbounds [19 x i8], [19 x i8]* %4, i64 0, i64 0
%39 = call i32 @system(i8* %38)
%40 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
br label %56
41: ; preds = %32
%42 = call i32 @wait(i32* null)
%43 = call i32 (...) @fork()
store i32 %43, i32* %11
%44 = load i32, i32* %11
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %41
%47 = getelementptr inbounds [36 x i8], [36 x i8]* %5, i64 0, i64 0
%48 = call i32 @system(i8* %47)
%49 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
br label %55
50: ; preds = %41
%51 = call i32 @wait(i32* null)
%52 = getelementptr inbounds [48 x i8], [48 x i8]* %6, i64 0, i64 0
%53 = call i32 @system(i8* %52)
%54 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
br label %55
55: ; preds = %50, %46
br label %56
56: ; preds = %55, %37
br label %57
57: ; preds = %56, %28
br label %67
58: ; preds = %0
%59 = load i32, i32* %8
%60 = icmp sgt i32 %59, 0
br i1 %60, label %61, label %66
61: ; preds = %58
%62 = call i32 @wait(i32* null)
%63 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%64 = call i32 @system(i8* %63)
%65 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
br label %66
66: ; preds = %61, %58
br label %67
67: ; preds = %66, %57
ret i32 0
}

LLVM IR (-O2):
@__const.main.command1 = [127 x i8] c"java -cp \22.:./JLex\22 JLex.Main /Users/javon/Desktop/School/Language_Processors/assignment_2/hpl-eval-pset/src/hpl/lang/HPLLexer\00"
@__const.main.command2 = [143 x i8] c"java -jar java_cup.jar -parser HPLParser /Users/javon/Desktop/School/Language_Processors/assignment_2/hpl-eval-pset/src/hpl/lang/HPLParser.cup\00"
@__const.main.command3 = [19 x i8] c"mv *.java hpl/lang\00"
@__const.main.command4 = [36 x i8] c"find . -name \22*.java\22 > sources.txt\00"
@__const.main.command5 = [48 x i8] c"javac -cp \22java_cup.runtime.jar:.\22 @sources.txt\00"
@__const.main.command6 = [50 x i8] c"java -cp \22java_cup.runtime.jar:.\22 hpl/sys/HPLRepl\00"
@str = [25 x i8] c"Program ran successfully\00"
@str.6 = [23 x i8] c"Lexer ran successfully\00"
@str.7 = [34 x i8] c"Compiled all classes successfully\00"
@str.8 = [33 x i8] c"Generated location to java files\00"
@str.9 = [34 x i8] c"Moved HPLParser.java and sym.java\00"
@str.10 = [24 x i8] c"Parser ran successfully\00"
define i32 @main() {
%1 = alloca [127 x i8]
%2 = alloca [143 x i8]
%3 = alloca [19 x i8]
%4 = alloca [36 x i8]
%5 = alloca [48 x i8]
%6 = alloca [50 x i8]
%7 = getelementptr inbounds [127 x i8], [127 x i8]* %1, i64 0, i64 0
%8 = getelementptr inbounds [143 x i8], [143 x i8]* %2, i64 0, i64 0
%9 = getelementptr inbounds [19 x i8], [19 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [36 x i8], [36 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%13 = tail call i32 (...) @fork()
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %28
15: ; preds = %0
%16 = call i32 @system(i8* %7)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.6, i64 0, i64 0))
%18 = tail call i32 (...) @fork()
%19 = icmp eq i32 %18, 0
br i1 %19, label %34, label %20
20: ; preds = %15
%21 = tail call i32 @wait(i32* null)
%22 = tail call i32 (...) @fork()
%23 = icmp eq i32 %22, 0
br i1 %23, label %34, label %24
24: ; preds = %20
%25 = tail call i32 @wait(i32* null)
%26 = tail call i32 (...) @fork()
%27 = icmp eq i32 %26, 0
br i1 %27, label %34, label %30
28: ; preds = %0
%29 = icmp sgt i32 %13, 0
br i1 %29, label %30, label %39
30: ; preds = %28, %24
%31 = phi i8* [ %11, %24 ], [ %12, %28 ]
%32 = phi i8* [ getelementptr inbounds ([34 x i8], [34 x i8]* @str.7, i64 0, i64 0), %24 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0), %28 ]
%33 = tail call i32 @wait(i32* null)
br label %34
34: ; preds = %30, %24, %20, %15
%35 = phi i8* [ %8, %15 ], [ %9, %20 ], [ %10, %24 ], [ %31, %30 ]
%36 = phi i8* [ getelementptr inbounds ([24 x i8], [24 x i8]* @str.10, i64 0, i64 0), %15 ], [ getelementptr inbounds ([34 x i8], [34 x i8]* @str.9, i64 0, i64 0), %20 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @str.8, i64 0, i64 0), %24 ], [ %32, %30 ]
%37 = call i32 @system(i8* %35)
%38 = tail call i32 @puts(i8* dereferenceable(1) %36)
br label %39
39: ; preds = %34, %28
ret i32 0
}