#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*/ MATRIX_CHAIN_ORDER(int **, int **, int *, int);
int /*<<< orphan*/ PRINT_OPTIMAL_PARENS(int **, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ system(char *);
int main() {
  int m[100][100], s[100][100];
  int case1[4 + 1] = {3, 5, 2, 1, 10};
  MATRIX_CHAIN_ORDER(m, s, case1, 4 + 1);
  PRINT_OPTIMAL_PARENS(s, 1, 4);
  printf("\n");
  int case2[4 + 1] = {2, 7, 3, 6, 10};
  MATRIX_CHAIN_ORDER(m, s, case2, 4 + 1);
  PRINT_OPTIMAL_PARENS(s, 1, 4);
  printf("\n");
  int case3[5 + 1] = {10, 3, 15, 12, 7, 2};
  MATRIX_CHAIN_ORDER(m, s, case3, 5 + 1);
  PRINT_OPTIMAL_PARENS(s, 1, 5);
  printf("\n");
  int case4[6 + 1] = {5, 10, 3, 12, 5, 50, 6};
  MATRIX_CHAIN_ORDER(m, s, case4, 6 + 1);
  PRINT_OPTIMAL_PARENS(s, 1, 6);
  printf("\n");
  for (int i = 0; i <= 6; i++) {
    for (int j = 0; j <= 6; j++) {
      printf("%-15d", s[i][j]);
    }
    printf("\n");
  }
  printf("\n");
  system("pause");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x13920,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xea7(%rip),%rax
mov    %rax,-0x138b0(%rbp)
mov    0xea1(%rip),%rax
mov    %rax,-0x138a8(%rbp)
mov    0xe9c(%rip),%eax
mov    %eax,-0x138a0(%rbp)
lea    -0x9c50(%rbp),%rdi
lea    -0x13890(%rbp),%rsi
lea    -0x138b0(%rbp),%rdx
mov    $0x5,%ecx
call   1040 <MATRIX_CHAIN_ORDER@plt>
lea    -0x13890(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <PRINT_OPTIMAL_PARENS@plt>
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0xe5c(%rip),%rax
mov    %rax,-0x138d0(%rbp)
mov    0xe56(%rip),%rax
mov    %rax,-0x138c8(%rbp)
mov    0xe51(%rip),%eax
mov    %eax,-0x138c0(%rbp)
lea    -0x9c50(%rbp),%rdi
lea    -0x13890(%rbp),%rsi
lea    -0x138d0(%rbp),%rdx
mov    $0x5,%ecx
call   1040 <MATRIX_CHAIN_ORDER@plt>
lea    -0x13890(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <PRINT_OPTIMAL_PARENS@plt>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0xe11(%rip),%rax
mov    %rax,-0x138f0(%rbp)
mov    0xe0b(%rip),%rax
mov    %rax,-0x138e8(%rbp)
mov    0xe05(%rip),%rax
mov    %rax,-0x138e0(%rbp)
lea    -0x9c50(%rbp),%rdi
lea    -0x13890(%rbp),%rsi
lea    -0x138f0(%rbp),%rdx
mov    $0x6,%ecx
call   1040 <MATRIX_CHAIN_ORDER@plt>
lea    -0x13890(%rbp),%rdi
mov    $0x1,%esi
mov    $0x5,%edx
call   1030 <PRINT_OPTIMAL_PARENS@plt>
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0xdc4(%rip),%rax
mov    %rax,-0x13910(%rbp)
mov    0xdbe(%rip),%rax
mov    %rax,-0x13908(%rbp)
mov    0xdb8(%rip),%rax
mov    %rax,-0x13900(%rbp)
mov    0xdb3(%rip),%eax
mov    %eax,-0x138f8(%rbp)
lea    -0x9c50(%rbp),%rdi
lea    -0x13890(%rbp),%rsi
lea    -0x13910(%rbp),%rdx
mov    $0x7,%ecx
call   1040 <MATRIX_CHAIN_ORDER@plt>
lea    -0x13890(%rbp),%rdi
mov    $0x1,%esi
mov    $0x6,%edx
call   1030 <PRINT_OPTIMAL_PARENS@plt>
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x13914(%rbp)
cmpl   $0x6,-0x13914(%rbp)
jg     13a2 <main+0x262>
movl   $0x0,-0x13918(%rbp)
cmpl   $0x6,-0x13918(%rbp)
jg     1380 <main+0x240>
movslq -0x13914(%rbp),%rcx
lea    -0x13890(%rbp),%rax
imul   $0x190,%rcx,%rcx
add    %rcx,%rax
movslq -0x13918(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xd19(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x13918(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x13918(%rbp)
jmp    132f <main+0x1ef>
lea    0xcf5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x13914(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x13914(%rbp)
jmp    1318 <main+0x1d8>
lea    0xcd3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xccd(%rip),%rdi
call   1050 <system@plt>
xor    %eax,%eax
add    $0x13920,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x13908,%rsp
mov    0xeb0(%rip),%eax
mov    %eax,0x30(%rsp)
movaps 0xe95(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
lea    0x9cc0(%rsp),%r14
lea    0x80(%rsp),%rbx
lea    0x20(%rsp),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x5,%ecx
call   1050 <MATRIX_CHAIN_ORDER@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1040 <PRINT_OPTIMAL_PARENS@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0xe79(%rip),%eax
mov    %eax,0x10(%rsp)
movaps 0xe5e(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x5,%ecx
call   1050 <MATRIX_CHAIN_ORDER@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1040 <PRINT_OPTIMAL_PARENS@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0xe54(%rip),%rax
mov    %rax,0x50(%rsp)
movaps 0xe38(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
lea    0x40(%rsp),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x6,%ecx
call   1050 <MATRIX_CHAIN_ORDER@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x5,%edx
call   1040 <PRINT_OPTIMAL_PARENS@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movups 0xe27(%rip),%xmm0
movups %xmm0,0x6c(%rsp)
movaps 0xe0f(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
lea    0x60(%rsp),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x7,%ecx
call   1050 <MATRIX_CHAIN_ORDER@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x6,%edx
call   1040 <PRINT_OPTIMAL_PARENS@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x18,%ebx
lea    0xde9(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x68(%rsp,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x6c(%rsp,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x70(%rsp,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x74(%rsp,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x78(%rsp,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x7c(%rsp,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x80(%rsp,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x190,%rbx
cmp    $0xb08,%rbx
jne    12a0 <main+0x150>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xd52(%rip),%rdi
call   1060 <system@plt>
xor    %eax,%eax
add    $0x13908,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.case1 = [5 x i32] [i32 3, i32 5, i32 2, i32 1, i32 10]
@.str = [2 x i8] c"\0A\00"
@__const.main.case2 = [5 x i32] [i32 2, i32 7, i32 3, i32 6, i32 10]
@__const.main.case3 = [6 x i32] [i32 10, i32 3, i32 15, i32 12, i32 7, i32 2]
@__const.main.case4 = [7 x i32] [i32 5, i32 10, i32 3, i32 12, i32 5, i32 50, i32 6]
@.str.1 = [6 x i8] c"%-15d\00"
@.str.2 = [6 x i8] c"pause\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x [100 x i32]]
%3 = alloca [100 x [100 x i32]]
%4 = alloca [5 x i32]
%5 = alloca [5 x i32]
%6 = alloca [6 x i32]
%7 = alloca [7 x i32]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = bitcast [5 x i32]* %4 to i8*
%11 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %2, i64 0, i64 0
%12 = bitcast [100 x i32]* %11 to i32**
%13 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %3, i64 0, i64 0
%14 = bitcast [100 x i32]* %13 to i32**
%15 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 0
%16 = call i32 @MATRIX_CHAIN_ORDER(i32** %12, i32** %14, i32* %15, i32 5)
%17 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %3, i64 0, i64 0
%18 = bitcast [100 x i32]* %17 to i32**
%19 = call i32 @PRINT_OPTIMAL_PARENS(i32** %18, i32 1, i32 4)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = bitcast [5 x i32]* %5 to i8*
%22 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %2, i64 0, i64 0
%23 = bitcast [100 x i32]* %22 to i32**
%24 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %3, i64 0, i64 0
%25 = bitcast [100 x i32]* %24 to i32**
%26 = getelementptr inbounds [5 x i32], [5 x i32]* %5, i64 0, i64 0
%27 = call i32 @MATRIX_CHAIN_ORDER(i32** %23, i32** %25, i32* %26, i32 5)
%28 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %3, i64 0, i64 0
%29 = bitcast [100 x i32]* %28 to i32**
%30 = call i32 @PRINT_OPTIMAL_PARENS(i32** %29, i32 1, i32 4)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%32 = bitcast [6 x i32]* %6 to i8*
%33 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %2, i64 0, i64 0
%34 = bitcast [100 x i32]* %33 to i32**
%35 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %3, i64 0, i64 0
%36 = bitcast [100 x i32]* %35 to i32**
%37 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 0
%38 = call i32 @MATRIX_CHAIN_ORDER(i32** %34, i32** %36, i32* %37, i32 6)
%39 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %3, i64 0, i64 0
%40 = bitcast [100 x i32]* %39 to i32**
%41 = call i32 @PRINT_OPTIMAL_PARENS(i32** %40, i32 1, i32 5)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%43 = bitcast [7 x i32]* %7 to i8*
%44 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %2, i64 0, i64 0
%45 = bitcast [100 x i32]* %44 to i32**
%46 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %3, i64 0, i64 0
%47 = bitcast [100 x i32]* %46 to i32**
%48 = getelementptr inbounds [7 x i32], [7 x i32]* %7, i64 0, i64 0
%49 = call i32 @MATRIX_CHAIN_ORDER(i32** %45, i32** %47, i32* %48, i32 7)
%50 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %3, i64 0, i64 0
%51 = bitcast [100 x i32]* %50 to i32**
%52 = call i32 @PRINT_OPTIMAL_PARENS(i32** %51, i32 1, i32 6)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %8
br label %54
54: ; preds = %75, %0
%55 = load i32, i32* %8
%56 = icmp sle i32 %55, 6
br i1 %56, label %57, label %78
57: ; preds = %54
store i32 0, i32* %9
br label %58
58: ; preds = %70, %57
%59 = load i32, i32* %9
%60 = icmp sle i32 %59, 6
br i1 %60, label %61, label %73
61: ; preds = %58
%62 = load i32, i32* %8
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %3, i64 0, i64 %63
%65 = load i32, i32* %9
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [100 x i32], [100 x i32]* %64, i64 0, i64 %66
%68 = load i32, i32* %67
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %68)
br label %70
70: ; preds = %61
%71 = load i32, i32* %9
%72 = add nsw i32 %71, 1
store i32 %72, i32* %9
br label %58
73: ; preds = %58
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %75
75: ; preds = %73
%76 = load i32, i32* %8
%77 = add nsw i32 %76, 1
store i32 %77, i32* %8
br label %54
78: ; preds = %54
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%80 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@__const.main.case1 = [5 x i32] [i32 3, i32 5, i32 2, i32 1, i32 10]
@__const.main.case2 = [5 x i32] [i32 2, i32 7, i32 3, i32 6, i32 10]
@__const.main.case3 = [6 x i32] [i32 10, i32 3, i32 15, i32 12, i32 7, i32 2]
@__const.main.case4 = [7 x i32] [i32 5, i32 10, i32 3, i32 12, i32 5, i32 50, i32 6]
@.str.1 = [6 x i8] c"%-15d\00"
@.str.2 = [6 x i8] c"pause\00"
define i32 @main() {
%1 = alloca [100 x [100 x i32]]
%2 = alloca [100 x [100 x i32]]
%3 = alloca [5 x i32]
%4 = alloca [5 x i32]
%5 = alloca [6 x i32]
%6 = alloca [7 x i32]
%7 = bitcast [100 x [100 x i32]]* %1 to i8*
%8 = bitcast [100 x [100 x i32]]* %2 to i8*
%9 = bitcast [5 x i32]* %3 to i8*
%10 = bitcast [100 x [100 x i32]]* %1 to i32**
%11 = bitcast [100 x [100 x i32]]* %2 to i32**
%12 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 0
%13 = call i32 @MATRIX_CHAIN_ORDER(i32** %10, i32** %11, i32* %12, i32 5)
%14 = call i32 @PRINT_OPTIMAL_PARENS(i32** %11, i32 1, i32 4)
%15 = call i32 @putchar(i32 10)
%16 = bitcast [5 x i32]* %4 to i8*
%17 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 0
%18 = call i32 @MATRIX_CHAIN_ORDER(i32** %10, i32** %11, i32* %17, i32 5)
%19 = call i32 @PRINT_OPTIMAL_PARENS(i32** %11, i32 1, i32 4)
%20 = call i32 @putchar(i32 10)
%21 = bitcast [6 x i32]* %5 to i8*
%22 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 0
%23 = call i32 @MATRIX_CHAIN_ORDER(i32** %10, i32** %11, i32* %22, i32 6)
%24 = call i32 @PRINT_OPTIMAL_PARENS(i32** %11, i32 1, i32 5)
%25 = call i32 @putchar(i32 10)
%26 = bitcast [7 x i32]* %6 to i8*
%27 = getelementptr inbounds [7 x i32], [7 x i32]* %6, i64 0, i64 0
%28 = call i32 @MATRIX_CHAIN_ORDER(i32** %10, i32** %11, i32* %27, i32 7)
%29 = call i32 @PRINT_OPTIMAL_PARENS(i32** %11, i32 1, i32 6)
%30 = call i32 @putchar(i32 10)
br label %31
31: ; preds = %0, %31
%32 = phi i64 [ 0, %0 ], [ %55, %31 ]
%33 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %2, i64 0, i64 %32, i64 0
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %2, i64 0, i64 %32, i64 1
%37 = load i32, i32* %36
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %37)
%39 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %2, i64 0, i64 %32, i64 2
%40 = load i32, i32* %39
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %40)
%42 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %2, i64 0, i64 %32, i64 3
%43 = load i32, i32* %42
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %43)
%45 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %2, i64 0, i64 %32, i64 4
%46 = load i32, i32* %45
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %2, i64 0, i64 %32, i64 5
%49 = load i32, i32* %48
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %49)
%51 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %2, i64 0, i64 %32, i64 6
%52 = load i32, i32* %51
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %52)
%54 = call i32 @putchar(i32 10)
%55 = add nuw nsw i64 %32, 1
%56 = icmp eq i64 %55, 7
br i1 %56, label %57, label %31
57: ; preds = %31
%58 = call i32 @putchar(i32 10)
%59 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}