#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 getchar();
int /*<<< orphan*/ menu_cursor_move_up(int);
int menu_read_input(int *selected, int *return_pressed) {
  switch (getchar()) {
  case 'q':
    menu_cursor_move_up(1);
    return 1;
  case '\n':
    menu_cursor_move_up(1);
    *return_pressed = 1;
    return 1;
  case 033:
    if (getchar() == '[') {
      switch (getchar()) {
      case 'A':
        (*selected)--;
        break;
      case 'B':
        (*selected)++;
        break;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<menu_read_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
sub    $0xa,%eax
je     1182 <menu_read_input+0x62>
jmp    114a <menu_read_input+0x2a>
mov    -0x1c(%rbp),%eax
sub    $0x1b,%eax
je     11a2 <menu_read_input+0x82>
jmp    115b <menu_read_input+0x3b>
mov    -0x1c(%rbp),%eax
sub    $0x71,%eax
jne    1202 <menu_read_input+0xe2>
jmp    116c <menu_read_input+0x4c>
mov    $0x1,%edi
call   1030 <menu_cursor_move_up@plt>
movl   $0x1,-0x4(%rbp)
jmp    1209 <menu_read_input+0xe9>
mov    $0x1,%edi
call   1030 <menu_cursor_move_up@plt>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1209 <menu_read_input+0xe9>
mov    $0x0,%al
call   1040 <getchar@plt>
cmp    $0x5b,%eax
jne    11fd <menu_read_input+0xdd>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x20(%rbp)
sub    $0x41,%eax
je     11dd <menu_read_input+0xbd>
jmp    11cc <menu_read_input+0xac>
mov    -0x20(%rbp),%eax
sub    $0x42,%eax
je     11ed <menu_read_input+0xcd>
jmp    11f8 <menu_read_input+0xd8>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
jmp    11f8 <menu_read_input+0xd8>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    11fd <menu_read_input+0xdd>
jmp    1202 <menu_read_input+0xe2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<menu_read_input>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
je     1154 <menu_read_input+0x34>
cmp    $0x1b,%eax
je     116c <menu_read_input+0x4c>
cmp    $0x71,%eax
jne    1197 <menu_read_input+0x77>
mov    $0x1,%ebx
mov    $0x1,%edi
call   1030 <menu_cursor_move_up@plt>
jmp    1197 <menu_read_input+0x77>
mov    $0x1,%ebx
mov    $0x1,%edi
call   1030 <menu_cursor_move_up@plt>
movl   $0x1,(%r15)
jmp    1197 <menu_read_input+0x77>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0x5b,%eax
jne    1197 <menu_read_input+0x77>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0x42,%eax
je     1193 <menu_read_input+0x73>
cmp    $0x41,%eax
jne    1197 <menu_read_input+0x77>
addl   $0xffffffff,(%r14)
jmp    1197 <menu_read_input+0x77>
addl   $0x1,(%r14)
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @menu_read_input(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
store i32* %0, i32** %4
store i32* %1, i32** %5
%6 = call i32 (...) @getchar()
switch i32 %6, label %27 [
i32 113, label %7
i32 10, label %9
i32 27, label %12
]
7: ; preds = %2
%8 = call i32 @menu_cursor_move_up(i32 1)
store i32 1, i32* %3
br label %28
9: ; preds = %2
%10 = call i32 @menu_cursor_move_up(i32 1)
%11 = load i32*, i32** %5
store i32 1, i32* %11
store i32 1, i32* %3
br label %28
12: ; preds = %2
%13 = call i32 (...) @getchar()
%14 = icmp eq i32 %13, 91
br i1 %14, label %15, label %26
15: ; preds = %12
%16 = call i32 (...) @getchar()
switch i32 %16, label %25 [
i32 65, label %17
i32 66, label %21
]
17: ; preds = %15
%18 = load i32*, i32** %4
%19 = load i32, i32* %18
%20 = add nsw i32 %19, -1
store i32 %20, i32* %18
br label %25
21: ; preds = %15
%22 = load i32*, i32** %4
%23 = load i32, i32* %22
%24 = add nsw i32 %23, 1
store i32 %24, i32* %22
br label %25
25: ; preds = %15, %21, %17
br label %26
26: ; preds = %25, %12
br label %27
27: ; preds = %26, %2
store i32 0, i32* %3
br label %28
28: ; preds = %27, %9, %7
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
define i32 @menu_read_input(i32* nocapture %0, i32* nocapture writeonly %1) {
%3 = tail call i32 (...) @getchar()
switch i32 %3, label %19 [
i32 113, label %4
i32 10, label %6
i32 27, label %8
]
4: ; preds = %2
%5 = tail call i32 @menu_cursor_move_up(i32 1)
br label %19
6: ; preds = %2
%7 = tail call i32 @menu_cursor_move_up(i32 1)
store i32 1, i32* %1
br label %19
8: ; preds = %2
%9 = tail call i32 (...) @getchar()
%10 = icmp eq i32 %9, 91
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = tail call i32 (...) @getchar()
switch i32 %12, label %19 [
i32 65, label %13
i32 66, label %16
]
13: ; preds = %11
%14 = load i32, i32* %0
%15 = add nsw i32 %14, -1
store i32 %15, i32* %0
br label %19
16: ; preds = %11
%17 = load i32, i32* %0
%18 = add nsw i32 %17, 1
store i32 %18, i32* %0
br label %19
19: ; preds = %2, %13, %16, %11, %8, %6, %4
%20 = phi i32 [ 1, %6 ], [ 1, %4 ], [ 0, %8 ], [ 0, %11 ], [ 0, %16 ], [ 0, %13 ], [ 0, %2 ]
ret i32 %20
}