#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 *, char, int, int);
int task1_main();
int task2_main();
int main(void) {
  int option = 0, lab_state = 0;
  while (lab_state >= 0) {
    option = display_standard_menu(
        "Lab 7: Main Menu",
        "1. Task 1 - InternetLite\n2. Task 2 - Broadway Revenue\n3. Exit Lab 7",
        'i', 3, 1);
    if (option == 1) {
      lab_state = task1_main();
    } else if (option == 2) {
      lab_state = task2_main();
    } else if (option == 3) {
      lab_state = -1;
    }
  }
  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,-0xc(%rbp)
jl     11cf <main+0x9f>
lea    0xea2(%rip),%rdi
lea    0xeac(%rip),%rsi
mov    $0x69,%edx
mov    $0x3,%ecx
mov    $0x1,%r8d
call   1040 <display_standard_menu@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1196 <main+0x66>
mov    $0x0,%al
call   1030 <task1_main@plt>
mov    %eax,-0xc(%rbp)
jmp    11ca <main+0x9a>
cmpl   $0x2,-0x8(%rbp)
jne    11af <main+0x7f>
mov    $0x0,%al
call   1050 <task2_main@plt>
mov    %eax,-0xc(%rbp)
jmp    11c5 <main+0x95>
cmpl   $0x3,-0x8(%rbp)
jne    11c0 <main+0x90>
movl   $0xffffffff,-0xc(%rbp)
jmp    11c5 <main+0x95>
jmp    11ca <main+0x9a>
jmp    114d <main+0x1d>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xec5(%rip),%r14
lea    0xecf(%rip),%rbx
xor    %ebp,%ebp
jmp    115d <main+0x2d>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <task2_main@plt>
mov    %eax,%ebp
test   %ebp,%ebp
js     1199 <main+0x69>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x69,%edx
mov    $0x3,%ecx
mov    $0x1,%r8d
call   1040 <display_standard_menu@plt>
cmp    $0x1,%eax
je     1190 <main+0x60>
cmp    $0x2,%eax
je     1150 <main+0x20>
cmp    $0x3,%eax
jne    1159 <main+0x29>
jmp    1199 <main+0x69>
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <task1_main@plt>
jmp    1157 <main+0x27>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Lab 7: Main Menu\00"
@.str.1 = [68 x i8] c"1. Task 1 - InternetLite\0A2. Task 2 - Broadway Revenue\0A3. Exit Lab 7\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 = %24, %0
%5 = load i32, i32* %3
%6 = icmp sge i32 %5, 0
br i1 %6, label %7, label %25
7: ; preds = %4
%8 = call i32 @display_standard_menu(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0), i8 signext 105, i32 3, i32 1)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 (...) @task1_main()
store i32 %12, i32* %3
br label %24
13: ; preds = %7
%14 = load i32, i32* %2
%15 = icmp eq i32 %14, 2
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 (...) @task2_main()
store i32 %17, i32* %3
br label %23
18: ; preds = %13
%19 = load i32, i32* %2
%20 = icmp eq i32 %19, 3
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 -1, i32* %3
br label %22
22: ; preds = %21, %18
br label %23
23: ; preds = %22, %16
br label %24
24: ; preds = %23, %11
br label %4
25: ; preds = %4
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"Lab 7: Main Menu\00"
@.str.1 = [68 x i8] c"1. Task 1 - InternetLite\0A2. Task 2 - Broadway Revenue\0A3. Exit Lab 7\00"
define i32 @main() {
br label %1
1: ; preds = %0, %8
%2 = phi i32 [ 0, %0 ], [ %9, %8 ]
%3 = tail call i32 @display_standard_menu(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0), i8 signext 105, i32 3, i32 1)
switch i32 %3, label %8 [
i32 1, label %4
i32 2, label %6
i32 3, label %11
]
4: ; preds = %1
%5 = tail call i32 (...) @task1_main()
br label %8
6: ; preds = %1
%7 = tail call i32 (...) @task2_main()
br label %8
8: ; preds = %1, %6, %4
%9 = phi i32 [ %5, %4 ], [ %7, %6 ], [ %2, %1 ]
%10 = icmp sgt i32 %9, -1
br i1 %10, label %1, label %11
11: ; preds = %1, %8
ret i32 0
}