#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 tgetc();
get1key() {
  int c;
  int d;
  c = tgetc();
  if ((unsigned)c == 155) {
    c = tgetc();
    if ((c >= 'A' && c <= 'D') || c == 'S' || c == 'T')
      return (0x0800 | c);
    d = tgetc();
    if (d == '~')
      return (0x0800 | c);
    c = d + 32;
    if (d >= '0' && d <= '9')
      d = tgetc();
    return (0x0800 | c);
  }
  if (c >= 0x00 && c <= 0x1F)
    c = 0x0100 | (c + '@');
  return (c);
}


x86 assembly (clang, -O0):
<get1key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <tgetc@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x9b,-0x8(%rbp)
jne    11cc <get1key+0xbc>
mov    $0x0,%al
call   1030 <tgetc@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x41,-0x8(%rbp)
jl     114d <get1key+0x3d>
cmpl   $0x44,-0x8(%rbp)
jle    1161 <get1key+0x51>
cmpl   $0x53,-0x8(%rbp)
je     1161 <get1key+0x51>
cmpl   $0x54,-0x8(%rbp)
jne    1171 <get1key+0x61>
mov    -0x8(%rbp),%eax
or     $0x800,%eax
mov    %eax,-0x4(%rbp)
jmp    11f4 <get1key+0xe4>
mov    $0x0,%al
call   1030 <tgetc@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x7e,-0xc(%rbp)
jne    1195 <get1key+0x85>
mov    -0x8(%rbp),%eax
or     $0x800,%eax
mov    %eax,-0x4(%rbp)
jmp    11f4 <get1key+0xe4>
mov    -0xc(%rbp),%eax
add    $0x20,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x30,-0xc(%rbp)
jl     11bc <get1key+0xac>
cmpl   $0x39,-0xc(%rbp)
jg     11bc <get1key+0xac>
mov    $0x0,%al
call   1030 <tgetc@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
or     $0x800,%eax
mov    %eax,-0x4(%rbp)
jmp    11f4 <get1key+0xe4>
cmpl   $0x0,-0x8(%rbp)
jl     11ee <get1key+0xde>
cmpl   $0x1f,-0x8(%rbp)
jg     11ee <get1key+0xde>
mov    -0x8(%rbp),%eax
add    $0x40,%eax
or     $0x100,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get1key>:
push   %rbx
xor    %eax,%eax
call   1030 <tgetc@plt>
cmp    $0x9b,%eax
jne    1142 <get1key+0x32>
xor    %eax,%eax
call   1030 <tgetc@plt>
mov    %eax,%ebx
lea    -0x41(%rbx),%eax
cmp    $0x13,%eax
ja     1155 <get1key+0x45>
mov    $0xc000f,%ecx
bt     %eax,%ecx
jae    1155 <get1key+0x45>
or     $0x800,%ebx
jmp    1151 <get1key+0x41>
lea    0x40(%rax),%ebx
or     $0x100,%ebx
cmp    $0x20,%eax
cmovae %eax,%ebx
mov    %ebx,%eax
pop    %rbx
ret
xor    %eax,%eax
call   1030 <tgetc@plt>
cmp    $0x7e,%eax
je     113a <get1key+0x2a>
lea    0x20(%rax),%ebx
add    $0xffffffd0,%eax
cmp    $0x9,%eax
ja     113a <get1key+0x2a>
xor    %eax,%eax
call   1030 <tgetc@plt>
jmp    113a <get1key+0x2a>

LLVM IR (-O0):
define i32 @get1key() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 (...) @tgetc()
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, 155
br i1 %6, label %7, label %43
7: ; preds = %0
%8 = call i32 (...) @tgetc()
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp sge i32 %9, 65
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i32, i32* %2
%13 = icmp sle i32 %12, 68
br i1 %13, label %20, label %14
14: ; preds = %11, %7
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, 83
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = load i32, i32* %2
%19 = icmp eq i32 %18, 84
br i1 %19, label %20, label %23
20: ; preds = %17, %14, %11
%21 = load i32, i32* %2
%22 = or i32 2048, %21
store i32 %22, i32* %1
br label %55
23: ; preds = %17
%24 = call i32 (...) @tgetc()
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = icmp eq i32 %25, 126
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i32, i32* %2
%29 = or i32 2048, %28
store i32 %29, i32* %1
br label %55
30: ; preds = %23
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 32
store i32 %32, i32* %2
%33 = load i32, i32* %3
%34 = icmp sge i32 %33, 48
br i1 %34, label %35, label %40
35: ; preds = %30
%36 = load i32, i32* %3
%37 = icmp sle i32 %36, 57
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 (...) @tgetc()
store i32 %39, i32* %3
br label %40
40: ; preds = %38, %35, %30
%41 = load i32, i32* %2
%42 = or i32 2048, %41
store i32 %42, i32* %1
br label %55
43: ; preds = %0
%44 = load i32, i32* %2
%45 = icmp sge i32 %44, 0
br i1 %45, label %46, label %53
46: ; preds = %43
%47 = load i32, i32* %2
%48 = icmp sle i32 %47, 31
br i1 %48, label %49, label %53
49: ; preds = %46
%50 = load i32, i32* %2
%51 = add nsw i32 %50, 64
%52 = or i32 256, %51
store i32 %52, i32* %2
br label %53
53: ; preds = %49, %46, %43
%54 = load i32, i32* %2
store i32 %54, i32* %1
br label %55
55: ; preds = %53, %40, %27, %20
%56 = load i32, i32* %1
ret i32 %56
}

LLVM IR (-O2):
define i32 @get1key() {
%1 = tail call i32 (...) @tgetc()
%2 = icmp eq i32 %1, 155
br i1 %2, label %3, label %20
3: ; preds = %0
%4 = tail call i32 (...) @tgetc()
switch i32 %4, label %7 [
i32 84, label %5
i32 83, label %5
i32 68, label %5
i32 67, label %5
i32 66, label %5
i32 65, label %5
]
5: ; preds = %3, %3, %3, %3, %3, %3
%6 = or i32 %4, 2048
br label %25
7: ; preds = %3
%8 = tail call i32 (...) @tgetc()
%9 = icmp eq i32 %8, 126
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = or i32 %4, 2048
br label %25
12: ; preds = %7
%13 = add nsw i32 %8, 32
%14 = add i32 %8, -48
%15 = icmp ult i32 %14, 10
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = tail call i32 (...) @tgetc()
br label %18
18: ; preds = %16, %12
%19 = or i32 %13, 2048
br label %25
20: ; preds = %0
%21 = icmp ult i32 %1, 32
%22 = add nsw i32 %1, 64
%23 = or i32 %22, 256
%24 = select i1 %21, i32 %23, i32 %1
br label %25
25: ; preds = %20, %18, %10, %5
%26 = phi i32 [ %6, %5 ], [ %11, %10 ], [ %19, %18 ], [ %24, %20 ]
ret i32 %26
}