#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 */
long binomial_coefficient(int, int);
long count_partitions_(int num, int partitions_number, int limit,
                       long combinations) {
  long count = 0;
  if (num <= 0)
    count = 0;
  else if (partitions_number == 1) {
    if (num <= limit)
      count = combinations * binomial_coefficient(limit, num);
    else
      count = 0;
  } else {
    int max_addition = ((num) < (limit) ? (num) : (limit));
    for (int i = 1; i <= max_addition; i++)
      count += count_partitions_(num - i, partitions_number - 1, limit,
                                 combinations * binomial_coefficient(limit, i));
  }
  return count;
}


x86 assembly (clang, -O0):
<count_partitions_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x0,-0x4(%rbp)
jg     1154 <count_partitions_+0x34>
movq   $0x0,-0x20(%rbp)
jmp    1235 <count_partitions_+0x115>
cmpl   $0x1,-0x8(%rbp)
jne    119e <count_partitions_+0x7e>
mov    -0x4(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1191 <count_partitions_+0x71>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1030 <binomial_coefficient@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
imul   %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    1199 <count_partitions_+0x79>
movq   $0x0,-0x20(%rbp)
jmp    1230 <count_partitions_+0x110>
mov    -0x4(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b5 <count_partitions_+0x95>
mov    -0x4(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    11bb <count_partitions_+0x9b>
mov    -0xc(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jg     122b <count_partitions_+0x10b>
mov    -0x4(%rbp),%eax
sub    -0x28(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1030 <binomial_coefficient@plt>
mov    -0x48(%rbp),%rcx
mov    -0x40(%rbp),%edi
mov    -0x3c(%rbp),%esi
mov    -0x38(%rbp),%edx
imul   %rax,%rcx
call   1040 <count_partitions_@plt>
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11c8 <count_partitions_+0xa8>
jmp    1230 <count_partitions_+0x110>
jmp    1235 <count_partitions_+0x115>
mov    -0x20(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_partitions_>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
jle    11ba <count_partitions_+0x9a>
mov    %rcx,%rbp
mov    %edx,%r12d
mov    %edi,%ebx
cmp    $0x1,%esi
jne    1158 <count_partitions_+0x38>
cmp    %r12d,%ebx
jg     11ba <count_partitions_+0x9a>
mov    %r12d,%edi
mov    %ebx,%esi
call   1030 <binomial_coefficient@plt>
mov    %rax,%r13
imul   %rbp,%r13
jmp    11bd <count_partitions_+0x9d>
cmp    %r12d,%ebx
mov    %r12d,%r14d
cmovl  %ebx,%r14d
test   %r14d,%r14d
jle    11ba <count_partitions_+0x9a>
add    $0xffffffff,%esi
neg    %r14d
add    $0xffffffff,%ebx
mov    %rbp,(%rsp)
mov    $0x1,%ebp
xor    %r13d,%r13d
mov    %esi,%r15d
nop
mov    %r12d,%edi
mov    %ebp,%esi
call   1030 <binomial_coefficient@plt>
imul   (%rsp),%rax
mov    %ebx,%edi
mov    %r15d,%esi
mov    %r12d,%edx
mov    %rax,%rcx
call   1040 <count_partitions_@plt>
add    %rax,%r13
lea    (%r14,%rbp,1),%eax
add    $0x1,%eax
mov    %ebp,%ecx
add    $0x1,%ecx
add    $0xffffffff,%ebx
mov    %ecx,%ebp
cmp    $0x1,%eax
jne    1180 <count_partitions_+0x60>
jmp    11bd <count_partitions_+0x9d>
xor    %r13d,%r13d
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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