#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 getCursorPos();
int /*<<< orphan*/ setCursorPos(int);
void navigate(int c) {
  int position = getCursorPos();
  int mov;
  switch (c) {
  case 'W':
  case 'w':
    mov = -((1024 / 6) / 2);
    break;
  case 'A':
  case 'a':
    mov = -1;
    ;
    break;
  case 'S':
  case 's':
    mov = ((1024 / 6) / 2);
    break;
  case 'D':
  case 'd':
    mov = 1;
    break;
  };
  if (position + mov >= ((((768 / 8) / 2)) - 1) * ((1024 / 6) / 2))
    return;
  position += mov;
  setCursorPos(position);
}


x86 assembly (clang, -O0):
<navigate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
xor    %eax,%eax
call   1030 <getCursorPos@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffbf,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x36,%eax
ja     1189 <navigate+0x69>
mov    -0x18(%rbp),%rax
lea    0xeab(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0xffffffab,-0xc(%rbp)
jmp    1189 <navigate+0x69>
movl   $0xffffffff,-0xc(%rbp)
jmp    1189 <navigate+0x69>
movl   $0x55,-0xc(%rbp)
jmp    1189 <navigate+0x69>
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
cmp    $0xf9b,%eax
jl     119f <navigate+0x7f>
jmp    11b0 <navigate+0x90>
mov    -0xc(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <setCursorPos@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<navigate>:
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <getCursorPos@plt>
mov    $0xffffffab,%edi
add    $0xffffffbf,%ebx
cmp    $0x32,%ebx
ja     117a <navigate+0x5a>
movabs $0x100000001,%rcx
bt     %rbx,%rcx
jb     116e <navigate+0x4e>
movabs $0x800000008,%rcx
bt     %rbx,%rcx
jb     1175 <navigate+0x55>
movabs $0x4000000040000,%rcx
bt     %rbx,%rcx
jae    117a <navigate+0x5a>
mov    $0x55,%edi
jmp    117a <navigate+0x5a>
mov    $0xffffffff,%edi
jmp    117a <navigate+0x5a>
mov    $0x1,%edi
add    %eax,%edi
cmp    $0xf9a,%edi
jle    1186 <navigate+0x66>
pop    %rbx
ret
pop    %rbx
jmp    1040 <setCursorPos@plt>

LLVM IR (-O0):
define void @navigate(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i32 (...) @getCursorPos()
store i32 %5, i32* %3
%6 = load i32, i32* %2
switch i32 %6, label %11 [
i32 87, label %7
i32 119, label %7
i32 65, label %8
i32 97, label %8
i32 83, label %9
i32 115, label %9
i32 68, label %10
i32 100, label %10
]
7: ; preds = %1, %1
store i32 -85, i32* %4
br label %11
8: ; preds = %1, %1
store i32 -1, i32* %4
br label %11
9: ; preds = %1, %1
store i32 85, i32* %4
br label %11
10: ; preds = %1, %1
store i32 1, i32* %4
br label %11
11: ; preds = %1, %10, %9, %8, %7
%12 = load i32, i32* %3
%13 = load i32, i32* %4
%14 = add nsw i32 %12, %13
%15 = icmp sge i32 %14, 3995
br i1 %15, label %16, label %17
16: ; preds = %11
br label %23
17: ; preds = %11
%18 = load i32, i32* %4
%19 = load i32, i32* %3
%20 = add nsw i32 %19, %18
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = call i32 @setCursorPos(i32 %21)
br label %23
23: ; preds = %17, %16
ret void
}

LLVM IR (-O2):
define void @navigate(i32 %0) {
%2 = tail call i32 (...) @getCursorPos()
switch i32 %0, label %6 [
i32 100, label %5
i32 68, label %5
i32 65, label %3
i32 97, label %3
i32 83, label %4
i32 115, label %4
]
3: ; preds = %1, %1
br label %6
4: ; preds = %1, %1
br label %6
5: ; preds = %1, %1
br label %6
6: ; preds = %1, %5, %4, %3
%7 = phi i32 [ 1, %5 ], [ 85, %4 ], [ -1, %3 ], [ -85, %1 ]
%8 = add nsw i32 %7, %2
%9 = icmp sgt i32 %8, 3994
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i32 @setCursorPos(i32 %8)
br label %12
12: ; preds = %6, %10
ret void
}