#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*/ bist();
int /*<<< orphan*/ dump_registers();
char getchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ write_register();
int do_menu() {
  printf("1. Run BIST (No stat)\n");
  printf("2. Dump registers\n");
  printf("3. Write Registers\n");
  printf("4. Quit\n");
  printf("Enter command : ");
  char c = getchar();
  while (c == '\n')
    c = getchar();
  switch (c) {
  case '1':
    bist();
    break;
  case '2':
    dump_registers();
    break;
  case '3':
    write_register();
    break;
  default:
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<do_menu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
lea    0xeac(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb3(%rip),%rdi
call   1030 <printf@plt>
lea    0xebb(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb8(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0xa,%eax
jne    11ba <do_menu+0x6a>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x5(%rbp)
jmp    119e <do_menu+0x4e>
movsbl -0x5(%rbp),%eax
mov    %eax,-0xc(%rbp)
sub    $0x31,%eax
je     11f1 <do_menu+0xa1>
jmp    11cf <do_menu+0x7f>
mov    -0xc(%rbp),%eax
sub    $0x32,%eax
je     11fd <do_menu+0xad>
jmp    11e0 <do_menu+0x90>
mov    -0xc(%rbp),%eax
sub    $0x33,%eax
je     1209 <do_menu+0xb9>
jmp    1215 <do_menu+0xc5>
mov    $0x0,%al
call   1070 <bist@plt>
jmp    1221 <do_menu+0xd1>
mov    $0x0,%al
call   1050 <dump_registers@plt>
jmp    1221 <do_menu+0xd1>
mov    $0x0,%al
call   1060 <write_register@plt>
jmp    1221 <do_menu+0xd1>
movl   $0x1,-0x4(%rbp)
jmp    1228 <do_menu+0xd8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_menu>:
push   %rbx
lea    0xea9(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb3(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb9(%rip),%rdi
call   1030 <puts@plt>
lea    0xec0(%rip),%rdi
call   1030 <puts@plt>
lea    0xe68(%rip),%rdi
call   1040 <printf@plt>
nopl   (%rax)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
je     11a0 <do_menu+0x40>
movsbl %al,%eax
cmp    $0x33,%eax
je     11cd <do_menu+0x6d>
cmp    $0x32,%eax
je     11d8 <do_menu+0x78>
mov    $0x1,%ebx
cmp    $0x31,%eax
jne    11e1 <do_menu+0x81>
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <bist@plt>
jmp    11e1 <do_menu+0x81>
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <write_register@plt>
jmp    11e1 <do_menu+0x81>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <dump_registers@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"1. Run BIST (No stat)\0A\00"
@.str.1 = [19 x i8] c"2. Dump registers\0A\00"
@.str.2 = [20 x i8] c"3. Write Registers\0A\00"
@.str.3 = [9 x i8] c"4. Quit\0A\00"
@.str.4 = [17 x i8] c"Enter command : \00"
define i32 @do_menu() {
%1 = alloca i32
%2 = alloca i8
%3 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%8 = call signext i8 (...) @getchar()
store i8 %8, i8* %2
br label %9
9: ; preds = %13, %0
%10 = load i8, i8* %2
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 10
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call signext i8 (...) @getchar()
store i8 %14, i8* %2
br label %9
15: ; preds = %9
%16 = load i8, i8* %2
%17 = sext i8 %16 to i32
switch i32 %17, label %24 [
i32 49, label %18
i32 50, label %20
i32 51, label %22
]
18: ; preds = %15
%19 = call i32 (...) @bist()
br label %25
20: ; preds = %15
%21 = call i32 (...) @dump_registers()
br label %25
22: ; preds = %15
%23 = call i32 (...) @write_register()
br label %25
24: ; preds = %15
store i32 1, i32* %1
br label %26
25: ; preds = %22, %20, %18
store i32 0, i32* %1
br label %26
26: ; preds = %25, %24
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@.str.4 = [17 x i8] c"Enter command : \00"
@str = [22 x i8] c"1. Run BIST (No stat)\00"
@str.5 = [18 x i8] c"2. Dump registers\00"
@str.6 = [19 x i8] c"3. Write Registers\00"
@str.7 = [8 x i8] c"4. Quit\00"
define i32 @do_menu() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.5, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.6, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.7, i64 0, i64 0))
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%6 = tail call signext i8 (...) @getchar()
%7 = icmp eq i8 %6, 10
br i1 %7, label %8, label %11
8: ; preds = %0, %8
%9 = tail call signext i8 (...) @getchar()
%10 = icmp eq i8 %9, 10
br i1 %10, label %8, label %11
11: ; preds = %8, %0
%12 = phi i8 [ %6, %0 ], [ %9, %8 ]
%13 = sext i8 %12 to i32
switch i32 %13, label %20 [
i32 49, label %14
i32 50, label %16
i32 51, label %18
]
14: ; preds = %11
%15 = tail call i32 (...) @bist()
br label %20
16: ; preds = %11
%17 = tail call i32 (...) @dump_registers()
br label %20
18: ; preds = %11
%19 = tail call i32 (...) @write_register()
br label %20
20: ; preds = %14, %16, %18, %11
%21 = phi i32 [ 1, %11 ], [ 0, %18 ], [ 0, %16 ], [ 0, %14 ]
ret i32 %21
}