#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 char_convert(char);
int /*<<< orphan*/ flushall();
int /*<<< orphan*/ is_valid_item(int, int, int);
int /*<<< orphan*/ printf(char *, char *);
int scanf(char *, ...);
int /*<<< orphan*/ system(char *);
int display_standard_menu(char menu_title[], char menu_items[], int menu_type,
                          int num_items, int min_items) {
  int option = 0, error_check = 0;
  char char_option = '\0';
  do {
    printf("%s\n\n", menu_title);
    printf("%s\n\n", menu_items);
    if (menu_type == 0) {
      error_check = scanf(" %d", &option);
      if (!error_check) {
        option = min_items - 1;
      }
    } else if (menu_type == 1) {
      error_check = scanf(" %c", &char_option);
      if (!error_check) {
        option = min_items - 1;
      } else {
        option = char_convert(char_option);
      }
    }
    flushall();
    system("cls");
  } while (!is_valid_item(option, num_items, min_items));
  return option;
}


x86 assembly (clang, -O0):
<display_standard_menu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movb   $0x0,-0x25(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe69(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe59(%rip),%rdi
call   1050 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jne    11e3 <display_standard_menu+0x83>
lea    0xe48(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11de <display_standard_menu+0x7e>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1230 <display_standard_menu+0xd0>
cmpl   $0x1,-0x14(%rbp)
jne    122b <display_standard_menu+0xcb>
lea    0xe15(%rip),%rdi
lea    -0x25(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    121a <display_standard_menu+0xba>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1226 <display_standard_menu+0xc6>
movsbl -0x25(%rbp),%edi
call   1030 <char_convert@plt>
mov    %eax,-0x20(%rbp)
jmp    122b <display_standard_menu+0xcb>
jmp    1230 <display_standard_menu+0xd0>
mov    $0x0,%al
call   1060 <flushall@plt>
lea    0xdcf(%rip),%rdi
call   1040 <system@plt>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1070 <is_valid_item@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    118c <display_standard_menu+0x2c>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display_standard_menu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r12d
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%r13
movl   $0x0,0x10(%rsp)
movb   $0x0,0xf(%rsp)
lea    -0x1(%r12),%eax
mov    %eax,0x14(%rsp)
lea    0xe67(%rip),%rbx
jmp    11ce <display_standard_menu+0x6e>
nopl   0x0(%rax,%rax,1)
mov    0x14(%rsp),%eax
mov    %eax,0x10(%rsp)
xor    %eax,%eax
call   1060 <flushall@plt>
lea    0xe57(%rip),%rdi
call   1040 <system@plt>
mov    0x10(%rsp),%edi
mov    %r14d,%esi
mov    %r12d,%edx
call   1070 <is_valid_item@plt>
test   %eax,%eax
jne    123a <display_standard_menu+0xda>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
cmp    $0x1,%ebp
je     1210 <display_standard_menu+0xb0>
test   %ebp,%ebp
jne    11a8 <display_standard_menu+0x48>
lea    0xe11(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
test   %eax,%eax
jne    11a8 <display_standard_menu+0x48>
jmp    11a0 <display_standard_menu+0x40>
cs nopw 0x0(%rax,%rax,1)
lea    0xdf2(%rip),%rdi
lea    0xf(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
test   %eax,%eax
je     11a0 <display_standard_menu+0x40>
movsbl 0xf(%rsp),%edi
call   1030 <char_convert@plt>
jmp    11a4 <display_standard_menu+0x44>
mov    0x10(%rsp),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s\0A\0A\00"
@.str.1 = [4 x i8] c" %d\00"
@.str.2 = [4 x i8] c" %c\00"
@.str.3 = [4 x i8] c"cls\00"
define i32 @display_standard_menu(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i8 0, i8* %13
br label %14
14: ; preds = %47, %5
%15 = load i8*, i8** %6
%16 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i8*, i8** %7
%18 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* %8
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %14
%22 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %11)
store i32 %22, i32* %12
%23 = load i32, i32* %12
%24 = icmp ne i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %21
%26 = load i32, i32* %10
%27 = sub nsw i32 %26, 1
store i32 %27, i32* %11
br label %28
28: ; preds = %25, %21
br label %44
29: ; preds = %14
%30 = load i32, i32* %8
%31 = icmp eq i32 %30, 1
br i1 %31, label %32, label %43
32: ; preds = %29
%33 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %13)
store i32 %33, i32* %12
%34 = load i32, i32* %12
%35 = icmp ne i32 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %32
%37 = load i32, i32* %10
%38 = sub nsw i32 %37, 1
store i32 %38, i32* %11
br label %42
39: ; preds = %32
%40 = load i8, i8* %13
%41 = call i32 @char_convert(i8 signext %40)
store i32 %41, i32* %11
br label %42
42: ; preds = %39, %36
br label %43
43: ; preds = %42, %29
br label %44
44: ; preds = %43, %28
%45 = call i32 (...) @flushall()
%46 = call i32 @system(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %44
%48 = load i32, i32* %11
%49 = load i32, i32* %9
%50 = load i32, i32* %10
%51 = call i32 @is_valid_item(i32 %48, i32 %49, i32 %50)
%52 = icmp ne i32 %51, 0
%53 = xor i1 %52, true
br i1 %53, label %14, label %54
54: ; preds = %47
%55 = load i32, i32* %11
ret i32 %55
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s\0A\0A\00"
@.str.1 = [4 x i8] c" %d\00"
@.str.2 = [4 x i8] c" %c\00"
@.str.3 = [4 x i8] c"cls\00"
define i32 @display_standard_menu(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8
%8 = bitcast i32* %6 to i8*
store i32 0, i32* %6
store i8 0, i8* %7
%9 = add nsw i32 %4, -1
br label %10
10: ; preds = %24, %5
%11 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
%12 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %1)
switch i32 %2, label %24 [
i32 0, label %13
i32 1, label %17
]
13: ; preds = %10
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %13
store i32 %9, i32* %6
br label %24
17: ; preds = %10
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 %9, i32* %6
br label %24
21: ; preds = %17
%22 = load i8, i8* %7
%23 = call i32 @char_convert(i8 signext %22)
store i32 %23, i32* %6
br label %24
24: ; preds = %10, %21, %20, %13, %16
%25 = call i32 (...) @flushall()
%26 = call i32 @system(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%27 = load i32, i32* %6
%28 = call i32 @is_valid_item(i32 %27, i32 %3, i32 %4)
%29 = icmp eq i32 %28, 0
br i1 %29, label %10, label %30
30: ; preds = %24
%31 = load i32, i32* %6
ret i32 %31
}