#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 *malloc(int);
int /*<<< orphan*/ memset(int *, int, int);
int /*<<< orphan*/ printArrayData(int *, int);
int /*<<< orphan*/ printData(int *, int);
int /*<<< orphan*/ printMatrixList(int *, int, int, int);
int /*<<< orphan*/ printf(char *, ...);
void optimize(int c[], int N) {
  int i, k, left, right;
  long minM;
  int *M = malloc(sizeof(int) * N * N);
  int *LastChange = malloc(sizeof(int) * N * N);
  printf("N: %2d\n", N);
  printf("c[]: ");
  printData(c, N);
  memset(M, 0, sizeof(int) * N * N);
  memset(LastChange, -1, sizeof(int) * N * N);
  for (k = 1; k < (N - 1); k++) {
    printf("========================================\n");
    printf("k = %d\n", k);
    for (left = 1; left <= N - 1 - k; left++) {
      right = left + k;
      *(M + left * N + right) = 32768;
      printf("------------------------------\n");
      printf("(left, right) = (%d, %d)\n", left, right);
      for (i = left; i < right; i++) {
        printf("--------------------\n");
        printf("(left,i)(i+1, right) = (%d, %d)(%d, %d)\n", left, i, i + 1,
               right);
        printf("M(left,i), M(i+1, right), c = %d, %d, %d\n",
               *(M + left * N + i), *(M + (i + 1) * N + right),
               c[left - 1] * c[i] * c[right]);
        minM = *(M + left * N + i) + *(M + (i + 1) * N + right) +
               c[left - 1] * c[i] * c[right];
        printf("minM = %d\n", minM);
        if (minM < *(M + left * N + right)) {
          *(M + left * N + right) = minM;
          *(LastChange + left * N + right) = i;
        }
      }
      printf("--------------------\n");
      printf("M[][]: ");
      printArrayData(M, N);
      printf("LastChange[][]: ");
      printArrayData(LastChange, N);
    }
  }
  printf("------------------------------\n");
  printMatrixList(LastChange, N, 1, N - 1);
  printf("\n");
  printf("========================================\n");
}


