#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 */
typedef int /*<<< orphan*/ prices;

/* Variables and functions */
int bottom_up_cut_rod(int *, int);
int cut_rod(int *, int);
int memoized_cut_rod(int *, int);
int /*<<< orphan*/ print_cut_rod_solution(int *, int, int *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int prices[] = {1, 5, 8, 9, 10, 17, 17, 20, 24, 30, 35, 41, 43, 50};
  int revenue;
  int s[(sizeof(prices) / sizeof(prices[0]))];
  int i;
  revenue = cut_rod(prices, 4);
  printf("%d\n", revenue);
  revenue = memoized_cut_rod(prices, 5);
  printf("%d\n", revenue);
  revenue = bottom_up_cut_rod(prices, 5);
  printf("%d\n", revenue);
  for (i = 0; i <= (sizeof(prices) / sizeof(prices[0])); ++i)
    print_cut_rod_solution(prices, i, s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe83(%rip),%rsi
mov    $0x38,%edx
call   1050 <memcpy@plt>
lea    -0x40(%rbp),%rdi
mov    $0x4,%esi
call   1060 <cut_rod@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%esi
lea    0xe96(%rip),%rdi
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    $0x5,%esi
call   1030 <memoized_cut_rod@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%esi
lea    0xe76(%rip),%rdi
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    $0x5,%esi
call   1080 <bottom_up_cut_rod@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%esi
lea    0xe56(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x84(%rbp)
movslq -0x84(%rbp),%rax
cmp    $0xe,%rax
ja     1229 <main+0xc9>
lea    -0x40(%rbp),%rdi
mov    -0x84(%rbp),%esi
lea    -0x80(%rbp),%rdx
call   1070 <print_cut_rod_solution@plt>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    11f1 <main+0x91>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    0xed2(%rip),%rax
mov    %rax,0x30(%rsp)
movaps 0xeb6(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe9a(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe7e(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x4,%esi
call   1050 <cut_rod@plt>
lea    0xe9b(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x5,%esi
call   1030 <memoized_cut_rod@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x5,%esi
call   1070 <bottom_up_cut_rod@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
lea    0x40(%rsp),%rbx
mov    %r14,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1060 <print_cut_rod_solution@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
call   1060 <print_cut_rod_solution@plt>
mov    %r14,%rdi
mov    $0x2,%esi
mov    %rbx,%rdx
call   1060 <print_cut_rod_solution@plt>
mov    %r14,%rdi
mov    $0x3,%esi
mov    %rbx,%rdx
call   1060 <print_cut_rod_solution@plt>
mov    %r14,%rdi
mov    $0x4,%esi
mov    %rbx,%rdx
call   1060 <print_cut_rod_solution@plt>
mov    %r14,%rdi
mov    $0x5,%esi
mov    %rbx,%rdx
call   1060 <print_cut_rod_solution@plt>
mov    %r14,%rdi
mov    $0x6,%esi
mov    %rbx,%rdx
call   1060 <print_cut_rod_solution@plt>
mov    %r14,%rdi
mov    $0x7,%esi
mov    %rbx,%rdx
call   1060 <print_cut_rod_solution@plt>
mov    %r14,%rdi
mov    $0x8,%esi
mov    %rbx,%rdx
call   1060 <print_cut_rod_solution@plt>
mov    %r14,%rdi
mov    $0x9,%esi
mov    %rbx,%rdx
call   1060 <print_cut_rod_solution@plt>
mov    %r14,%rdi
mov    $0xa,%esi
mov    %rbx,%rdx
call   1060 <print_cut_rod_solution@plt>
mov    %r14,%rdi
mov    $0xb,%esi
mov    %rbx,%rdx
call   1060 <print_cut_rod_solution@plt>
mov    %r14,%rdi
mov    $0xc,%esi
mov    %rbx,%rdx
call   1060 <print_cut_rod_solution@plt>
mov    %r14,%rdi
mov    $0xd,%esi
mov    %rbx,%rdx
call   1060 <print_cut_rod_solution@plt>
mov    %r14,%rdi
mov    $0xe,%esi
mov    %rbx,%rdx
call   1060 <print_cut_rod_solution@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.prices = [14 x i32] [i32 1, i32 5, i32 8, i32 9, i32 10, i32 17, i32 17, i32 20, i32 24, i32 30, i32 35, i32 41, i32 43, i32 50]
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [14 x i32]
%3 = alloca i32
%4 = alloca [14 x i32]
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [14 x i32]* %2 to i8*
%7 = getelementptr inbounds [14 x i32], [14 x i32]* %2, i64 0, i64 0
%8 = call i32 @cut_rod(i32* %7, i32 4)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds [14 x i32], [14 x i32]* %2, i64 0, i64 0
%12 = call i32 @memoized_cut_rod(i32* %11, i32 5)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [14 x i32], [14 x i32]* %2, i64 0, i64 0
%16 = call i32 @bottom_up_cut_rod(i32* %15, i32 5)
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %17)
store i32 0, i32* %5
br label %19
19: ; preds = %28, %0
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = icmp ule i64 %21, 14
br i1 %22, label %23, label %31
23: ; preds = %19
%24 = getelementptr inbounds [14 x i32], [14 x i32]* %2, i64 0, i64 0
%25 = load i32, i32* %5
%26 = getelementptr inbounds [14 x i32], [14 x i32]* %4, i64 0, i64 0
%27 = call i32 @print_cut_rod_solution(i32* %24, i32 %25, i32* %26)
br label %28
28: ; preds = %23
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %19
31: ; preds = %19
ret i32 0
}

LLVM IR (-O2):
@__const.main.prices = [14 x i32] [i32 1, i32 5, i32 8, i32 9, i32 10, i32 17, i32 17, i32 20, i32 24, i32 30, i32 35, i32 41, i32 43, i32 50]
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [14 x i32]
%2 = alloca [14 x i32]
%3 = bitcast [14 x i32]* %1 to i8*
%4 = bitcast [14 x i32]* %2 to i8*
%5 = getelementptr inbounds [14 x i32], [14 x i32]* %1, i64 0, i64 0
%6 = call i32 @cut_rod(i32* %5, i32 4)
%7 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = call i32 @memoized_cut_rod(i32* %5, i32 5)
%9 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 @bottom_up_cut_rod(i32* %5, i32 5)
%11 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds [14 x i32], [14 x i32]* %2, i64 0, i64 0
%13 = call i32 @print_cut_rod_solution(i32* %5, i32 0, i32* %12)
%14 = call i32 @print_cut_rod_solution(i32* %5, i32 1, i32* %12)
%15 = call i32 @print_cut_rod_solution(i32* %5, i32 2, i32* %12)
%16 = call i32 @print_cut_rod_solution(i32* %5, i32 3, i32* %12)
%17 = call i32 @print_cut_rod_solution(i32* %5, i32 4, i32* %12)
%18 = call i32 @print_cut_rod_solution(i32* %5, i32 5, i32* %12)
%19 = call i32 @print_cut_rod_solution(i32* %5, i32 6, i32* %12)
%20 = call i32 @print_cut_rod_solution(i32* %5, i32 7, i32* %12)
%21 = call i32 @print_cut_rod_solution(i32* %5, i32 8, i32* %12)
%22 = call i32 @print_cut_rod_solution(i32* %5, i32 9, i32* %12)
%23 = call i32 @print_cut_rod_solution(i32* %5, i32 10, i32* %12)
%24 = call i32 @print_cut_rod_solution(i32* %5, i32 11, i32* %12)
%25 = call i32 @print_cut_rod_solution(i32* %5, i32 12, i32* %12)
%26 = call i32 @print_cut_rod_solution(i32* %5, i32 13, i32* %12)
%27 = call i32 @print_cut_rod_solution(i32* %5, i32 14, i32* %12)
ret i32 0
}