#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("\n\nVirtual address mapping:\n");
    printf("----------------------------\n");
    printf("1) Enter parameters\n");
    printf("2) Map virtual address\n");
    printf("3) Print page table\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    0xeaa(%rip),%rdi
call   1040 <printf@plt>
lea    0xebc(%rip),%rdi
call   1040 <printf@plt>
lea    0xec5(%rip),%rdi
call   1040 <printf@plt>
lea    0xed1(%rip),%rdi
call   1040 <printf@plt>
lea    0xeda(%rip),%rdi
call   1040 <printf@plt>
lea    0xed8(%rip),%rdi
call   1040 <printf@plt>
lea    0xede(%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    0xe67(%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    0xf06(%rip),%rbx
lea    0xf13(%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    0xe76(%rip),%rdi
call   1040 <puts@plt>
lea    0xe87(%rip),%rdi
call   1040 <puts@plt>
lea    0xe8f(%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 = [28 x i8] c"\0A\0AVirtual address mapping:\0A\00"
@.str.1 = [30 x i8] c"----------------------------\0A\00"
@.str.2 = [21 x i8] c"1) Enter parameters\0A\00"
@.str.3 = [24 x i8] c"2) Map virtual address\0A\00"
@.str.4 = [21 x i8] c"3) Print page table\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 ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 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 = [27 x i8] c"\0A\0AVirtual address mapping:\00"
@str.9 = [29 x i8] c"----------------------------\00"
@str.10 = [20 x i8] c"1) Enter parameters\00"
@str.11 = [23 x i8] c"2) Map virtual address\00"
@str.12 = [20 x i8] c"3) Print page table\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 ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.9, i64 0, i64 0))
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.10, i64 0, i64 0))
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.11, i64 0, i64 0))
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 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
}