#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 /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ option_one();
int /*<<< orphan*/ option_three();
int /*<<< orphan*/ option_two();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int choice;
  while (1) {
    printf("\nPipelined/Superscalar instruction performance:\n");
    printf("-----------------------------------------------\n");
    printf("1) Enter instructions\n");
    printf(
        "2) Calculate/chart total cycles on a 6-stage piplined architecture\n");
    printf("3) Calculate/chart total cycles on a 6-stage superscalar "
           "architecture\n");
    printf("4) Quit\n\n");
    printf("Enter selection: ");
    scanf("%d", &choice);
    switch (choice) {
    case 1:
      option_one();
      break;
    case 2:
      option_two();
      break;
    case 3:
      option_three();
      break;
    case 4:
      exit(0);
      break;
    default:
      printf("");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
lea    0xebf(%rip),%rdi
call   1040 <printf@plt>
lea    0xee4(%rip),%rdi
call   1040 <printf@plt>
lea    0xeef(%rip),%rdi
call   1040 <printf@plt>
lea    0xf27(%rip),%rdi
call   1040 <printf@plt>
lea    0xf62(%rip),%rdi
call   1040 <printf@plt>
lea    0xf60(%rip),%rdi
call   1040 <printf@plt>
lea    0xf66(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x3,%eax
ja     1227 <main+0xc7>
mov    -0x10(%rbp),%rax
lea    0xe0d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1080 <option_one@plt>
jmp    1233 <main+0xd3>
mov    $0x0,%al
call   1050 <option_two@plt>
jmp    1233 <main+0xd3>
mov    $0x0,%al
call   1030 <option_three@plt>
jmp    1233 <main+0xd3>
xor    %edi,%edi
call   1070 <exit@plt>
lea    0xeef(%rip),%rdi
call   1040 <printf@plt>
jmp    116f <main+0xf>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xf5c(%rip),%rbx
lea    0xf9b(%rip),%rbp
lea    0xe80(%rip),%r14
lea    0xe8b(%rip),%r15
lea    0x4(%rsp),%r12
lea    0xe5d(%rip),%r13
jmp    11b7 <main+0x47>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1030 <option_three@plt>
lea    0xe67(%rip),%rdi
call   1040 <puts@plt>
lea    0xe8b(%rip),%rdi
call   1040 <puts@plt>
lea    0xeaf(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb9(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <scanf@plt>
mov    0x4(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x3,%eax
ja     11b7 <main+0x47>
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
xor    %eax,%eax
call   1090 <option_one@plt>
jmp    11b7 <main+0x47>
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <option_two@plt>
jmp    11b7 <main+0x47>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [49 x i8] c"\0APipelined/Superscalar instruction performance:\0A\00"
@.str.1 = [49 x i8] c"-----------------------------------------------\0A\00"
@.str.2 = [23 x i8] c"1) Enter instructions\0A\00"
@.str.3 = [68 x i8] c"2) Calculate/chart total cycles on a 6-stage piplined architecture\0A\00"
@.str.4 = [71 x i8] c"3) Calculate/chart total cycles on a 6-stage superscalar architecture\0A\00"
@.str.5 = [10 x i8] c"4) Quit\0A\0A\00"
@.str.6 = [18 x i8] c"Enter selection: \00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [1 x i8] zeroinitializer
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
br label %3
3: ; preds = %0, %23
%4 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.3, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.4, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %2)
%12 = load i32, i32* %2
switch i32 %12, label %21 [
i32 1, label %13
i32 2, label %15
i32 3, label %17
i32 4, label %19
]
13: ; preds = %3
%14 = call i32 (...) @option_one()
br label %23
15: ; preds = %3
%16 = call i32 (...) @option_two()
br label %23
17: ; preds = %3
%18 = call i32 (...) @option_three()
br label %23
19: ; preds = %3
%20 = call i32 @exit(i32 0)
unreachable
21: ; preds = %3
%22 = call i32 @printf(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.8, i64 0, i64 0))
br label %23
23: ; preds = %21, %17, %15, %13
br label %3
}

LLVM IR (-O2):
@.str.6 = [18 x i8] c"Enter selection: \00"
@.str.7 = [3 x i8] c"%d\00"
@str = [48 x i8] c"\0APipelined/Superscalar instruction performance:\00"
@str.9 = [48 x i8] c"-----------------------------------------------\00"
@str.10 = [22 x i8] c"1) Enter instructions\00"
@str.11 = [67 x i8] c"2) Calculate/chart total cycles on a 6-stage piplined architecture\00"
@str.12 = [70 x i8] c"3) Calculate/chart total cycles on a 6-stage superscalar architecture\00"
@str.13 = [9 x i8] c"4) Quit\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %13, %0
%4 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str, i64 0, i64 0))
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.9, i64 0, i64 0))
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.10, i64 0, i64 0))
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str.11, i64 0, i64 0))
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str.12, i64 0, i64 0))
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.13, i64 0, i64 0))
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %1)
%12 = load i32, i32* %1
switch i32 %12, label %13 [
i32 1, label %14
i32 2, label %16
i32 3, label %18
i32 4, label %20
]
13: ; preds = %3, %18, %16, %14
br label %3
14: ; preds = %3
%15 = call i32 (...) @option_one()
br label %13
16: ; preds = %3
%17 = call i32 (...) @option_two()
br label %13
18: ; preds = %3
%19 = call i32 (...) @option_three()
br label %13
20: ; preds = %3
%21 = call i32 @exit(i32 0)
unreachable
}