#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 predict(double);
int /*<<< orphan*/ printf(char *, ...);
double revenue(int);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ system(char *);
int task2_main(void) {
  int option = 0, task_state = 0;
  int year = 0;
  double money = 0;
  while (task_state >= 0) {
    option = display_standard_menu(
        "Lab 7, Task 2: Main Menu",
        "1. Calculate Revenue\n2. Predict Year\n3. Exit Task 2", 'i', 3, 1);
    if (option == 1) {
      printf("Year to Calculate Revenue? ");
      scanf(" %d", &year);
      money = revenue(year);
      printf("Revenue for %d is $.2%lf million.\n\n", year, money);
      system("pause");
    } else if (option == 2) {
      printf("Revenue? ");
      scanf(" %lf", &money);
      year = predict(money);
      printf("Revenue will pass $%.2lf million in %d.\n\n", money, year);
      system("pause");
    } else if (option == 3) {
      task_state = -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<task2_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1291 <task2_main+0x131>
lea    0xe6a(%rip),%rdi
lea    0xe7c(%rip),%rsi
mov    $0x69,%edx
mov    $0x3,%ecx
mov    $0x1,%r8d
call   1060 <display_standard_menu@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x1,-0x4(%rbp)
jne    1213 <task2_main+0xb3>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe95(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0xc(%rbp),%edi
call   1030 <revenue@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%esi
movsd  -0x18(%rbp),%xmm0
lea    0xe72(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xe88(%rip),%rdi
call   1040 <system@plt>
jmp    128c <task2_main+0x12c>
cmpl   $0x2,-0x4(%rbp)
jne    1271 <task2_main+0x111>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe65(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
movsd  -0x18(%rbp),%xmm0
call   1070 <predict@plt>
mov    %eax,-0xc(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0xc(%rbp),%esi
lea    0xe43(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xe2a(%rip),%rdi
call   1040 <system@plt>
jmp    1287 <task2_main+0x127>
cmpl   $0x3,-0x4(%rbp)
jne    1282 <task2_main+0x122>
movl   $0xffffffff,-0x8(%rbp)
jmp    1287 <task2_main+0x127>
jmp    128c <task2_main+0x12c>
jmp    1185 <task2_main+0x25>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<task2_main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0xc(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe7a(%rip),%r14
lea    0xe8c(%rip),%rbx
lea    0xefd(%rip),%r15
lea    0xefc(%rip),%r13
lea    0x10(%rsp),%rbp
lea    0xef5(%rip),%r12
jmp    11f4 <task2_main+0x94>
nopl   0x0(%rax)
lea    0xea8(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
movsd  0x10(%rsp),%xmm0
call   1070 <predict@plt>
mov    %eax,0xc(%rsp)
movsd  0x10(%rsp),%xmm0
mov    %r12,%rdi
mov    %eax,%esi
mov    $0x1,%al
call   1050 <printf@plt>
mov    %r15,%rdi
call   1040 <system@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x69,%edx
mov    $0x3,%ecx
mov    $0x1,%r8d
call   1060 <display_standard_menu@plt>
cmp    $0x1,%eax
je     1220 <task2_main+0xc0>
cmp    $0x2,%eax
je     11b0 <task2_main+0x50>
cmp    $0x3,%eax
jne    11f4 <task2_main+0x94>
jmp    1264 <task2_main+0x104>
lea    0xe26(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe34(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0xc(%rsp),%edi
call   1030 <revenue@plt>
movsd  %xmm0,0x10(%rsp)
mov    0xc(%rsp),%esi
lea    0xe12(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
jmp    11ec <task2_main+0x8c>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Lab 7, Task 2: Main Menu\00"
@.str.1 = [52 x i8] c"1. Calculate Revenue\0A2. Predict Year\0A3. Exit Task 2\00"
@.str.2 = [28 x i8] c"Year to Calculate Revenue? \00"
@.str.3 = [4 x i8] c" %d\00"
@.str.4 = [36 x i8] c"Revenue for %d is $.2%lf million.\0A\0A\00"
@.str.5 = [6 x i8] c"pause\00"
@.str.6 = [10 x i8] c"Revenue? \00"
@.str.7 = [5 x i8] c" %lf\00"
@.str.8 = [42 x i8] c"Revenue will pass $%.2lf million in %d.\0A\0A\00"
define i32 @task2_main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store double 0.000000e+00, double* %4
br label %5
5: ; preds = %39, %0
%6 = load i32, i32* %2
%7 = icmp sge i32 %6, 0
br i1 %7, label %8, label %40
8: ; preds = %5
%9 = call i32 @display_standard_menu(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i8 signext 105, i32 3, i32 1)
store i32 %9, i32* %1
%10 = load i32, i32* %1
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %21
12: ; preds = %8
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%15 = load i32, i32* %3
%16 = call double @revenue(i32 %15)
store double %16, double* %4
%17 = load i32, i32* %3
%18 = load double, double* %4
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i32 %17, double %18)
%20 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %39
21: ; preds = %8
%22 = load i32, i32* %1
%23 = icmp eq i32 %22, 2
br i1 %23, label %24, label %33
24: ; preds = %21
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%26 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), double* %4)
%27 = load double, double* %4
%28 = call i32 @predict(double %27)
store i32 %28, i32* %3
%29 = load double, double* %4
%30 = load i32, i32* %3
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.8, i64 0, i64 0), double %29, i32 %30)
%32 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %38
33: ; preds = %21
%34 = load i32, i32* %1
%35 = icmp eq i32 %34, 3
br i1 %35, label %36, label %37
36: ; preds = %33
store i32 -1, i32* %2
br label %37
37: ; preds = %36, %33
br label %38
38: ; preds = %37, %24
br label %39
39: ; preds = %38, %12
br label %5
40: ; preds = %5
ret i32 0
}

LLVM IR (-O2):
@.str = [25 x i8] c"Lab 7, Task 2: Main Menu\00"
@.str.1 = [52 x i8] c"1. Calculate Revenue\0A2. Predict Year\0A3. Exit Task 2\00"
@.str.2 = [28 x i8] c"Year to Calculate Revenue? \00"
@.str.3 = [4 x i8] c" %d\00"
@.str.4 = [36 x i8] c"Revenue for %d is $.2%lf million.\0A\0A\00"
@.str.5 = [6 x i8] c"pause\00"
@.str.6 = [10 x i8] c"Revenue? \00"
@.str.7 = [5 x i8] c" %lf\00"
@.str.8 = [42 x i8] c"Revenue will pass $%.2lf million in %d.\0A\0A\00"
define i32 @task2_main() {
%1 = alloca i32
%2 = alloca double
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = bitcast double* %2 to i8*
store double 0.000000e+00, double* %2
br label %5
5: ; preds = %23, %0
%6 = call i32 @display_standard_menu(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i8 signext 105, i32 3, i32 1)
switch i32 %6, label %23 [
i32 1, label %7
i32 2, label %14
i32 3, label %24
]
7: ; preds = %5
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%10 = load i32, i32* %1
%11 = call double @revenue(i32 %10)
store double %11, double* %2
%12 = load i32, i32* %1
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i32 %12, double %11)
br label %21
14: ; preds = %5
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), double* %2)
%17 = load double, double* %2
%18 = call i32 @predict(double %17)
store i32 %18, i32* %1
%19 = load double, double* %2
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.8, i64 0, i64 0), double %19, i32 %18)
br label %21
21: ; preds = %7, %14
%22 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %23
23: ; preds = %21, %5
br label %5
24: ; preds = %5
ret i32 0
}