#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 */
scalar_t__ check_cursor_boundary(unsigned char);
int /*<<< orphan*/ enter_game(unsigned char);
scalar_t__ isBtnCtrl();
scalar_t__ isBtnDown();
scalar_t__ isBtnUp();
int /*<<< orphan*/ print_menu(unsigned char);
int /*<<< orphan*/ tone(int /*<<< orphan*/);
void enter_menu() {
  unsigned char cursor = 1;
  print_menu(cursor);
  while (1) {
    print_menu(cursor);
    if (isBtnUp() && check_cursor_boundary(cursor - 1)) {
      cursor -= 1;
      print_menu(cursor);
      tone(0);
    }
    if (isBtnDown() && check_cursor_boundary(cursor + 1)) {
      cursor += 1;
      print_menu(cursor);
      tone(0);
    }
    if (isBtnCtrl()) {
      tone(0);
      enter_game(cursor);
    }
  }
}


x86 assembly (clang, -O0):
<enter_menu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movb   $0x1,-0x1(%rbp)
movzbl -0x1(%rbp),%edi
call   1040 <print_menu@plt>
movzbl -0x1(%rbp),%edi
call   1040 <print_menu@plt>
mov    $0x0,%al
call   1050 <isBtnUp@plt>
cmp    $0x0,%rax
je     11d2 <enter_menu+0x62>
movzbl -0x1(%rbp),%eax
sub    $0x1,%eax
movzbl %al,%edi
call   1070 <check_cursor_boundary@plt>
cmp    $0x0,%rax
je     11d2 <enter_menu+0x62>
movzbl -0x1(%rbp),%eax
sub    $0x1,%eax
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%edi
call   1040 <print_menu@plt>
xor    %edi,%edi
call   1060 <tone@plt>
mov    $0x0,%al
call   1090 <isBtnDown@plt>
cmp    $0x0,%rax
je     1216 <enter_menu+0xa6>
movzbl -0x1(%rbp),%eax
add    $0x1,%eax
movzbl %al,%edi
call   1070 <check_cursor_boundary@plt>
cmp    $0x0,%rax
je     1216 <enter_menu+0xa6>
movzbl -0x1(%rbp),%eax
add    $0x1,%eax
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%edi
call   1040 <print_menu@plt>
xor    %edi,%edi
call   1060 <tone@plt>
mov    $0x0,%al
call   1030 <isBtnCtrl@plt>
cmp    $0x0,%rax
je     1237 <enter_menu+0xc7>
xor    %edi,%edi
call   1060 <tone@plt>
movzbl -0x1(%rbp),%edi
call   1080 <enter_game@plt>
jmp    1185 <enter_menu+0x15>

x86 assembly (clang, -O2):
<enter_menu>:
push   %rbp
push   %r14
push   %rbx
mov    $0x1,%edi
call   1040 <print_menu@plt>
mov    $0x1,%r14b
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl %r14b,%edi
call   1040 <print_menu@plt>
xor    %eax,%eax
call   1050 <isBtnUp@plt>
test   %rax,%rax
je     11ca <enter_menu+0x5a>
lea    -0x1(%r14),%ebp
movzbl %bpl,%ebx
mov    %ebx,%edi
call   1070 <check_cursor_boundary@plt>
test   %rax,%rax
je     11ca <enter_menu+0x5a>
mov    %ebx,%edi
call   1040 <print_menu@plt>
xor    %edi,%edi
call   1060 <tone@plt>
mov    %ebp,%r14d
xor    %eax,%eax
call   1090 <isBtnDown@plt>
test   %rax,%rax
je     11fb <enter_menu+0x8b>
lea    0x1(%r14),%ebp
movzbl %bpl,%ebx
mov    %ebx,%edi
call   1070 <check_cursor_boundary@plt>
test   %rax,%rax
je     11fb <enter_menu+0x8b>
mov    %ebx,%edi
call   1040 <print_menu@plt>
xor    %edi,%edi
call   1060 <tone@plt>
mov    %ebp,%r14d
xor    %eax,%eax
call   1030 <isBtnCtrl@plt>
test   %rax,%rax
je     1190 <enter_menu+0x20>
xor    %edi,%edi
call   1060 <tone@plt>
movzbl %r14b,%edi
call   1080 <enter_game@plt>
jmp    1190 <enter_menu+0x20>

