#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 getStartOfNewFactorInd(char *, int, int, int);
int getWeightMaximalFactoring(char str[], int start, int mEnd,
                              int memoTable[][100]) {
  int endFactorInd, minWeight, nextInd, weight;
  if (start > mEnd)
    return 0;
  if (start == mEnd)
    return 1;
  if (memoTable[start][mEnd] >= 0)
    return memoTable[start][mEnd];
  minWeight = mEnd - start + 1;
  for (endFactorInd = start; endFactorInd < mEnd; endFactorInd++) {
    nextInd = getStartOfNewFactorInd(str, start, mEnd, endFactorInd);
    weight = getWeightMaximalFactoring(str, start, endFactorInd, memoTable) +
             getWeightMaximalFactoring(str, nextInd, mEnd, memoTable);
    if (minWeight > weight)
      minWeight = weight;
  }
  memoTable[start][mEnd] = minWeight;
  return minWeight;
}


x86 assembly (clang, -O0):
<getWeightMaximalFactoring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    114e <getWeightMaximalFactoring+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    1254 <getWeightMaximalFactoring+0x134>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    1166 <getWeightMaximalFactoring+0x46>
movl   $0x1,-0x4(%rbp)
jmp    1254 <getWeightMaximalFactoring+0x134>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   $0x190,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jl     11a7 <getWeightMaximalFactoring+0x87>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   $0x190,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x4(%rbp)
jmp    1254 <getWeightMaximalFactoring+0x134>
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1232 <getWeightMaximalFactoring+0x112>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x24(%rbp),%ecx
call   1040 <getStartOfNewFactorInd@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1030 <getWeightMaximalFactoring@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1030 <getWeightMaximalFactoring@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x30(%rbp),%eax
jle    121f <getWeightMaximalFactoring+0xff>
mov    -0x30(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    1224 <getWeightMaximalFactoring+0x104>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b9 <getWeightMaximalFactoring+0x99>
mov    -0x28(%rbp),%edx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   $0x190,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getWeightMaximalFactoring>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
xor    %eax,%eax
mov    %edx,%r13d
sub    %esi,%r13d
jl     11f6 <getWeightMaximalFactoring+0xd6>
mov    $0x1,%eax
je     11f6 <getWeightMaximalFactoring+0xd6>
mov    %edx,%r12d
mov    %esi,%ebp
movslq %esi,%rax
movslq %edx,%rsi
imul   $0x190,%rax,%rbx
add    %rcx,%rbx
mov    (%rbx,%rsi,4),%eax
test   %eax,%eax
jns    11f6 <getWeightMaximalFactoring+0xd6>
lea    (%rbx,%rsi,4),%rax
mov    %rax,0x10(%rsp)
add    $0x1,%r13d
cmp    %ebp,%r12d
jle    11eb <getWeightMaximalFactoring+0xcb>
mov    %rdi,0x20(%rsp)
mov    %ebp,%ebx
mov    %rcx,0x18(%rsp)
mov    %ebp,0x8(%rsp)
mov    0x20(%rsp),%r15
mov    0x18(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r12d,%edx
mov    %ebx,%ecx
call   1040 <getStartOfNewFactorInd@plt>
mov    %eax,0xc(%rsp)
mov    %r15,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r14,%rcx
call   1030 <getWeightMaximalFactoring@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    0xc(%rsp),%esi
mov    %r12d,%edx
mov    %r14,%rcx
call   1030 <getWeightMaximalFactoring@plt>
add    %ebp,%eax
mov    0x8(%rsp),%ebp
cmp    %eax,%r13d
cmovg  %eax,%r13d
add    $0x1,%ebx
cmp    %ebx,%r12d
jne    11a0 <getWeightMaximalFactoring+0x80>
mov    0x10(%rsp),%rax
mov    %r13d,(%rax)
mov    %r13d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @getWeightMaximalFactoring(i8* %0, i32 %1, i32 %2, [100 x i32]* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [100 x i32]*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store [100 x i32]* %3, [100 x i32]** %9
%14 = load i32, i32* %7
%15 = load i32, i32* %8
%16 = icmp sgt i32 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %4
store i32 0, i32* %5
br label %88
18: ; preds = %4
%19 = load i32, i32* %7
%20 = load i32, i32* %8
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 1, i32* %5
br label %88
23: ; preds = %18
%24 = load [100 x i32]*, [100 x i32]** %9
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [100 x i32], [100 x i32]* %24, i64 %26
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [100 x i32], [100 x i32]* %27, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = icmp sge i32 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %23
%34 = load [100 x i32]*, [100 x i32]** %9
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [100 x i32], [100 x i32]* %34, i64 %36
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [100 x i32], [100 x i32]* %37, i64 0, i64 %39
%41 = load i32, i32* %40
store i32 %41, i32* %5
br label %88
42: ; preds = %23
%43 = load i32, i32* %8
%44 = load i32, i32* %7
%45 = sub nsw i32 %43, %44
%46 = add nsw i32 %45, 1
store i32 %46, i32* %11
%47 = load i32, i32* %7
store i32 %47, i32* %10
br label %48
48: ; preds = %75, %42
%49 = load i32, i32* %10
%50 = load i32, i32* %8
%51 = icmp slt i32 %49, %50
br i1 %51, label %52, label %78
52: ; preds = %48
%53 = load i8*, i8** %6
%54 = load i32, i32* %7
%55 = load i32, i32* %8
%56 = load i32, i32* %10
%57 = call i32 @getStartOfNewFactorInd(i8* %53, i32 %54, i32 %55, i32 %56)
store i32 %57, i32* %12
%58 = load i8*, i8** %6
%59 = load i32, i32* %7
%60 = load i32, i32* %10
%61 = load [100 x i32]*, [100 x i32]** %9
%62 = call i32 @getWeightMaximalFactoring(i8* %58, i32 %59, i32 %60, [100 x i32]* %61)
%63 = load i8*, i8** %6
%64 = load i32, i32* %12
%65 = load i32, i32* %8
%66 = load [100 x i32]*, [100 x i32]** %9
%67 = call i32 @getWeightMaximalFactoring(i8* %63, i32 %64, i32 %65, [100 x i32]* %66)
%68 = add nsw i32 %62, %67
store i32 %68, i32* %13
%69 = load i32, i32* %11
%70 = load i32, i32* %13
%71 = icmp sgt i32 %69, %70
br i1 %71, label %72, label %74
72: ; preds = %52
%73 = load i32, i32* %13
store i32 %73, i32* %11
br label %74
74: ; preds = %72, %52
br label %75
75: ; preds = %74
%76 = load i32, i32* %10
%77 = add nsw i32 %76, 1
store i32 %77, i32* %10
br label %48
78: ; preds = %48
%79 = load i32, i32* %11
%80 = load [100 x i32]*, [100 x i32]** %9
%81 = load i32, i32* %7
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [100 x i32], [100 x i32]* %80, i64 %82
%84 = load i32, i32* %8
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [100 x i32], [100 x i32]* %83, i64 0, i64 %85
store i32 %79, i32* %86
%87 = load i32, i32* %11
store i32 %87, i32* %5
br label %88
88: ; preds = %78, %33, %22, %17
%89 = load i32, i32* %5
ret i32 %89
}

LLVM IR (-O2):
define i32 @getWeightMaximalFactoring(i8* %0, i32 %1, i32 %2, [100 x i32]* %3) {
%5 = icmp slt i32 %2, %1
br i1 %5, label %31, label %6
6: ; preds = %4
%7 = icmp eq i32 %2, %1
br i1 %7, label %31, label %8
8: ; preds = %6
%9 = sext i32 %1 to i64
%10 = sext i32 %2 to i64
%11 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 %9, i64 %10
%12 = load i32, i32* %11
%13 = icmp sgt i32 %12, -1
br i1 %13, label %31, label %14
14: ; preds = %8
%15 = sub i32 1, %1
%16 = add i32 %15, %2
%17 = icmp slt i32 %1, %2
br i1 %17, label %18, label %29
18: ; preds = %14, %18
%19 = phi i32 [ %27, %18 ], [ %1, %14 ]
%20 = phi i32 [ %26, %18 ], [ %16, %14 ]
%21 = tail call i32 @getStartOfNewFactorInd(i8* %0, i32 %1, i32 %2, i32 %19)
%22 = tail call i32 @getWeightMaximalFactoring(i8* %0, i32 %1, i32 %19, [100 x i32]* %3)
%23 = tail call i32 @getWeightMaximalFactoring(i8* %0, i32 %21, i32 %2, [100 x i32]* %3)
%24 = add nsw i32 %23, %22
%25 = icmp sgt i32 %20, %24
%26 = select i1 %25, i32 %24, i32 %20
%27 = add i32 %19, 1
%28 = icmp eq i32 %27, %2
br i1 %28, label %29, label %18
29: ; preds = %18, %14
%30 = phi i32 [ %16, %14 ], [ %26, %18 ]
store i32 %30, i32* %11
br label %31
31: ; preds = %8, %6, %4, %29
%32 = phi i32 [ %30, %29 ], [ 0, %4 ], [ 1, %6 ], [ %12, %8 ]
ret i32 %32
}