#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 */
char keycode2char(int keycode, bool is_shift_on) {
  static char keytbl[0x80] = {
      0, 0,   '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^',
      0, 0,   'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[',
      0, 0,   'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0,
      0, ']', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0,   '*',
      0, ' ', 0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
      0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.'};
  static char keytbl_shift[0x80] = {
      0,   0,   '!', 0x22, '#', '$', '%', '&', 0x27, '(', ')', '~', '=',
      '~', 0,   0,   'Q',  'W', 'E', 'R', 'T', 'Y',  'U', 'I', 'O', 'P',
      '`', '{', 0,   0,    'A', 'S', 'D', 'F', 'G',  'H', 'J', 'K', 'L',
      '+', '*', 0,   0,    '}', 'Z', 'X', 'C', 'V',  'B', 'N', 'M', '<',
      '>', '?', 0,   '*',  0,   ' ', 0,   0,   0,    0,   0,   0,   0,
      0,   0,   0,   0,    0,   0,   '7', '8', '9',  '-', '4', '5', '6',
      '+', '1', '2', '3',  '0', '.', 0,   0,   0,    0,   0,   0,   0,
      0,   0,   0,   0,    0,   0,   0,   0,   0,    0,   0,   0,   0,
      0,   0,   0,   0,    0,   0,   0,   0,   0,    0,   0,   '_', 0,
      0,   0,   0,   0,    0,   0,   0,   0,   '|',  0,   0};
  char ch;
  if (keycode < 0x80) {
    if (is_shift_on) {
      ch = keytbl_shift[keycode];
    } else {
      ch = keytbl[keycode];
    }
  } else {
    ch = 0;
  }
  if ('A' <= ch && ch <= 'Z') {
    if (!is_shift_on) {
      ch += 0x20;
    }
  }
  if (ch != 0) {
    return ch;
  }
  return 0;
}


x86 assembly (clang, -O0):
<keycode2char>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x80,-0x8(%rbp)
jge    114d <keycode2char+0x4d>
cmpl   $0x0,-0xc(%rbp)
je     1137 <keycode2char+0x37>
movslq -0x8(%rbp),%rcx
lea    0x2f84(%rip),%rax
mov    (%rax,%rcx,1),%al
mov    %al,-0xd(%rbp)
jmp    1148 <keycode2char+0x48>
movslq -0x8(%rbp),%rcx
lea    0x2eee(%rip),%rax
mov    (%rax,%rcx,1),%al
mov    %al,-0xd(%rbp)
jmp    1151 <keycode2char+0x51>
movb   $0x0,-0xd(%rbp)
movsbl -0xd(%rbp),%ecx
mov    $0x41,%eax
cmp    %ecx,%eax
jg     1188 <keycode2char+0x88>
movsbl -0xd(%rbp),%eax
cmp    $0x5a,%eax
jg     1188 <keycode2char+0x88>
cmpl   $0x0,-0xc(%rbp)
jne    1183 <keycode2char+0x83>
movsbl -0xd(%rbp),%eax
add    $0x20,%eax
mov    %al,-0xd(%rbp)
jmp    1188 <keycode2char+0x88>
movsbl -0xd(%rbp),%eax
cmp    $0x0,%eax
je     11a0 <keycode2char+0xa0>
mov    -0xd(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    11a4 <keycode2char+0xa4>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<keycode2char>:
cmp    $0x7f,%edi
jg     1121 <keycode2char+0x21>
test   %esi,%esi
movslq %edi,%rax
lea    0xeef(%rip),%rcx
lea    0xf68(%rip),%rdx
cmove  %rcx,%rdx
mov    (%rdx,%rax,1),%al
jmp    1123 <keycode2char+0x23>
xor    %eax,%eax
lea    -0x5b(%rax),%ecx
lea    0x20(%rax),%edx
cmp    $0xe6,%cl
movzbl %al,%ecx
movzbl %dl,%eax
cmovb  %ecx,%eax
test   %esi,%esi
cmovne %ecx,%eax
ret

LLVM IR (-O0):
@keycode2char.keytbl = internal global <{ [84 x i8], [44 x i8] }> <{ [84 x i8] c"\00\001234567890-^\00\00QWERTYUIOP@[\00\00ASDFGHJKL;:\00\00]ZXCVBNM,./\00*\00 \00\00\00\00\00\00\00\00\00\00\00\00\00789-456+1230.", [44 x i8] zeroinitializer }>
@keycode2char.keytbl_shift = internal global [128 x i8] c"\00\00!\22#$%&'()~=~\00\00QWERTYUIOP`{\00\00ASDFGHJKL+*\00\00}ZXCVBNM<>?\00*\00 \00\00\00\00\00\00\00\00\00\00\00\00\00789-456+1230.\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00_\00\00\00\00\00\00\00\00\00|\00\00"
define signext i8 @keycode2char(i32 %0, i32 %1) {
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 128
br i1 %8, label %9, label %23
9: ; preds = %2
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [128 x i8], [128 x i8]* @keycode2char.keytbl_shift, i64 0, i64 %14
%16 = load i8, i8* %15
store i8 %16, i8* %6
br label %22
17: ; preds = %9
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [128 x i8], [128 x i8]* bitcast (<{ [84 x i8], [44 x i8] }>* @keycode2char.keytbl to [128 x i8]*), i64 0, i64 %19
%21 = load i8, i8* %20
store i8 %21, i8* %6
br label %22
22: ; preds = %17, %12
br label %24
23: ; preds = %2
store i8 0, i8* %6
br label %24
24: ; preds = %23, %22
%25 = load i8, i8* %6
%26 = sext i8 %25 to i32
%27 = icmp sle i32 65, %26
br i1 %27, label %28, label %41
28: ; preds = %24
%29 = load i8, i8* %6
%30 = sext i8 %29 to i32
%31 = icmp sle i32 %30, 90
br i1 %31, label %32, label %41
32: ; preds = %28
%33 = load i32, i32* %5
%34 = icmp ne i32 %33, 0
br i1 %34, label %40, label %35
35: ; preds = %32
%36 = load i8, i8* %6
%37 = sext i8 %36 to i32
%38 = add nsw i32 %37, 32
%39 = trunc i32 %38 to i8
store i8 %39, i8* %6
br label %40
40: ; preds = %35, %32
br label %41
41: ; preds = %40, %28, %24
%42 = load i8, i8* %6
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = load i8, i8* %6
store i8 %46, i8* %3
br label %48
47: ; preds = %41
store i8 0, i8* %3
br label %48
48: ; preds = %47, %45
%49 = load i8, i8* %3
ret i8 %49
}

LLVM IR (-O2):
@keycode2char.keytbl = internal unnamed_addr constant <{ [84 x i8], [44 x i8] }> <{ [84 x i8] c"\00\001234567890-^\00\00QWERTYUIOP@[\00\00ASDFGHJKL;:\00\00]ZXCVBNM,./\00*\00 \00\00\00\00\00\00\00\00\00\00\00\00\00789-456+1230.", [44 x i8] zeroinitializer }>
@keycode2char.keytbl_shift = internal unnamed_addr constant [128 x i8] c"\00\00!\22#$%&'()~=~\00\00QWERTYUIOP`{\00\00ASDFGHJKL+*\00\00}ZXCVBNM<>?\00*\00 \00\00\00\00\00\00\00\00\00\00\00\00\00789-456+1230.\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00_\00\00\00\00\00\00\00\00\00|\00\00"
define signext i8 @keycode2char(i32 %0, i32 %1) {
%3 = icmp slt i32 %0, 128
br i1 %3, label %4, label %10
4: ; preds = %2
%5 = icmp eq i32 %1, 0
%6 = sext i32 %0 to i64
%7 = select i1 %5, [128 x i8]* bitcast (<{ [84 x i8], [44 x i8] }>* @keycode2char.keytbl to [128 x i8]*), [128 x i8]* @keycode2char.keytbl_shift
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 %6
%9 = load i8, i8* %8
br label %10
10: ; preds = %4, %2
%11 = phi i8 [ 0, %2 ], [ %9, %4 ]
%12 = add i8 %11, -91
%13 = icmp ult i8 %12, -26
%14 = icmp ne i32 %1, 0
%15 = or i1 %14, %13
%16 = add i8 %11, 32
%17 = select i1 %15, i8 %11, i8 %16
ret i8 %17
}