#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 getch();
scalar_t__ kbhit();
int /*<<< orphan*/ pauseMenu();
int checkKeysPressed(int direction) {
  int pressed;
  if (kbhit()) {
    pressed = getch();
    if (direction != pressed) {
      if (pressed == (char)'B' && direction != (char)'A')
        direction = pressed;
      else if (pressed == (char)'A' && direction != (char)'B')
        direction = pressed;
      else if (pressed == (char)'D' && direction != (char)'C')
        direction = pressed;
      else if (pressed == (char)'C' && direction != (char)'D')
        direction = pressed;
      else if (pressed == 27 || pressed == 112)
        pauseMenu();
    }
  }
  return (direction);
}


x86 assembly (clang, -O0):
<checkKeysPressed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1030 <kbhit@plt>
cmp    $0x0,%rax
je     1217 <checkKeysPressed+0xe7>
mov    $0x0,%al
call   1050 <getch@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     1212 <checkKeysPressed+0xe2>
cmpl   $0x42,-0x8(%rbp)
jne    1181 <checkKeysPressed+0x51>
cmpl   $0x41,-0x4(%rbp)
je     1181 <checkKeysPressed+0x51>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    120d <checkKeysPressed+0xdd>
cmpl   $0x41,-0x8(%rbp)
jne    11a0 <checkKeysPressed+0x70>
cmpl   $0x42,-0x4(%rbp)
je     11a0 <checkKeysPressed+0x70>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1208 <checkKeysPressed+0xd8>
cmpl   $0x44,-0x8(%rbp)
jne    11bf <checkKeysPressed+0x8f>
cmpl   $0x43,-0x4(%rbp)
je     11bf <checkKeysPressed+0x8f>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1203 <checkKeysPressed+0xd3>
cmpl   $0x43,-0x8(%rbp)
jne    11de <checkKeysPressed+0xae>
cmpl   $0x44,-0x4(%rbp)
je     11de <checkKeysPressed+0xae>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11fe <checkKeysPressed+0xce>
cmpl   $0x1b,-0x8(%rbp)
je     11f2 <checkKeysPressed+0xc2>
cmpl   $0x70,-0x8(%rbp)
jne    11f9 <checkKeysPressed+0xc9>
mov    $0x0,%al
call   1040 <pauseMenu@plt>
jmp    11fe <checkKeysPressed+0xce>
jmp    1203 <checkKeysPressed+0xd3>
jmp    1208 <checkKeysPressed+0xd8>
jmp    120d <checkKeysPressed+0xdd>
jmp    1212 <checkKeysPressed+0xe2>
jmp    1217 <checkKeysPressed+0xe7>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkKeysPressed>:
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <kbhit@plt>
test   %rax,%rax
je     114a <checkKeysPressed+0x1a>
xor    %eax,%eax
call   1050 <getch@plt>
cmp    %ebx,%eax
jne    1150 <checkKeysPressed+0x20>
mov    %ebx,%ecx
mov    %ecx,%eax
pop    %rbx
ret
cmp    $0x41,%ebx
je     115f <checkKeysPressed+0x2f>
mov    $0x42,%ecx
cmp    $0x42,%eax
je     114c <checkKeysPressed+0x1c>
cmp    $0x42,%ebx
je     116e <checkKeysPressed+0x3e>
mov    $0x41,%ecx
cmp    $0x41,%eax
je     114c <checkKeysPressed+0x1c>
cmp    $0x43,%ebx
je     117d <checkKeysPressed+0x4d>
mov    $0x44,%ecx
cmp    $0x44,%eax
je     114c <checkKeysPressed+0x1c>
cmp    $0x44,%ebx
je     118c <checkKeysPressed+0x5c>
mov    $0x43,%ecx
cmp    $0x43,%eax
je     114c <checkKeysPressed+0x1c>
cmp    $0x70,%eax
je     1196 <checkKeysPressed+0x66>
cmp    $0x1b,%eax
jne    114a <checkKeysPressed+0x1a>
xor    %eax,%eax
call   1040 <pauseMenu@plt>
jmp    114a <checkKeysPressed+0x1a>

