#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 /*<<< orphan*/ print_optimal_parens(int **, int, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, const char *argv[]) {
  int p[7] = {30, 35, 15, 5, 10, 20, 25};
  int m[7][7] = {0};
  int s[7][7] = {0};
  int i, j;
  matrix_chain_order(p, m, s);
  printf("table m:\n");
  for (i = 1; i < 7; i++) {
    for (j = 1; j < 7; j++)
      printf("%5d ", m[i][j]);
    printf("\n");
  }
  printf("\n矩阵链A1...A6所需的最少乘法次数为： %d\n", m[1][6]);
  printf("最优解为：");
  print_optimal_parens(s, 1, 6);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1e0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xea0(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe9d(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe9a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe98(%rip),%eax
mov    %eax,-0x18(%rbp)
lea    -0x100(%rbp),%rdi
xor    %esi,%esi
mov    $0xc4,%edx
call   1050 <memset@plt>
lea    -0x1d0(%rbp),%rdi
xor    %esi,%esi
mov    $0xc4,%edx
call   1050 <memset@plt>
lea    -0x30(%rbp),%rdi
lea    -0x100(%rbp),%rsi
lea    -0x1d0(%rbp),%rdx
call   1030 <matrix_chain_order@plt>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x1d4(%rbp)
cmpl   $0x7,-0x1d4(%rbp)
jge    125f <main+0x11f>
movl   $0x1,-0x1d8(%rbp)
cmpl   $0x7,-0x1d8(%rbp)
jge    123d <main+0xfd>
movslq -0x1d4(%rbp),%rcx
lea    -0x100(%rbp),%rax
imul   $0x1c,%rcx,%rcx
add    %rcx,%rax
movslq -0x1d8(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1d8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1d8(%rbp)
jmp    11ef <main+0xaf>
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1d4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1d4(%rbp)
jmp    11d8 <main+0x98>
mov    -0xcc(%rbp),%esi
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1d0(%rbp),%rdi
mov    $0x1,%esi
mov    $0x6,%edx
call   1060 <print_optimal_parens@plt>
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x1e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x1b8,%rsp
movups 0xeab(%rip),%xmm0
movups %xmm0,0xdc(%rsp)
movaps 0xe90(%rip),%xmm0
movaps %xmm0,0xd0(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0xc0(%rsp)
movaps %xmm0,0x1a0(%rsp)
movaps %xmm0,0x190(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movl   $0x0,0x1b0(%rsp)
lea    0xd0(%rsp),%rdi
mov    %rsp,%rsi
lea    0xf0(%rsp),%rdx
call   1050 <matrix_chain_order@plt>
lea    0xe11(%rip),%rdi
call   1040 <puts@plt>
mov    $0x34,%ebx
lea    0xdb4(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    -0x14(%rsp,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    -0x10(%rsp,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    -0xc(%rsp,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    -0x8(%rsp,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    -0x4(%rsp,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%rsp,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1c,%rbx
cmp    $0xdc,%rbx
jne    1270 <main+0x120>
mov    0x34(%rsp),%esi
lea    0xd3c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd65(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xf0(%rsp),%rdi
mov    $0x1,%esi
mov    $0x6,%edx
call   1070 <print_optimal_parens@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x1b8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.p = [7 x i32] [i32 30, i32 35, i32 15, i32 5, i32 10, i32 20, i32 25]
@.str = [10 x i8] c"table m:\0A\00"
@.str.1 = [5 x i8] c"%5d \00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [55 x i8] c"\0A\E7\9F\A9\E9\98\B5\E9\93\BEA1...A6\E6\89\80\E9\9C\80\E7\9A\84\E6\9C\80\E5\B0\91\E4\B9\98\E6\B3\95\E6\AC\A1\E6\95\B0\E4\B8\BA\EF\BC\9A %d\0A\00"
@.str.4 = [16 x i8] c"\E6\9C\80\E4\BC\98\E8\A7\A3\E4\B8\BA\EF\BC\9A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [7 x i32]
%7 = alloca [7 x [7 x i32]]
%8 = alloca [7 x [7 x i32]]
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [7 x i32]* %6 to i8*
%12 = bitcast [7 x [7 x i32]]* %7 to i8*
%13 = bitcast [7 x [7 x i32]]* %8 to i8*
%14 = getelementptr inbounds [7 x i32], [7 x i32]* %6, i64 0, i64 0
%15 = getelementptr inbounds [7 x [7 x i32]], [7 x [7 x i32]]* %7, i64 0, i64 0
%16 = bitcast [7 x i32]* %15 to i32**
%17 = getelementptr inbounds [7 x [7 x i32]], [7 x [7 x i32]]* %8, i64 0, i64 0
%18 = bitcast [7 x i32]* %17 to i32**
%19 = call i32 @matrix_chain_order(i32* %14, i32** %16, i32** %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %9
br label %21
21: ; preds = %42, %2
%22 = load i32, i32* %9
%23 = icmp slt i32 %22, 7
br i1 %23, label %24, label %45
24: ; preds = %21
store i32 1, i32* %10
br label %25
25: ; preds = %37, %24
%26 = load i32, i32* %10
%27 = icmp slt i32 %26, 7
br i1 %27, label %28, label %40
28: ; preds = %25
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [7 x [7 x i32]], [7 x [7 x i32]]* %7, i64 0, i64 %30
%32 = load i32, i32* %10
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [7 x i32], [7 x i32]* %31, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %28
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 1
store i32 %39, i32* %10
br label %25
40: ; preds = %25
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %40
%43 = load i32, i32* %9
%44 = add nsw i32 %43, 1
store i32 %44, i32* %9
br label %21
45: ; preds = %21
%46 = getelementptr inbounds [7 x [7 x i32]], [7 x [7 x i32]]* %7, i64 0, i64 1
%47 = getelementptr inbounds [7 x i32], [7 x i32]* %46, i64 0, i64 6
%48 = load i32, i32* %47
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), i32 %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%51 = getelementptr inbounds [7 x [7 x i32]], [7 x [7 x i32]]* %8, i64 0, i64 0
%52 = bitcast [7 x i32]* %51 to i32**
%53 = call i32 @print_optimal_parens(i32** %52, i32 1, i32 6)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@__const.main.p = [7 x i32] [i32 30, i32 35, i32 15, i32 5, i32 10, i32 20, i32 25]
@.str.1 = [5 x i8] c"%5d \00"
@.str.3 = [55 x i8] c"\0A\E7\9F\A9\E9\98\B5\E9\93\BEA1...A6\E6\89\80\E9\9C\80\E7\9A\84\E6\9C\80\E5\B0\91\E4\B9\98\E6\B3\95\E6\AC\A1\E6\95\B0\E4\B8\BA\EF\BC\9A %d\0A\00"
@.str.4 = [16 x i8] c"\E6\9C\80\E4\BC\98\E8\A7\A3\E4\B8\BA\EF\BC\9A\00"
@str = [9 x i8] c"table m:\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [7 x i32]
%4 = alloca [7 x [7 x i32]]
%5 = alloca [7 x [7 x i32]]
%6 = bitcast [7 x i32]* %3 to i8*
%7 = bitcast [7 x [7 x i32]]* %4 to i8*
%8 = bitcast [7 x [7 x i32]]* %5 to i8*
%9 = getelementptr inbounds [7 x i32], [7 x i32]* %3, i64 0, i64 0
%10 = bitcast [7 x [7 x i32]]* %4 to i32**
%11 = bitcast [7 x [7 x i32]]* %5 to i32**
%12 = call i32 @matrix_chain_order(i32* %9, i32** %10, i32** %11)
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %14
14: ; preds = %2, %14
%15 = phi i64 [ 1, %2 ], [ %35, %14 ]
%16 = getelementptr inbounds [7 x [7 x i32]], [7 x [7 x i32]]* %4, i64 0, i64 %15, i64 1
%17 = load i32, i32* %16
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = getelementptr inbounds [7 x [7 x i32]], [7 x [7 x i32]]* %4, i64 0, i64 %15, i64 2
%20 = load i32, i32* %19
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds [7 x [7 x i32]], [7 x [7 x i32]]* %4, i64 0, i64 %15, i64 3
%23 = load i32, i32* %22
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = getelementptr inbounds [7 x [7 x i32]], [7 x [7 x i32]]* %4, i64 0, i64 %15, i64 4
%26 = load i32, i32* %25
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds [7 x [7 x i32]], [7 x [7 x i32]]* %4, i64 0, i64 %15, i64 5
%29 = load i32, i32* %28
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds [7 x [7 x i32]], [7 x [7 x i32]]* %4, i64 0, i64 %15, i64 6
%32 = load i32, i32* %31
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = call i32 @putchar(i32 10)
%35 = add nuw nsw i64 %15, 1
%36 = icmp eq i64 %35, 7
br i1 %36, label %37, label %14
37: ; preds = %14
%38 = getelementptr inbounds [7 x [7 x i32]], [7 x [7 x i32]]* %4, i64 0, i64 1, i64 6
%39 = load i32, i32* %38
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), i32 %39)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%42 = call i32 @print_optimal_parens(i32** %11, i32 1, i32 6)
%43 = call i32 @putchar(i32 10)
ret i32 0
}