#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 min(int, 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 *qmat, 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] = qmat[0];
  path_matrix[0] = "0, 0";
  for (i = 1; i < size; i++) {
    cost_matrix[i] = cost_matrix[i - 1] + qmat[i];
    snprintf(path, 32, "%d, %d", 0, i - 1);
    path_matrix[i] = strdup(path);
    cost_matrix[i * size] = cost_matrix[(i - 1) * size] + qmat[i * size];
    snprintf(path, 32, "%d, %d", i - 1, 0);
    path_matrix[i * size] = strdup(path);
  }
  for (sum = 1; sum < (2 * size - 1); sum++) {
    for (i = 1; i < min(sum, size); i++) {
      j = sum - i;
      fill_cost_path(cost_matrix, path_matrix, qmat, 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    $0x60,%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   1090 <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   1080 <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    0xe06(%rip),%rcx
mov    %rcx,(%rax)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12ed <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    0xdb7(%rip),%rdx
xor    %ecx,%ecx
call   1070 <snprintf@plt>
lea    -0x50(%rbp),%rdi
call   10b0 <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    0xd4c(%rip),%rdx
xor    %r8d,%r8d
call   1070 <snprintf@plt>
lea    -0x50(%rbp),%rdi
call   10b0 <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    1204 <find_path+0x74>
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1373 <find_path+0x1e3>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1060 <min@plt>
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
cmp    %ecx,%eax
jge    1360 <find_path+0x1d0>
mov    -0x2c(%rbp),%eax
sub    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
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    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    130f <find_path+0x17f>
jmp    1365 <find_path+0x1d5>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12f4 <find_path+0x164>
mov    -0x20(%rbp),%rdi
mov    $0x5,%esi
lea    0xc89(%rip),%rdx
call   10a0 <print_matrix@plt>
mov    -0x18(%rbp),%rdi
mov    $0x5,%esi
lea    0xc79(%rip),%rdx
call   1030 <print_path_matrix@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_path>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %esi,%r15d
mov    %rdi,%r14
mov    %esi,%ebx
imul   %esi,%ebx
shl    $0x3,%ebx
mov    %ebx,%edi
call   1090 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1080 <memset@plt>
mov    %r15d,%edi
call   1040 <create_matrix@plt>
mov    %r14,0x30(%rsp)
mov    (%r14),%edx
mov    %rax,0x18(%rsp)
mov    %edx,(%rax)
lea    0xe20(%rip),%rcx
mov    %rbp,0x28(%rsp)
mov    %rcx,0x0(%rbp)
cmp    $0x2,%r15d
jl     136e <find_path+0x1de>
mov    %r15,0x38(%rsp)
mov    %r15d,%ebp
mov    $0x2,%eax
sub    %rbp,%rax
mov    %rax,0x10(%rsp)
xor    %eax,%eax
mov    %rax,0x8(%rsp)
xor    %r13d,%r13d
mov    %rbp,0x20(%rsp)
mov    0x18(%rsp),%r15
nopl   0x0(%rax)
mov    0x30(%rsp),%rbx
add    0x4(%rbx,%r13,4),%edx
mov    %edx,0x4(%r15,%r13,4)
lea    0x40(%rsp),%r14
mov    %r14,%rdi
mov    $0x20,%esi
lea    0xdc2(%rip),%r12
mov    %r12,%rdx
xor    %ecx,%ecx
mov    %r13d,%r8d
call   1070 <snprintf@plt>
mov    %r14,%rdi
call   10b0 <strdup@plt>
mov    0x28(%rsp),%rcx
mov    %rax,0x8(%rcx,%r13,8)
mov    (%rbx,%rbp,4),%eax
mov    %rcx,%rbx
mov    0x8(%rsp),%rcx
add    (%r15,%rcx,4),%eax
mov    %eax,(%r15,%rbp,4)
mov    %r14,%rdi
mov    $0x20,%esi
mov    %r12,%rdx
mov    %r13d,%ecx
xor    %r8d,%r8d
call   1070 <snprintf@plt>
mov    %r14,%rdi
call   10b0 <strdup@plt>
mov    %rax,(%rbx,%rbp,8)
mov    0x10(%rsp),%rax
add    %r13,%rax
je     12bc <find_path+0x12c>
mov    0x4(%r15,%r13,4),%edx
mov    0x20(%rsp),%rax
add    %rax,%rbp
add    $0x1,%r13
add    %rax,0x8(%rsp)
jmp    1220 <find_path+0x90>
mov    0x38(%rsp),%r12
cmp    $0x2,%r12d
jl     136e <find_path+0x1de>
lea    (%r12,%r12,1),%eax
add    $0xffffffff,%eax
cmp    $0x3,%eax
mov    $0x2,%ecx
cmovge %eax,%ecx
mov    %ecx,0x20(%rsp)
mov    $0x1,%r14d
movl   $0x0,0x10(%rsp)
mov    0x30(%rsp),%r13
mov    0x28(%rsp),%r15
jmp    1315 <find_path+0x185>
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%r14d
add    $0x1,%r14d
addl   $0x1,0x10(%rsp)
cmp    0x20(%rsp),%r14d
je     136e <find_path+0x1de>
mov    %r14d,%edi
mov    %r14d,0x8(%rsp)
mov    %r12d,%esi
call   1060 <min@plt>
cmp    $0x2,%eax
mov    0x18(%rsp),%r14
jl     1300 <find_path+0x170>
mov    $0x1,%ebx
mov    0x10(%rsp),%ebp
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
mov    %ebx,%ecx
mov    %ebp,%r8d
mov    %r12d,%r9d
call   1050 <fill_cost_path@plt>
add    $0x1,%ebx
mov    0x8(%rsp),%edi
mov    %r12d,%esi
call   1060 <min@plt>
add    $0xffffffff,%ebp
cmp    %eax,%ebx
jl     1340 <find_path+0x1b0>
jmp    1300 <find_path+0x170>
lea    0xc97(%rip),%rdx
mov    0x18(%rsp),%rdi
mov    $0x5,%esi
call   10a0 <print_matrix@plt>
lea    0xc86(%rip),%rdx
mov    0x28(%rsp),%rdi
mov    $0x5,%esi
call   1030 <print_path_matrix@plt>
add    $0x68,%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* %9
br label %107
107: ; preds = %135, %106
%108 = load i32, i32* %9
%109 = load i32, i32* %4
%110 = mul nsw i32 2, %109
%111 = sub nsw i32 %110, 1
%112 = icmp slt i32 %108, %111
br i1 %112, label %113, label %138
113: ; preds = %107
store i32 1, i32* %7
br label %114
114: ; preds = %131, %113
%115 = load i32, i32* %7
%116 = load i32, i32* %9
%117 = load i32, i32* %4
%118 = call i32 @min(i32 %116, i32 %117)
%119 = icmp slt i32 %115, %118
br i1 %119, label %120, label %134
120: ; preds = %114
%121 = load i32, i32* %9
%122 = load i32, i32* %7
%123 = sub nsw i32 %121, %122
store i32 %123, i32* %8
%124 = load i32*, i32** %6
%125 = load i8**, i8*** %5
%126 = load i32*, i32** %3
%127 = load i32, i32* %7
%128 = load i32, i32* %8
%129 = load i32, i32* %4
%130 = call i32 @fill_cost_path(i32* %124, i8** %125, i32* %126, i32 %127, i32 %128, i32 %129)
br label %131
131: ; preds = %120
%132 = load i32, i32* %7
%133 = add nsw i32 %132, 1
store i32 %133, i32* %7
br label %114
134: ; preds = %114
br label %135
135: ; preds = %134
%136 = load i32, i32* %9
%137 = add nsw i32 %136, 1
store i32 %137, i32* %9
br label %107
138: ; preds = %107
%139 = load i32*, i32** %6
%140 = call i32 @print_matrix(i32* %139, i32 5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%141 = load i8**, i8*** %5
%142 = call i32 @print_path_matrix(i8** %141, 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 %62
13: ; preds = %2
%14 = zext i32 %1 to i64
%15 = zext i32 %1 to i64
br label %21
16: ; preds = %21
br i1 %12, label %17, label %62
17: ; preds = %16
%18 = shl nuw nsw i32 %1, 1
%19 = add i32 %18, -1
%20 = call i32 @llvm.smax.i32(i32 %19, i32 2)
br label %48
21: ; preds = %46, %13
%22 = phi i32 [ %11, %13 ], [ %47, %46 ]
%23 = phi i64 [ 1, %13 ], [ %44, %46 ]
%24 = add nsw i64 %23, -1
%25 = getelementptr inbounds i32, i32* %0, i64 %23
%26 = load i32, i32* %25
%27 = add nsw i32 %26, %22
%28 = getelementptr inbounds i32, i32* %10, i64 %23
store i32 %27, i32* %28
%29 = trunc i64 %24 to i32
%30 = 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 %29)
%31 = call i8* @strdup(i8* %4)
%32 = getelementptr inbounds i8*, i8** %8, i64 %23
store i8* %31, i8** %32
%33 = mul nsw i64 %24, %14
%34 = getelementptr inbounds i32, i32* %10, i64 %33
%35 = load i32, i32* %34
%36 = mul nsw i64 %23, %14
%37 = getelementptr inbounds i32, i32* %0, i64 %36
%38 = load i32, i32* %37
%39 = add nsw i32 %38, %35
%40 = getelementptr inbounds i32, i32* %10, i64 %36
store i32 %39, i32* %40
%41 = call i32 @snprintf(i8* %4, i32 32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %29, i32 0)
%42 = call i8* @strdup(i8* %4)
%43 = getelementptr inbounds i8*, i8** %8, i64 %36
store i8* %42, i8** %43
%44 = add nuw nsw i64 %23, 1
%45 = icmp eq i64 %44, %15
br i1 %45, label %16, label %46
46: ; preds = %21
%47 = load i32, i32* %28
br label %21
48: ; preds = %17, %59
%49 = phi i32 [ %60, %59 ], [ 1, %17 ]
%50 = call i32 @min(i32 %49, i32 %1)
%51 = icmp sgt i32 %50, 1
br i1 %51, label %52, label %59
52: ; preds = %48, %52
%53 = phi i32 [ %56, %52 ], [ 1, %48 ]
%54 = sub nsw i32 %49, %53
%55 = call i32 @fill_cost_path(i32* %10, i8** %8, i32* %0, i32 %53, i32 %54, i32 %1)
%56 = add nuw nsw i32 %53, 1
%57 = call i32 @min(i32 %49, i32 %1)
%58 = icmp slt i32 %56, %57
br i1 %58, label %52, label %59
59: ; preds = %52, %48
%60 = add nuw nsw i32 %49, 1
%61 = icmp eq i32 %60, %20
br i1 %61, label %62, label %48
62: ; preds = %59, %2, %16
%63 = call i32 @print_matrix(i32* %10, i32 5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%64 = 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
}