#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*/ XKeyEvent;
typedef int KeySym;

/* Variables and functions */
#define XK_Down 133
#define XK_Escape 132
#define XK_Left 131
#define XK_Right 130
#define XK_Up 129
#define XK_space 128
int /*<<< orphan*/ XLookupString(int /*<<< orphan*/ *, char *, int, int *,
                                 int /*<<< orphan*/);
int trans_key(XKeyEvent *event) {
  int key = -1;
  KeySym keysym;
  char buf[100];
  XLookupString(event, buf, 100, &keysym, 0);
  switch (keysym) {
  case XK_Left:
    key = 1;
    break;
  case XK_Right:
    key = 2;
    break;
  case XK_Down:
    key = 3;
    break;
  case XK_Up:
    key = 4;
    break;
  case XK_space:
    key = 5;
    break;
  case XK_Escape:
    key = 6;
    break;
  default:
    key = *(unsigned char *)buf;
    if (key >= 'A' && key <= 'Z')
      key = key - 'A' + 'a';
  }
  return key;
}


x86 assembly (clang, -O0):
<trans_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
lea    -0x10(%rbp),%rcx
xor    %r8d,%r8d
call   1030 <XLookupString@plt>
mov    -0x10(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x88(%rbp)
sub    $0x5,%eax
ja     11b6 <trans_key+0xa6>
mov    -0x88(%rbp),%rax
lea    0xe9b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0xc(%rbp)
jmp    11e2 <trans_key+0xd2>
movl   $0x2,-0xc(%rbp)
jmp    11e2 <trans_key+0xd2>
movl   $0x3,-0xc(%rbp)
jmp    11e2 <trans_key+0xd2>
movl   $0x4,-0xc(%rbp)
jmp    11e2 <trans_key+0xd2>
movl   $0x5,-0xc(%rbp)
jmp    11e2 <trans_key+0xd2>
movl   $0x6,-0xc(%rbp)
jmp    11e2 <trans_key+0xd2>
movzbl -0x80(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x41,-0xc(%rbp)
jl     11dd <trans_key+0xcd>
cmpl   $0x5a,-0xc(%rbp)
jg     11dd <trans_key+0xcd>
mov    -0xc(%rbp),%eax
sub    $0x41,%eax
add    $0x61,%eax
mov    %eax,-0xc(%rbp)
jmp    11e2 <trans_key+0xd2>
mov    -0xc(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trans_key>:
sub    $0x78,%rsp
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rcx
mov    $0x64,%edx
xor    %r8d,%r8d
call   1030 <XLookupString@plt>
mov    0xc(%rsp),%eax
add    $0xffffff80,%eax
cmp    $0x6,%eax
jae    1148 <trans_key+0x38>
cltq
lea    0xec0(%rip),%rcx
mov    (%rcx,%rax,4),%eax
add    $0x78,%rsp
ret
movzbl 0x10(%rsp),%ecx
lea    -0x41(%rcx),%edx
lea    0x20(%rcx),%eax
cmp    $0x1a,%dl
cmovae %ecx,%eax
add    $0x78,%rsp
ret

LLVM IR (-O0):
define i32 @trans_key(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [100 x i8]
store i32* %0, i32** %2
store i32 -1, i32* %3
%6 = load i32*, i32** %2
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%8 = call i32 @XLookupString(i32* %6, i8* %7, i32 100, i32* %4, i32 0)
%9 = load i32, i32* %4
switch i32 %9, label %16 [
i32 131, label %10
i32 130, label %11
i32 133, label %12
i32 129, label %13
i32 128, label %14
i32 132, label %15
]
10: ; preds = %1
store i32 1, i32* %3
br label %30
11: ; preds = %1
store i32 2, i32* %3
br label %30
12: ; preds = %1
store i32 3, i32* %3
br label %30
13: ; preds = %1
store i32 4, i32* %3
br label %30
14: ; preds = %1
store i32 5, i32* %3
br label %30
15: ; preds = %1
store i32 6, i32* %3
br label %30
16: ; preds = %1
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
store i32 %19, i32* %3
%20 = load i32, i32* %3
%21 = icmp sge i32 %20, 65
br i1 %21, label %22, label %29
22: ; preds = %16
%23 = load i32, i32* %3
%24 = icmp sle i32 %23, 90
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i32, i32* %3
%27 = sub nsw i32 %26, 65
%28 = add nsw i32 %27, 97
store i32 %28, i32* %3
br label %29
29: ; preds = %25, %22, %16
br label %30
30: ; preds = %29, %15, %14, %13, %12, %11, %10
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@switch.table.trans_key = [6 x i32] [i32 5, i32 4, i32 2, i32 1, i32 6, i32 3]
define i32 @trans_key(i32* %0) {
%2 = alloca i32
%3 = alloca [100 x i8]
%4 = bitcast i32* %2 to i8*
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = call i32 @XLookupString(i32* %0, i8* %5, i32 100, i32* %2, i32 0)
%7 = load i32, i32* %2
%8 = add i32 %7, -128
%9 = icmp ult i32 %8, 6
br i1 %9, label %17, label %10
10: ; preds = %1
%11 = load i8, i8* %5
%12 = zext i8 %11 to i32
%13 = add i8 %11, -65
%14 = icmp ult i8 %13, 26
%15 = add nuw nsw i32 %12, 32
%16 = select i1 %14, i32 %15, i32 %12
br label %21
17: ; preds = %1
%18 = sext i32 %8 to i64
%19 = getelementptr inbounds [6 x i32], [6 x i32]* @switch.table.trans_key, i64 0, i64 %18
%20 = load i32, i32* %19
br label %21
21: ; preds = %17, %10
%22 = phi i32 [ %16, %10 ], [ %20, %17 ]
ret i32 %22
}