#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 */
typedef char int8_t;
typedef char int32_t;

/* Variables and functions */
char getch();
int /*<<< orphan*/ putch(char);
int32_t getkey(void) {
  int8_t ch = 0;
  while (true) {
    if ((ch = getch()) == '\'' || ch == '\"')
      return 0;
    if (ch == 27 || ch == '\r' || ch >= 32 && ch <= 125) {
      putch(ch);
      return ch;
    }
    if (ch == 0)
      getch();
  }
}


x86 assembly (clang, -O0):
<getkey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movb   $0x0,-0x2(%rbp)
mov    $0x0,%al
call   1030 <getch@plt>
mov    %al,-0x2(%rbp)
movsbl %al,%eax
cmp    $0x27,%eax
je     114f <getkey+0x2f>
movsbl -0x2(%rbp),%eax
cmp    $0x22,%eax
jne    1158 <getkey+0x38>
movb   $0x0,-0x1(%rbp)
jmp    11b9 <getkey+0x99>
movsbl -0x2(%rbp),%eax
cmp    $0x1b,%eax
je     118c <getkey+0x6c>
movsbl -0x2(%rbp),%eax
cmp    $0xd,%eax
je     118c <getkey+0x6c>
movsbl -0x2(%rbp),%eax
cmp    $0x20,%eax
jl     11a0 <getkey+0x80>
movsbl -0x2(%rbp),%eax
cmp    $0x7d,%eax
jg     11a0 <getkey+0x80>
movsbl -0x2(%rbp),%edi
call   1040 <putch@plt>
mov    -0x2(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    11b9 <getkey+0x99>
movsbl -0x2(%rbp),%eax
cmp    $0x0,%eax
jne    11b4 <getkey+0x94>
mov    $0x0,%al
call   1030 <getch@plt>
jmp    112c <getkey+0xc>
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getkey>:
push   %r14
push   %rbx
push   %rax
lea    0xed5(%rip),%r14
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <getch@plt>
mov    %eax,%ebx
lea    -0xd(%rbx),%eax
cmp    $0x1a,%al
ja     114c <getkey+0x2c>
movzbl %al,%eax
movslq (%r14,%rax,4),%rax
add    %r14,%rax
jmp    *%rax
lea    -0x20(%rbx),%eax
cmp    $0x5d,%al
jbe    1160 <getkey+0x40>
test   %bl,%bl
jne    1130 <getkey+0x10>
xor    %eax,%eax
call   1030 <getch@plt>
jmp    1130 <getkey+0x10>
movsbl %bl,%edi
call   1040 <putch@plt>
jmp    116c <getkey+0x4c>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define signext i8 @getkey() {
%1 = alloca i8
%2 = alloca i8
store i8 0, i8* %2
br label %3
3: ; preds = %0, %38
%4 = call signext i8 (...) @getch()
store i8 %4, i8* %2
%5 = sext i8 %4 to i32
%6 = icmp eq i32 %5, 39
br i1 %6, label %11, label %7
7: ; preds = %3
%8 = load i8, i8* %2
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 34
br i1 %10, label %11, label %12
11: ; preds = %7, %3
store i8 0, i8* %1
br label %39
12: ; preds = %7
%13 = load i8, i8* %2
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 27
br i1 %15, label %28, label %16
16: ; preds = %12
%17 = load i8, i8* %2
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 13
br i1 %19, label %28, label %20
20: ; preds = %16
%21 = load i8, i8* %2
%22 = sext i8 %21 to i32
%23 = icmp sge i32 %22, 32
br i1 %23, label %24, label %32
24: ; preds = %20
%25 = load i8, i8* %2
%26 = sext i8 %25 to i32
%27 = icmp sle i32 %26, 125
br i1 %27, label %28, label %32
28: ; preds = %24, %16, %12
%29 = load i8, i8* %2
%30 = call i32 @putch(i8 signext %29)
%31 = load i8, i8* %2
store i8 %31, i8* %1
br label %39
32: ; preds = %24, %20
%33 = load i8, i8* %2
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call signext i8 (...) @getch()
br label %38
38: ; preds = %36, %32
br label %3
39: ; preds = %28, %11
%40 = load i8, i8* %1
ret i8 %40
}

LLVM IR (-O2):
define signext i8 @getkey() {
br label %1
1: ; preds = %12, %0
%2 = tail call signext i8 (...) @getch()
switch i8 %2, label %3 [
i8 39, label %13
i8 34, label %13
i8 27, label %6
i8 13, label %6
]
3: ; preds = %1
%4 = add i8 %2, -32
%5 = icmp ult i8 %4, 94
br i1 %5, label %6, label %8
6: ; preds = %1, %1, %3
%7 = tail call i32 @putch(i8 signext %2)
br label %13
8: ; preds = %3
%9 = icmp eq i8 %2, 0
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = tail call signext i8 (...) @getch()
br label %12
12: ; preds = %10, %8
br label %1
13: ; preds = %1, %1, %6
%14 = phi i8 [ %2, %6 ], [ 0, %1 ], [ 0, %1 ]
ret i8 %14
}