#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 getch0();
int /*<<< orphan*/ quit();
int egetch() {
  int c, d, e;
  c = getch0();
  if (c == 3 || c == 4 || c == -1 || c == 'q' || c == 'Q')
    quit();
  if (c != 27)
    return c;
  d = getch0();
  e = getch0();
  if (e == 'A')
    return 257;
  if (e == 'B')
    return 258;
  if (e == 'C')
    return 259;
  if (e == 'D')
    return 260;
  return 0;
}


x86 assembly (clang, -O0):
<egetch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <getch0@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1164 <egetch+0x44>
cmpl   $0x4,-0x8(%rbp)
je     1164 <egetch+0x44>
cmpl   $0xffffffff,-0x8(%rbp)
je     1164 <egetch+0x44>
cmpl   $0x71,-0x8(%rbp)
je     1164 <egetch+0x44>
cmpl   $0x51,-0x8(%rbp)
jne    116b <egetch+0x4b>
mov    $0x0,%al
call   1030 <quit@plt>
cmpl   $0x1b,-0x8(%rbp)
je     1180 <egetch+0x60>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f3 <egetch+0xd3>
mov    $0x0,%al
call   1040 <getch0@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1040 <getch0@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x41,-0x10(%rbp)
jne    11aa <egetch+0x8a>
movl   $0x101,-0x4(%rbp)
jmp    11f3 <egetch+0xd3>
cmpl   $0x42,-0x10(%rbp)
jne    11c0 <egetch+0xa0>
movl   $0x102,-0x4(%rbp)
jmp    11f3 <egetch+0xd3>
cmpl   $0x43,-0x10(%rbp)
jne    11d6 <egetch+0xb6>
movl   $0x103,-0x4(%rbp)
jmp    11f3 <egetch+0xd3>
cmpl   $0x44,-0x10(%rbp)
jne    11ec <egetch+0xcc>
movl   $0x104,-0x4(%rbp)
jmp    11f3 <egetch+0xd3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<egetch>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <getch0@plt>
mov    %eax,%ebx
cmp    $0x1a,%eax
jg     1140 <egetch+0x20>
lea    -0x3(%rbx),%eax
cmp    $0x2,%eax
jb     114f <egetch+0x2f>
cmp    $0xffffffff,%ebx
je     114f <egetch+0x2f>
jmp    117c <egetch+0x5c>
cmp    $0x1b,%ebx
je     115b <egetch+0x3b>
cmp    $0x71,%ebx
je     114f <egetch+0x2f>
cmp    $0x51,%ebx
jne    117c <egetch+0x5c>
xor    %eax,%eax
call   1030 <quit@plt>
cmp    $0x1b,%ebx
jne    117c <egetch+0x5c>
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <getch0@plt>
xor    %eax,%eax
call   1040 <getch0@plt>
mov    %eax,%ebx
lea    -0x41(%rbx),%eax
add    $0xc0,%ebx
cmp    $0x4,%eax
cmovae %ebp,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @egetch() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i32 (...) @getch0()
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, 3
br i1 %7, label %20, label %8
8: ; preds = %0
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 4
br i1 %10, label %20, label %11
11: ; preds = %8
%12 = load i32, i32* %2
%13 = icmp eq i32 %12, -1
br i1 %13, label %20, label %14
14: ; preds = %11
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, 113
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = load i32, i32* %2
%19 = icmp eq i32 %18, 81
br i1 %19, label %20, label %22
20: ; preds = %17, %14, %11, %8, %0
%21 = call i32 (...) @quit()
br label %22
22: ; preds = %20, %17
%23 = load i32, i32* %2
%24 = icmp ne i32 %23, 27
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = load i32, i32* %2
store i32 %26, i32* %1
br label %46
27: ; preds = %22
%28 = call i32 (...) @getch0()
store i32 %28, i32* %3
%29 = call i32 (...) @getch0()
store i32 %29, i32* %4
%30 = load i32, i32* %4
%31 = icmp eq i32 %30, 65
br i1 %31, label %32, label %33
32: ; preds = %27
store i32 257, i32* %1
br label %46
33: ; preds = %27
%34 = load i32, i32* %4
%35 = icmp eq i32 %34, 66
br i1 %35, label %36, label %37
36: ; preds = %33
store i32 258, i32* %1
br label %46
37: ; preds = %33
%38 = load i32, i32* %4
%39 = icmp eq i32 %38, 67
br i1 %39, label %40, label %41
40: ; preds = %37
store i32 259, i32* %1
br label %46
41: ; preds = %37
%42 = load i32, i32* %4
%43 = icmp eq i32 %42, 68
br i1 %43, label %44, label %45
44: ; preds = %41
store i32 260, i32* %1
br label %46
45: ; preds = %41
store i32 0, i32* %1
br label %46
46: ; preds = %45, %44, %40, %36, %32, %25
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
define i32 @egetch() {
%1 = tail call i32 (...) @getch0()
switch i32 %1, label %12 [
i32 -1, label %2
i32 113, label %2
i32 81, label %2
i32 4, label %2
i32 3, label %2
i32 27, label %5
]
2: ; preds = %0, %0, %0, %0, %0
%3 = tail call i32 (...) @quit()
%4 = icmp eq i32 %1, 27
br i1 %4, label %5, label %12
5: ; preds = %0, %2
%6 = tail call i32 (...) @getch0()
%7 = tail call i32 (...) @getch0()
%8 = add i32 %7, -65
%9 = icmp ult i32 %8, 4
%10 = add i32 %7, 192
%11 = select i1 %9, i32 %10, i32 0
br label %12
12: ; preds = %5, %2, %0
%13 = phi i32 [ %1, %0 ], [ %1, %2 ], [ %11, %5 ]
ret i32 %13
}