int find_max_profit_by_cutting_a_rod_v1(int *array, int array_len,
                                        int rod_length) {
  int max_profit, temp_profit, len;
  if (!array || (array_len <= 0) || (rod_length <= 0)) {
    return (0);
  }
  max_profit = 0;
  for (len = 1; len < array_len; ++len) {
    if ((rod_length - len) >= 0) {
      temp_profit = array[len] + find_max_profit_by_cutting_a_rod_v1(
                                     array, array_len, rod_length - len);
      if (temp_profit > max_profit) {
        max_profit = temp_profit;
      }
    }
  }
  return (max_profit);
}


x86 assembly (clang, -O0):
<find_max_profit_by_cutting_a_rod_v1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1141 <find_max_profit_by_cutting_a_rod_v1+0x31>
cmpl   $0x0,-0x14(%rbp)
jle    1141 <find_max_profit_by_cutting_a_rod_v1+0x31>
cmpl   $0x0,-0x18(%rbp)
jg     114d <find_max_profit_by_cutting_a_rod_v1+0x3d>
movl   $0x0,-0x4(%rbp)
jmp    11d0 <find_max_profit_by_cutting_a_rod_v1+0xc0>
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ca <find_max_profit_by_cutting_a_rod_v1+0xba>
mov    -0x18(%rbp),%eax
sub    -0x24(%rbp),%eax
cmp    $0x0,%eax
jl     11b7 <find_max_profit_by_cutting_a_rod_v1+0xa7>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
sub    -0x24(%rbp),%edx
call   1030 <find_max_profit_by_cutting_a_rod_v1@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    11b2 <find_max_profit_by_cutting_a_rod_v1+0xa2>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11b7 <find_max_profit_by_cutting_a_rod_v1+0xa7>
jmp    11bc <find_max_profit_by_cutting_a_rod_v1+0xac>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115b <find_max_profit_by_cutting_a_rod_v1+0x4b>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_max_profit_by_cutting_a_rod_v1>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r15d,%r15d
test   %rdi,%rdi
je     117d <find_max_profit_by_cutting_a_rod_v1+0x6d>
test   %esi,%esi
jle    117d <find_max_profit_by_cutting_a_rod_v1+0x6d>
mov    %edx,%ebp
test   %edx,%edx
jle    117d <find_max_profit_by_cutting_a_rod_v1+0x6d>
cmp    $0x2,%esi
jl     117d <find_max_profit_by_cutting_a_rod_v1+0x6d>
mov    %rdi,%r14
mov    %esi,%r12d
add    $0xffffffff,%ebp
xor    %r15d,%r15d
mov    $0x1,%ebx
jmp    115c <find_max_profit_by_cutting_a_rod_v1+0x4c>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
add    $0xffffffff,%ebp
cmp    %rbx,%r12
je     117d <find_max_profit_by_cutting_a_rod_v1+0x6d>
test   %ebp,%ebp
js     1150 <find_max_profit_by_cutting_a_rod_v1+0x40>
mov    (%r14,%rbx,4),%r13d
mov    %r14,%rdi
mov    %r12d,%esi
mov    %ebp,%edx
call   1030 <find_max_profit_by_cutting_a_rod_v1@plt>
add    %r13d,%eax
cmp    %r15d,%eax
cmovg  %eax,%r15d
jmp    1150 <find_max_profit_by_cutting_a_rod_v1+0x40>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @find_max_profit_by_cutting_a_rod_v1(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%11 = load i32*, i32** %5
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %19
13: ; preds = %3
%14 = load i32, i32* %6
%15 = icmp sle i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = load i32, i32* %7
%18 = icmp sle i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16, %13, %3
store i32 0, i32* %4
br label %55
20: ; preds = %16
store i32 0, i32* %8
store i32 1, i32* %10
br label %21
21: ; preds = %50, %20
%22 = load i32, i32* %10
%23 = load i32, i32* %6
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %53
25: ; preds = %21
%26 = load i32, i32* %7
%27 = load i32, i32* %10
%28 = sub nsw i32 %26, %27
%29 = icmp sge i32 %28, 0
br i1 %29, label %30, label %49
30: ; preds = %25
%31 = load i32*, i32** %5
%32 = load i32, i32* %10
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
%35 = load i32, i32* %34
%36 = load i32*, i32** %5
%37 = load i32, i32* %6
%38 = load i32, i32* %7
%39 = load i32, i32* %10
%40 = sub nsw i32 %38, %39
%41 = call i32 @find_max_profit_by_cutting_a_rod_v1(i32* %36, i32 %37, i32 %40)
%42 = add nsw i32 %35, %41
store i32 %42, i32* %9
%43 = load i32, i32* %9
%44 = load i32, i32* %8
%45 = icmp sgt i32 %43, %44
br i1 %45, label %46, label %48
46: ; preds = %30
%47 = load i32, i32* %9
store i32 %47, i32* %8
br label %48
48: ; preds = %46, %30
br label %49
49: ; preds = %48, %25
br label %50
50: ; preds = %49
%51 = load i32, i32* %10
%52 = add nsw i32 %51, 1
store i32 %52, i32* %10
br label %21
53: ; preds = %21
%54 = load i32, i32* %8
store i32 %54, i32* %4
br label %55
55: ; preds = %53, %19
%56 = load i32, i32* %4
ret i32 %56
}

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