#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 /*<<< orphan*/ printf(char *, int /*<<< orphan*/, int);
void print_cut_rod_solution(int rod_length, int *solution) {
  int j = 1;
  for (int i = rod_length; i > 0;) {
    printf("The %dth cut is of length %d\n", j++, solution[i]);
    i -= solution[i];
  }
}


x86 assembly (clang, -O0):
<print_cut_rod_solution>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    1170 <print_cut_rod_solution+0x60>
mov    -0x14(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xead(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
jmp    112c <print_cut_rod_solution+0x1c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_cut_rod_solution>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edi,%edi
jle    114b <print_cut_rod_solution+0x3b>
mov    %rsi,%r15
mov    %edi,%ebp
mov    $0x1,%esi
lea    0xed3(%rip),%r14
nopl   (%rax)
lea    0x1(%rsi),%r12d
mov    %ebp,%ebx
mov    (%r15,%rbx,4),%edx
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %r12d,%esi
sub    (%r15,%rbx,4),%ebp
jg     1130 <print_cut_rod_solution+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"The %dth cut is of length %d\0A\00"
define void @print_cut_rod_solution(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
store i32 1, i32* %5
%7 = load i32, i32* %3
store i32 %7, i32* %6
br label %8
8: ; preds = %11, %2
%9 = load i32, i32* %6
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %8
%12 = load i32, i32* %5
%13 = add nsw i32 %12, 1
store i32 %13, i32* %5
%14 = load i32*, i32** %4
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %14, i64 %16
%18 = load i32, i32* %17
%19 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %18)
%20 = load i32*, i32** %4
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32, i32* %23
%25 = load i32, i32* %6
%26 = sub nsw i32 %25, %24
store i32 %26, i32* %6
br label %8
27: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"The %dth cut is of length %d\0A\00"
define void @print_cut_rod_solution(i32 %0, i32* nocapture %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %5, label %4
4: ; preds = %5, %2
ret void
5: ; preds = %2, %5
%6 = phi i32 [ %14, %5 ], [ %0, %2 ]
%7 = phi i32 [ %8, %5 ], [ 1, %2 ]
%8 = add nuw nsw i32 %7, 1
%9 = zext i32 %6 to i64
%10 = getelementptr inbounds i32, i32* %1, i64 %9
%11 = load i32, i32* %10
%12 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %11)
%13 = load i32, i32* %10
%14 = sub nsw i32 %6, %13
%15 = icmp sgt i32 %14, 0
br i1 %15, label %5, label %4
}