#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 *, ...);
void partitionGeneric(int value, int *partition, int offset,
                      int (*comparator)(int nextValue, int *partition,
                                        int offset)) {
  int i;
  if (value == 0) {
    printf("= ");
    for (i = 0; i < offset - 1; i++) {
      printf("%d + ", partition[i]);
    }
    printf("%d\n", partition[offset - 1]);
  } else {
    for (i = 1; i <= value; i++) {
      if (comparator(i, partition, offset)) {
        partition[offset] = i;
        partitionGeneric(value - i, partition, offset + 1, comparator);
      }
    }
  }
}


x86 assembly (clang, -O0):
<partitionGeneric>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    11b0 <partitionGeneric+0x90>
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    118d <partitionGeneric+0x6d>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1155 <partitionGeneric+0x35>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    121b <partitionGeneric+0xfb>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     1216 <partitionGeneric+0xf6>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   *%rax
cmp    $0x0,%eax
je     1203 <partitionGeneric+0xe3>
mov    -0x24(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x4(%rbp),%edi
sub    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
mov    -0x20(%rbp),%rcx
call   1030 <partitionGeneric@plt>
jmp    1208 <partitionGeneric+0xe8>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b7 <partitionGeneric+0x97>
jmp    121b <partitionGeneric+0xfb>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<partitionGeneric>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r13
test   %edi,%edi
je     11a1 <partitionGeneric+0x81>
jle    1192 <partitionGeneric+0x72>
mov    %rcx,%r15
mov    %edi,%ebp
movslq %r14d,%rcx
mov    %rcx,%rax
mov    %rcx,(%rsp)
lea    0x1(%rcx),%r12d
add    $0xffffffff,%ebp
mov    $0x1,%ebx
jmp    1168 <partitionGeneric+0x48>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%ebx
add    $0xffffffff,%ebp
jae    1192 <partitionGeneric+0x72>
mov    %ebx,%edi
mov    %r13,%rsi
mov    %r14d,%edx
call   *%r15
test   %eax,%eax
je     1160 <partitionGeneric+0x40>
mov    (%rsp),%rax
mov    %ebx,0x0(%r13,%rax,4)
mov    %ebp,%edi
mov    %r13,%rsi
mov    %r12d,%edx
mov    %r15,%rcx
call   1030 <partitionGeneric@plt>
jmp    1160 <partitionGeneric+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe58(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    -0x1(%r14),%r15d
cmp    $0x2,%r14d
jl     11e8 <partitionGeneric+0xc8>
mov    %r15d,%ebp
lea    0xe40(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%r13,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11d0 <partitionGeneric+0xb0>
movslq %r15d,%rax
mov    0x0(%r13,%rax,4),%esi
lea    0xe12(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"= \00"
@.str.1 = [6 x i8] c"%d + \00"
@.str.2 = [4 x i8] c"%d\0A\00"
define void @partitionGeneric(i32 %0, i32* %1, i32 %2, i32 (i32, i32*, i32)* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32 (i32, i32*, i32)*
%9 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 (i32, i32*, i32)* %3, i32 (i32, i32*, i32)** %8
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %37
12: ; preds = %4
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %9
br label %14
14: ; preds = %26, %12
%15 = load i32, i32* %9
%16 = load i32, i32* %7
%17 = sub nsw i32 %16, 1
%18 = icmp slt i32 %15, %17
br i1 %18, label %19, label %29
19: ; preds = %14
%20 = load i32*, i32** %6
%21 = load i32, i32* %9
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32, i32* %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %19
%27 = load i32, i32* %9
%28 = add nsw i32 %27, 1
store i32 %28, i32* %9
br label %14
29: ; preds = %14
%30 = load i32*, i32** %6
%31 = load i32, i32* %7
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %30, i64 %33
%35 = load i32, i32* %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %35)
br label %67
37: ; preds = %4
store i32 1, i32* %9
br label %38
38: ; preds = %63, %37
%39 = load i32, i32* %9
%40 = load i32, i32* %5
%41 = icmp sle i32 %39, %40
br i1 %41, label %42, label %66
42: ; preds = %38
%43 = load i32 (i32, i32*, i32)*, i32 (i32, i32*, i32)** %8
%44 = load i32, i32* %9
%45 = load i32*, i32** %6
%46 = load i32, i32* %7
%47 = call i32 %43(i32 %44, i32* %45, i32 %46)
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %62
49: ; preds = %42
%50 = load i32, i32* %9
%51 = load i32*, i32** %6
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %51, i64 %53
store i32 %50, i32* %54
%55 = load i32, i32* %5
%56 = load i32, i32* %9
%57 = sub nsw i32 %55, %56
%58 = load i32*, i32** %6
%59 = load i32, i32* %7
%60 = add nsw i32 %59, 1
%61 = load i32 (i32, i32*, i32)*, i32 (i32, i32*, i32)** %8
br label %62
62: ; preds = %49, %42
br label %63
63: ; preds = %62
%64 = load i32, i32* %9
%65 = add nsw i32 %64, 1
store i32 %65, i32* %9
br label %38
66: ; preds = %38
br label %67
67: ; preds = %66, %29
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"= \00"
@.str.1 = [6 x i8] c"%d + \00"
@.str.2 = [4 x i8] c"%d\0A\00"
define void @partitionGeneric(i32 %0, i32* %1, i32 %2, i32 (i32, i32*, i32)* nocapture %3) {
%5 = icmp eq i32 %0, 0
br i1 %5, label %12, label %6
6: ; preds = %4
%7 = icmp slt i32 %0, 1
br i1 %7, label %39, label %8
8: ; preds = %6
%9 = sext i32 %2 to i64
%10 = getelementptr inbounds i32, i32* %1, i64 %9
%11 = add nsw i32 %2, 1
br label %30
12: ; preds = %4
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = add i32 %2, -1
%15 = icmp sgt i32 %2, 1
br i1 %15, label %16, label %25
16: ; preds = %12
%17 = zext i32 %14 to i64
br label %18
18: ; preds = %16, %18
%19 = phi i64 [ 0, %16 ], [ %23, %18 ]
%20 = getelementptr inbounds i32, i32* %1, i64 %19
%21 = load i32, i32* %20
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = add nuw nsw i64 %19, 1
%24 = icmp eq i64 %23, %17
br i1 %24, label %25, label %18
25: ; preds = %18, %12
%26 = sext i32 %14 to i64
%27 = getelementptr inbounds i32, i32* %1, i64 %26
%28 = load i32, i32* %27
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %28)
br label %39
30: ; preds = %8, %36
%31 = phi i32 [ 1, %8 ], [ %37, %36 ]
%32 = tail call i32 %3(i32 %31, i32* %1, i32 %2)
%33 = icmp eq i32 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %30
store i32 %31, i32* %10
%35 = sub nsw i32 %0, %31
tail call void @partitionGeneric(i32 %35, i32* %1, i32 %11, i32 (i32, i32*, i32)* %3)
br label %36
36: ; preds = %30, %34
%37 = add nuw i32 %31, 1
%38 = icmp eq i32 %31, %0
br i1 %38, label %39, label %30
39: ; preds = %36, %6, %25
ret void
}