#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 /*<<< orphan*/ printf(char *);
int readch();
void get_way() {
  int ch;
  ch = readch();
  ch = readch();
  switch (ch) {
  case 65:
    printf("UP\n");
    break;
  case 66:
    printf("DOWN\n");
    break;
  case 67:
    printf("RIGHT\n");
    break;
  case 68:
    printf("LEFT\n");
    break;
  default:
    printf("Unknow\n");
  }
}


x86 assembly (clang, -O0):
<get_way>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xor    %eax,%eax
mov    %al,-0x11(%rbp)
call   1040 <readch@plt>
mov    %eax,%ecx
mov    -0x11(%rbp),%al
mov    %ecx,-0x4(%rbp)
call   1040 <readch@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffbf,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x3,%eax
ja     11af <get_way+0x8f>
mov    -0x10(%rbp),%rax
lea    0xe9e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
jmp    11bb <get_way+0x9b>
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
jmp    11bb <get_way+0x9b>
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
jmp    11bb <get_way+0x9b>
lea    0xe7c(%rip),%rdi
call   1030 <printf@plt>
jmp    11bb <get_way+0x9b>
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_way>:
push   %rax
xor    %eax,%eax
call   1040 <readch@plt>
xor    %eax,%eax
call   1040 <readch@plt>
add    $0xffffffbf,%eax
cmp    $0x3,%eax
ja     114d <get_way+0x2d>
cltq
lea    0xedc(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
pop    %rax
jmp    1030 <puts@plt>
lea    0xebf(%rip),%rdi
pop    %rax
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"UP\0A\00"
@.str.1 = [6 x i8] c"DOWN\0A\00"
@.str.2 = [7 x i8] c"RIGHT\0A\00"
@.str.3 = [6 x i8] c"LEFT\0A\00"
@.str.4 = [8 x i8] c"Unknow\0A\00"
define void @get_way() {
%1 = alloca i32
%2 = call i32 (...) @readch()
store i32 %2, i32* %1
%3 = call i32 (...) @readch()
store i32 %3, i32* %1
%4 = load i32, i32* %1
switch i32 %4, label %13 [
i32 65, label %5
i32 66, label %7
i32 67, label %9
i32 68, label %11
]
5: ; preds = %0
%6 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %15
7: ; preds = %0
%8 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %15
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %15
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %15
13: ; preds = %0
%14 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %15
15: ; preds = %13, %11, %9, %7, %5
ret void
}

LLVM IR (-O2):
@str = [5 x i8] c"LEFT\00"
@str.5 = [6 x i8] c"RIGHT\00"
@str.6 = [5 x i8] c"DOWN\00"
@str.7 = [3 x i8] c"UP\00"
@str.8 = [7 x i8] c"Unknow\00"
@reltable.get_way = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @str.7 to i64), i64 ptrtoint ([4 x i32]* @reltable.get_way to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @str.6 to i64), i64 ptrtoint ([4 x i32]* @reltable.get_way to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @str.5 to i64), i64 ptrtoint ([4 x i32]* @reltable.get_way to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @str to i64), i64 ptrtoint ([4 x i32]* @reltable.get_way to i64)) to i32)]
define void @get_way() {
%1 = tail call i32 (...) @readch()
%2 = tail call i32 (...) @readch()
%3 = add i32 %2, -65
%4 = icmp ult i32 %3, 4
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = sext i32 %3 to i64
%7 = shl i64 %6, 2
%8 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.get_way to i8*), i64 %7)
br label %9
9: ; preds = %0, %5
%10 = phi i8* [ %8, %5 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @str.8, i64 0, i64 0), %0 ]
%11 = tail call i32 @puts(i8* dereferenceable(1) %10)
ret void
}