#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 */
scalar_t__ check_valid_index(int, int *);
int /*<<< orphan*/ printf(char *);
int get_index(int start_index, int direction, int *board) {
  if (direction > 3 || direction < 0)
    return -1;
  int tmp = 0;
  switch (direction) {
  case 0:
    tmp = start_index + 10;
    break;
  case 1:
    tmp = start_index - 10;
    break;
  case 2:
    tmp = start_index + 1;
    break;
  case 3:
    tmp = start_index - 1;
    break;
  default:
    printf("Direction invalid\n");
  }
  return check_valid_index(tmp, board) ? tmp : -1;
}


x86 assembly (clang, -O0):
<get_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x3,-0xc(%rbp)
jg     1146 <get_index+0x26>
cmpl   $0x0,-0xc(%rbp)
jge    1152 <get_index+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f6 <get_index+0xd6>
movl   $0x0,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    %rax,-0x28(%rbp)
sub    $0x3,%rax
ja     11b6 <get_index+0x96>
mov    -0x28(%rbp),%rax
lea    0xe8b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c2 <get_index+0xa2>
mov    -0x8(%rbp),%eax
sub    $0xa,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c2 <get_index+0xa2>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c2 <get_index+0xa2>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c2 <get_index+0xa2>
lea    0xe53(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1040 <check_valid_index@plt>
cmp    $0x0,%rax
je     11e3 <get_index+0xc3>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    11f0 <get_index+0xd0>
mov    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    11f0 <get_index+0xd0>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_index>:
mov    $0xffffffff,%eax
cmp    $0x3,%esi
ja     1180 <get_index+0x60>
push   %rbp
push   %rbx
push   %rax
mov    %rdx,%rbx
ja     114b <get_index+0x2b>
mov    %edi,%ebp
mov    %esi,%eax
lea    0xec3(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
add    $0xa,%ebp
jmp    1168 <get_index+0x48>
lea    0xebe(%rip),%rdi
call   1030 <puts@plt>
xor    %ebp,%ebp
jmp    1168 <get_index+0x48>
add    $0xfffffff6,%ebp
jmp    1168 <get_index+0x48>
add    $0x1,%ebp
jmp    1168 <get_index+0x48>
add    $0xffffffff,%ebp
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <check_valid_index@plt>
cmp    $0x1,%rax
sbb    %eax,%eax
or     %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Direction invalid\0A\00"
define i32 @get_index(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%9 = load i32, i32* %6
%10 = icmp sgt i32 %9, 3
br i1 %10, label %14, label %11
11: ; preds = %3
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11, %3
store i32 -1, i32* %4
br label %41
15: ; preds = %11
store i32 0, i32* %8
%16 = load i32, i32* %6
switch i32 %16, label %29 [
i32 0, label %17
i32 1, label %20
i32 2, label %23
i32 3, label %26
]
17: ; preds = %15
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 10
store i32 %19, i32* %8
br label %31
20: ; preds = %15
%21 = load i32, i32* %5
%22 = sub nsw i32 %21, 10
store i32 %22, i32* %8
br label %31
23: ; preds = %15
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %8
br label %31
26: ; preds = %15
%27 = load i32, i32* %5
%28 = sub nsw i32 %27, 1
store i32 %28, i32* %8
br label %31
29: ; preds = %15
%30 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %29, %26, %23, %20, %17
%32 = load i32, i32* %8
%33 = load i32*, i32** %7
%34 = call i64 @check_valid_index(i32 %32, i32* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = load i32, i32* %8
br label %39
38: ; preds = %31
br label %39
39: ; preds = %38, %36
%40 = phi i32 [ %37, %36 ], [ -1, %38 ]
store i32 %40, i32* %4
br label %41
41: ; preds = %39, %14
%42 = load i32, i32* %4
ret i32 %42
}

LLVM IR (-O2):
@str = [18 x i8] c"Direction invalid\00"
define i32 @get_index(i32 %0, i32 %1, i32* %2) {
%4 = icmp ugt i32 %1, 3
br i1 %4, label %21, label %5
5: ; preds = %3
switch i32 %1, label %14 [
i32 0, label %6
i32 1, label %8
i32 2, label %10
i32 3, label %12
]
6: ; preds = %5
%7 = add nsw i32 %0, 10
br label %16
8: ; preds = %5
%9 = add nsw i32 %0, -10
br label %16
10: ; preds = %5
%11 = add nsw i32 %0, 1
br label %16
12: ; preds = %5
%13 = add nsw i32 %0, -1
br label %16
14: ; preds = %5
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %16
16: ; preds = %14, %12, %10, %8, %6
%17 = phi i32 [ 0, %14 ], [ %13, %12 ], [ %11, %10 ], [ %9, %8 ], [ %7, %6 ]
%18 = tail call i64 @check_valid_index(i32 %17, i32* %2)
%19 = icmp eq i64 %18, 0
%20 = select i1 %19, i32 -1, i32 %17
br label %21
21: ; preds = %3, %16
%22 = phi i32 [ %20, %16 ], [ -1, %3 ]
ret i32 %22
}