LLVM IR (-O0):
define void @enter_menu() {
%1 = alloca i8
store i8 1, i8* %1
%2 = load i8, i8* %1
%3 = call i32 @print_menu(i8 zeroext %2)
br label %4
4: ; preds = %0, %49
%5 = load i8, i8* %1
%6 = call i32 @print_menu(i8 zeroext %5)
%7 = call i64 (...) @isBtnUp()
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %24
9: ; preds = %4
%10 = load i8, i8* %1
%11 = zext i8 %10 to i32
%12 = sub nsw i32 %11, 1
%13 = trunc i32 %12 to i8
%14 = call i64 @check_cursor_boundary(i8 zeroext %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %9
%17 = load i8, i8* %1
%18 = zext i8 %17 to i32
%19 = sub nsw i32 %18, 1
%20 = trunc i32 %19 to i8
store i8 %20, i8* %1
%21 = load i8, i8* %1
%22 = call i32 @print_menu(i8 zeroext %21)
%23 = call i32 @tone(i32 0)
br label %24
24: ; preds = %16, %9, %4
%25 = call i64 (...) @isBtnDown()
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %42
27: ; preds = %24
%28 = load i8, i8* %1
%29 = zext i8 %28 to i32
%30 = add nsw i32 %29, 1
%31 = trunc i32 %30 to i8
%32 = call i64 @check_cursor_boundary(i8 zeroext %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %42
34: ; preds = %27
%35 = load i8, i8* %1
%36 = zext i8 %35 to i32
%37 = add nsw i32 %36, 1
%38 = trunc i32 %37 to i8
store i8 %38, i8* %1
%39 = load i8, i8* %1
%40 = call i32 @print_menu(i8 zeroext %39)
%41 = call i32 @tone(i32 0)
br label %42
42: ; preds = %34, %27, %24
%43 = call i64 (...) @isBtnCtrl()
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = call i32 @tone(i32 0)
%47 = load i8, i8* %1
%48 = call i32 @enter_game(i8 zeroext %47)
br label %49
49: ; preds = %45, %42
br label %4
}

LLVM IR (-O2):
define void @enter_menu() {
%1 = tail call i32 @print_menu(i8 zeroext 1)
br label %2
2: ; preds = %32, %0
%3 = phi i8 [ 1, %0 ], [ %26, %32 ]
%4 = tail call i32 @print_menu(i8 zeroext %3)
%5 = tail call i64 (...) @isBtnUp()
%6 = icmp eq i64 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %2
%8 = add i8 %3, -1
%9 = tail call i64 @check_cursor_boundary(i8 zeroext %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %7
%12 = tail call i32 @print_menu(i8 zeroext %8)
%13 = tail call i32 @tone(i32 0)
br label %14
14: ; preds = %11, %7, %2
%15 = phi i8 [ %8, %11 ], [ %3, %7 ], [ %3, %2 ]
%16 = tail call i64 (...) @isBtnDown()
%17 = icmp eq i64 %16, 0
br i1 %17, label %25, label %18
18: ; preds = %14
%19 = add i8 %15, 1
%20 = tail call i64 @check_cursor_boundary(i8 zeroext %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = tail call i32 @print_menu(i8 zeroext %19)
%24 = tail call i32 @tone(i32 0)
br label %25
25: ; preds = %22, %18, %14
%26 = phi i8 [ %19, %22 ], [ %15, %18 ], [ %15, %14 ]
%27 = tail call i64 (...) @isBtnCtrl()
%28 = icmp eq i64 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %25
%30 = tail call i32 @tone(i32 0)
%31 = tail call i32 @enter_game(i8 zeroext %26)
br label %32
32: ; preds = %29, %25
br label %2
}