LLVM IR (-O0):
define i32 @checkKeysPressed(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = call i64 (...) @kbhit()
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %57
6: ; preds = %1
%7 = call i32 (...) @getch()
store i32 %7, i32* %3
%8 = load i32, i32* %2
%9 = load i32, i32* %3
%10 = icmp ne i32 %8, %9
br i1 %10, label %11, label %56
11: ; preds = %6
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 66
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i32, i32* %2
%16 = icmp ne i32 %15, 65
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = load i32, i32* %3
store i32 %18, i32* %2
br label %55
19: ; preds = %14, %11
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, 65
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i32, i32* %2
%24 = icmp ne i32 %23, 66
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = load i32, i32* %3
store i32 %26, i32* %2
br label %54
27: ; preds = %22, %19
%28 = load i32, i32* %3
%29 = icmp eq i32 %28, 68
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = load i32, i32* %2
%32 = icmp ne i32 %31, 67
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = load i32, i32* %3
store i32 %34, i32* %2
br label %53
35: ; preds = %30, %27
%36 = load i32, i32* %3
%37 = icmp eq i32 %36, 67
br i1 %37, label %38, label %43
38: ; preds = %35
%39 = load i32, i32* %2
%40 = icmp ne i32 %39, 68
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = load i32, i32* %3
store i32 %42, i32* %2
br label %52
43: ; preds = %38, %35
%44 = load i32, i32* %3
%45 = icmp eq i32 %44, 27
br i1 %45, label %49, label %46
46: ; preds = %43
%47 = load i32, i32* %3
%48 = icmp eq i32 %47, 112
br i1 %48, label %49, label %51
49: ; preds = %46, %43
%50 = call i32 (...) @pauseMenu()
br label %51
51: ; preds = %49, %46
br label %52
52: ; preds = %51, %41
br label %53
53: ; preds = %52, %33
br label %54
54: ; preds = %53, %25
br label %55
55: ; preds = %54, %17
br label %56
56: ; preds = %55, %6
br label %57
57: ; preds = %56, %1
%58 = load i32, i32* %2
ret i32 %58
}

LLVM IR (-O2):
define i32 @checkKeysPressed(i32 %0) {
%2 = tail call i64 (...) @kbhit()
%3 = icmp eq i64 %2, 0
br i1 %3, label %26, label %4
4: ; preds = %1
%5 = tail call i32 (...) @getch()
%6 = icmp eq i32 %5, %0
br i1 %6, label %26, label %7
7: ; preds = %4
%8 = icmp eq i32 %5, 66
%9 = icmp ne i32 %0, 65
%10 = and i1 %9, %8
br i1 %10, label %26, label %11
11: ; preds = %7
%12 = icmp eq i32 %5, 65
%13 = icmp ne i32 %0, 66
%14 = and i1 %13, %12
br i1 %14, label %26, label %15
15: ; preds = %11
%16 = icmp eq i32 %5, 68
%17 = icmp ne i32 %0, 67
%18 = and i1 %17, %16
br i1 %18, label %26, label %19
19: ; preds = %15
%20 = icmp eq i32 %5, 67
%21 = icmp ne i32 %0, 68
%22 = and i1 %21, %20
br i1 %22, label %26, label %23
23: ; preds = %19
switch i32 %5, label %26 [
i32 112, label %24
i32 27, label %24
]
24: ; preds = %23, %23
%25 = tail call i32 (...) @pauseMenu()
br label %26
26: ; preds = %23, %19, %15, %11, %7, %4, %24, %1
%27 = phi i32 [ %0, %24 ], [ %0, %23 ], [ %0, %4 ], [ %0, %1 ], [ 66, %7 ], [ 65, %11 ], [ 68, %15 ], [ 67, %19 ]
ret i32 %27
}