#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 */
char getchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ query();
int /*<<< orphan*/ registerObject();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ unregisterObject();
int mainMenu(void) {
  int option = -1;
  printf("Welcome\n");
  printf("1. Register\n");
  printf("2. Unregister\n");
  printf("3. Query\n");
  printf("4. Exit\n");
  printf("\nOption: ");
  scanf("%d", &option);
  switch (option) {
  case 1:
    registerObject();
    break;
  case 2:
    unregisterObject();
    break;
  case 3:
    query();
    break;
  case 4:
    printf("All done!\n");
    break;
  default:
    while (getchar() != '\n')
      ;
    break;
  }
  return option;
}


x86 assembly (clang, -O0):
<mainMenu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xffffffff,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
lea    0xe98(%rip),%rdi
call   1040 <printf@plt>
lea    0xe9b(%rip),%rdi
call   1040 <printf@plt>
lea    0xe99(%rip),%rdi
call   1040 <printf@plt>
lea    0xe96(%rip),%rdi
call   1040 <printf@plt>
lea    0xe94(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x3,%eax
ja     1225 <mainMenu+0xc5>
mov    -0x10(%rbp),%rax
lea    0xe19(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1080 <registerObject@plt>
jmp    1247 <mainMenu+0xe7>
mov    $0x0,%al
call   1030 <unregisterObject@plt>
jmp    1247 <mainMenu+0xe7>
mov    $0x0,%al
call   1060 <query@plt>
jmp    1247 <mainMenu+0xe7>
lea    0xe3a(%rip),%rdi
call   1040 <printf@plt>
jmp    1247 <mainMenu+0xe7>
jmp    122a <mainMenu+0xca>
mov    $0x0,%al
call   1050 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     1242 <mainMenu+0xe2>
jmp    122a <mainMenu+0xca>
jmp    1247 <mainMenu+0xe7>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mainMenu>:
push   %rax
movl   $0xffffffff,0x4(%rsp)
ff
lea    0xe9d(%rip),%rdi
call   1030 <puts@plt>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
lea    0xe54(%rip),%rdi
call   1050 <printf@plt>
lea    0xe52(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1080 <scanf@plt>
mov    0x4(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x3,%eax
ja     1200 <mainMenu+0x90>
lea    0xe1b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
xor    %eax,%eax
call   1090 <registerObject@plt>
jmp    122b <mainMenu+0xbb>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%al
jne    1200 <mainMenu+0x90>
jmp    122b <mainMenu+0xbb>
xor    %eax,%eax
call   1040 <unregisterObject@plt>
jmp    122b <mainMenu+0xbb>
xor    %eax,%eax
call   1070 <query@plt>
jmp    122b <mainMenu+0xbb>
lea    0xe2a(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"Welcome\0A\00"
@.str.1 = [13 x i8] c"1. Register\0A\00"
@.str.2 = [15 x i8] c"2. Unregister\0A\00"
@.str.3 = [10 x i8] c"3. Query\0A\00"
@.str.4 = [9 x i8] c"4. Exit\0A\00"
@.str.5 = [10 x i8] c"\0AOption: \00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [11 x i8] c"All done!\0A\00"
define i32 @mainMenu() {
%1 = alloca i32
store i32 -1, i32* %1
%2 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%3 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%5 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %1)
%9 = load i32, i32* %1
switch i32 %9, label %18 [
i32 1, label %10
i32 2, label %12
i32 3, label %14
i32 4, label %16
]
10: ; preds = %0
%11 = call i32 (...) @registerObject()
br label %25
12: ; preds = %0
%13 = call i32 (...) @unregisterObject()
br label %25
14: ; preds = %0
%15 = call i32 (...) @query()
br label %25
16: ; preds = %0
%17 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %25
18: ; preds = %0
br label %19
19: ; preds = %23, %18
%20 = call signext i8 (...) @getchar()
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 10
br i1 %22, label %23, label %24
23: ; preds = %19
br label %19
24: ; preds = %19
br label %25
25: ; preds = %24, %16, %14, %12, %10
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str.5 = [10 x i8] c"\0AOption: \00"
@.str.6 = [3 x i8] c"%d\00"
@str = [8 x i8] c"Welcome\00"
@str.8 = [12 x i8] c"1. Register\00"
@str.9 = [14 x i8] c"2. Unregister\00"
@str.10 = [9 x i8] c"3. Query\00"
@str.11 = [8 x i8] c"4. Exit\00"
@str.12 = [10 x i8] c"All done!\00"
define i32 @mainMenu() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 -1, i32* %1
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.8, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.9, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.10, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.11, i64 0, i64 0))
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %1)
%10 = load i32, i32* %1
switch i32 %10, label %19 [
i32 1, label %11
i32 2, label %13
i32 3, label %15
i32 4, label %17
]
11: ; preds = %0
%12 = call i32 (...) @registerObject()
br label %22
13: ; preds = %0
%14 = call i32 (...) @unregisterObject()
br label %22
15: ; preds = %0
%16 = call i32 (...) @query()
br label %22
17: ; preds = %0
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.12, i64 0, i64 0))
br label %22
19: ; preds = %0, %19
%20 = call signext i8 (...) @getchar()
%21 = icmp eq i8 %20, 10
br i1 %21, label %22, label %19
22: ; preds = %19, %17, %15, %13, %11
%23 = load i32, i32* %1
ret i32 %23
}