#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 *grid_traverse(int, int, int *);
int *get_area_start(int *current_cell, int choice, int *grid_start) {
  int cell_index = current_cell - grid_start;
  int choice_index = 0;
  switch (choice) {
  case 1:
    choice_index = cell_index % 9;
    break;
  case 2:
    choice_index = cell_index / 9;
    break;
  case 3:
    choice_index = (((cell_index / 27) * 3)) + ((cell_index % 9) / 3);
    break;
  }
  return grid_traverse(choice, choice_index, grid_start);
}


x86 assembly (clang, -O0):
<get_area_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
shr    $0x2,%rax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x1,%eax
je     1172 <get_area_start+0x62>
jmp    1150 <get_area_start+0x40>
mov    -0x24(%rbp),%eax
sub    $0x2,%eax
je     1185 <get_area_start+0x75>
jmp    1161 <get_area_start+0x51>
mov    -0x24(%rbp),%eax
sub    $0x3,%eax
je     1198 <get_area_start+0x88>
jmp    11c8 <get_area_start+0xb8>
mov    -0x1c(%rbp),%eax
mov    $0x9,%ecx
cltd
idiv   %ecx
mov    %edx,-0x20(%rbp)
jmp    11c8 <get_area_start+0xb8>
mov    -0x1c(%rbp),%eax
mov    $0x9,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
jmp    11c8 <get_area_start+0xb8>
mov    -0x1c(%rbp),%eax
mov    $0x1b,%ecx
cltd
idiv   %ecx
imul   $0x3,%eax,%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x9,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1030 <grid_traverse@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_area_start>:
mov    %esi,%eax
sub    %rdx,%rdi
shr    $0x2,%rdi
cmp    $0x3,%esi
je     1153 <get_area_start+0x43>
cmp    $0x2,%eax
je     11a9 <get_area_start+0x99>
xor    %esi,%esi
cmp    $0x1,%eax
jne    114c <get_area_start+0x3c>
movslq %edi,%rcx
imul   $0x38e38e39,%rcx,%rcx
mov    %rcx,%rsi
shr    $0x3f,%rsi
sar    $0x21,%rcx
add    %esi,%ecx
lea    (%rcx,%rcx,8),%ecx
sub    %ecx,%edi
mov    %edi,%esi
mov    %eax,%edi
jmp    1030 <grid_traverse@plt>
movslq %edi,%rsi
imul   $0x4bda12f7,%rsi,%rcx
mov    %rcx,%rdi
shr    $0x3f,%rdi
sar    $0x23,%rcx
add    %edi,%ecx
lea    (%rcx,%rcx,2),%r8d
imul   $0x38e38e39,%rsi,%rdi
mov    %rdi,%rcx
shr    $0x3f,%rcx
shr    $0x21,%rdi
add    %ecx,%edi
lea    (%rdi,%rdi,8),%ecx
sub    %ecx,%esi
movsbl %sil,%ecx
imul   $0x56,%ecx,%ecx
movzwl %cx,%ecx
mov    %ecx,%esi
shr    $0xf,%esi
shr    $0x8,%ecx
add    %sil,%cl
movsbl %cl,%esi
add    %r8d,%esi
mov    %eax,%edi
jmp    1030 <grid_traverse@plt>
movslq %edi,%rcx
imul   $0x38e38e39,%rcx,%rsi
mov    %rsi,%rcx
shr    $0x3f,%rcx
sar    $0x21,%rsi
add    %ecx,%esi
mov    %eax,%edi
jmp    1030 <grid_traverse@plt>

LLVM IR (-O0):
define i32* @get_area_start(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** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%9 = load i32*, i32** %4
%10 = load i32*, i32** %6
%11 = ptrtoint i32* %9 to i64
%12 = ptrtoint i32* %10 to i64
%13 = sub i64 %11, %12
%14 = sdiv exact i64 %13, 4
%15 = trunc i64 %14 to i32
store i32 %15, i32* %7
store i32 0, i32* %8
%16 = load i32, i32* %5
switch i32 %16, label %31 [
i32 1, label %17
i32 2, label %20
i32 3, label %23
]
17: ; preds = %3
%18 = load i32, i32* %7
%19 = srem i32 %18, 9
store i32 %19, i32* %8
br label %31
20: ; preds = %3
%21 = load i32, i32* %7
%22 = sdiv i32 %21, 9
store i32 %22, i32* %8
br label %31
23: ; preds = %3
%24 = load i32, i32* %7
%25 = sdiv i32 %24, 27
%26 = mul nsw i32 %25, 3
%27 = load i32, i32* %7
%28 = srem i32 %27, 9
%29 = sdiv i32 %28, 3
%30 = add nsw i32 %26, %29
store i32 %30, i32* %8
br label %31
31: ; preds = %3, %23, %20, %17
%32 = load i32, i32* %5
%33 = load i32, i32* %8
%34 = load i32*, i32** %6
%35 = call i32* @grid_traverse(i32 %32, i32 %33, i32* %34)
ret i32* %35
}

LLVM IR (-O2):
define i32* @get_area_start(i32* %0, i32 %1, i32* %2) {
%4 = ptrtoint i32* %0 to i64
%5 = ptrtoint i32* %2 to i64
%6 = sub i64 %4, %5
%7 = lshr exact i64 %6, 2
%8 = trunc i64 %7 to i32
switch i32 %1, label %21 [
i32 1, label %9
i32 2, label %11
i32 3, label %13
]
9: ; preds = %3
%10 = srem i32 %8, 9
br label %21
11: ; preds = %3
%12 = sdiv i32 %8, 9
br label %21
13: ; preds = %3
%14 = sdiv i32 %8, 27
%15 = mul nsw i32 %14, 3
%16 = srem i32 %8, 9
%17 = trunc i32 %16 to i8
%18 = sdiv i8 %17, 3
%19 = sext i8 %18 to i32
%20 = add nsw i32 %15, %19
br label %21
21: ; preds = %3, %13, %11, %9
%22 = phi i32 [ 0, %3 ], [ %20, %13 ], [ %12, %11 ], [ %10, %9 ]
%23 = tail call i32* @grid_traverse(i32 %1, i32 %22, i32* %2)
ret i32* %23
}