#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 findSubsetWithGivenSumHelper(int A[], int lengthA, int startingIndex,
                                  int sum, int summandPosition[],
                                  int summandCount) {
  if (startingIndex == lengthA) {
    if (sum == 0) {
      int index;
      for (index = 0; index < summandCount; index++) {
        printf("[%d @ i=%d] ", A[summandPosition[index]],
               summandPosition[index]);
      }
      printf("\n");
    } else {
      return;
    }
  } else {
    findSubsetWithGivenSumHelper(A, lengthA, startingIndex + 1, sum,
                                 summandPosition, summandCount);
    summandPosition[summandCount] = startingIndex;
    findSubsetWithGivenSumHelper(A, lengthA, startingIndex + 1,
                                 sum - A[startingIndex], summandPosition,
                                 summandCount + 1);
  }
}


x86 assembly (clang, -O0):
<findSubsetWithGivenSumHelper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    11bd <findSubsetWithGivenSumHelper+0x9d>
cmpl   $0x0,-0x14(%rbp)
jne    11b3 <findSubsetWithGivenSumHelper+0x93>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11a0 <findSubsetWithGivenSumHelper+0x80>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq -0x28(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
mov    (%rax,%rcx,4),%esi
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    115a <findSubsetWithGivenSumHelper+0x3a>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b8 <findSubsetWithGivenSumHelper+0x98>
jmp    1215 <findSubsetWithGivenSumHelper+0xf5>
jmp    1215 <findSubsetWithGivenSumHelper+0xf5>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
add    $0x1,%edx
mov    -0x14(%rbp),%ecx
mov    -0x20(%rbp),%r8
mov    -0x24(%rbp),%r9d
call   1040 <findSubsetWithGivenSumHelper@plt>
mov    -0x10(%rbp),%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
add    $0x1,%edx
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%r8
sub    (%rax,%r8,4),%ecx
mov    -0x20(%rbp),%r8
mov    -0x24(%rbp),%r9d
add    $0x1,%r9d
call   1040 <findSubsetWithGivenSumHelper@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findSubsetWithGivenSumHelper>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,%ebp
mov    %ecx,%ebx
mov    %rdi,%r12
cmp    %esi,%edx
mov    %r8,0x8(%rsp)
je     11b7 <findSubsetWithGivenSumHelper+0x87>
mov    %esi,%r13d
movslq %ebp,%rax
movslq %edx,%rcx
lea    (%r12,%rcx,4),%rcx
mov    %rcx,0x18(%rsp)
lea    (%r8,%rax,4),%rax
mov    %rax,0x10(%rsp)
xor    %r15d,%r15d
nopl   (%rax)
mov    %rdx,0x20(%rsp)
lea    0x1(%rdx),%r14d
mov    %r12,%rdi
mov    %r13d,%esi
mov    %r14d,%edx
mov    %ebx,%ecx
mov    0x8(%rsp),%r8
mov    %ebp,%r9d
call   1050 <findSubsetWithGivenSumHelper@plt>
mov    0x10(%rsp),%rax
mov    0x20(%rsp),%rcx
mov    %ecx,(%rax,%r15,1)
mov    0x18(%rsp),%rax
sub    (%rax,%r15,1),%ebx
add    $0x4,%r15
add    $0x1,%ebp
mov    %r14d,%edx
cmp    %r14d,%r13d
jne    1170 <findSubsetWithGivenSumHelper+0x40>
mov    0x8(%rsp),%r15
test   %ebx,%ebx
je     11cf <findSubsetWithGivenSumHelper+0x9f>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   %ebp,%ebp
jle    11fb <findSubsetWithGivenSumHelper+0xcb>
mov    %ebp,%ebp
lea    0xe24(%rip),%r14
xor    %ebx,%ebx
xchg   %ax,%ax
movslq (%r15,%rbx,4),%rdx
mov    (%r12,%rdx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11e0 <findSubsetWithGivenSumHelper+0xb0>
mov    $0xa,%edi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

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