#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__ find_path(int, int, int **, int, int, int, int);
int /*<<< orphan*/ printf(char *);
int scanf(char *, int *, ...);
int main(void) {
  printf("Enter the dimensions of the puzzle, followed by each puzzle cell "
         "element,\n"
         "followed by the origin coordinates, followed by the target "
         "coordinates.\n");
  printf("> ");
  int size_x, size_y;
  while (scanf("%d%d", &size_x, &size_y) == 2) {
    int puzzle[size_x][size_y];
    int i;
    for (i = 0; i < size_x; i++) {
      int j;
      for (j = 0; j < size_y; j++) {
        scanf("%d", &puzzle[i][j]);
      }
    }
    int origin_x, origin_y;
    int target_x, target_y;
    scanf("%d%d%d%d", &origin_x, &origin_y, &target_x, &target_y);
    if (find_path(size_x, size_y, puzzle, origin_x, origin_y, target_x,
                  target_y)) {
      printf("Found path.\n");
    } else {
      printf("Path not found.\n");
    }
    printf("> ");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1040 <printf@plt>
lea    0xf41(%rip),%rdi
call   1040 <printf@plt>
lea    0xf3c(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1050 <scanf@plt>
cmp    $0x2,%eax
jne    12ad <main+0x17d>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
mov    %rax,-0x50(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x18(%rbp)
mov    %rcx,%rdx
imul   %rax,%rdx
lea    0xf(,%rdx,4),%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x48(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x20(%rbp)
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1228 <main+0xf8>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1215 <main+0xe5>
mov    -0x48(%rbp),%rsi
mov    -0x50(%rbp),%rcx
movslq -0x2c(%rbp),%rax
imul   %rcx,%rax
shl    $0x2,%rax
add    %rax,%rsi
movslq -0x30(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11cb <main+0x9b>
jmp    121a <main+0xea>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b8 <main+0x88>
lea    0xe67(%rip),%rdi
lea    -0x34(%rbp),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x3c(%rbp),%rcx
lea    -0x40(%rbp),%r8
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x48(%rbp),%rdx
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x34(%rbp),%ecx
mov    -0x38(%rbp),%r8d
mov    -0x3c(%rbp),%r9d
mov    -0x40(%rbp),%eax
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   1030 <find_path@plt>
add    $0x10,%rsp
cmp    $0x0,%rax
je     1289 <main+0x159>
lea    0xe20(%rip),%rdi
call   1040 <printf@plt>
jmp    1295 <main+0x165>
lea    0xe1c(%rip),%rdi
call   1040 <printf@plt>
lea    0xdf7(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
jmp    1157 <main+0x27>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xeb4(%rip),%rdi
call   1040 <puts@plt>
lea    0xe9c(%rip),%rdi
call   1050 <printf@plt>
lea    0xe97(%rip),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
cmp    $0x2,%eax
jne    12c3 <main+0x183>
lea    0xe7a(%rip),%rbx
jmp    122d <main+0xed>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xe5c(%rip),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
lea    -0x38(%rbp),%rcx
lea    -0x34(%rbp),%r8
xor    %eax,%eax
call   1060 <scanf@plt>
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x40(%rbp),%ecx
mov    -0x3c(%rbp),%r8d
mov    -0x38(%rbp),%r9d
mov    -0x34(%rbp),%eax
sub    $0x8,%rsp
mov    -0x48(%rbp),%rdx
push   %rax
call   1030 <find_path@plt>
add    $0x10,%rsp
test   %rax,%rax
lea    0xec0(%rip),%rdi
lea    0xea9(%rip),%rax
cmove  %rax,%rdi
call   1040 <puts@plt>
lea    0xdfb(%rip),%rdi
call   1050 <printf@plt>
mov    -0x58(%rbp),%rsp
lea    0xdf2(%rip),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
cmp    $0x2,%eax
jne    12c3 <main+0x183>
mov    %rsp,-0x58(%rbp)
mov    -0x30(%rbp),%eax
mov    -0x2c(%rbp),%ecx
mov    %rcx,-0x50(%rbp)
imul   %rcx,%rax
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rcx
sub    %rax,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    -0x30(%rbp),%ecx
test   %ecx,%ecx
jle    11a0 <main+0x60>
mov    -0x2c(%rbp),%eax
shlq   $0x2,-0x50(%rbp)
mov    -0x48(%rbp),%r15
xor    %r13d,%r13d
jmp    1294 <main+0x154>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r13
movslq %ecx,%rdx
add    -0x50(%rbp),%r15
cmp    %rdx,%r13
jge    11a0 <main+0x60>
test   %eax,%eax
jle    1280 <main+0x140>
mov    %r15,%r12
xor    %r14d,%r14d
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
add    $0x1,%r14
movslq -0x2c(%rbp),%rax
add    $0x4,%r12
cmp    %rax,%r14
jl     12a0 <main+0x160>
mov    -0x30(%rbp),%ecx
jmp    1280 <main+0x140>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [147 x i8] c"Enter the dimensions of the puzzle, followed by each puzzle cell element,\0Afollowed by the origin coordinates, followed by the target coordinates.\0A\00"
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [5 x i8] c"%d%d\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [9 x i8] c"%d%d%d%d\00"
@.str.5 = [13 x i8] c"Found path.\0A\00"
@.str.6 = [17 x i8] c"Path not found.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %1
%13 = call i32 @printf(i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %66, %0
%16 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %2, i32* %3)
%17 = icmp eq i32 %16, 2
br i1 %17, label %18, label %69
18: ; preds = %15
%19 = load i32, i32* %2
%20 = zext i32 %19 to i64
%21 = load i32, i32* %3
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %4
%24 = mul nuw i64 %20, %22
%25 = alloca i32, i64 %24
store i64 %20, i64* %5
store i64 %22, i64* %6
store i32 0, i32* %7
br label %26
26: ; preds = %48, %18
%27 = load i32, i32* %7
%28 = load i32, i32* %2
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %51
30: ; preds = %26
store i32 0, i32* %8
br label %31
31: ; preds = %44, %30
%32 = load i32, i32* %8
%33 = load i32, i32* %3
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %47
35: ; preds = %31
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = mul nsw i64 %37, %22
%39 = getelementptr inbounds i32, i32* %25, i64 %38
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
%43 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %42)
br label %44
44: ; preds = %35
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
br label %31
47: ; preds = %31
br label %48
48: ; preds = %47
%49 = load i32, i32* %7
%50 = add nsw i32 %49, 1
store i32 %50, i32* %7
br label %26
51: ; preds = %26
%52 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32* %9, i32* %10, i32* %11, i32* %12)
%53 = load i32, i32* %2
%54 = load i32, i32* %3
%55 = bitcast i32* %25 to i32**
%56 = load i32, i32* %9
%57 = load i32, i32* %10
%58 = load i32, i32* %11
%59 = load i32, i32* %12
%60 = call i64 @find_path(i32 %53, i32 %54, i32** %55, i32 %56, i32 %57, i32 %58, i32 %59)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %51
%63 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %66
64: ; preds = %51
%65 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
br label %66
66: ; preds = %64, %62
%67 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%68 = load i8*, i8** %4
br label %15
69: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [5 x i8] c"%d%d\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [9 x i8] c"%d%d%d%d\00"
@str = [146 x i8] c"Enter the dimensions of the puzzle, followed by each puzzle cell element,\0Afollowed by the origin coordinates, followed by the target coordinates.\00"
@str.7 = [16 x i8] c"Path not found.\00"
@str.8 = [12 x i8] c"Found path.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([146 x i8], [146 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = bitcast i32* %1 to i8*
%10 = bitcast i32* %2 to i8*
%11 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %1, i32* %2)
%12 = icmp eq i32 %11, 2
br i1 %12, label %13, label %70
13: ; preds = %0
%14 = bitcast i32* %3 to i8*
%15 = bitcast i32* %4 to i8*
%16 = bitcast i32* %5 to i8*
%17 = bitcast i32* %6 to i8*
br label %18
18: ; preds = %13, %54
%19 = load i32, i32* %1
%20 = zext i32 %19 to i64
%21 = load i32, i32* %2
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
%24 = mul nuw i64 %22, %20
%25 = alloca i32, i64 %24
%26 = load i32, i32* %1
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %54
28: ; preds = %18
%29 = load i32, i32* %2
br label %30
30: ; preds = %28, %48
%31 = phi i32 [ %26, %28 ], [ %49, %48 ]
%32 = phi i32 [ %29, %28 ], [ %50, %48 ]
%33 = phi i64 [ 0, %28 ], [ %51, %48 ]
%34 = icmp sgt i32 %32, 0
br i1 %34, label %35, label %48
35: ; preds = %30
%36 = mul nuw nsw i64 %33, %22
%37 = getelementptr inbounds i32, i32* %25, i64 %36
br label %38
38: ; preds = %35, %38
%39 = phi i64 [ 0, %35 ], [ %42, %38 ]
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %40)
%42 = add nuw nsw i64 %39, 1
%43 = load i32, i32* %2
%44 = sext i32 %43 to i64
%45 = icmp slt i64 %42, %44
br i1 %45, label %38, label %46
46: ; preds = %38
%47 = load i32, i32* %1
br label %48
48: ; preds = %46, %30
%49 = phi i32 [ %47, %46 ], [ %31, %30 ]
%50 = phi i32 [ %43, %46 ], [ %32, %30 ]
%51 = add nuw nsw i64 %33, 1
%52 = sext i32 %49 to i64
%53 = icmp slt i64 %51, %52
br i1 %53, label %30, label %54
54: ; preds = %48, %18
%55 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32* %3, i32* %4, i32* %5, i32* %6)
%56 = load i32, i32* %1
%57 = load i32, i32* %2
%58 = bitcast i32* %25 to i32**
%59 = load i32, i32* %3
%60 = load i32, i32* %4
%61 = load i32, i32* %5
%62 = load i32, i32* %6
%63 = call i64 @find_path(i32 %56, i32 %57, i32** %58, i32 %59, i32 %60, i32 %61, i32 %62)
%64 = icmp eq i64 %63, 0
%65 = select i1 %64, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @str.7, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str.8, i64 0, i64 0)
%66 = call i32 @puts(i8* dereferenceable(1) %65)
%67 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%68 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %1, i32* %2)
%69 = icmp eq i32 %68, 2
br i1 %69, label %18, label %70
70: ; preds = %54, %0
ret i32 0
}