#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*/ _flushall();
int char_convert(char);
int /*<<< orphan*/ is_valid_item(int, int, int);
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, ...);
int /*<<< orphan*/ system(char *);
int display_game_menu(int questions, int term1, int term2, int term3, int term4,
                      char operand1, char operand2, char operand3,
                      char menu_items[], int menu_type, int num_items,
                      int min_items) {
  int option = 0, error_check = 0;
  char char_option = '\0';
  do {
    printf("Question #%d: %d %c %d", questions, term1, operand1, term2);
    if (operand2 != '0') {
      printf(" %c %d", operand2, term3);
    }
    if (operand3 != '0') {
      printf(" %c %d", operand3, term4);
    }
    printf(" = ?\n");
    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_game_menu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %r9b,%al
mov    0x38(%rbp),%r9d
mov    0x30(%rbp),%r9d
mov    0x28(%rbp),%r9d
mov    0x20(%rbp),%r9
mov    0x18(%rbp),%r9b
mov    0x10(%rbp),%r9b
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
mov    %al,-0x15(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movb   $0x0,-0x21(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
movsbl -0x15(%rbp),%ecx
mov    -0xc(%rbp),%r8d
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movsbl 0x10(%rbp),%eax
cmp    $0x30,%eax
je     11e6 <display_game_menu+0x86>
movsbl 0x10(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movsbl 0x18(%rbp),%eax
cmp    $0x30,%eax
je     1208 <display_game_menu+0xa8>
movsbl 0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x20(%rbp),%rsi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,0x28(%rbp)
jne    125f <display_game_menu+0xff>
lea    0xdda(%rip),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    125a <display_game_menu+0xfa>
mov    0x38(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12ac <display_game_menu+0x14c>
cmpl   $0x1,0x28(%rbp)
jne    12a7 <display_game_menu+0x147>
lea    0xdb2(%rip),%rdi
lea    -0x21(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    1296 <display_game_menu+0x136>
mov    0x38(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12a2 <display_game_menu+0x142>
movsbl -0x21(%rbp),%edi
call   1030 <char_convert@plt>
mov    %eax,-0x1c(%rbp)
jmp    12a7 <display_game_menu+0x147>
jmp    12ac <display_game_menu+0x14c>
mov    $0x0,%al
call   1070 <_flushall@plt>
lea    0xd6c(%rip),%rdi
call   1040 <system@plt>
mov    -0x1c(%rbp),%edi
mov    0x30(%rbp),%esi
mov    0x38(%rbp),%edx
call   1060 <is_valid_item@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11a8 <display_game_menu+0x48>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display_game_menu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,%r12d
mov    %r8d,0x24(%rsp)
mov    %ecx,0x20(%rsp)
mov    %edx,%r13d
mov    %esi,%ebx
mov    %edi,%ebp
mov    0x88(%rsp),%eax
mov    0x78(%rsp),%r15d
movl   $0x0,0x10(%rsp)
movb   $0x0,0xf(%rsp)
movsbl 0x60(%rsp),%ecx
mov    %ecx,0x1c(%rsp)
movsbl 0x68(%rsp),%ecx
mov    %ecx,0x18(%rsp)
add    $0xffffffff,%eax
mov    %eax,0x14(%rsp)
lea    0xe46(%rip),%r14
jmp    120a <display_game_menu+0x9a>
nopl   0x0(%rax)
mov    0x14(%rsp),%eax
mov    %eax,0x10(%rsp)
xor    %eax,%eax
call   1080 <_flushall@plt>
lea    0xe3a(%rip),%rdi
call   1050 <system@plt>
mov    0x10(%rsp),%edi
mov    0x80(%rsp),%esi
mov    0x88(%rsp),%edx
call   1070 <is_valid_item@plt>
test   %eax,%eax
jne    12da <display_game_menu+0x16a>
lea    0xdef(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r12d,%ecx
mov    %r13d,%r8d
xor    %eax,%eax
call   1060 <printf@plt>
cmpb   $0x30,0x60(%rsp)
je     123b <display_game_menu+0xcb>
mov    %r14,%rdi
mov    0x1c(%rsp),%esi
mov    0x20(%rsp),%edx
xor    %eax,%eax
call   1060 <printf@plt>
cmpb   $0x30,0x68(%rsp)
je     1254 <display_game_menu+0xe4>
mov    %r14,%rdi
mov    0x18(%rsp),%esi
mov    0x24(%rsp),%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdc9(%rip),%rdi
call   1040 <puts@plt>
lea    0xdb0(%rip),%rdi
mov    0x70(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x1,%r15d
je     12b0 <display_game_menu+0x140>
test   %r15d,%r15d
jne    11d8 <display_game_menu+0x68>
lea    0xd8a(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
test   %eax,%eax
jne    11d8 <display_game_menu+0x68>
jmp    11d0 <display_game_menu+0x60>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xd65(%rip),%rdi
lea    0xf(%rsp),%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
test   %eax,%eax
je     11d0 <display_game_menu+0x60>
movsbl 0xf(%rsp),%edi
call   1030 <char_convert@plt>
jmp    11d4 <display_game_menu+0x64>
mov    0x10(%rsp),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Question #%d: %d %c %d\00"
@.str.1 = [7 x i8] c" %c %d\00"
@.str.2 = [6 x i8] c" = ?\0A\00"
@.str.3 = [5 x i8] c"%s\0A\0A\00"
@.str.4 = [4 x i8] c" %d\00"
@.str.5 = [4 x i8] c" %c\00"
@.str.6 = [4 x i8] c"cls\00"
define i32 @display_game_menu(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i8 signext %5, i8 signext %6, i8 signext %7, i8* %8, i32 %9, i32 %10, i32 %11) {
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i8
%19 = alloca i8
%20 = alloca i8
%21 = alloca i8*
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca i8
store i32 %0, i32* %13
store i32 %1, i32* %14
store i32 %2, i32* %15
store i32 %3, i32* %16
store i32 %4, i32* %17
store i8 %5, i8* %18
store i8 %6, i8* %19
store i8 %7, i8* %20
store i8* %8, i8** %21
store i32 %9, i32* %22
store i32 %10, i32* %23
store i32 %11, i32* %24
store i32 0, i32* %25
store i32 0, i32* %26
store i8 0, i8* %27
br label %28
28: ; preds = %84, %12
%29 = load i32, i32* %13
%30 = load i32, i32* %14
%31 = load i8, i8* %18
%32 = sext i8 %31 to i32
%33 = load i32, i32* %15
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %29, i32 %30, i32 %32, i32 %33)
%35 = load i8, i8* %19
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 48
br i1 %37, label %38, label %43
38: ; preds = %28
%39 = load i8, i8* %19
%40 = sext i8 %39 to i32
%41 = load i32, i32* %16
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %40, i32 %41)
br label %43
43: ; preds = %38, %28
%44 = load i8, i8* %20
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %45, 48
br i1 %46, label %47, label %52
47: ; preds = %43
%48 = load i8, i8* %20
%49 = sext i8 %48 to i32
%50 = load i32, i32* %17
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %49, i32 %50)
br label %52
52: ; preds = %47, %43
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%54 = load i8*, i8** %21
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %54)
%56 = load i32, i32* %22
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %66
58: ; preds = %52
%59 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %25)
store i32 %59, i32* %26
%60 = load i32, i32* %26
%61 = icmp ne i32 %60, 0
br i1 %61, label %65, label %62
62: ; preds = %58
%63 = load i32, i32* %24
%64 = sub nsw i32 %63, 1
store i32 %64, i32* %25
br label %65
65: ; preds = %62, %58
br label %81
66: ; preds = %52
%67 = load i32, i32* %22
%68 = icmp eq i32 %67, 1
br i1 %68, label %69, label %80
69: ; preds = %66
%70 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %27)
store i32 %70, i32* %26
%71 = load i32, i32* %26
%72 = icmp ne i32 %71, 0
br i1 %72, label %76, label %73
73: ; preds = %69
%74 = load i32, i32* %24
%75 = sub nsw i32 %74, 1
store i32 %75, i32* %25
br label %79
76: ; preds = %69
%77 = load i8, i8* %27
%78 = call i32 @char_convert(i8 signext %77)
store i32 %78, i32* %25
br label %79
79: ; preds = %76, %73
br label %80
80: ; preds = %79, %66
br label %81
81: ; preds = %80, %65
%82 = call i32 (...) @_flushall()
%83 = call i32 @system(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
br label %84
84: ; preds = %81
%85 = load i32, i32* %25
%86 = load i32, i32* %23
%87 = load i32, i32* %24
%88 = call i32 @is_valid_item(i32 %85, i32 %86, i32 %87)
%89 = icmp ne i32 %88, 0
%90 = xor i1 %89, true
br i1 %90, label %28, label %91
91: ; preds = %84
%92 = load i32, i32* %25
ret i32 %92
}

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