#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 maze {
  int dummy;
};

/* Variables and functions */
int maze_get_cell_distance(struct maze *, int, int);
int /*<<< orphan*/ maze_try_visit_cell(struct maze *, int, int, int, int, int *,
                                       int *, int);
int maze_find_any_next_cell(struct maze *mp, int cr, int cc, int *nr, int *nc) {
  int d = maze_get_cell_distance(mp, cr, cc) + 1;
  if (!maze_try_visit_cell(mp, cr, cc, cr, cc - 1, nr, nc, d))
    return 1;
  if (!maze_try_visit_cell(mp, cr, cc, cr, cc + 1, nr, nc, d))
    return 1;
  if (!maze_try_visit_cell(mp, cr, cc, cr - 1, cc, nr, nc, d))
    return 1;
  if (!maze_try_visit_cell(mp, cr, cc, cr + 1, cc, nr, nc, d))
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<maze_find_any_next_cell>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1040 <maze_get_cell_distance@plt>
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
sub    $0x1,%r8d
mov    -0x20(%rbp),%r9
mov    -0x28(%rbp),%r10
mov    -0x2c(%rbp),%eax
mov    %r10,(%rsp)
mov    %eax,0x8(%rsp)
call   1030 <maze_try_visit_cell@plt>
cmp    $0x0,%eax
jne    1191 <maze_find_any_next_cell+0x71>
movl   $0x1,-0x4(%rbp)
jmp    125c <maze_find_any_next_cell+0x13c>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
add    $0x1,%r8d
mov    -0x20(%rbp),%r9
mov    -0x28(%rbp),%r10
mov    -0x2c(%rbp),%eax
mov    %r10,(%rsp)
mov    %eax,0x8(%rsp)
call   1030 <maze_try_visit_cell@plt>
cmp    $0x0,%eax
jne    11d3 <maze_find_any_next_cell+0xb3>
movl   $0x1,-0x4(%rbp)
jmp    125c <maze_find_any_next_cell+0x13c>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x18(%rbp),%r8d
mov    -0x20(%rbp),%r9
mov    -0x28(%rbp),%r10
mov    -0x2c(%rbp),%eax
mov    %r10,(%rsp)
mov    %eax,0x8(%rsp)
call   1030 <maze_try_visit_cell@plt>
cmp    $0x0,%eax
jne    1214 <maze_find_any_next_cell+0xf4>
movl   $0x1,-0x4(%rbp)
jmp    125c <maze_find_any_next_cell+0x13c>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%r8d
mov    -0x20(%rbp),%r9
mov    -0x28(%rbp),%r10
mov    -0x2c(%rbp),%eax
mov    %r10,(%rsp)
mov    %eax,0x8(%rsp)
call   1030 <maze_try_visit_cell@plt>
cmp    $0x0,%eax
jne    1255 <maze_find_any_next_cell+0x135>
movl   $0x1,-0x4(%rbp)
jmp    125c <maze_find_any_next_cell+0x13c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<maze_find_any_next_cell>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r14
mov    %rcx,%rbp
mov    %edx,%r12d
mov    %esi,%ebx
mov    %rdi,%r13
call   1040 <maze_get_cell_distance@plt>
mov    %eax,%r15d
add    $0x1,%r15d
lea    -0x1(%r12),%r8d
mov    %r13,%rdi
mov    %ebx,%esi
mov    %r12d,%edx
mov    %ebx,%ecx
mov    %rbp,0x10(%rsp)
mov    %rbp,%r9
push   %r15
mov    %r14,0x10(%rsp)
push   %r14
call   1030 <maze_try_visit_cell@plt>
add    $0x10,%rsp
mov    $0x1,%r14d
test   %eax,%eax
je     11f2 <maze_find_any_next_cell+0xd2>
lea    0x1(%r12),%r8d
mov    %r13,%rdi
mov    %ebx,%esi
mov    %r12d,%edx
mov    %ebx,%ecx
mov    0x10(%rsp),%rbp
mov    %rbp,%r9
push   %r15
push   0x10(%rsp)
call   1030 <maze_try_visit_cell@plt>
add    $0x10,%rsp
test   %eax,%eax
je     11f2 <maze_find_any_next_cell+0xd2>
lea    -0x1(%rbx),%ecx
mov    %r13,%rdi
mov    %ebx,%esi
mov    %r12d,%edx
mov    %r12d,%r8d
mov    %rbp,%r9
push   %r15
push   0x10(%rsp)
call   1030 <maze_try_visit_cell@plt>
add    $0x10,%rsp
test   %eax,%eax
je     11f2 <maze_find_any_next_cell+0xd2>
lea    0x1(%rbx),%ecx
mov    %r13,%rdi
mov    %ebx,%esi
mov    %r12d,%edx
mov    %r12d,%r8d
mov    %rbp,%r9
push   %r15
push   0x10(%rsp)
call   1030 <maze_try_visit_cell@plt>
add    $0x10,%rsp
xor    %r14d,%r14d
test   %eax,%eax
sete   %r14b
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.maze = type { i32 }
define i32 @maze_find_any_next_cell(%struct.maze* %0, i32 %1, i32 %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca %struct.maze*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
store %struct.maze* %0, %struct.maze** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32* %3, i32** %10
store i32* %4, i32** %11
%13 = load %struct.maze*, %struct.maze** %7
%14 = load i32, i32* %8
%15 = load i32, i32* %9
%16 = call i32 @maze_get_cell_distance(%struct.maze* %13, i32 %14, i32 %15)
%17 = add nsw i32 %16, 1
store i32 %17, i32* %12
%18 = load %struct.maze*, %struct.maze** %7
%19 = load i32, i32* %8
%20 = load i32, i32* %9
%21 = load i32, i32* %8
%22 = load i32, i32* %9
%23 = sub nsw i32 %22, 1
%24 = load i32*, i32** %10
%25 = load i32*, i32** %11
%26 = load i32, i32* %12
%27 = call i32 @maze_try_visit_cell(%struct.maze* %18, i32 %19, i32 %20, i32 %21, i32 %23, i32* %24, i32* %25, i32 %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %5
store i32 1, i32* %6
br label %70
30: ; preds = %5
%31 = load %struct.maze*, %struct.maze** %7
%32 = load i32, i32* %8
%33 = load i32, i32* %9
%34 = load i32, i32* %8
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
%37 = load i32*, i32** %10
%38 = load i32*, i32** %11
%39 = load i32, i32* %12
%40 = call i32 @maze_try_visit_cell(%struct.maze* %31, i32 %32, i32 %33, i32 %34, i32 %36, i32* %37, i32* %38, i32 %39)
%41 = icmp ne i32 %40, 0
br i1 %41, label %43, label %42
42: ; preds = %30
store i32 1, i32* %6
br label %70
43: ; preds = %30
%44 = load %struct.maze*, %struct.maze** %7
%45 = load i32, i32* %8
%46 = load i32, i32* %9
%47 = load i32, i32* %8
%48 = sub nsw i32 %47, 1
%49 = load i32, i32* %9
%50 = load i32*, i32** %10
%51 = load i32*, i32** %11
%52 = load i32, i32* %12
%53 = call i32 @maze_try_visit_cell(%struct.maze* %44, i32 %45, i32 %46, i32 %48, i32 %49, i32* %50, i32* %51, i32 %52)
%54 = icmp ne i32 %53, 0
br i1 %54, label %56, label %55
55: ; preds = %43
store i32 1, i32* %6
br label %70
56: ; preds = %43
%57 = load %struct.maze*, %struct.maze** %7
%58 = load i32, i32* %8
%59 = load i32, i32* %9
%60 = load i32, i32* %8
%61 = add nsw i32 %60, 1
%62 = load i32, i32* %9
%63 = load i32*, i32** %10
%64 = load i32*, i32** %11
%65 = load i32, i32* %12
%66 = call i32 @maze_try_visit_cell(%struct.maze* %57, i32 %58, i32 %59, i32 %61, i32 %62, i32* %63, i32* %64, i32 %65)
%67 = icmp ne i32 %66, 0
br i1 %67, label %69, label %68
68: ; preds = %56
store i32 1, i32* %6
br label %70
69: ; preds = %56
store i32 0, i32* %6
br label %70
70: ; preds = %69, %68, %55, %42, %29
%71 = load i32, i32* %6
ret i32 %71
}

LLVM IR (-O2):
%struct.maze = type { i32 }
define i32 @maze_find_any_next_cell(%struct.maze* %0, i32 %1, i32 %2, i32* %3, i32* %4) {
%6 = tail call i32 @maze_get_cell_distance(%struct.maze* %0, i32 %1, i32 %2)
%7 = add nsw i32 %6, 1
%8 = add nsw i32 %2, -1
%9 = tail call i32 @maze_try_visit_cell(%struct.maze* %0, i32 %1, i32 %2, i32 %1, i32 %8, i32* %3, i32* %4, i32 %7)
%10 = icmp eq i32 %9, 0
br i1 %10, label %24, label %11
11: ; preds = %5
%12 = add nsw i32 %2, 1
%13 = tail call i32 @maze_try_visit_cell(%struct.maze* %0, i32 %1, i32 %2, i32 %1, i32 %12, i32* %3, i32* %4, i32 %7)
%14 = icmp eq i32 %13, 0
br i1 %14, label %24, label %15
15: ; preds = %11
%16 = add nsw i32 %1, -1
%17 = tail call i32 @maze_try_visit_cell(%struct.maze* %0, i32 %1, i32 %2, i32 %16, i32 %2, i32* %3, i32* %4, i32 %7)
%18 = icmp eq i32 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %15
%20 = add nsw i32 %1, 1
%21 = tail call i32 @maze_try_visit_cell(%struct.maze* %0, i32 %1, i32 %2, i32 %20, i32 %2, i32* %3, i32* %4, i32 %7)
%22 = icmp eq i32 %21, 0
%23 = zext i1 %22 to i32
br label %24
24: ; preds = %19, %15, %11, %5
%25 = phi i32 [ 1, %5 ], [ 1, %11 ], [ 1, %15 ], [ %23, %19 ]
ret i32 %25
}