#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 *create_matrix(int);
int /*<<< orphan*/ fill_cost_path(int *, char **, int *, int, int, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char **, int /*<<< orphan*/, int);
int /*<<< orphan*/ print_matrix(int *, int, char *);
int /*<<< orphan*/ print_path_matrix(char **, int, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int);
char *strdup(char *);
void find_path(int *questionMatrix, int size) {
  char **path_matrix;
  int *cost_matrix;
  int i, j, sum;
  char path[32];
  path_matrix = (char **)malloc(sizeof(char *) * size * size);
  memset(path_matrix, 0, sizeof(char *) * size * size);
  cost_matrix = create_matrix(size);
  cost_matrix[0] = questionMatrix[0];
  path_matrix[0] = "0, 0";
  for (i = 1; i < size; i++) {
    cost_matrix[i] = cost_matrix[i - 1] + questionMatrix[i];
    snprintf(path, 32, "%d, %d", 0, i - 1);
    path_matrix[i] = strdup(path);
    cost_matrix[i * size] =
        cost_matrix[(i - 1) * size] + questionMatrix[i * size];
    snprintf(path, 32, "%d, %d", i - 1, 0);
    path_matrix[i * size] = strdup(path);
  }
  for (i = 1; i < size; i++) {
    for (j = 0; j < size; j++) {
      fill_cost_path(cost_matrix, path_matrix, questionMatrix, i, j, size);
    }
  }
  print_matrix(cost_matrix, 5, "Cost");
  print_path_matrix(path_matrix, 5, "Path");
}


