#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*/ print_result(int *, int);
int /*<<< orphan*/ printf(char *);
void find_combination(int n, int sum, int *array) {
  int result;
  if (n > sum) {
    return find_combination(sum, sum, array);
  }
  result = ((n + 1) * n) >> 1;
  if (result < sum) {
    return;
  }
  if (sum == 0) {
    print_result(array, 100);
    printf("\n");
    return;
  }
  if (n < 1) {
    return;
  }
  array[n] = 1;
  find_combination(n - 1, sum - n, array);
  array[n] = 0;
  find_combination(n - 1, sum, array);
}


x86 assembly (clang, -O0):
<find_combination>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    1162 <find_combination+0x32>
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1050 <find_combination@plt>
jmp    1200 <find_combination+0xd0>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
imul   -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1183 <find_combination+0x53>
jmp    1200 <find_combination+0xd0>
cmpl   $0x0,-0x8(%rbp)
jne    11ac <find_combination+0x7c>
mov    -0x10(%rbp),%rdi
mov    $0x64,%esi
call   1040 <print_result@plt>
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
jmp    1200 <find_combination+0xd0>
cmpl   $0x1,-0x4(%rbp)
jge    11bb <find_combination+0x8b>
jmp    1200 <find_combination+0xd0>
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x8(%rbp),%esi
sub    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1050 <find_combination@plt>
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1050 <find_combination@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_combination>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ebp
nopl   0x0(%rax)
mov    %edi,%ebx
mov    %ebp,%edi
cmp    %ebp,%ebx
jg     1140 <find_combination+0x10>
lea    0x1(%rbx),%eax
imul   %ebx,%eax
sar    %eax
cmp    %ebp,%eax
jl     1184 <find_combination+0x54>
test   %ebp,%ebp
je     118f <find_combination+0x5f>
test   %ebx,%ebx
jle    1184 <find_combination+0x54>
mov    %ebx,%r15d
movl   $0x1,(%r14,%r15,4)
mov    %ebp,%esi
sub    %ebx,%esi
add    $0xffffffff,%ebx
mov    %ebx,%edi
mov    %r14,%rdx
call   1050 <find_combination@plt>
movl   $0x0,(%r14,%r15,4)
mov    %ebx,%edi
jmp    1140 <find_combination+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
mov    $0x64,%esi
call   1040 <print_result@plt>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define void @find_combination(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* %4
%9 = load i32, i32* %5
%10 = icmp sgt i32 %8, %9
br i1 %10, label %11, label %15
11: ; preds = %3
%12 = load i32, i32* %5
%13 = load i32, i32* %5
%14 = load i32*, i32** %6
br label %55
15: ; preds = %3
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
%18 = load i32, i32* %4
%19 = mul nsw i32 %17, %18
%20 = ashr i32 %19, 1
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = load i32, i32* %5
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %15
br label %55
25: ; preds = %15
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i32*, i32** %6
%30 = call i32 @print_result(i32* %29, i32 100)
%31 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %55
32: ; preds = %25
%33 = load i32, i32* %4
%34 = icmp slt i32 %33, 1
br i1 %34, label %35, label %36
35: ; preds = %32
br label %55
36: ; preds = %32
%37 = load i32*, i32** %6
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
store i32 1, i32* %40
%41 = load i32, i32* %4
%42 = sub nsw i32 %41, 1
%43 = load i32, i32* %5
%44 = load i32, i32* %4
%45 = sub nsw i32 %43, %44
%46 = load i32*, i32** %6
%47 = load i32*, i32** %6
%48 = load i32, i32* %4
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %47, i64 %49
store i32 0, i32* %50
%51 = load i32, i32* %4
%52 = sub nsw i32 %51, 1
%53 = load i32, i32* %5
%54 = load i32*, i32** %6
br label %55
55: ; preds = %36, %35, %28, %24, %11
ret void
}

LLVM IR (-O2):
define void @find_combination(i32 %0, i32 %1, i32* %2) {
%4 = icmp eq i32 %1, 0
br label %5
5: ; preds = %24, %3
%6 = phi i32 [ %0, %3 ], [ %25, %24 ]
%7 = icmp sgt i32 %6, %1
br i1 %7, label %24, label %8
8: ; preds = %5
%9 = add nsw i32 %6, 1
%10 = mul nsw i32 %9, %6
%11 = ashr i32 %10, 1
%12 = icmp slt i32 %11, %1
br i1 %12, label %26, label %13
13: ; preds = %8
br i1 %4, label %14, label %17
14: ; preds = %13
%15 = tail call i32 @print_result(i32* %2, i32 100)
%16 = tail call i32 @putchar(i32 10)
br label %26
17: ; preds = %13
%18 = icmp slt i32 %6, 1
br i1 %18, label %26, label %19
19: ; preds = %17
%20 = zext i32 %6 to i64
%21 = getelementptr inbounds i32, i32* %2, i64 %20
store i32 1, i32* %21
%22 = add nsw i32 %6, -1
%23 = sub nsw i32 %1, %6
tail call void @find_combination(i32 %22, i32 %23, i32* %2)
store i32 0, i32* %21
br label %24
24: ; preds = %19, %5
%25 = phi i32 [ %22, %19 ], [ %1, %5 ]
br label %5
26: ; preds = %17, %8, %14
ret void
}