#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*/ printPartition(int *, int);
void partition(int *arr, int ind, int left) {
  int val;
  if (left == 0) {
    printPartition(arr, ind);
    return;
  }
  for (val = 1; val <= left; val++) {
    int valid = 0;
    if (ind == 0) {
      valid = 1;
    } else {
      valid = (arr[ind - 1] % 2) != (val % 2);
    }
    if (valid == 1) {
      arr[ind] = val;
      partition(arr, ind + 1, left - val);
    }
  }
}


x86 assembly (clang, -O0):
<partition>:
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    114d <partition+0x2d>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <printPartition@plt>
jmp    11f5 <partition+0xd5>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11f5 <partition+0xd5>
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    117d <partition+0x5d>
movl   $0x1,-0x18(%rbp)
jmp    11b5 <partition+0x95>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    -0x1c(%rbp),%edx
cmp    %eax,%edx
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jne    11e2 <partition+0xc2>
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 <partition@plt>
jmp    11e7 <partition+0xc7>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1154 <partition+0x34>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<partition>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
test   %edx,%edx
je     11ad <partition+0x8d>
jle    119e <partition+0x7e>
mov    %edx,%ebp
lea    -0x1(%r14),%eax
cltq
mov    %rax,(%rsp)
movslq %r14d,%r13
lea    0x1(%r13),%r15d
add    $0xffffffff,%ebp
mov    $0x1,%r12d
jmp    117a <partition+0x5a>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12d,(%rbx,%r13,4)
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
call   1030 <partition@plt>
add    $0x1,%r12d
add    $0xffffffff,%ebp
jae    119e <partition+0x7e>
test   %r14d,%r14d
je     1160 <partition+0x40>
mov    (%rsp),%rax
mov    (%rbx,%rax,4),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
and    $0xfffffffe,%ecx
sub    %ecx,%eax
mov    %r12d,%ecx
and    $0x1,%ecx
cmp    %ecx,%eax
jne    1160 <partition+0x40>
jmp    1171 <partition+0x51>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
mov    %r14d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printPartition@plt>

LLVM IR (-O0):
define void @partition(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %3
%12 = load i32*, i32** %4
%13 = load i32, i32* %5
%14 = call i32 @printPartition(i32* %12, i32 %13)
br label %55
15: ; preds = %3
store i32 1, i32* %7
br label %16
16: ; preds = %52, %15
%17 = load i32, i32* %7
%18 = load i32, i32* %6
%19 = icmp sle i32 %17, %18
br i1 %19, label %20, label %55
20: ; preds = %16
store i32 0, i32* %8
%21 = load i32, i32* %5
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 1, i32* %8
br label %36
24: ; preds = %20
%25 = load i32*, i32** %4
%26 = load i32, i32* %5
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %25, i64 %28
%30 = load i32, i32* %29
%31 = srem i32 %30, 2
%32 = load i32, i32* %7
%33 = srem i32 %32, 2
%34 = icmp ne i32 %31, %33
%35 = zext i1 %34 to i32
store i32 %35, i32* %8
br label %36
36: ; preds = %24, %23
%37 = load i32, i32* %8
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %51
39: ; preds = %36
%40 = load i32, i32* %7
%41 = load i32*, i32** %4
%42 = load i32, i32* %5
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
store i32 %40, i32* %44
%45 = load i32*, i32** %4
%46 = load i32, i32* %5
%47 = add nsw i32 %46, 1
%48 = load i32, i32* %6
%49 = load i32, i32* %7
%50 = sub nsw i32 %48, %49
br label %51
51: ; preds = %39, %36
br label %52
52: ; preds = %51
%53 = load i32, i32* %7
%54 = add nsw i32 %53, 1
store i32 %54, i32* %7
br label %16
55: ; preds = %11, %16
ret void
}

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