#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*/ STDIN_FILENO;
int /*<<< orphan*/ TCIFLUSH;
char getch();
int /*<<< orphan*/ kbhit();
int menu_handle_input(char);
int /*<<< orphan*/ tcflush(int /*<<< orphan*/, int /*<<< orphan*/);
int handle_input(void) {
  if (!kbhit()) {
    return 0;
  }
  char c = getch();
  tcflush(STDIN_FILENO, TCIFLUSH);
  if (c == 3 || c == 'q' || c == 'Q') {
    return 1;
  }
  return menu_handle_input(c);
}


x86 assembly (clang, -O0):
<handle_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <kbhit@plt>
cmp    $0x0,%eax
jne    1164 <handle_input+0x24>
movl   $0x0,-0x4(%rbp)
jmp    11c4 <handle_input+0x84>
mov    $0x0,%al
call   1050 <getch@plt>
mov    %al,-0x5(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
call   1030 <tcflush@plt>
movsbl -0x5(%rbp),%eax
cmp    $0x3,%eax
je     11ac <handle_input+0x6c>
movsbl -0x5(%rbp),%eax
cmp    $0x71,%eax
je     11ac <handle_input+0x6c>
movsbl -0x5(%rbp),%eax
cmp    $0x51,%eax
jne    11b8 <handle_input+0x78>
movl   $0x1,-0x4(%rbp)
jmp    11c4 <handle_input+0x84>
movsbl -0x5(%rbp),%edi
call   1060 <menu_handle_input@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_input>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <kbhit@plt>
test   %eax,%eax
je     1184 <handle_input+0x44>
xor    %eax,%eax
call   1050 <getch@plt>
mov    %eax,%ebx
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
call   1030 <tcflush@plt>
mov    $0x1,%ebp
cmp    $0x3,%bl
je     1184 <handle_input+0x44>
cmp    $0x51,%bl
je     1184 <handle_input+0x44>
cmp    $0x71,%bl
jne    118d <handle_input+0x4d>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
movsbl %bl,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <menu_handle_input@plt>

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@TCIFLUSH = global i32 0
define i32 @handle_input() {
%1 = alloca i32
%2 = alloca i8
%3 = call i32 (...) @kbhit()
%4 = icmp ne i32 %3, 0
br i1 %4, label %6, label %5
5: ; preds = %0
store i32 0, i32* %1
br label %26
6: ; preds = %0
%7 = call signext i8 (...) @getch()
store i8 %7, i8* %2
%8 = load i32, i32* @STDIN_FILENO
%9 = load i32, i32* @TCIFLUSH
%10 = call i32 @tcflush(i32 %8, i32 %9)
%11 = load i8, i8* %2
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 3
br i1 %13, label %22, label %14
14: ; preds = %6
%15 = load i8, i8* %2
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 113
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = load i8, i8* %2
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 81
br i1 %21, label %22, label %23
22: ; preds = %18, %14, %6
store i32 1, i32* %1
br label %26
23: ; preds = %18
%24 = load i8, i8* %2
%25 = call i32 @menu_handle_input(i8 signext %24)
store i32 %25, i32* %1
br label %26
26: ; preds = %23, %22, %5
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@TCIFLUSH = global i32 0
define i32 @handle_input() {
%1 = tail call i32 (...) @kbhit()
%2 = icmp eq i32 %1, 0
br i1 %2, label %10, label %3
3: ; preds = %0
%4 = tail call signext i8 (...) @getch()
%5 = load i32, i32* @STDIN_FILENO
%6 = load i32, i32* @TCIFLUSH
%7 = tail call i32 @tcflush(i32 %5, i32 %6)
switch i8 %4, label %8 [
i8 113, label %10
i8 81, label %10
i8 3, label %10
]
8: ; preds = %3
%9 = tail call i32 @menu_handle_input(i8 signext %4)
br label %10
10: ; preds = %8, %3, %3, %3, %0
%11 = phi i32 [ 0, %0 ], [ %9, %8 ], [ 1, %3 ], [ 1, %3 ], [ 1, %3 ]
ret i32 %11
}