#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 getch_();
int getch() {
  int c = getch_();
  if (c == 27)
    return 96 + ({
             int _c = (getch_());
             _c >= 'a' ? _c - 32 : _c;
           });
  if (c == -64 + 'X')
    return 256 + ({
             int _c = (getch_());
             _c >= 'a' ? _c - 32 : _c;
           });
  return c;
}


x86 assembly (clang, -O0):
<getch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1030 <getch_@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x1b,-0x8(%rbp)
jne    1168 <getch+0x58>
mov    $0x0,%al
call   1030 <getch_@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x61,-0xc(%rbp)
jl     114e <getch+0x3e>
mov    -0xc(%rbp),%eax
sub    $0x20,%eax
mov    %eax,-0x1c(%rbp)
jmp    1154 <getch+0x44>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x60,%eax
mov    %eax,-0x4(%rbp)
jmp    11b6 <getch+0xa6>
cmpl   $0x18,-0x8(%rbp)
jne    11b0 <getch+0xa0>
mov    $0x0,%al
call   1030 <getch_@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x61,-0x14(%rbp)
jl     1194 <getch+0x84>
mov    -0x14(%rbp),%eax
sub    $0x20,%eax
mov    %eax,-0x20(%rbp)
jmp    119a <getch+0x8a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x100,%eax
mov    %eax,-0x4(%rbp)
jmp    11b6 <getch+0xa6>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getch>:
push   %rax
xor    %eax,%eax
call   1030 <getch_@plt>
cmp    $0x18,%eax
je     1139 <getch+0x29>
cmp    $0x1b,%eax
jne    1150 <getch+0x40>
xor    %eax,%eax
call   1030 <getch_@plt>
mov    %eax,%ecx
lea    -0x20(%rcx),%eax
cmp    $0x61,%ecx
cmovl  %ecx,%eax
add    $0x60,%eax
pop    %rcx
ret
xor    %eax,%eax
call   1030 <getch_@plt>
mov    %eax,%ecx
lea    -0x20(%rcx),%eax
cmp    $0x61,%ecx
cmovl  %ecx,%eax
add    $0x100,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @getch() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = call i32 (...) @getch_()
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, 27
br i1 %9, label %10, label %23
10: ; preds = %0
%11 = call i32 (...) @getch_()
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp sge i32 %12, 97
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i32, i32* %3
%16 = sub nsw i32 %15, 32
br label %19
17: ; preds = %10
%18 = load i32, i32* %3
br label %19
19: ; preds = %17, %14
%20 = phi i32 [ %16, %14 ], [ %18, %17 ]
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = add nsw i32 96, %21
store i32 %22, i32* %1
br label %41
23: ; preds = %0
%24 = load i32, i32* %2
%25 = icmp eq i32 %24, 24
br i1 %25, label %26, label %39
26: ; preds = %23
%27 = call i32 (...) @getch_()
store i32 %27, i32* %5
%28 = load i32, i32* %5
%29 = icmp sge i32 %28, 97
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i32, i32* %5
%32 = sub nsw i32 %31, 32
br label %35
33: ; preds = %26
%34 = load i32, i32* %5
br label %35
35: ; preds = %33, %30
%36 = phi i32 [ %32, %30 ], [ %34, %33 ]
store i32 %36, i32* %6
%37 = load i32, i32* %6
%38 = add nsw i32 256, %37
store i32 %38, i32* %1
br label %41
39: ; preds = %23
%40 = load i32, i32* %2
store i32 %40, i32* %1
br label %41
41: ; preds = %39, %35, %19
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
define i32 @getch() {
%1 = tail call i32 (...) @getch_()
switch i32 %1, label %14 [
i32 27, label %2
i32 24, label %8
]
2: ; preds = %0
%3 = tail call i32 (...) @getch_()
%4 = icmp sgt i32 %3, 96
%5 = add nsw i32 %3, -32
%6 = select i1 %4, i32 %5, i32 %3
%7 = add nsw i32 %6, 96
br label %14
8: ; preds = %0
%9 = tail call i32 (...) @getch_()
%10 = icmp sgt i32 %9, 96
%11 = add nsw i32 %9, -32
%12 = select i1 %10, i32 %11, i32 %9
%13 = add nsw i32 %12, 256
br label %14
14: ; preds = %0, %8, %2
%15 = phi i32 [ %7, %2 ], [ %13, %8 ], [ %1, %0 ]
ret i32 %15
}