#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 */
struct grid {
  int dummy;
};

/* Variables and functions */
scalar_t__ can_walk_to(struct grid *, int, int, int);
scalar_t__ is_within_ij(struct grid *, int, int);
int walk_attempt(struct grid *g, int ni, int nj, int k) {
  if (is_within_ij(g, ni, nj) && k >= 0 && k < 8) {
    if (can_walk_to(g, ni, nj, k)) {
      return 0;
    } else {
      if (k + 1 < 8 && can_walk_to(g, ni, nj, k + 1)) {
        return 1;
      } else {
        if (k > 0 && can_walk_to(g, ni, nj, k - 1)) {
          return -1;
        } else {
          return -99;
        }
      }
    }
  } else {
    return -99;
  }
}


x86 assembly (clang, -O0):
<walk_attempt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1040 <is_within_ij@plt>
cmp    $0x0,%rax
je     1205 <walk_attempt+0xe5>
cmpl   $0x0,-0x1c(%rbp)
jl     1205 <walk_attempt+0xe5>
cmpl   $0x8,-0x1c(%rbp)
jge    1205 <walk_attempt+0xe5>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1030 <can_walk_to@plt>
cmp    $0x0,%rax
je     118a <walk_attempt+0x6a>
movl   $0x0,-0x4(%rbp)
jmp    120c <walk_attempt+0xec>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cmp    $0x8,%eax
jge    11c4 <walk_attempt+0xa4>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
call   1030 <can_walk_to@plt>
cmp    $0x0,%rax
je     11c4 <walk_attempt+0xa4>
movl   $0x1,-0x4(%rbp)
jmp    120c <walk_attempt+0xec>
cmpl   $0x0,-0x1c(%rbp)
jle    11f9 <walk_attempt+0xd9>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
call   1030 <can_walk_to@plt>
cmp    $0x0,%rax
je     11f9 <walk_attempt+0xd9>
movl   $0xffffffff,-0x4(%rbp)
jmp    120c <walk_attempt+0xec>
movl   $0xffffff9d,-0x4(%rbp)
jmp    120c <walk_attempt+0xec>
movl   $0xffffff9d,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<walk_attempt>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbp
call   1040 <is_within_ij@plt>
mov    %rax,%rcx
mov    $0xffffff9d,%eax
cmp    $0x7,%ebx
ja     1163 <walk_attempt+0x43>
test   %rcx,%rcx
je     1163 <walk_attempt+0x43>
mov    %rbp,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
mov    %ebx,%ecx
call   1030 <can_walk_to@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     116e <walk_attempt+0x4e>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0x6,%ebx
ja     1195 <walk_attempt+0x75>
lea    0x1(%rbx),%ecx
mov    %rbp,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
call   1030 <can_walk_to@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    1163 <walk_attempt+0x43>
test   %ebx,%ebx
je     11b5 <walk_attempt+0x95>
add    $0xffffffff,%ebx
mov    %rbp,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
mov    %ebx,%ecx
call   1030 <can_walk_to@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    1163 <walk_attempt+0x43>
mov    $0xffffff9d,%eax
jmp    1163 <walk_attempt+0x43>

LLVM IR (-O0):
%struct.grid = type { i32 }
define i32 @walk_attempt(%struct.grid* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.grid*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store %struct.grid* %0, %struct.grid** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%10 = load %struct.grid*, %struct.grid** %6
%11 = load i32, i32* %7
%12 = load i32, i32* %8
%13 = call i64 @is_within_ij(%struct.grid* %10, i32 %11, i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %55
15: ; preds = %4
%16 = load i32, i32* %9
%17 = icmp sge i32 %16, 0
br i1 %17, label %18, label %55
18: ; preds = %15
%19 = load i32, i32* %9
%20 = icmp slt i32 %19, 8
br i1 %20, label %21, label %55
21: ; preds = %18
%22 = load %struct.grid*, %struct.grid** %6
%23 = load i32, i32* %7
%24 = load i32, i32* %8
%25 = load i32, i32* %9
%26 = call i64 @can_walk_to(%struct.grid* %22, i32 %23, i32 %24, i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %21
store i32 0, i32* %5
br label %56
29: ; preds = %21
%30 = load i32, i32* %9
%31 = add nsw i32 %30, 1
%32 = icmp slt i32 %31, 8
br i1 %32, label %33, label %42
33: ; preds = %29
%34 = load %struct.grid*, %struct.grid** %6
%35 = load i32, i32* %7
%36 = load i32, i32* %8
%37 = load i32, i32* %9
%38 = add nsw i32 %37, 1
%39 = call i64 @can_walk_to(%struct.grid* %34, i32 %35, i32 %36, i32 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %33
store i32 1, i32* %5
br label %56
42: ; preds = %33, %29
%43 = load i32, i32* %9
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %54
45: ; preds = %42
%46 = load %struct.grid*, %struct.grid** %6
%47 = load i32, i32* %7
%48 = load i32, i32* %8
%49 = load i32, i32* %9
%50 = sub nsw i32 %49, 1
%51 = call i64 @can_walk_to(%struct.grid* %46, i32 %47, i32 %48, i32 %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %45
store i32 -1, i32* %5
br label %56
54: ; preds = %45, %42
store i32 -99, i32* %5
br label %56
55: ; preds = %18, %15, %4
store i32 -99, i32* %5
br label %56
56: ; preds = %55, %54, %53, %41, %28
%57 = load i32, i32* %5
ret i32 %57
}

LLVM IR (-O2):
%struct.grid = type { i32 }
define i32 @walk_attempt(%struct.grid* %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i64 @is_within_ij(%struct.grid* %0, i32 %1, i32 %2)
%6 = icmp ne i64 %5, 0
%7 = icmp ult i32 %3, 8
%8 = and i1 %7, %6
br i1 %8, label %9, label %25
9: ; preds = %4
%10 = tail call i64 @can_walk_to(%struct.grid* %0, i32 %1, i32 %2, i32 %3)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %25
12: ; preds = %9
%13 = icmp ult i32 %3, 7
br i1 %13, label %14, label %20
14: ; preds = %12
%15 = add nuw nsw i32 %3, 1
%16 = tail call i64 @can_walk_to(%struct.grid* %0, i32 %1, i32 %2, i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %14
%19 = icmp eq i32 %3, 0
br i1 %19, label %24, label %20
20: ; preds = %12, %18
%21 = add nsw i32 %3, -1
%22 = tail call i64 @can_walk_to(%struct.grid* %0, i32 %1, i32 %2, i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20, %18
br label %25
25: ; preds = %4, %20, %14, %9, %24
%26 = phi i32 [ -99, %24 ], [ 0, %9 ], [ 1, %14 ], [ -1, %20 ], [ -99, %4 ]
ret i32 %26
}