#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 getch();
int /*<<< orphan*/ printf(char *);
void updateLevel(char level[40][20], int *runGame) {
  char keyPress = getch();
  switch (keyPress) {
  case 'w':
    printf("up");
    break;
  case 's':
    printf("down");
    break;
  case 'a':
    printf("left");
    break;
  case 'd':
    printf("right");
    break;
  case 'q':
    printf("exiting game");
    *runGame = 0;
    break;
  default:
    printf("wsad, q to exit");
  }
}


x86 assembly (clang, -O0):
<updateLevel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
call   1040 <getch@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x16,%eax
ja     11c3 <updateLevel+0xa3>
mov    -0x20(%rbp),%rax
lea    0xea5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xef1(%rip),%rdi
call   1030 <printf@plt>
jmp    11cf <updateLevel+0xaf>
lea    0xee3(%rip),%rdi
call   1030 <printf@plt>
jmp    11cf <updateLevel+0xaf>
lea    0xed7(%rip),%rdi
call   1030 <printf@plt>
jmp    11cf <updateLevel+0xaf>
lea    0xecb(%rip),%rdi
call   1030 <printf@plt>
jmp    11cf <updateLevel+0xaf>
lea    0xec0(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
jmp    11cf <updateLevel+0xaf>
lea    0xeb2(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<updateLevel>:
push   %rbx
mov    %rsi,%rbx
xor    %eax,%eax
call   1040 <getch@plt>
movsbl %al,%eax
add    $0xffffff9f,%eax
cmp    $0x16,%eax
ja     1153 <updateLevel+0x33>
lea    0xec3(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xf17(%rip),%rdi
pop    %rbx
jmp    1030 <printf@plt>
lea    0xf22(%rip),%rdi
pop    %rbx
jmp    1030 <printf@plt>
lea    0xf02(%rip),%rdi
pop    %rbx
jmp    1030 <printf@plt>
lea    0xefb(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,(%rbx)
pop    %rbx
ret
lea    0xed7(%rip),%rdi
pop    %rbx
jmp    1030 <printf@plt>
lea    0xec7(%rip),%rdi
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"up\00"
@.str.1 = [5 x i8] c"down\00"
@.str.2 = [5 x i8] c"left\00"
@.str.3 = [6 x i8] c"right\00"
@.str.4 = [13 x i8] c"exiting game\00"
@.str.5 = [16 x i8] c"wsad, q to exit\00"
define void @updateLevel([20 x i8]* %0, i32* %1) {
%3 = alloca [20 x i8]*
%4 = alloca i32*
%5 = alloca i8
store [20 x i8]* %0, [20 x i8]** %3
store i32* %1, i32** %4
%6 = call signext i8 (...) @getch()
store i8 %6, i8* %5
%7 = load i8, i8* %5
%8 = sext i8 %7 to i32
switch i32 %8, label %20 [
i32 119, label %9
i32 115, label %11
i32 97, label %13
i32 100, label %15
i32 113, label %17
]
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %22
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %22
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %22
15: ; preds = %2
%16 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %22
17: ; preds = %2
%18 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%19 = load i32*, i32** %4
store i32 0, i32* %19
br label %22
20: ; preds = %2
%21 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %22
22: ; preds = %20, %17, %15, %13, %11, %9
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"up\00"
@.str.1 = [5 x i8] c"down\00"
@.str.2 = [5 x i8] c"left\00"
@.str.3 = [6 x i8] c"right\00"
@.str.4 = [13 x i8] c"exiting game\00"
@.str.5 = [16 x i8] c"wsad, q to exit\00"
define void @updateLevel([20 x i8]* nocapture readnone %0, i32* nocapture writeonly %1) {
%3 = tail call signext i8 (...) @getch()
%4 = sext i8 %3 to i32
switch i32 %4, label %15 [
i32 119, label %5
i32 115, label %7
i32 97, label %9
i32 100, label %11
i32 113, label %13
]
5: ; preds = %2
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %17
7: ; preds = %2
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %17
9: ; preds = %2
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %17
11: ; preds = %2
%12 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %17
13: ; preds = %2
%14 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %17
15: ; preds = %2
%16 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %17
17: ; preds = %15, %13, %11, %9, %7, %5
ret void
}