#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 bottom_up_cut_rod(int *, int, int);
int bottom_up_cut_rod_with_solution(int *, int, int, int *, int *);
int cut_rod(int *, int, int);
int /*<<< orphan*/ free(int *);
int *malloc(int);
int memoized_cut_rod(int *, int, int);
int /*<<< orphan*/ print_cut_rod_solution(int, int *);
int /*<<< orphan*/ printf(char *, int, int, int, int, int);
int main() {
  int p[] = {1, 5, 8, 9, 10, 17, 17, 20, 24, 30};
  for (int i = 1; i < 11; i++) {
    int *value = malloc((i + 1) * sizeof(int));
    int *solution = malloc((i + 1) * sizeof(int));
    printf("The result of %d is recursive: %d, memoized: %d, bottom up dp: %d "
           "and %d\n",
           i, cut_rod(p, 10, i), memoized_cut_rod(p, 10, i),
           bottom_up_cut_rod(p, 10, i),
           bottom_up_cut_rod_with_solution(p, 10, i, value, solution));
    print_cut_rod_solution(i, solution);
    free(value);
    free(solution);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xe56(%rip),%rsi
mov    $0x28,%edx
call   1070 <memcpy@plt>
movl   $0x1,-0x34(%rbp)
cmpl   $0xb,-0x34(%rbp)
jge    1296 <main+0x106>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x58(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    $0xa,%esi
call   1090 <cut_rod@plt>
mov    %eax,-0x54(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    $0xa,%esi
call   1040 <memoized_cut_rod@plt>
mov    %eax,-0x50(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    $0xa,%esi
call   10b0 <bottom_up_cut_rod@plt>
mov    %eax,-0x4c(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    -0x40(%rbp),%rcx
mov    -0x48(%rbp),%r8
mov    $0xa,%esi
call   1050 <bottom_up_cut_rod_with_solution@plt>
mov    -0x58(%rbp),%esi
mov    -0x54(%rbp),%edx
mov    -0x50(%rbp),%ecx
mov    -0x4c(%rbp),%r8d
mov    %eax,%r9d
lea    0xdc3(%rip),%rdi
call   1060 <printf@plt>
mov    -0x34(%rbp),%edi
mov    -0x48(%rbp),%rsi
call   10a0 <print_cut_rod_solution@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11bb <main+0x2b>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    0xe8b(%rip),%rax
mov    %rax,0x30(%rsp)
movaps 0xe6f(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe53(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
mov    $0x1,%ebx
mov    $0x8,%ebp
nopl   0x0(%rax)
lea    0x1(%rbx),%eax
mov    %eax,0x4(%rsp)
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%r13
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    $0xa,%esi
mov    %ebx,%edx
call   1080 <cut_rod@plt>
mov    %eax,(%rsp)
mov    %r12,%rdi
mov    $0xa,%esi
mov    %ebx,%edx
call   1040 <memoized_cut_rod@plt>
mov    %eax,%r14d
mov    %r12,%rdi
mov    $0xa,%esi
mov    %ebx,%edx
call   10a0 <bottom_up_cut_rod@plt>
mov    %eax,%r15d
mov    %r12,%rdi
mov    $0xa,%esi
mov    %ebx,%edx
mov    0x8(%rsp),%r12
mov    %r12,%rcx
mov    %r13,%r8
call   1050 <bottom_up_cut_rod_with_solution@plt>
lea    0xdef(%rip),%rdi
mov    %ebx,%esi
mov    (%rsp),%edx
mov    %r14d,%ecx
mov    %r15d,%r8d
mov    %eax,%r9d
call   1060 <printf@plt>
mov    %ebx,%edi
mov    %r13,%rsi
call   1090 <print_cut_rod_solution@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
add    $0x4,%ebp
mov    0x4(%rsp),%eax
mov    %eax,%ebx
cmp    $0xb,%eax
jne    11c0 <main+0x40>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.p = [10 x i32] [i32 1, i32 5, i32 8, i32 9, i32 10, i32 17, i32 17, i32 20, i32 24, i32 30]
@.str = [74 x i8] c"The result of %d is recursive: %d, memoized: %d, bottom up dp: %d and %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
store i32 0, i32* %1
%6 = bitcast [10 x i32]* %2 to i8*
store i32 1, i32* %3
br label %7
7: ; preds = %46, %0
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 11
br i1 %9, label %10, label %49
10: ; preds = %7
%11 = load i32, i32* %3
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 4
%15 = trunc i64 %14 to i32
%16 = call i32* @malloc(i32 %15)
store i32* %16, i32** %4
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 4
%21 = trunc i64 %20 to i32
%22 = call i32* @malloc(i32 %21)
store i32* %22, i32** %5
%23 = load i32, i32* %3
%24 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%25 = load i32, i32* %3
%26 = call i32 @cut_rod(i32* %24, i32 10, i32 %25)
%27 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%28 = load i32, i32* %3
%29 = call i32 @memoized_cut_rod(i32* %27, i32 10, i32 %28)
%30 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%31 = load i32, i32* %3
%32 = call i32 @bottom_up_cut_rod(i32* %30, i32 10, i32 %31)
%33 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%34 = load i32, i32* %3
%35 = load i32*, i32** %4
%36 = load i32*, i32** %5
%37 = call i32 @bottom_up_cut_rod_with_solution(i32* %33, i32 10, i32 %34, i32* %35, i32* %36)
%38 = call i32 @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %26, i32 %29, i32 %32, i32 %37)
%39 = load i32, i32* %3
%40 = load i32*, i32** %5
%41 = call i32 @print_cut_rod_solution(i32 %39, i32* %40)
%42 = load i32*, i32** %4
%43 = call i32 @free(i32* %42)
%44 = load i32*, i32** %5
%45 = call i32 @free(i32* %44)
br label %46
46: ; preds = %10
%47 = load i32, i32* %3
%48 = add nsw i32 %47, 1
store i32 %48, i32* %3
br label %7
49: ; preds = %7
%50 = load i32, i32* %1
ret i32 %50
}

LLVM IR (-O2):
@__const.main.p = [10 x i32] [i32 1, i32 5, i32 8, i32 9, i32 10, i32 17, i32 17, i32 20, i32 24, i32 30]
@.str = [74 x i8] c"The result of %d is recursive: %d, memoized: %d, bottom up dp: %d and %d\0A\00"
define i32 @main() {
%1 = alloca [10 x i32]
%2 = bitcast [10 x i32]* %1 to i8*
%3 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
br label %5
4: ; preds = %5
ret i32 0
5: ; preds = %0, %5
%6 = phi i32 [ 1, %0 ], [ %7, %5 ]
%7 = add nuw nsw i32 %6, 1
%8 = shl nuw nsw i32 %7, 2
%9 = call i32* @malloc(i32 %8)
%10 = call i32* @malloc(i32 %8)
%11 = call i32 @cut_rod(i32* %3, i32 10, i32 %6)
%12 = call i32 @memoized_cut_rod(i32* %3, i32 10, i32 %6)
%13 = call i32 @bottom_up_cut_rod(i32* %3, i32 10, i32 %6)
%14 = call i32 @bottom_up_cut_rod_with_solution(i32* %3, i32 10, i32 %6, i32* %9, i32* %10)
%15 = call i32 @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %11, i32 %12, i32 %13, i32 %14)
%16 = call i32 @print_cut_rod_solution(i32 %6, i32* %10)
%17 = call i32 @free(i32* %9)
%18 = call i32 @free(i32* %10)
%19 = icmp eq i32 %7, 11
br i1 %19, label %4, label %5
}