#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 extended_bottom_up_cut_rod(int *, int, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ printvinl(int *, int);
void print_cut_rod_solution(int p[], int n, int s[]) {
  int revenue = extended_bottom_up_cut_rod(p, n, s);
  if (revenue <= 0)
    return;
  printf("---------------------------------------------------------------------"
         "----------\n");
  printf("Rot prices: ");
  printvinl(p, n);
  printf("Cut a rot of length %d like this:", n);
  while (n > 0) {
    printf(" %d", s[n - 1]);
    n = n - s[n - 1];
  }
  printf(", will get the largest revenue %d.\n", revenue);
}


x86 assembly (clang, -O0):
<print_cut_rod_solution>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1040 <extended_bottom_up_cut_rod@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     1165 <print_cut_rod_solution+0x35>
jmp    11f2 <print_cut_rod_solution+0xc2>
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <printvinl@plt>
mov    -0xc(%rbp),%esi
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0xc(%rbp)
jle    11e1 <print_cut_rod_solution+0xb1>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    -0x18(%rbp),%rcx
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
sub    (%rcx,%rdx,4),%eax
mov    %eax,-0xc(%rbp)
jmp    119e <print_cut_rod_solution+0x6e>
mov    -0x1c(%rbp),%esi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_cut_rod_solution>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %esi,%ebx
mov    %rdi,%rbp
call   1050 <extended_bottom_up_cut_rod@plt>
test   %eax,%eax
jle    11d0 <print_cut_rod_solution+0x90>
mov    %eax,%r15d
lea    0xef4(%rip),%rdi
call   1030 <puts@plt>
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    %ebx,%esi
call   1060 <printvinl@plt>
lea    0xe86(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
jle    11b7 <print_cut_rod_solution+0x77>
lea    0xe94(%rip),%r12
nopl   0x0(%rax,%rax,1)
lea    -0x1(%rbx),%ebp
mov    (%r14,%rbp,4),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
sub    (%r14,%rbp,4),%ebx
jg     11a0 <print_cut_rod_solution+0x60>
lea    0xe75(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [81 x i8] c"-------------------------------------------------------------------------------\0A\00"
@.str.1 = [13 x i8] c"Rot prices: \00"
@.str.2 = [34 x i8] c"Cut a rot of length %d like this:\00"
@.str.3 = [4 x i8] c" %d\00"
@.str.4 = [36 x i8] c", will get the largest revenue %d.\0A\00"
define void @print_cut_rod_solution(i32* %0, i32 %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%8 = load i32*, i32** %4
%9 = load i32, i32* %5
%10 = load i32*, i32** %6
%11 = call i32 @extended_bottom_up_cut_rod(i32* %8, i32 %9, i32* %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp sle i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %3
br label %45
15: ; preds = %3
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32*, i32** %4
%19 = load i32, i32* %5
%20 = call i32 @printvinl(i32* %18, i32 %19)
%21 = load i32, i32* %5
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %26, %15
%24 = load i32, i32* %5
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %42
26: ; preds = %23
%27 = load i32*, i32** %6
%28 = load i32, i32* %5
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %27, i64 %30
%32 = load i32, i32* %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %5
%35 = load i32*, i32** %6
%36 = load i32, i32* %5
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %35, i64 %38
%40 = load i32, i32* %39
%41 = sub nsw i32 %34, %40
store i32 %41, i32* %5
br label %23
42: ; preds = %23
%43 = load i32, i32* %7
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %42, %14
ret void
}

LLVM IR (-O2):
@.str.1 = [13 x i8] c"Rot prices: \00"
@.str.2 = [34 x i8] c"Cut a rot of length %d like this:\00"
@.str.3 = [4 x i8] c" %d\00"
@.str.4 = [36 x i8] c", will get the largest revenue %d.\0A\00"
@str = [80 x i8] c"-------------------------------------------------------------------------------\00"
define void @print_cut_rod_solution(i32* %0, i32 %1, i32* %2) {
%4 = tail call i32 @extended_bottom_up_cut_rod(i32* %0, i32 %1, i32* %2)
%5 = icmp slt i32 %4, 1
br i1 %5, label %24, label %6
6: ; preds = %3
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([80 x i8], [80 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @printvinl(i32* %0, i32 %1)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%11 = icmp sgt i32 %1, 0
br i1 %11, label %12, label %22
12: ; preds = %6, %12
%13 = phi i32 [ %20, %12 ], [ %1, %6 ]
%14 = add nsw i32 %13, -1
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %2, i64 %15
%17 = load i32, i32* %16
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %16
%20 = sub nsw i32 %13, %19
%21 = icmp sgt i32 %20, 0
br i1 %21, label %12, label %22
22: ; preds = %12, %6
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i32 %4)
br label %24
24: ; preds = %3, %22
ret void
}