#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 */
typedef int /*<<< orphan*/ test_lengths;

/* Variables and functions */
int constrained_subset_sum(int *, size_t);
int /*<<< orphan*/ printf(char *, int, int);
int main(int argc, char **argv) {
  int test_case1[] = {1, 2, 3};
  int test_case2[] = {-5, -3, -1, 2, 4, 6};
  int test_case3[] = {-1, 1};
  int *test_cases[] = {test_case1, test_case2, test_case3};
  size_t test_lengths[] = {3, 6, 2};
  for (size_t i = 0; i < sizeof(test_lengths) / sizeof(size_t); ++i) {
    printf("Test: %d, Result: %d\n", (int)i + 1,
           constrained_subset_sum(test_cases[i], test_lengths[i]));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xec0(%rip),%rax
mov    %rax,-0x1c(%rbp)
mov    0xebe(%rip),%eax
mov    %eax,-0x14(%rbp)
mov    0xebc(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xeb9(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xeb6(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xed3(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    -0x1c(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    0xe98(%rip),%rax
mov    %rax,-0x80(%rbp)
mov    0xe95(%rip),%rax
mov    %rax,-0x78(%rbp)
mov    0xe92(%rip),%rax
mov    %rax,-0x70(%rbp)
movq   $0x0,-0x88(%rbp)
cmpq   $0x3,-0x88(%rbp)
03
jae    1223 <main+0x103>
mov    -0x88(%rbp),%rax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
mov    -0x88(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rdi
mov    -0x88(%rbp),%rax
mov    -0x80(%rbp,%rax,8),%rsi
call   1040 <constrained_subset_sum@plt>
mov    -0x8c(%rbp),%esi
mov    %eax,%edx
lea    0xe49(%rip),%rdi
call   1030 <printf@plt>
mov    -0x88(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x88(%rbp)
jmp    11bd <main+0x9d>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
mov    0xedd(%rip),%eax
mov    %eax,0x18(%rsp)
mov    0xeca(%rip),%rax
mov    %rax,0x10(%rsp)
mov    0xede(%rip),%rax
mov    %rax,0x30(%rsp)
movaps 0xec2(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movabs $0x1ffffffff,%rax
mov    %rax,0x8(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x3,%esi
call   1040 <constrained_subset_sum@plt>
lea    0xeb0(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
call   1030 <printf@plt>
lea    0x20(%rsp),%rdi
mov    $0x6,%esi
call   1040 <constrained_subset_sum@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %eax,%edx
call   1030 <printf@plt>
lea    0x8(%rsp),%rdi
mov    $0x2,%esi
call   1040 <constrained_subset_sum@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
mov    %eax,%edx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.test_case1 = [3 x i32] [i32 1, i32 2, i32 3]
@__const.main.test_case2 = [6 x i32] [i32 -5, i32 -3, i32 -1, i32 2, i32 4, i32 6]
@__const.main.test_case3 = [2 x i32] [i32 -1, i32 1]
@__const.main.test_lengths = [3 x i64] [i64 3, i64 6, i64 2]
@.str = [22 x i8] c"Test: %d, Result: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [3 x i32]
%7 = alloca [6 x i32]
%8 = alloca [2 x i32]
%9 = alloca [3 x i32*]
%10 = alloca [3 x i64]
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [3 x i32]* %6 to i8*
%13 = bitcast [6 x i32]* %7 to i8*
%14 = bitcast [2 x i32]* %8 to i8*
%15 = getelementptr inbounds [3 x i32*], [3 x i32*]* %9, i64 0, i64 0
%16 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 0
store i32* %16, i32** %15
%17 = getelementptr inbounds i32*, i32** %15, i64 1
%18 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 0
store i32* %18, i32** %17
%19 = getelementptr inbounds i32*, i32** %17, i64 1
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
store i32* %20, i32** %19
%21 = bitcast [3 x i64]* %10 to i8*
store i64 0, i64* %11
br label %22
22: ; preds = %37, %2
%23 = load i64, i64* %11
%24 = icmp ult i64 %23, 3
br i1 %24, label %25, label %40
25: ; preds = %22
%26 = load i64, i64* %11
%27 = trunc i64 %26 to i32
%28 = add nsw i32 %27, 1
%29 = load i64, i64* %11
%30 = getelementptr inbounds [3 x i32*], [3 x i32*]* %9, i64 0, i64 %29
%31 = load i32*, i32** %30
%32 = load i64, i64* %11
%33 = getelementptr inbounds [3 x i64], [3 x i64]* %10, i64 0, i64 %32
%34 = load i64, i64* %33
%35 = call i32 @constrained_subset_sum(i32* %31, i64 %34)
%36 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %28, i32 %35)
br label %37
37: ; preds = %25
%38 = load i64, i64* %11
%39 = add i64 %38, 1
store i64 %39, i64* %11
br label %22
40: ; preds = %22
ret i32 0
}

LLVM IR (-O2):
@__const.main.test_case1 = [3 x i32] [i32 1, i32 2, i32 3]
@__const.main.test_case2 = [6 x i32] [i32 -5, i32 -3, i32 -1, i32 2, i32 4, i32 6]
@.str = [22 x i8] c"Test: %d, Result: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [3 x i32]
%4 = alloca [6 x i32]
%5 = alloca i64
%6 = bitcast [3 x i32]* %3 to i8*
%7 = bitcast [6 x i32]* %4 to i8*
%8 = bitcast i64* %5 to i8*
store i64 8589934591, i64* %5
%9 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 0
%10 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 0
%11 = bitcast i64* %5 to i32*
%12 = call i32 @constrained_subset_sum(i32* %9, i64 3)
%13 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 1, i32 %12)
%14 = call i32 @constrained_subset_sum(i32* %10, i64 6)
%15 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 2, i32 %14)
%16 = call i32 @constrained_subset_sum(i32* %11, i64 2)
%17 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 3, i32 %16)
ret i32 0
}