#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*/ gotoxy(int, int);
int /*<<< orphan*/ printf(char *);
char waitForAnyKey();
int menuSelector(int x, int y, int yStart) {
  char key;
  int i = 0;
  x = x - 2;
  gotoxy(x, yStart);
  printf(">");
  gotoxy(1, 1);
  do {
    key = waitForAnyKey();
    if (key == (char)(char)'A') {
      gotoxy(x, yStart + i);
      printf(" ");
      if (yStart >= yStart + i)
        i = y - yStart - 2;
      else
        i--;
      gotoxy(x, yStart + i);
      printf(">");
    } else if (key == (char)(char)'B') {
      gotoxy(x, yStart + i);
      printf(" ");
      if (i + 2 >= y - yStart)
        i = 0;
      else
        i++;
      gotoxy(x, yStart + i);
      printf(">");
    }
  } while (key != (char)10);
  return (i);
}


x86 assembly (clang, -O0):
<menuSelector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <gotoxy@plt>
lea    0xe9d(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%esi
mov    %esi,%edi
call   1050 <gotoxy@plt>
mov    $0x0,%al
call   1040 <waitForAnyKey@plt>
mov    %al,-0xd(%rbp)
movsbl -0xd(%rbp),%eax
cmp    $0x41,%eax
jne    11ef <menuSelector+0xbf>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
add    -0x14(%rbp),%esi
call   1050 <gotoxy@plt>
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    -0x14(%rbp),%ecx
cmp    %ecx,%eax
jl     11c7 <menuSelector+0x97>
mov    -0x8(%rbp),%eax
sub    -0xc(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    11d0 <menuSelector+0xa0>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
add    -0x14(%rbp),%esi
call   1050 <gotoxy@plt>
lea    0xe1b(%rip),%rdi
call   1030 <printf@plt>
jmp    125e <menuSelector+0x12e>
movsbl -0xd(%rbp),%eax
cmp    $0x42,%eax
jne    1259 <menuSelector+0x129>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
add    -0x14(%rbp),%esi
call   1050 <gotoxy@plt>
lea    0xdf1(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    -0x8(%rbp),%ecx
sub    -0xc(%rbp),%ecx
cmp    %ecx,%eax
jl     1236 <menuSelector+0x106>
movl   $0x0,-0x14(%rbp)
jmp    123f <menuSelector+0x10f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
add    -0x14(%rbp),%esi
call   1050 <gotoxy@plt>
lea    0xdac(%rip),%rdi
call   1030 <printf@plt>
jmp    125e <menuSelector+0x12e>
jmp    1263 <menuSelector+0x133>
movsbl -0xd(%rbp),%eax
cmp    $0xa,%eax
jne    1174 <menuSelector+0x44>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<menuSelector>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%r14d
mov    %edi,%r12d
add    $0xfffffffe,%r12d
mov    %r12d,%edi
mov    %edx,%esi
call   1050 <gotoxy@plt>
mov    $0x3e,%edi
call   1030 <putchar@plt>
mov    $0x1,%edi
mov    $0x1,%esi
call   1050 <gotoxy@plt>
sub    %r15d,%r14d
lea    -0x2(%r14),%r13d
xor    %ebp,%ebp
jmp    11c2 <menuSelector+0x92>
cs nopw 0x0(%rax,%rax,1)
lea    (%r15,%rbp,1),%esi
mov    %r12d,%edi
call   1050 <gotoxy@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
lea    0x2(%rbp),%eax
add    $0x1,%ebp
cmp    %r14d,%eax
mov    $0x0,%eax
cmovge %eax,%ebp
lea    (%r15,%rbp,1),%esi
mov    %r12d,%edi
call   1050 <gotoxy@plt>
mov    $0x3e,%edi
call   1030 <putchar@plt>
cmp    $0xa,%bl
je     11f7 <menuSelector+0xc7>
xor    %eax,%eax
call   1040 <waitForAnyKey@plt>
mov    %eax,%ebx
cmp    $0x42,%al
je     1180 <menuSelector+0x50>
cmp    $0x41,%bl
jne    11bd <menuSelector+0x8d>
lea    (%r15,%rbp,1),%esi
mov    %r12d,%edi
call   1050 <gotoxy@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
test   %ebp,%ebp
lea    -0x1(%rbp),%eax
cmovle %r13d,%eax
mov    %eax,%ebp
jmp    11a7 <menuSelector+0x77>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @menuSelector(i32 %0, i32 %1, i32 %2) {
%4 = add nsw i32 %0, -2
%5 = tail call i32 @gotoxy(i32 %4, i32 %2)
%6 = tail call i32 @putchar(i32 62)
%7 = tail call i32 @gotoxy(i32 1, i32 1)
%8 = sub nsw i32 %1, %2
%9 = add i32 %1, -2
%10 = sub i32 %9, %2
br label %11
11: ; preds = %34, %3
%12 = phi i32 [ 0, %3 ], [ %35, %34 ]
%13 = tail call signext i8 (...) @waitForAnyKey()
switch i8 %13, label %34 [
i8 65, label %14
i8 66, label %21
]
14: ; preds = %11
%15 = add nsw i32 %12, %2
%16 = tail call i32 @gotoxy(i32 %4, i32 %15)
%17 = tail call i32 @putchar(i32 32)
%18 = icmp sgt i32 %12, 0
%19 = add nsw i32 %12, -1
%20 = select i1 %18, i32 %19, i32 %10
br label %29
21: ; preds = %11
%22 = add nsw i32 %12, %2
%23 = tail call i32 @gotoxy(i32 %4, i32 %22)
%24 = tail call i32 @putchar(i32 32)
%25 = add nsw i32 %12, 2
%26 = icmp slt i32 %25, %8
%27 = add nsw i32 %12, 1
%28 = select i1 %26, i32 %27, i32 0
br label %29
29: ; preds = %21, %14
%30 = phi i32 [ %20, %14 ], [ %28, %21 ]
%31 = add nsw i32 %30, %2
%32 = tail call i32 @gotoxy(i32 %4, i32 %31)
%33 = tail call i32 @putchar(i32 62)
br label %34
34: ; preds = %29, %11
%35 = phi i32 [ %12, %11 ], [ %30, %29 ]
%36 = icmp eq i8 %13, 10
br i1 %36, label %37, label %11
37: ; preds = %34
ret i32 %35
}