x86 assembly (clang, -O0):
<find_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
movslq -0xc(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
movslq -0xc(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0xc(%rbp),%edi
call   1040 <create_matrix@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
lea    0xe16(%rip),%rcx
mov    %rcx,(%rax)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12dd <find_path+0x15d>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
add    (%rax,%rcx,4),%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
lea    -0x50(%rbp),%rdi
mov    -0x24(%rbp),%r8d
sub    $0x1,%r8d
mov    $0x20,%esi
lea    0xdc7(%rip),%rdx
xor    %ecx,%ecx
call   1060 <snprintf@plt>
lea    -0x50(%rbp),%rdi
call   10a0 <strdup@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
imul   -0xc(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0xc(%rbp),%ecx
movslq %ecx,%rcx
add    (%rax,%rcx,4),%edx
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0xc(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
lea    -0x50(%rbp),%rdi
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x20,%esi
lea    0xd5c(%rip),%rdx
xor    %r8d,%r8d
call   1060 <snprintf@plt>
lea    -0x50(%rbp),%rdi
call   10a0 <strdup@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0xc(%rbp),%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11f4 <find_path+0x74>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1340 <find_path+0x1c0>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    132d <find_path+0x1ad>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0xc(%rbp),%r9d
call   1050 <fill_cost_path@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    12f7 <find_path+0x177>
jmp    1332 <find_path+0x1b2>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12e4 <find_path+0x164>
mov    -0x20(%rbp),%rdi
mov    $0x5,%esi
lea    0xcbc(%rip),%rdx
call   1090 <print_matrix@plt>
mov    -0x18(%rbp),%rdi
mov    $0x5,%esi
lea    0xcac(%rip),%rdx
call   1030 <print_path_matrix@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_path>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %esi,%r12d
mov    %rdi,%r15
mov    %esi,%ebx
imul   %esi,%ebx
shl    $0x3,%ebx
mov    %ebx,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1070 <memset@plt>
mov    %r12d,%edi
call   1040 <create_matrix@plt>
mov    %rax,%r13
mov    (%r15),%eax
mov    %eax,0x0(%r13)
lea    0xe35(%rip),%rcx
mov    %rcx,(%r14)
cmp    $0x2,%r12d
jl     12d6 <find_path+0x156>
mov    %r12d,%ebx
mov    $0x2,%ecx
sub    %rbx,%rcx
mov    %rcx,0x18(%rsp)
xor    %ecx,%ecx
mov    %rcx,0x8(%rsp)
xor    %ebp,%ebp
mov    %rbx,0x10(%rsp)
cs nopw 0x0(%rax,%rax,1)
add    0x4(%r15,%rbp,4),%eax
mov    %eax,0x4(%r13,%rbp,4)
lea    0x20(%rsp),%rdi
mov    $0x20,%esi
lea    0xdea(%rip),%rdx
xor    %ecx,%ecx
mov    %ebp,%r8d
call   1060 <snprintf@plt>
lea    0x20(%rsp),%rdi
call   10a0 <strdup@plt>
mov    %rax,0x8(%r14,%rbp,8)
mov    (%r15,%rbx,4),%eax
mov    0x8(%rsp),%rcx
add    0x0(%r13,%rcx,4),%eax
mov    %eax,0x0(%r13,%rbx,4)
lea    0x20(%rsp),%rdi
mov    $0x20,%esi
lea    0xdad(%rip),%rdx
mov    %ebp,%ecx
xor    %r8d,%r8d
call   1060 <snprintf@plt>
lea    0x20(%rsp),%rdi
call   10a0 <strdup@plt>
mov    %rax,(%r14,%rbx,8)
mov    0x18(%rsp),%rax
add    %rbp,%rax
je     1295 <find_path+0x115>
mov    0x4(%r13,%rbp,4),%eax
mov    0x10(%rsp),%rcx
add    %rcx,%rbx
add    $0x1,%rbp
add    %rcx,0x8(%rsp)
jmp    1200 <find_path+0x80>
cmp    $0x2,%r12d
jl     12d6 <find_path+0x156>
mov    $0x1,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %ebx,%ecx
mov    %ebp,%r8d
mov    %r12d,%r9d
call   1050 <fill_cost_path@plt>
add    $0x1,%ebp
cmp    %ebp,%r12d
jne    12b0 <find_path+0x130>
add    $0x1,%ebx
cmp    %r12d,%ebx
jne    12a0 <find_path+0x120>
lea    0xd2f(%rip),%rdx
mov    %r13,%rdi
mov    $0x5,%esi
call   1090 <print_matrix@plt>
lea    0xd20(%rip),%rdx
mov    %r14,%rdi
mov    $0x5,%esi
call   1030 <print_path_matrix@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"0, 0\00"
@.str.1 = [7 x i8] c"%d, %d\00"
@.str.2 = [5 x i8] c"Cost\00"
@.str.3 = [5 x i8] c"Path\00"
define void @find_path(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [32 x i8]
store i32* %0, i32** %3
store i32 %1, i32* %4
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = mul i64 8, %12
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = mul i64 %13, %15
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8**
store i8** %19, i8*** %5
%20 = load i8**, i8*** %5
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = mul i64 8, %22
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = mul i64 %23, %25
%27 = trunc i64 %26 to i32
%28 = call i32 @memset(i8** %20, i32 0, i32 %27)
%29 = load i32, i32* %4
%30 = call i32* @create_matrix(i32 %29)
store i32* %30, i32** %6
%31 = load i32*, i32** %3
%32 = getelementptr inbounds i32, i32* %31, i64 0
%33 = load i32, i32* %32
%34 = load i32*, i32** %6
%35 = getelementptr inbounds i32, i32* %34, i64 0
store i32 %33, i32* %35
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %37
store i32 1, i32* %7
br label %38
38: ; preds = %103, %2
%39 = load i32, i32* %7
%40 = load i32, i32* %4
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %106
42: ; preds = %38
%43 = load i32*, i32** %6
%44 = load i32, i32* %7
%45 = sub nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %43, i64 %46
%48 = load i32, i32* %47
%49 = load i32*, i32** %3
%50 = load i32, i32* %7
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %49, i64 %51
%53 = load i32, i32* %52
%54 = add nsw i32 %48, %53
%55 = load i32*, i32** %6
%56 = load i32, i32* %7
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32, i32* %55, i64 %57
store i32 %54, i32* %58
%59 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%60 = load i32, i32* %7
%61 = sub nsw i32 %60, 1
%62 = call i32 @snprintf(i8* %59, i32 32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 %61)
%63 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%64 = call i8* @strdup(i8* %63)
%65 = load i8**, i8*** %5
%66 = load i32, i32* %7
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8*, i8** %65, i64 %67
store i8* %64, i8** %68
%69 = load i32*, i32** %6
%70 = load i32, i32* %7
%71 = sub nsw i32 %70, 1
%72 = load i32, i32* %4
%73 = mul nsw i32 %71, %72
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i32, i32* %69, i64 %74
%76 = load i32, i32* %75
%77 = load i32*, i32** %3
%78 = load i32, i32* %7
%79 = load i32, i32* %4
%80 = mul nsw i32 %78, %79
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i32, i32* %77, i64 %81
%83 = load i32, i32* %82
%84 = add nsw i32 %76, %83
%85 = load i32*, i32** %6
%86 = load i32, i32* %7
%87 = load i32, i32* %4
%88 = mul nsw i32 %86, %87
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i32, i32* %85, i64 %89
store i32 %84, i32* %90
%91 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%92 = load i32, i32* %7
%93 = sub nsw i32 %92, 1
%94 = call i32 @snprintf(i8* %91, i32 32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %93, i32 0)
%95 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%96 = call i8* @strdup(i8* %95)
%97 = load i8**, i8*** %5
%98 = load i32, i32* %7
%99 = load i32, i32* %4
%100 = mul nsw i32 %98, %99
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds i8*, i8** %97, i64 %101
store i8* %96, i8** %102
br label %103
103: ; preds = %42
%104 = load i32, i32* %7
%105 = add nsw i32 %104, 1
store i32 %105, i32* %7
br label %38
106: ; preds = %38
store i32 1, i32* %7
br label %107
107: ; preds = %128, %106
%108 = load i32, i32* %7
%109 = load i32, i32* %4
%110 = icmp slt i32 %108, %109
br i1 %110, label %111, label %131
111: ; preds = %107
store i32 0, i32* %8
br label %112
112: ; preds = %124, %111
%113 = load i32, i32* %8
%114 = load i32, i32* %4
%115 = icmp slt i32 %113, %114
br i1 %115, label %116, label %127
116: ; preds = %112
%117 = load i32*, i32** %6
%118 = load i8**, i8*** %5
%119 = load i32*, i32** %3
%120 = load i32, i32* %7
%121 = load i32, i32* %8
%122 = load i32, i32* %4
%123 = call i32 @fill_cost_path(i32* %117, i8** %118, i32* %119, i32 %120, i32 %121, i32 %122)
br label %124
124: ; preds = %116
%125 = load i32, i32* %8
%126 = add nsw i32 %125, 1
store i32 %126, i32* %8
br label %112
127: ; preds = %112
br label %128
128: ; preds = %127
%129 = load i32, i32* %7
%130 = add nsw i32 %129, 1
store i32 %130, i32* %7
br label %107
131: ; preds = %107
%132 = load i32*, i32** %6
%133 = call i32 @print_matrix(i32* %132, i32 5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%134 = load i8**, i8*** %5
%135 = call i32 @print_path_matrix(i8** %134, i32 5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"0, 0\00"
@.str.1 = [7 x i8] c"%d, %d\00"
@.str.2 = [5 x i8] c"Cost\00"
@.str.3 = [5 x i8] c"Path\00"
define void @find_path(i32* %0, i32 %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = shl i32 %1, 3
%6 = mul i32 %5, %1
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8**
%9 = tail call i32 @memset(i8** %8, i32 0, i32 %6)
%10 = tail call i32* @create_matrix(i32 %1)
%11 = load i32, i32* %0
store i32 %11, i32* %10
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %8
%12 = icmp sgt i32 %1, 1
br i1 %12, label %13, label %54
13: ; preds = %2
%14 = zext i32 %1 to i64
%15 = zext i32 %1 to i64
br label %17
16: ; preds = %17
br i1 %12, label %44, label %54
17: ; preds = %42, %13
%18 = phi i32 [ %11, %13 ], [ %43, %42 ]
%19 = phi i64 [ 1, %13 ], [ %40, %42 ]
%20 = add nsw i64 %19, -1
%21 = getelementptr inbounds i32, i32* %0, i64 %19
%22 = load i32, i32* %21
%23 = add nsw i32 %22, %18
%24 = getelementptr inbounds i32, i32* %10, i64 %19
store i32 %23, i32* %24
%25 = trunc i64 %20 to i32
%26 = call i32 @snprintf(i8* %4, i32 32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 %25)
%27 = call i8* @strdup(i8* %4)
%28 = getelementptr inbounds i8*, i8** %8, i64 %19
store i8* %27, i8** %28
%29 = mul nsw i64 %20, %14
%30 = getelementptr inbounds i32, i32* %10, i64 %29
%31 = load i32, i32* %30
%32 = mul nsw i64 %19, %14
%33 = getelementptr inbounds i32, i32* %0, i64 %32
%34 = load i32, i32* %33
%35 = add nsw i32 %34, %31
%36 = getelementptr inbounds i32, i32* %10, i64 %32
store i32 %35, i32* %36
%37 = call i32 @snprintf(i8* %4, i32 32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %25, i32 0)
%38 = call i8* @strdup(i8* %4)
%39 = getelementptr inbounds i8*, i8** %8, i64 %32
store i8* %38, i8** %39
%40 = add nuw nsw i64 %19, 1
%41 = icmp eq i64 %40, %15
br i1 %41, label %16, label %42
42: ; preds = %17
%43 = load i32, i32* %24
br label %17
44: ; preds = %16, %51
%45 = phi i32 [ %52, %51 ], [ 1, %16 ]
br label %46
46: ; preds = %44, %46
%47 = phi i32 [ %49, %46 ], [ 0, %44 ]
%48 = call i32 @fill_cost_path(i32* %10, i8** %8, i32* %0, i32 %45, i32 %47, i32 %1)
%49 = add nuw nsw i32 %47, 1
%50 = icmp eq i32 %49, %1
br i1 %50, label %51, label %46
51: ; preds = %46
%52 = add nuw nsw i32 %45, 1
%53 = icmp eq i32 %52, %1
br i1 %53, label %54, label %44
54: ; preds = %51, %2, %16
%55 = call i32 @print_matrix(i32* %10, i32 5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%56 = call i32 @print_path_matrix(i8** %8, i32 5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
ret void
}