#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 display_standard_menu(char *, char *, int /*<<< orphan*/, int, int);
int task1_main();
int task2_main();
int task3_main();
int main(void) {
  int lab_state = 0, option = 0;
  while (lab_state >= 0) {
    if (lab_state == 0) {
      option = display_standard_menu(
          "Lab 8: Awesome Arrays\nMain Menu",
          "1. Task 1 - Reading a File and Reversing an Array\n2. Task 2 - "
          "Random Array\n3. Task 3 - Project 9\n4. Quit",
          0, 4, 1);
      if (option == 1) {
        lab_state = 1;
      } else if (option == 2) {
        lab_state = 2;
      } else if (option == 3) {
        lab_state = 3;
      } else {
        lab_state = -1;
      }
    } else if (lab_state == 1) {
      lab_state = task1_main();
    } else if (lab_state == 2) {
      lab_state = task2_main();
    } else if (lab_state == 3) {
      lab_state = task3_main();
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1246 <main+0x106>
cmpl   $0x0,-0x8(%rbp)
jne    11ec <main+0xac>
lea    0xe88(%rip),%rdi
lea    0xea1(%rip),%rsi
xor    %edx,%edx
mov    $0x4,%ecx
mov    $0x1,%r8d
call   1040 <display_standard_menu@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    11aa <main+0x6a>
movl   $0x1,-0x8(%rbp)
jmp    11e7 <main+0xa7>
cmpl   $0x2,-0xc(%rbp)
jne    11c0 <main+0x80>
movl   $0x2,-0x8(%rbp)
jmp    11e2 <main+0xa2>
cmpl   $0x3,-0xc(%rbp)
jne    11d6 <main+0x96>
movl   $0x3,-0x8(%rbp)
jmp    11dd <main+0x9d>
movl   $0xffffffff,-0x8(%rbp)
jmp    11e2 <main+0xa2>
jmp    11e7 <main+0xa7>
jmp    1241 <main+0x101>
cmpl   $0x1,-0x8(%rbp)
jne    1205 <main+0xc5>
mov    $0x0,%al
call   1030 <task1_main@plt>
mov    %eax,-0x8(%rbp)
jmp    123c <main+0xfc>
cmpl   $0x2,-0x8(%rbp)
jne    121e <main+0xde>
mov    $0x0,%al
call   1050 <task2_main@plt>
mov    %eax,-0x8(%rbp)
jmp    1237 <main+0xf7>
cmpl   $0x3,-0x8(%rbp)
jne    1232 <main+0xf2>
mov    $0x0,%al
call   1060 <task3_main@plt>
mov    %eax,-0x8(%rbp)
jmp    1237 <main+0xf7>
jmp    123c <main+0xfc>
jmp    1241 <main+0x101>
jmp    115d <main+0x1d>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xeb4(%rip),%rbx
lea    0xebd(%rip),%r14
lea    0xed6(%rip),%r15
xor    %eax,%eax
jmp    1174 <main+0x34>
xchg   %ax,%ax
xor    %eax,%eax
call   1060 <task3_main@plt>
nopw   0x0(%rax,%rax,1)
test   %eax,%eax
js     11c9 <main+0x89>
cmp    $0x3,%eax
ja     1170 <main+0x30>
mov    %eax,%eax
movslq (%rbx,%rax,4),%rax
add    %rbx,%rax
jmp    *%rax
mov    %r14,%rdi
mov    %r15,%rsi
xor    %edx,%edx
mov    $0x4,%ecx
mov    $0x1,%r8d
call   1040 <display_standard_menu@plt>
mov    %eax,%ecx
add    $0xffffffff,%ecx
cmp    $0x3,%ecx
jb     1170 <main+0x30>
jmp    11c9 <main+0x89>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <task1_main@plt>
jmp    1170 <main+0x30>
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <task2_main@plt>
jmp    1170 <main+0x30>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Lab 8: Awesome Arrays\0AMain Menu\00"
@.str.1 = [105 x i8] c"1. Task 1 - Reading a File and Reversing an Array\0A2. Task 2 - Random Array\0A3. Task 3 - Project 9\0A4. Quit\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
br label %4
4: ; preds = %45, %0
%5 = load i32, i32* %2
%6 = icmp sge i32 %5, 0
br i1 %6, label %7, label %46
7: ; preds = %4
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %27
10: ; preds = %7
%11 = call i32 @display_standard_menu(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([105 x i8], [105 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 4, i32 1)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %15
14: ; preds = %10
store i32 1, i32* %2
br label %26
15: ; preds = %10
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 2
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 2, i32* %2
br label %25
19: ; preds = %15
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, 3
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 3, i32* %2
br label %24
23: ; preds = %19
store i32 -1, i32* %2
br label %24
24: ; preds = %23, %22
br label %25
25: ; preds = %24, %18
br label %26
26: ; preds = %25, %14
br label %45
27: ; preds = %7
%28 = load i32, i32* %2
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 (...) @task1_main()
store i32 %31, i32* %2
br label %44
32: ; preds = %27
%33 = load i32, i32* %2
%34 = icmp eq i32 %33, 2
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 (...) @task2_main()
store i32 %36, i32* %2
br label %43
37: ; preds = %32
%38 = load i32, i32* %2
%39 = icmp eq i32 %38, 3
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = call i32 (...) @task3_main()
store i32 %41, i32* %2
br label %42
42: ; preds = %40, %37
br label %43
43: ; preds = %42, %35
br label %44
44: ; preds = %43, %30
br label %45
45: ; preds = %44, %26
br label %4
46: ; preds = %4
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"Lab 8: Awesome Arrays\0AMain Menu\00"
@.str.1 = [105 x i8] c"1. Task 1 - Reading a File and Reversing an Array\0A2. Task 2 - Random Array\0A3. Task 3 - Project 9\0A4. Quit\00"
define i32 @main() {
br label %1
1: ; preds = %0, %13
%2 = phi i32 [ 0, %0 ], [ %14, %13 ]
switch i32 %2, label %13 [
i32 0, label %3
i32 1, label %7
i32 2, label %9
i32 3, label %11
]
3: ; preds = %1
%4 = tail call i32 @display_standard_menu(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([105 x i8], [105 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 4, i32 1)
%5 = add i32 %4, -1
%6 = icmp ult i32 %5, 3
br i1 %6, label %13, label %16
7: ; preds = %1
%8 = tail call i32 (...) @task1_main()
br label %13
9: ; preds = %1
%10 = tail call i32 (...) @task2_main()
br label %13
11: ; preds = %1
%12 = tail call i32 (...) @task3_main()
br label %13
13: ; preds = %3, %1, %7, %11, %9
%14 = phi i32 [ %8, %7 ], [ %10, %9 ], [ %12, %11 ], [ %2, %1 ], [ %4, %3 ]
%15 = icmp sgt i32 %14, -1
br i1 %15, label %1, label %16
16: ; preds = %3, %13
ret i32 0
}