#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 matrix_chain(int *, int);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  int p1[] = {10, 100, 5, 50};
  if (!(matrix_chain(p1, 1) == 0)) {
    printf("assert fail: %s\n", "boundary test 1");
    return -1;
  };
  if (!(matrix_chain(p1, 2) == 5000)) {
    printf("assert fail: %s\n", "boundary test 2");
    return -1;
  };
  if (!(matrix_chain(p1, 3) == 7500)) {
    printf("assert fail: %s\n", "should be ((A)x(B))x(C)");
    return -1;
  };
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xec3(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xec0(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1040 <matrix_chain@plt>
cmp    $0x0,%eax
je     1182 <main+0x62>
lea    0xea6(%rip),%rdi
lea    0xeb0(%rip),%rsi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <main+0xd9>
lea    -0x20(%rbp),%rdi
mov    $0x2,%esi
call   1040 <matrix_chain@plt>
cmp    $0x1388,%eax
je     11ba <main+0x9a>
lea    0xe6e(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <main+0xd9>
lea    -0x20(%rbp),%rdi
mov    $0x3,%esi
call   1040 <matrix_chain@plt>
cmp    $0x1d4c,%eax
je     11f2 <main+0xd2>
lea    0xe36(%rip),%rdi
lea    0xe60(%rip),%rsi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <main+0xd9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
movaps 0xed5(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0x1,%esi
call   1040 <matrix_chain@plt>
test   %eax,%eax
je     1149 <main+0x29>
lea    0xeda(%rip),%rsi
jmp    1186 <main+0x66>
mov    %rsp,%rdi
mov    $0x2,%esi
call   1040 <matrix_chain@plt>
cmp    $0x1388,%eax
jne    117f <main+0x5f>
mov    %rsp,%rdi
mov    $0x3,%esi
call   1040 <matrix_chain@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1d4c,%ecx
je     1197 <main+0x77>
lea    0xec4(%rip),%rsi
jmp    1186 <main+0x66>
lea    0xeab(%rip),%rsi
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@__const.main.p1 = [4 x i32] [i32 10, i32 100, i32 5, i32 50]
@.str = [17 x i8] c"assert fail: %s\0A\00"
@.str.1 = [16 x i8] c"boundary test 1\00"
@.str.2 = [16 x i8] c"boundary test 2\00"
@.str.3 = [24 x i8] c"should be ((A)x(B))x(C)\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = bitcast [4 x i32]* %6 to i8*
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 0
%9 = call i32 @matrix_chain(i32* %8, i32 1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %26
13: ; preds = %2
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 0
%15 = call i32 @matrix_chain(i32* %14, i32 2)
%16 = icmp eq i32 %15, 5000
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %26
19: ; preds = %13
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 0
%21 = call i32 @matrix_chain(i32* %20, i32 3)
%22 = icmp eq i32 %21, 7500
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %26
25: ; preds = %19
store i32 0, i32* %3
br label %26
26: ; preds = %25, %23, %17, %11
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@__const.main.p1 = [4 x i32] [i32 10, i32 100, i32 5, i32 50]
@.str = [17 x i8] c"assert fail: %s\0A\00"
@.str.1 = [16 x i8] c"boundary test 1\00"
@.str.2 = [16 x i8] c"boundary test 2\00"
@.str.3 = [24 x i8] c"should be ((A)x(B))x(C)\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4 x i32]
%4 = bitcast [4 x i32]* %3 to i8*
%5 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%6 = call i32 @matrix_chain(i32* %5, i32 1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = call i32 @matrix_chain(i32* %5, i32 2)
%10 = icmp eq i32 %9, 5000
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = call i32 @matrix_chain(i32* %5, i32 3)
%13 = icmp eq i32 %12, 7500
br i1 %13, label %17, label %14
14: ; preds = %11, %8, %2
%15 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), %8 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), %11 ]
%16 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %14, %11
%18 = phi i32 [ 0, %11 ], [ -1, %14 ]
ret i32 %18
}