x86 assembly (clang, -O0):
<optimize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
movslq -0xc(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
movslq -0xc(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <printData@plt>
mov    -0x30(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
movslq -0xc(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x38(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
movslq -0xc(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edx
mov    $0xffffffff,%esi
call   1040 <memset@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    14b7 <optimize+0x357>
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
sub    -0x14(%rbp),%ecx
cmp    %ecx,%eax
jg     14a4 <optimize+0x344>
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%ecx
imul   -0xc(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x1c(%rbp),%rcx
movl   $0x8000,(%rax,%rcx,4)
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1454 <optimize+0x2f4>
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
mov    -0x1c(%rbp),%r8d
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%ecx
imul   -0xc(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
imul   -0xc(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rdi
imul   (%rax,%rdi,4),%ecx
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rdi
imul   (%rax,%rdi,4),%ecx
lea    0xd51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%ecx
imul   -0xc(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%edx
add    $0x1,%edx
imul   -0xc(%rbp),%edx
movslq %edx,%rdx
shl    $0x2,%rdx
add    %rdx,%rcx
movslq -0x1c(%rbp),%rdx
add    (%rcx,%rdx,4),%eax
mov    -0x8(%rbp),%rcx
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
mov    (%rcx,%rdx,4),%ecx
mov    -0x8(%rbp),%rdx
movslq -0x10(%rbp),%rsi
imul   (%rdx,%rsi,4),%ecx
mov    -0x8(%rbp),%rdx
movslq -0x1c(%rbp),%rsi
imul   (%rdx,%rsi,4),%ecx
add    %ecx,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xcfe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%edx
imul   -0xc(%rbp),%edx
movslq %edx,%rdx
shl    $0x2,%rdx
add    %rdx,%rcx
movslq -0x1c(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
cmp    %rcx,%rax
jge    1441 <optimize+0x2e1>
mov    -0x28(%rbp),%rax
mov    %eax,%edx
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%ecx
imul   -0xc(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%edx
mov    -0x38(%rbp),%rax
mov    -0x18(%rbp),%ecx
imul   -0xc(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1446 <optimize+0x2e6>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    12b0 <optimize+0x150>
lea    0xbef(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xc6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1080 <printArrayData@plt>
lea    0xc5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1080 <printArrayData@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    124b <optimize+0xeb>
jmp    14a9 <optimize+0x349>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1214 <optimize+0xb4>
lea    0xb82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%edx
call   1070 <printMatrixList@plt>
lea    0xb95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xb1d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<optimize>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
mov    %esi,%r15d
mov    %rdi,%r12
mov    %esi,%ebx
imul   %esi,%ebx
shl    $0x2,%ebx
mov    %ebx,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %ebx,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
lea    0xe46(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe3d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,0x30(%rsp)
mov    %r12,%rdi
mov    %r15d,%esi
call   1080 <printData@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1060 <memset@plt>
mov    %rbp,%rdi
mov    $0xffffffff,%esi
mov    %ebx,%edx
call   1060 <memset@plt>
lea    -0x1(%r15),%eax
mov    %eax,0x4(%rsp)
mov    %r15,0x8(%rsp)
cmp    $0x3,%r15d
jl     1529 <optimize+0x3a9>
mov    0x8(%rsp),%r12d
mov    0x4(%rsp),%ebx
mov    0x30(%rsp),%rax
add    $0x4,%rax
mov    %rax,0x70(%rsp)
lea    0x4(%r14,%r12,4),%rax
mov    %rax,0x68(%rsp)
lea    0x0(,%r12,4),%rax
mov    %rax,0xb8(%rsp)
lea    0x4(,%r12,4),%rax
mov    %rax,0x80(%rsp)
lea    0x8(%r14,%r12,8),%rax
mov    %rax,0x28(%rsp)
mov    $0x2,%eax
mov    %rax,0x20(%rsp)
mov    $0x1,%r15d
mov    %rbp,0x98(%rsp)
mov    %r14,0x90(%rsp)
mov    %r12,0x88(%rsp)
mov    %rbx,0x78(%rsp)
jmp    12ae <optimize+0x12e>
xchg   %ax,%ax
add    $0x1,%r15
addq   $0x1,0x20(%rsp)
addq   $0x4,0x28(%rsp)
mov    0x78(%rsp),%rbx
cmp    %rbx,%r15
je     1529 <optimize+0x3a9>
lea    0xdf2(%rip),%rdi
call   1040 <puts@plt>
lea    0xd4d(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %rbx,%r15
jae    1290 <optimize+0x110>
mov    $0x1,%ebx
mov    0x28(%rsp),%r13
mov    0x68(%rsp),%rax
mov    %rax,0x10(%rsp)
mov    0x70(%rsp),%rax
mov    %rax,0x40(%rsp)
xor    %eax,%eax
mov    %rax,0x38(%rsp)
mov    0x20(%rsp),%rcx
mov    %r15,0x48(%rsp)
jmp    13b0 <optimize+0x230>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xdc3(%rip),%rdi
call   1040 <puts@plt>
lea    0xd6b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x90(%rsp),%r14
mov    %r14,%rdi
mov    0x8(%rsp),%rbx
mov    %ebx,%esi
call   10a0 <printArrayData@plt>
lea    0xd4e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x98(%rsp),%rbp
mov    %rbp,%rdi
mov    %ebx,%esi
call   10a0 <printArrayData@plt>
mov    0x50(%rsp),%rbx
add    $0x1,%rbx
mov    0xa0(%rsp),%rcx
add    $0x1,%rcx
addq   $0x1,0x38(%rsp)
addq   $0x4,0x40(%rsp)
mov    0x80(%rsp),%rax
add    %rax,0x10(%rsp)
mov    0xa8(%rsp),%r13
add    %rax,%r13
mov    0x88(%rsp),%r12
cmp    %r12,%rcx
mov    0x48(%rsp),%r15
je     1290 <optimize+0x110>
mov    %rcx,0xa0(%rsp)
mov    %r14,%rax
mov    %rbp,%r14
lea    (%rbx,%r15,1),%rcx
add    %ebx,%r15d
mov    %rbx,%rbp
imul   %r12,%rbp
lea    (%rax,%rbp,4),%rax
mov    %rcx,0x60(%rsp)
mov    %rax,0x58(%rsp)
movl   $0x8000,(%rax,%rcx,4)
lea    0xce8(%rip),%rdi
call   1040 <puts@plt>
lea    0xc22(%rip),%rdi
mov    %rbx,0x50(%rsp)
mov    %ebx,%esi
mov    %r15d,0x1c(%rsp)
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    (%r14,%rbp,4),%rax
mov    %rax,0xb0(%rsp)
mov    %r13,0xa8(%rsp)
mov    %r13,%r15
xor    %ebx,%ebx
jmp    1447 <optimize+0x2c7>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
add    0xb8(%rsp),%r15
cmp    %rbx,0x48(%rsp)
je     1310 <optimize+0x190>
lea    0xc8c(%rip),%rdi
call   1040 <puts@plt>
mov    0x38(%rsp),%rax
lea    (%rax,%rbx,1),%rcx
add    $0x2,%ecx
lea    (%rax,%rbx,1),%rdx
add    $0x1,%rdx
lea    0xbc2(%rip),%rdi
mov    0x50(%rsp),%r13
mov    %r13d,%esi
mov    %rdx,0xc0(%rsp)
mov    0x1c(%rsp),%r8d
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp),%rax
mov    (%rax,%rbx,4),%esi
mov    (%r15),%edx
mov    0x40(%rsp),%r14
mov    (%r14,%rbx,4),%ecx
mov    0x30(%rsp),%rbp
imul   -0x4(%rbp,%r13,4),%ecx
mov    0x60(%rsp),%r12
imul   0x0(%rbp,%r12,4),%ecx
lea    0xb9e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%eax
mov    0x10(%rsp),%rcx
add    (%rcx,%rbx,4),%eax
mov    (%r14,%rbx,4),%r14d
imul   -0x4(%rbp,%r13,4),%r14d
imul   0x0(%rbp,%r12,4),%r14d
add    %eax,%r14d
movslq %r14d,%r13
lea    0xb99(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x58(%rsp),%rax
cmp    (%rax,%r12,4),%r13d
jge    1430 <optimize+0x2b0>
mov    0x60(%rsp),%rax
mov    0x58(%rsp),%rcx
mov    %r14d,(%rcx,%rax,4)
mov    0xb0(%rsp),%rcx
mov    0xc0(%rsp),%rdx
mov    %edx,(%rcx,%rax,4)
jmp    1430 <optimize+0x2b0>
lea    0xba0(%rip),%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
mov    0x8(%rsp),%rsi
mov    $0x1,%edx
mov    0x4(%rsp),%ecx
call   1090 <printMatrixList@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xb4b(%rip),%rdi
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"N: %2d\0A\00"
@.str.1 = [6 x i8] c"c[]: \00"
@.str.2 = [42 x i8] c"========================================\0A\00"
@.str.3 = [8 x i8] c"k = %d\0A\00"
@.str.4 = [32 x i8] c"------------------------------\0A\00"
@.str.5 = [26 x i8] c"(left, right) = (%d, %d)\0A\00"
@.str.6 = [22 x i8] c"--------------------\0A\00"
@.str.7 = [41 x i8] c"(left,i)(i+1, right) = (%d, %d)(%d, %d)\0A\00"
@.str.8 = [42 x i8] c"M(left,i), M(i+1, right), c = %d, %d, %d\0A\00"
@.str.9 = [11 x i8] c"minM = %d\0A\00"
@.str.10 = [8 x i8] c"M[][]: \00"
@.str.11 = [17 x i8] c"LastChange[][]: \00"
@.str.12 = [2 x i8] c"\0A\00"
define void @optimize(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i32*
%11 = alloca i32*
store i32* %0, i32** %3
store i32 %1, i32* %4
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = mul i64 4, %13
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = mul i64 %14, %16
%18 = trunc i64 %17 to i32
%19 = call i32* @malloc(i32 %18)
store i32* %19, i32** %10
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = mul i64 4, %21
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = mul i64 %22, %24
%26 = trunc i64 %25 to i32
%27 = call i32* @malloc(i32 %26)
store i32* %27, i32** %11
%28 = load i32, i32* %4
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%31 = load i32*, i32** %3
%32 = load i32, i32* %4
%33 = call i32 @printData(i32* %31, i32 %32)
%34 = load i32*, i32** %10
%35 = load i32, i32* %4
%36 = sext i32 %35 to i64
%37 = mul i64 4, %36
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = mul i64 %37, %39
%41 = trunc i64 %40 to i32
%42 = call i32 @memset(i32* %34, i32 0, i32 %41)
%43 = load i32*, i32** %11
%44 = load i32, i32* %4
%45 = sext i32 %44 to i64
%46 = mul i64 4, %45
%47 = load i32, i32* %4
%48 = sext i32 %47 to i64
%49 = mul i64 %46, %48
%50 = trunc i64 %49 to i32
%51 = call i32 @memset(i32* %43, i32 -1, i32 %50)
store i32 1, i32* %6
br label %52
52: ; preds = %235, %2
%53 = load i32, i32* %6
%54 = load i32, i32* %4
%55 = sub nsw i32 %54, 1
%56 = icmp slt i32 %53, %55
br i1 %56, label %57, label %238
57: ; preds = %52
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%59 = load i32, i32* %6
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %59)
store i32 1, i32* %7
br label %61
61: ; preds = %231, %57
%62 = load i32, i32* %7
%63 = load i32, i32* %4
%64 = sub nsw i32 %63, 1
%65 = load i32, i32* %6
%66 = sub nsw i32 %64, %65
%67 = icmp sle i32 %62, %66
br i1 %67, label %68, label %234
68: ; preds = %61
%69 = load i32, i32* %7
%70 = load i32, i32* %6
%71 = add nsw i32 %69, %70
store i32 %71, i32* %8
%72 = load i32*, i32** %10
%73 = load i32, i32* %7
%74 = load i32, i32* %4
%75 = mul nsw i32 %73, %74
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i32, i32* %72, i64 %76
%78 = load i32, i32* %8
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i32, i32* %77, i64 %79
store i32 32768, i32* %80
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%82 = load i32, i32* %7
%83 = load i32, i32* %8
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %82, i32 %83)
%85 = load i32, i32* %7
store i32 %85, i32* %5
br label %86
86: ; preds = %218, %68
%87 = load i32, i32* %5
%88 = load i32, i32* %8
%89 = icmp slt i32 %87, %88
br i1 %89, label %90, label %221
90: ; preds = %86
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%92 = load i32, i32* %7
%93 = load i32, i32* %5
%94 = load i32, i32* %5
%95 = add nsw i32 %94, 1
%96 = load i32, i32* %8
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i32 %92, i32 %93, i32 %95, i32 %96)
%98 = load i32*, i32** %10
%99 = load i32, i32* %7
%100 = load i32, i32* %4
%101 = mul nsw i32 %99, %100
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds i32, i32* %98, i64 %102
%104 = load i32, i32* %5
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds i32, i32* %103, i64 %105
%107 = load i32, i32* %106
%108 = load i32*, i32** %10
%109 = load i32, i32* %5
%110 = add nsw i32 %109, 1
%111 = load i32, i32* %4
%112 = mul nsw i32 %110, %111
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds i32, i32* %108, i64 %113
%115 = load i32, i32* %8
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds i32, i32* %114, i64 %116
%118 = load i32, i32* %117
%119 = load i32*, i32** %3
%120 = load i32, i32* %7
%121 = sub nsw i32 %120, 1
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds i32, i32* %119, i64 %122
%124 = load i32, i32* %123
%125 = load i32*, i32** %3
%126 = load i32, i32* %5
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds i32, i32* %125, i64 %127
%129 = load i32, i32* %128
%130 = mul nsw i32 %124, %129
%131 = load i32*, i32** %3
%132 = load i32, i32* %8
%133 = sext i32 %132 to i64
%134 = getelementptr inbounds i32, i32* %131, i64 %133
%135 = load i32, i32* %134
%136 = mul nsw i32 %130, %135
%137 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.8, i64 0, i64 0), i32 %107, i32 %118, i32 %136)
%138 = load i32*, i32** %10
%139 = load i32, i32* %7
%140 = load i32, i32* %4
%141 = mul nsw i32 %139, %140
%142 = sext i32 %141 to i64
%143 = getelementptr inbounds i32, i32* %138, i64 %142
%144 = load i32, i32* %5
%145 = sext i32 %144 to i64
%146 = getelementptr inbounds i32, i32* %143, i64 %145
%147 = load i32, i32* %146
%148 = load i32*, i32** %10
%149 = load i32, i32* %5
%150 = add nsw i32 %149, 1
%151 = load i32, i32* %4
%152 = mul nsw i32 %150, %151
%153 = sext i32 %152 to i64
%154 = getelementptr inbounds i32, i32* %148, i64 %153
%155 = load i32, i32* %8
%156 = sext i32 %155 to i64
%157 = getelementptr inbounds i32, i32* %154, i64 %156
%158 = load i32, i32* %157
%159 = add nsw i32 %147, %158
%160 = load i32*, i32** %3
%161 = load i32, i32* %7
%162 = sub nsw i32 %161, 1
%163 = sext i32 %162 to i64
%164 = getelementptr inbounds i32, i32* %160, i64 %163
%165 = load i32, i32* %164
%166 = load i32*, i32** %3
%167 = load i32, i32* %5
%168 = sext i32 %167 to i64
%169 = getelementptr inbounds i32, i32* %166, i64 %168
%170 = load i32, i32* %169
%171 = mul nsw i32 %165, %170
%172 = load i32*, i32** %3
%173 = load i32, i32* %8
%174 = sext i32 %173 to i64
%175 = getelementptr inbounds i32, i32* %172, i64 %174
%176 = load i32, i32* %175
%177 = mul nsw i32 %171, %176
%178 = add nsw i32 %159, %177
%179 = sext i32 %178 to i64
store i64 %179, i64* %9
%180 = load i64, i64* %9
%181 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i64 %180)
%182 = load i64, i64* %9
%183 = load i32*, i32** %10
%184 = load i32, i32* %7
%185 = load i32, i32* %4
%186 = mul nsw i32 %184, %185
%187 = sext i32 %186 to i64
%188 = getelementptr inbounds i32, i32* %183, i64 %187
%189 = load i32, i32* %8
%190 = sext i32 %189 to i64
%191 = getelementptr inbounds i32, i32* %188, i64 %190
%192 = load i32, i32* %191
%193 = sext i32 %192 to i64
%194 = icmp slt i64 %182, %193
br i1 %194, label %195, label %217
195: ; preds = %90
%196 = load i64, i64* %9
%197 = trunc i64 %196 to i32
%198 = load i32*, i32** %10
%199 = load i32, i32* %7
%200 = load i32, i32* %4
%201 = mul nsw i32 %199, %200
%202 = sext i32 %201 to i64
%203 = getelementptr inbounds i32, i32* %198, i64 %202
%204 = load i32, i32* %8
%205 = sext i32 %204 to i64
%206 = getelementptr inbounds i32, i32* %203, i64 %205
store i32 %197, i32* %206
%207 = load i32, i32* %5
%208 = load i32*, i32** %11
%209 = load i32, i32* %7
%210 = load i32, i32* %4
%211 = mul nsw i32 %209, %210
%212 = sext i32 %211 to i64
%213 = getelementptr inbounds i32, i32* %208, i64 %212
%214 = load i32, i32* %8
%215 = sext i32 %214 to i64
%216 = getelementptr inbounds i32, i32* %213, i64 %215
store i32 %207, i32* %216
br label %217
217: ; preds = %195, %90
br label %218
218: ; preds = %217
%219 = load i32, i32* %5
%220 = add nsw i32 %219, 1
store i32 %220, i32* %5
br label %86
221: ; preds = %86
%222 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%223 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
%224 = load i32*, i32** %10
%225 = load i32, i32* %4
%226 = call i32 @printArrayData(i32* %224, i32 %225)
%227 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
%228 = load i32*, i32** %11
%229 = load i32, i32* %4
%230 = call i32 @printArrayData(i32* %228, i32 %229)
br label %231
231: ; preds = %221
%232 = load i32, i32* %7
%233 = add nsw i32 %232, 1
store i32 %233, i32* %7
br label %61
234: ; preds = %61
br label %235
235: ; preds = %234
%236 = load i32, i32* %6
%237 = add nsw i32 %236, 1
store i32 %237, i32* %6
br label %52
238: ; preds = %52
%239 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%240 = load i32*, i32** %11
%241 = load i32, i32* %4
%242 = load i32, i32* %4
%243 = sub nsw i32 %242, 1
%244 = call i32 @printMatrixList(i32* %240, i32 %241, i32 1, i32 %243)
%245 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
%246 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"N: %2d\0A\00"
@.str.1 = [6 x i8] c"c[]: \00"
@.str.3 = [8 x i8] c"k = %d\0A\00"
@.str.5 = [26 x i8] c"(left, right) = (%d, %d)\0A\00"
@.str.7 = [41 x i8] c"(left,i)(i+1, right) = (%d, %d)(%d, %d)\0A\00"
@.str.8 = [42 x i8] c"M(left,i), M(i+1, right), c = %d, %d, %d\0A\00"
@.str.9 = [11 x i8] c"minM = %d\0A\00"
@.str.10 = [8 x i8] c"M[][]: \00"
@.str.11 = [17 x i8] c"LastChange[][]: \00"
@str.14 = [41 x i8] c"========================================\00"
@str.15 = [31 x i8] c"------------------------------\00"
@str.17 = [21 x i8] c"--------------------\00"
define void @optimize(i32* %0, i32 %1) {
%3 = shl i32 %1, 2
%4 = mul i32 %3, %1
%5 = tail call i32* @malloc(i32 %4)
%6 = tail call i32* @malloc(i32 %4)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %1)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @printData(i32* %0, i32 %1)
%10 = tail call i32 @memset(i32* %5, i32 0, i32 %4)
%11 = tail call i32 @memset(i32* %6, i32 -1, i32 %4)
%12 = add i32 %1, -1
%13 = icmp sgt i32 %1, 2
br i1 %13, label %14, label %91
14: ; preds = %2
%15 = zext i32 %1 to i64
%16 = zext i32 %12 to i64
%17 = zext i32 %12 to i64
%18 = zext i32 %1 to i64
br label %19
19: ; preds = %14, %87
%20 = phi i64 [ 1, %14 ], [ %88, %87 ]
%21 = phi i64 [ 2, %14 ], [ %89, %87 ]
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.14, i64 0, i64 0))
%23 = trunc i64 %20 to i32
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = icmp ult i64 %20, %16
br i1 %25, label %26, label %87
26: ; preds = %19, %78
%27 = phi i64 [ %85, %78 ], [ %21, %19 ]
%28 = phi i64 [ %84, %78 ], [ 1, %19 ]
%29 = trunc i64 %28 to i32
%30 = add nuw nsw i64 %28, %20
%31 = add nuw nsw i32 %29, %23
%32 = mul nsw i64 %28, %15
%33 = getelementptr inbounds i32, i32* %5, i64 %32
%34 = getelementptr inbounds i32, i32* %33, i64 %30
store i32 32768, i32* %34
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.15, i64 0, i64 0))
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %29, i32 %31)
%37 = add nsw i64 %28, -1
%38 = getelementptr inbounds i32, i32* %0, i64 %37
%39 = getelementptr inbounds i32, i32* %0, i64 %30
%40 = getelementptr inbounds i32, i32* %6, i64 %32
%41 = getelementptr inbounds i32, i32* %40, i64 %30
%42 = getelementptr inbounds i32, i32* %5, i64 %30
br label %43
43: ; preds = %26, %76
%44 = phi i64 [ %28, %26 ], [ %46, %76 ]
%45 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.17, i64 0, i64 0))
%46 = add nuw nsw i64 %44, 1
%47 = trunc i64 %46 to i32
%48 = trunc i64 %44 to i32
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i32 %29, i32 %48, i32 %47, i32 %31)
%50 = getelementptr inbounds i32, i32* %33, i64 %44
%51 = load i32, i32* %50
%52 = mul nsw i64 %46, %15
%53 = getelementptr inbounds i32, i32* %42, i64 %52
%54 = load i32, i32* %53
%55 = load i32, i32* %38
%56 = getelementptr inbounds i32, i32* %0, i64 %44
%57 = load i32, i32* %56
%58 = mul nsw i32 %57, %55
%59 = load i32, i32* %39
%60 = mul nsw i32 %58, %59
%61 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.8, i64 0, i64 0), i32 %51, i32 %54, i32 %60)
%62 = load i32, i32* %50
%63 = load i32, i32* %53
%64 = add nsw i32 %63, %62
%65 = load i32, i32* %38
%66 = load i32, i32* %56
%67 = mul nsw i32 %66, %65
%68 = load i32, i32* %39
%69 = mul nsw i32 %67, %68
%70 = add nsw i32 %64, %69
%71 = sext i32 %70 to i64
%72 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i64 %71)
%73 = load i32, i32* %34
%74 = icmp slt i32 %70, %73
br i1 %74, label %75, label %76
75: ; preds = %43
store i32 %70, i32* %34
store i32 %48, i32* %41
br label %76
76: ; preds = %43, %75
%77 = icmp eq i64 %46, %27
br i1 %77, label %78, label %43
78: ; preds = %76
%79 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.17, i64 0, i64 0))
%80 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
%81 = tail call i32 @printArrayData(i32* %5, i32 %1)
%82 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
%83 = tail call i32 @printArrayData(i32* %6, i32 %1)
%84 = add nuw nsw i64 %28, 1
%85 = add nuw nsw i64 %27, 1
%86 = icmp eq i64 %85, %18
br i1 %86, label %87, label %26
87: ; preds = %78, %19
%88 = add nuw nsw i64 %20, 1
%89 = add nuw nsw i64 %21, 1
%90 = icmp eq i64 %88, %17
br i1 %90, label %91, label %19
91: ; preds = %87, %2
%92 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.15, i64 0, i64 0))
%93 = tail call i32 @printMatrixList(i32* %6, i32 %1, i32 1, i32 %12)
%94 = tail call i32 @putchar(i32 10)
%95 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.14, i64 0, i64 0))
ret void
}