#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 int /*<<< orphan*/ buf;

/* Variables and functions */
int read(int /*<<< orphan*/, char *, int);
char get_key(void) {
  int n;
  char buf[3];
  n = read(0, buf, sizeof(buf));
  if (3 == n && buf[0] == 27 && buf[1] == 91) {
    return buf[2];
  } else if (1 == n) {
    return buf[0];
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0xb(%rbp),%rsi
xor    %edi,%edi
mov    $0x3,%edx
call   1030 <read@plt>
mov    %eax,-0x8(%rbp)
mov    $0x3,%eax
cmp    -0x8(%rbp),%eax
jne    115e <get_key+0x4e>
movsbl -0xb(%rbp),%eax
cmp    $0x1b,%eax
jne    115e <get_key+0x4e>
movsbl -0xa(%rbp),%eax
cmp    $0x5b,%eax
jne    115e <get_key+0x4e>
mov    -0x9(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    1180 <get_key+0x70>
mov    $0x1,%eax
cmp    -0x8(%rbp),%eax
jne    1177 <get_key+0x67>
mov    -0xb(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    1180 <get_key+0x70>
jmp    117c <get_key+0x6c>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_key>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
lea    0x5(%rsp),%rsi
xor    %edi,%edi
mov    $0x3,%edx
call   1030 <read@plt>
movzbl 0x5(%rsp),%ecx
mov    %ecx,%edx
xor    $0x1b,%dl
mov    0x6(%rsp),%bl
xor    $0x5b,%bl
cmp    $0x1,%eax
cmove  %ecx,%ebp
movzbl 0x7(%rsp),%ecx
or     %dl,%bl
cmovne %ebp,%ecx
cmp    $0x3,%eax
cmovne %ebp,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define signext i8 @get_key() {
%1 = alloca i8
%2 = alloca i32
%3 = alloca [3 x i8]
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%5 = call i32 @read(i32 0, i8* %4, i32 3)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp eq i32 3, %6
br i1 %7, label %8, label %21
8: ; preds = %0
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 27
br i1 %12, label %13, label %21
13: ; preds = %8
%14 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 91
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
%20 = load i8, i8* %19
store i8 %20, i8* %1
br label %29
21: ; preds = %13, %8, %0
%22 = load i32, i32* %2
%23 = icmp eq i32 1, %22
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%26 = load i8, i8* %25
store i8 %26, i8* %1
br label %29
27: ; preds = %21
br label %28
28: ; preds = %27
store i8 0, i8* %1
br label %29
29: ; preds = %28, %24, %18
%30 = load i8, i8* %1
ret i8 %30
}

LLVM IR (-O2):
define signext i8 @get_key() {
%1 = alloca [3 x i8]
%2 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 0
%3 = call i32 @read(i32 0, i8* %2, i32 3)
%4 = icmp eq i32 %3, 3
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 27
%7 = select i1 %4, i1 %6, i1 false
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 91
%11 = select i1 %7, i1 %10, i1 false
%12 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 2
%13 = load i8, i8* %12
%14 = icmp eq i32 %3, 1
%15 = select i1 %14, i8 %5, i8 0
%16 = select i1 %11, i8 %13, i8 %15
ret i8 %16
}