#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 isValid(int *, int);
int /*<<< orphan*/ printPartition(int *, int);
void partition2(int *arr, int ind, int left) {
  int val;
  if (left == 0) {
    if (isValid(arr, ind) == 1) {
      printPartition(arr, ind);
    }
    return;
  }
  for (val = 1; val <= left; val++) {
    arr[ind] = val;
    partition2(arr, ind + 1, left - val);
  }
}


x86 assembly (clang, -O0):
<partition2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1172 <partition2+0x42>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <isValid@plt>
cmp    $0x1,%eax
jne    116d <partition2+0x3d>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <printPartition@plt>
jmp    11b6 <partition2+0x86>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11b6 <partition2+0x86>
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
sub    -0x14(%rbp),%edx
call   1030 <partition2@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1179 <partition2+0x49>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<partition2>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r12
test   %edx,%edx
je     117b <partition2+0x4b>
jle    119e <partition2+0x6e>
mov    %edx,%ebp
movslq %r14d,%r15
lea    0x1(%r15),%r14d
add    $0xffffffff,%ebp
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,(%r12,%r15,4)
mov    %r12,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1030 <partition2@plt>
add    $0x1,%ebx
add    $0xffffffff,%ebp
jb     1160 <partition2+0x30>
jmp    119e <partition2+0x6e>
mov    %r12,%rdi
mov    %r14d,%esi
call   1050 <isValid@plt>
cmp    $0x1,%eax
jne    119e <partition2+0x6e>
mov    %r12,%rdi
mov    %r14d,%esi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printPartition@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @partition2(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* %6
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %20
10: ; preds = %3
%11 = load i32*, i32** %4
%12 = load i32, i32* %5
%13 = call i32 @isValid(i32* %11, i32 %12)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i32*, i32** %4
%17 = load i32, i32* %5
%18 = call i32 @printPartition(i32* %16, i32 %17)
br label %19
19: ; preds = %15, %10
br label %40
20: ; preds = %3
store i32 1, i32* %7
br label %21
21: ; preds = %37, %20
%22 = load i32, i32* %7
%23 = load i32, i32* %6
%24 = icmp sle i32 %22, %23
br i1 %24, label %25, label %40
25: ; preds = %21
%26 = load i32, i32* %7
%27 = load i32*, i32** %4
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
store i32 %26, i32* %30
%31 = load i32*, i32** %4
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
%34 = load i32, i32* %6
%35 = load i32, i32* %7
%36 = sub nsw i32 %34, %35
br label %37
37: ; preds = %25
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %21
40: ; preds = %19, %21
ret void
}

LLVM IR (-O2):
define void @partition2(i32* %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %11, label %5
5: ; preds = %3
%6 = icmp slt i32 %2, 1
br i1 %6, label %21, label %7
7: ; preds = %5
%8 = sext i32 %1 to i64
%9 = getelementptr inbounds i32, i32* %0, i64 %8
%10 = add nsw i32 %1, 1
br label %16
11: ; preds = %3
%12 = tail call i32 @isValid(i32* %0, i32 %1)
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = tail call i32 @printPartition(i32* %0, i32 %1)
br label %21
16: ; preds = %7, %16
%17 = phi i32 [ 1, %7 ], [ %19, %16 ]
store i32 %17, i32* %9
%18 = sub nsw i32 %2, %17
tail call void @partition2(i32* %0, i32 %10, i32 %18)
%19 = add nuw i32 %17, 1
%20 = icmp eq i32 %17, %2
br i1 %20, label %21, label %16
21: ; preds = %16, %5, %11, %14
ret void
}