#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 tty_getc();
int tty_getch() {
  int ch;
  ch = tty_getc();
  if (ch == 27) {
    ch = tty_getc();
    if (ch == '[' || ch == 'O') {
      ch = tty_getc();
      if (ch == 'A') {
        return 259;
      }
      if (ch == 'B') {
        return 258;
      }
      if (ch == 'C') {
        return 261;
      }
      if (ch == 'D') {
        return 260;
      }
    }
  }
  return ch;
}


x86 assembly (clang, -O0):
<tty_getch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <tty_getc@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x1b,-0x8(%rbp)
jne    11b6 <tty_getch+0xa6>
mov    $0x0,%al
call   1030 <tty_getc@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x5b,-0x8(%rbp)
je     114a <tty_getch+0x3a>
cmpl   $0x4f,-0x8(%rbp)
jne    11b1 <tty_getch+0xa1>
mov    $0x0,%al
call   1030 <tty_getc@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x41,-0x8(%rbp)
jne    116a <tty_getch+0x5a>
movl   $0x103,-0x4(%rbp)
jmp    11bc <tty_getch+0xac>
cmpl   $0x42,-0x8(%rbp)
jne    1180 <tty_getch+0x70>
movl   $0x102,-0x4(%rbp)
jmp    11bc <tty_getch+0xac>
cmpl   $0x43,-0x8(%rbp)
jne    1196 <tty_getch+0x86>
movl   $0x105,-0x4(%rbp)
jmp    11bc <tty_getch+0xac>
cmpl   $0x44,-0x8(%rbp)
jne    11ac <tty_getch+0x9c>
movl   $0x104,-0x4(%rbp)
jmp    11bc <tty_getch+0xac>
jmp    11b1 <tty_getch+0xa1>
jmp    11b6 <tty_getch+0xa6>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tty_getch>:
push   %rax
xor    %eax,%eax
call   1030 <tty_getc@plt>
cmp    $0x1b,%eax
jne    114c <tty_getch+0x3c>
xor    %eax,%eax
call   1030 <tty_getc@plt>
cmp    $0x5b,%eax
je     112e <tty_getch+0x1e>
cmp    $0x4f,%eax
jne    114c <tty_getch+0x3c>
xor    %eax,%eax
call   1030 <tty_getc@plt>
mov    %eax,%ecx
add    $0xffffffbf,%ecx
cmp    $0x3,%ecx
ja     114c <tty_getch+0x3c>
movslq %ecx,%rax
lea    0xeb7(%rip),%rcx
mov    (%rcx,%rax,4),%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @tty_getch() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @tty_getc()
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = icmp eq i32 %4, 27
br i1 %5, label %6, label %32
6: ; preds = %0
%7 = call i32 (...) @tty_getc()
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, 91
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 79
br i1 %12, label %13, label %31
13: ; preds = %10, %6
%14 = call i32 (...) @tty_getc()
store i32 %14, i32* %2
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, 65
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 259, i32* %1
br label %34
18: ; preds = %13
%19 = load i32, i32* %2
%20 = icmp eq i32 %19, 66
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 258, i32* %1
br label %34
22: ; preds = %18
%23 = load i32, i32* %2
%24 = icmp eq i32 %23, 67
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 261, i32* %1
br label %34
26: ; preds = %22
%27 = load i32, i32* %2
%28 = icmp eq i32 %27, 68
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 260, i32* %1
br label %34
30: ; preds = %26
br label %31
31: ; preds = %30, %10
br label %32
32: ; preds = %31, %0
%33 = load i32, i32* %2
store i32 %33, i32* %1
br label %34
34: ; preds = %32, %29, %25, %21, %17
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@switch.table.tty_getch = [4 x i32] [i32 259, i32 258, i32 261, i32 260]
define i32 @tty_getch() {
%1 = tail call i32 (...) @tty_getc()
%2 = icmp eq i32 %1, 27
br i1 %2, label %3, label %13
3: ; preds = %0
%4 = tail call i32 (...) @tty_getc()
switch i32 %4, label %13 [
i32 91, label %5
i32 79, label %5
]
5: ; preds = %3, %3
%6 = tail call i32 (...) @tty_getc()
%7 = add i32 %6, -65
%8 = icmp ult i32 %7, 4
br i1 %8, label %9, label %13
9: ; preds = %5
%10 = sext i32 %7 to i64
%11 = getelementptr inbounds [4 x i32], [4 x i32]* @switch.table.tty_getch, i64 0, i64 %10
%12 = load i32, i32* %11
br label %13
13: ; preds = %0, %3, %5, %9
%14 = phi i32 [ %12, %9 ], [ %4, %3 ], [ %1, %0 ], [ %6, %5 ]
ret i32 %14
}