#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 *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ subset_sum(int *, int, int);
int main() {
  printf("\nSubset sum \n");
  int arr[100], N, D;
  int i;
  printf("Enter the number of elements\n");
  scanf("%d", &N);
  printf("Enter %d elements\n", N);
  for (i = 0; i < N; i++)
    scanf("%d", &arr[i]);
  printf("Enter the required sum\n");
  scanf("%d", &D);
  subset_sum(arr, N, D);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec7(%rip),%rdi
lea    -0x1a4(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x1a4(%rbp),%esi
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1ac(%rbp)
mov    -0x1ac(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    11d6 <main+0xa6>
movslq -0x1ac(%rbp),%rax
lea    -0x1a0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe6f(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x1ac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1ac(%rbp)
jmp    118f <main+0x5f>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe41(%rip),%rdi
lea    -0x1a8(%rbp),%rsi
call   1040 <scanf@plt>
lea    -0x1a0(%rbp),%rdi
mov    -0x1a4(%rbp),%esi
mov    -0x1a8(%rbp),%edx
call   1050 <subset_sum@plt>
xor    %eax,%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x1a0,%rsp
lea    0xec3(%rip),%rdi
call   1030 <puts@plt>
lea    0xec4(%rip),%rdi
call   1030 <puts@plt>
lea    0xe95(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%esi
lea    0xe83(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0x8(%rsp)
jle    11bd <main+0x7d>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xe64(%rip),%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     11a0 <main+0x60>
lea    0xe7c(%rip),%rdi
call   1030 <puts@plt>
lea    0xe30(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
lea    0x10(%rsp),%rdi
call   1060 <subset_sum@plt>
xor    %eax,%eax
add    $0x1a0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"\0ASubset sum \0A\00"
@.str.1 = [30 x i8] c"Enter the number of elements\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [19 x i8] c"Enter %d elements\0A\00"
@.str.4 = [24 x i8] c"Enter the required sum\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%9 = load i32, i32* %3
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %9)
store i32 0, i32* %5
br label %11
11: ; preds = %20, %0
%12 = load i32, i32* %5
%13 = load i32, i32* %3
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %23
15: ; preds = %11
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %17
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %18)
br label %20
20: ; preds = %15
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %11
23: ; preds = %11
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%26 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%27 = load i32, i32* %3
%28 = load i32, i32* %4
%29 = call i32 @subset_sum(i32* %26, i32 %27, i32 %28)
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [19 x i8] c"Enter %d elements\0A\00"
@str = [13 x i8] c"\0ASubset sum \00"
@str.5 = [29 x i8] c"Enter the number of elements\00"
@str.6 = [23 x i8] c"Enter the required sum\00"
define i32 @main() {
%1 = alloca [100 x i32]
%2 = alloca i32
%3 = alloca i32
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%5 = bitcast [100 x i32]* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.5, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%10 = load i32, i32* %2
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %2
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %0, %14
%15 = phi i64 [ %18, %14 ], [ 0, %0 ]
%16 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %15
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %16)
%18 = add nuw nsw i64 %15, 1
%19 = load i32, i32* %2
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %18, %20
br i1 %21, label %14, label %22
22: ; preds = %14, %0
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.6, i64 0, i64 0))
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%25 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%26 = load i32, i32* %2
%27 = load i32, i32* %3
%28 = call i32 @subset_sum(i32* %25, i32 %26, i32 %27)
ret i32 0
}