#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 /*<<< orphan*/ printf(char *, ...);
int find_path(int *ptr, int last_row, int last_column) {
  if (last_row == 19 && last_column == 19) {
    printf("Shortest Path");
    return 0;
  }
  if (*(ptr) == 0) {
    printf("No shortest path from (0,0) to (19,19).\n");
    return 0;
  } else if (*(ptr) == 1) {
    ptr++;
    if (*(ptr) == 1) {
      last_column++;
      printf("(%d,%d)\n", last_row, last_column);
      return find_path(ptr, last_row, last_column);
    }
    ptr--;
    ptr += 20;
    if (*(ptr) == 1) {
      last_row++;
      printf("(%d,%d)\n", last_row, last_column);
      return find_path(ptr, last_row, last_column);
    }
    *(ptr) = 0;
    ptr -= 20;
    *(ptr) = 0;
    ptr--;
    if (*(ptr) == 1) {
      last_column--;
      printf("(%d,%d)\n", last_row, last_column);
      return find_path(ptr, last_row, last_column);
    } else {
      printf("Pointer did not shift any direction. There is no shortest path "
             "in this matrix.\n");
      return 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<find_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
cmpl   $0x13,-0x14(%rbp)
jne    1160 <find_path+0x40>
cmpl   $0x13,-0x18(%rbp)
jne    1160 <find_path+0x40>
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12cd <find_path+0x1ad>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1187 <find_path+0x67>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12cd <find_path+0x1ad>
mov    -0x10(%rbp),%rax
cmpl   $0x1,(%rax)
jne    12c1 <find_path+0x1a1>
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x1,(%rax)
jne    11e1 <find_path+0xc1>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <find_path@plt>
mov    %eax,-0x4(%rbp)
jmp    12cd <find_path+0x1ad>
mov    -0x10(%rbp),%rax
add    $0xfffffffffffffffc,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x50,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x1,(%rax)
jne    123a <find_path+0x11a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <find_path@plt>
mov    %eax,-0x4(%rbp)
jmp    12cd <find_path+0x1ad>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffb0,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0xfffffffffffffffc,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x1,(%rax)
jne    12a7 <find_path+0x187>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <find_path@plt>
mov    %eax,-0x4(%rbp)
jmp    12cd <find_path+0x1ad>
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12cd <find_path+0x1ad>
jmp    12c6 <find_path+0x1a6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_path>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%rbp
cmp    $0x13,%esi
sete   %r12b
jne    1151 <find_path+0x31>
cmp    $0x13,%ebx
jne    1151 <find_path+0x31>
lea    0xebb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11fc <find_path+0xdc>
lea    0xeb6(%rip),%r15
jmp    1185 <find_path+0x65>
nopw   0x0(%rax,%rax,1)
add    $0x4,%rbp
mov    $0x1,%eax
add    %eax,%ebx
mov    %r15,%rdi
mov    %r14d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x13,%ebx
sete   %al
test   %al,%r12b
jne    113e <find_path+0x1e>
mov    0x0(%rbp),%eax
cmp    $0x1,%eax
jne    11e3 <find_path+0xc3>
cmpl   $0x1,0x4(%rbp)
je     1160 <find_path+0x40>
cmpl   $0x1,0x50(%rbp)
je     11b8 <find_path+0x98>
movl   $0x0,0x50(%rbp)
movl   $0x0,0x0(%rbp)
cmpl   $0x1,-0x4(%rbp)
jne    11f0 <find_path+0xd0>
add    $0xfffffffffffffffc,%rbp
mov    $0xffffffff,%eax
jmp    1169 <find_path+0x49>
add    $0x50,%rbp
add    $0x1,%r14d
mov    %r15,%rdi
mov    %r14d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x13,%r14d
sete   %r12b
jne    1185 <find_path+0x65>
cmp    $0x13,%ebx
jne    1185 <find_path+0x65>
jmp    113e <find_path+0x1e>
test   %eax,%eax
jne    11fc <find_path+0xdc>
lea    0xe78(%rip),%rdi
jmp    11f7 <find_path+0xd7>
lea    0xe20(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Shortest Path\00"
@.str.1 = [41 x i8] c"No shortest path from (0,0) to (19,19).\0A\00"
@.str.2 = [9 x i8] c"(%d,%d)\0A\00"
@.str.3 = [80 x i8] c"Pointer did not shift any direction. There is no shortest path in this matrix.\0A\00"
define i32 @find_path(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i32, i32* %6
%9 = icmp eq i32 %8, 19
br i1 %9, label %10, label %15
10: ; preds = %3
%11 = load i32, i32* %7
%12 = icmp eq i32 %11, 19
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %83
15: ; preds = %10, %3
%16 = load i32*, i32** %5
%17 = load i32, i32* %16
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %83
21: ; preds = %15
%22 = load i32*, i32** %5
%23 = load i32, i32* %22
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %81
25: ; preds = %21
%26 = load i32*, i32** %5
%27 = getelementptr inbounds i32, i32* %26, i32 1
store i32* %27, i32** %5
%28 = load i32*, i32** %5
%29 = load i32, i32* %28
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %41
31: ; preds = %25
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
%34 = load i32, i32* %6
%35 = load i32, i32* %7
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %34, i32 %35)
%37 = load i32*, i32** %5
%38 = load i32, i32* %6
%39 = load i32, i32* %7
%40 = call i32 @find_path(i32* %37, i32 %38, i32 %39)
store i32 %40, i32* %4
br label %83
41: ; preds = %25
%42 = load i32*, i32** %5
%43 = getelementptr inbounds i32, i32* %42, i32 -1
store i32* %43, i32** %5
%44 = load i32*, i32** %5
%45 = getelementptr inbounds i32, i32* %44, i64 20
store i32* %45, i32** %5
%46 = load i32*, i32** %5
%47 = load i32, i32* %46
%48 = icmp eq i32 %47, 1
br i1 %48, label %49, label %59
49: ; preds = %41
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
store i32 %51, i32* %6
%52 = load i32, i32* %6
%53 = load i32, i32* %7
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %52, i32 %53)
%55 = load i32*, i32** %5
%56 = load i32, i32* %6
%57 = load i32, i32* %7
%58 = call i32 @find_path(i32* %55, i32 %56, i32 %57)
store i32 %58, i32* %4
br label %83
59: ; preds = %41
%60 = load i32*, i32** %5
store i32 0, i32* %60
%61 = load i32*, i32** %5
%62 = getelementptr inbounds i32, i32* %61, i64 -20
store i32* %62, i32** %5
%63 = load i32*, i32** %5
store i32 0, i32* %63
%64 = load i32*, i32** %5
%65 = getelementptr inbounds i32, i32* %64, i32 -1
store i32* %65, i32** %5
%66 = load i32*, i32** %5
%67 = load i32, i32* %66
%68 = icmp eq i32 %67, 1
br i1 %68, label %69, label %79
69: ; preds = %59
%70 = load i32, i32* %7
%71 = add nsw i32 %70, -1
store i32 %71, i32* %7
%72 = load i32, i32* %6
%73 = load i32, i32* %7
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %72, i32 %73)
%75 = load i32*, i32** %5
%76 = load i32, i32* %6
%77 = load i32, i32* %7
%78 = call i32 @find_path(i32* %75, i32 %76, i32 %77)
store i32 %78, i32* %4
br label %83
79: ; preds = %59
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %83
81: ; preds = %21
br label %82
82: ; preds = %81
store i32 0, i32* %4
br label %83
83: ; preds = %82, %79, %69, %49, %31, %19, %13
%84 = load i32, i32* %4
ret i32 %84
}

LLVM IR (-O2):
@.str = [14 x i8] c"Shortest Path\00"
@.str.2 = [9 x i8] c"(%d,%d)\0A\00"
@str = [79 x i8] c"Pointer did not shift any direction. There is no shortest path in this matrix.\00"
@str.4 = [40 x i8] c"No shortest path from (0,0) to (19,19).\00"
define i32 @find_path(i32* %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %1, 19
%5 = icmp eq i32 %2, 19
%6 = and i1 %4, %5
br i1 %6, label %12, label %7
7: ; preds = %3, %35
%8 = phi i1 [ %38, %35 ], [ %4, %3 ]
%9 = phi i32 [ %15, %35 ], [ %2, %3 ]
%10 = phi i32 [ %36, %35 ], [ %1, %3 ]
%11 = phi i32* [ %32, %35 ], [ %0, %3 ]
br label %14
12: ; preds = %35, %24, %3
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %47
14: ; preds = %7, %24
%15 = phi i32 [ %9, %7 ], [ %27, %24 ]
%16 = phi i32* [ %11, %7 ], [ %26, %24 ]
%17 = load i32, i32* %16
switch i32 %17, label %47 [
i32 0, label %18
i32 1, label %20
]
18: ; preds = %14
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.4, i64 0, i64 0))
br label %47
20: ; preds = %14
%21 = getelementptr inbounds i32, i32* %16, i64 1
%22 = load i32, i32* %21
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %31
24: ; preds = %20, %41
%25 = phi i32 [ -1, %41 ], [ 1, %20 ]
%26 = phi i32* [ %42, %41 ], [ %21, %20 ]
%27 = add nsw i32 %15, %25
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %10, i32 %27)
%29 = icmp eq i32 %27, 19
%30 = and i1 %8, %29
br i1 %30, label %12, label %14
31: ; preds = %20
%32 = getelementptr inbounds i32, i32* %16, i64 20
%33 = load i32, i32* %32
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %41
35: ; preds = %31
%36 = add nsw i32 %10, 1
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %36, i32 %15)
%38 = icmp eq i32 %36, 19
%39 = icmp eq i32 %15, 19
%40 = and i1 %38, %39
br i1 %40, label %12, label %7
41: ; preds = %31
store i32 0, i32* %32
store i32 0, i32* %16
%42 = getelementptr inbounds i32, i32* %16, i64 -1
%43 = load i32, i32* %42
%44 = icmp eq i32 %43, 1
br i1 %44, label %24, label %45
45: ; preds = %41
%46 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([79 x i8], [79 x i8]* @str, i64 0, i64 0))
br label %47
47: ; preds = %14, %45, %18, %12
ret i32 0
}