#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*/ display_menu();
unsigned int get_entry();
int getchar_timeout();
int /*<<< orphan*/ kbd_flush();
int /*<<< orphan*/ probe_cards(int);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puts(char *);
unsigned int mode_menu(void) {
  int key;
  unsigned int sel;
  puts("Press <ENTER> to see video modes available, "
       "<SPACE> to continue, or wait 30 sec\n");
  kbd_flush();
  while (1) {
    key = getchar_timeout();
    if (key == ' ' || key == 0)
      return 0x0f04;
    if (key == '\r')
      break;
    putchar('\a');
  }
  for (;;) {
    display_menu();
    puts("Enter a video mode or \"scan\" to scan for "
         "additional modes: ");
    sel = get_entry();
    if (sel != (((('s') - 'a' + 10) << 12) + ((('c') - 'a' + 10) << 8) +
                ((('a') - 'a' + 10) << 4) + (('n') - 'a' + 10)))
      return sel;
    probe_cards(1);
  }
}


x86 assembly (clang, -O0):
<mode_menu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe81(%rip),%rdi
call   1060 <puts@plt>
mov    $0x0,%al
call   1040 <kbd_flush@plt>
mov    $0x0,%al
call   1090 <getchar_timeout@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x20,-0x8(%rbp)
je     11a9 <mode_menu+0x39>
cmpl   $0x0,-0x8(%rbp)
jne    11b5 <mode_menu+0x45>
movl   $0xf04,-0x4(%rbp)
jmp    121c <mode_menu+0xac>
cmpl   $0xd,-0x8(%rbp)
jne    11c4 <mode_menu+0x54>
jmp    11d3 <mode_menu+0x63>
mov    $0x7,%edi
call   1050 <putchar@plt>
jmp    118b <mode_menu+0x1b>
jmp    11d8 <mode_menu+0x68>
mov    $0x0,%al
call   1070 <display_menu@plt>
lea    0xe6b(%rip),%rdi
call   1060 <puts@plt>
mov    $0x0,%al
call   1030 <get_entry@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1ccb7,-0xc(%rbp)
je     120d <mode_menu+0x9d>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121c <mode_menu+0xac>
mov    $0x1,%edi
call   1080 <probe_cards@plt>
jmp    11d8 <mode_menu+0x68>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mode_menu>:
push   %r14
push   %rbx
push   %rax
lea    0xe85(%rip),%rdi
call   1060 <puts@plt>
xor    %eax,%eax
call   1040 <kbd_flush@plt>
xor    %eax,%eax
call   1090 <getchar_timeout@plt>
mov    $0xf04,%ebx
test   $0xffffffdf,%eax
je     1219 <mode_menu+0xa9>
nopw   0x0(%rax,%rax,1)
cmp    $0xd,%eax
je     11bf <mode_menu+0x4f>
mov    $0x7,%edi
call   1050 <putchar@plt>
xor    %eax,%eax
call   1090 <getchar_timeout@plt>
test   $0xffffffdf,%eax
jne    11a0 <mode_menu+0x30>
jmp    1219 <mode_menu+0xa9>
xor    %eax,%eax
call   1070 <display_menu@plt>
lea    0xe84(%rip),%rdi
call   1060 <puts@plt>
xor    %eax,%eax
call   1030 <get_entry@plt>
mov    %eax,%ebx
cmp    $0x1ccb7,%eax
jne    1219 <mode_menu+0xa9>
lea    0xe68(%rip),%r14
nopl   0x0(%rax)
mov    $0x1,%edi
call   1080 <probe_cards@plt>
xor    %eax,%eax
call   1070 <display_menu@plt>
mov    %r14,%rdi
call   1060 <puts@plt>
xor    %eax,%eax
call   1030 <get_entry@plt>
cmp    $0x1ccb7,%eax
je     11f0 <mode_menu+0x80>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [81 x i8] c"Press <ENTER> to see video modes available, <SPACE> to continue, or wait 30 sec\0A\00"
@.str.1 = [60 x i8] c"Enter a video mode or \22scan\22 to scan for additional modes: \00"
define i32 @mode_menu() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @puts(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (...) @kbd_flush()
br label %6
6: ; preds = %0, %18
%7 = call i32 (...) @getchar_timeout()
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, 32
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10, %6
store i32 3844, i32* %1
br label %31
14: ; preds = %10
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, 13
br i1 %16, label %17, label %18
17: ; preds = %14
br label %20
18: ; preds = %14
%19 = call i32 @putchar(i8 signext 7)
br label %6
20: ; preds = %17
br label %21
21: ; preds = %29, %20
%22 = call i32 (...) @display_menu()
%23 = call i32 @puts(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 (...) @get_entry()
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = icmp ne i32 %25, 117943
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = load i32, i32* %3
store i32 %28, i32* %1
br label %31
29: ; preds = %21
%30 = call i32 @probe_cards(i32 1)
br label %21
31: ; preds = %27, %13
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
@.str = [81 x i8] c"Press <ENTER> to see video modes available, <SPACE> to continue, or wait 30 sec\0A\00"
@.str.1 = [60 x i8] c"Enter a video mode or \22scan\22 to scan for additional modes: \00"
define i32 @mode_menu() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 (...) @kbd_flush()
%3 = tail call i32 (...) @getchar_timeout()
%4 = and i32 %3, -33
%5 = icmp eq i32 %4, 0
br i1 %5, label %25, label %6
6: ; preds = %0, %14
%7 = phi i32 [ %16, %14 ], [ %3, %0 ]
%8 = icmp eq i32 %7, 13
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = tail call i32 (...) @display_menu()
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 (...) @get_entry()
%13 = icmp eq i32 %12, 117943
br i1 %13, label %19, label %25
14: ; preds = %6
%15 = tail call i32 @putchar(i8 signext 7)
%16 = tail call i32 (...) @getchar_timeout()
%17 = and i32 %16, -33
%18 = icmp eq i32 %17, 0
br i1 %18, label %25, label %6
19: ; preds = %9, %19
%20 = tail call i32 @probe_cards(i32 1)
%21 = tail call i32 (...) @display_menu()
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0))
%23 = tail call i32 (...) @get_entry()
%24 = icmp eq i32 %23, 117943
br i1 %24, label %19, label %25
25: ; preds = %14, %19, %0, %9
%26 = phi i32 [ %12, %9 ], [ 3844, %0 ], [ %23, %19 ], [ 3844, %14 ]
ret i32 %26
}