#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*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SEEK_SET;
int countInteger(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(int *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int isValidSet(int *, int);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int subsetSum(int *, int, int);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("Need input file name\n");
    return EXIT_FAILURE;
  }
  FILE *fptr = fopen(argv[1], "r");
  if (fptr == NULL) {
    printf("fopen fail\n");
    return EXIT_FAILURE;
  }
  int numInt = countInteger(fptr);
  fseek(fptr, 0, SEEK_SET);
  int kval;
  if (fscanf(fptr, "%d", &kval) != 1) {
    printf("fscanf error\n");
    fclose(fptr);
    return EXIT_FAILURE;
  }
  numInt--;
  int *setA = malloc(sizeof(int) * numInt);
  int ind = 0;
  for (ind = 0; ind < numInt; ind++) {
    int aval;
    if (fscanf(fptr, "%d", &aval) != 1) {
      printf("fscanf error\n");
      fclose(fptr);
      return EXIT_FAILURE;
    }
    setA[ind] = aval;
  }
  fclose(fptr);
  if (isValidSet(setA, numInt) == 1) {
    printf("There are %d subsets whose sums are %d\n",
           subsetSum(setA, numInt, kval), kval);
  } else {
    printf("Invalid set\n");
  }
  free(setA);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11df <main+0x3f>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1385 <main+0x1e5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe28(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1221 <main+0x81>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1385 <main+0x1e5>
mov    -0x18(%rbp),%rdi
call   1080 <countInteger@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2da8(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x18(%rbp),%rdi
lea    0xdd8(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1060 <fscanf@plt>
cmp    $0x1,%eax
je     1286 <main+0xe6>
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2d5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1385 <main+0x1e5>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    131d <main+0x17d>
mov    -0x18(%rbp),%rdi
lea    0xd5d(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1060 <fscanf@plt>
cmp    $0x1,%eax
je     1301 <main+0x161>
lea    0xd47(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2ce1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1385 <main+0x1e5>
mov    -0x30(%rbp),%edx
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12b0 <main+0x110>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10a0 <isValidSet@plt>
cmp    $0x1,%eax
jne    1362 <main+0x1c2>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1070 <subsetSum@plt>
mov    %eax,%esi
mov    -0x20(%rbp),%edx
lea    0xcdf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1370 <main+0x1d0>
lea    0xcf4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    0x2c50(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x1,%edi
jg     11cf <main+0x1f>
lea    0xe85(%rip),%rdi
jmp    12e0 <main+0x130>
mov    0x8(%rsi),%rdi
lea    0xe68(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     12d9 <main+0x129>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <countInteger@plt>
mov    %eax,%ebp
mov    0x2de4(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
lea    0xdf1(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
call   1070 <fscanf@plt>
cmp    $0x1,%eax
jne    12c3 <main+0x113>
lea    -0x1(%rbp),%eax
mov    %eax,0xc(%rsp)
lea    -0x4(,%rbp,4),%edi
call   10a0 <malloc@plt>
mov    %rax,%r14
cmp    $0x2,%ebp
jl     1284 <main+0xd4>
mov    0xc(%rsp),%ebp
xor    %r15d,%r15d
lea    0xdb2(%rip),%r12
lea    0x14(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1070 <fscanf@plt>
cmp    $0x1,%eax
jne    12c3 <main+0x113>
mov    0x14(%rsp),%eax
mov    %eax,(%r14,%r15,4)
add    $0x1,%r15
cmp    %r15,%rbp
jne    1260 <main+0xb0>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
mov    0xc(%rsp),%ebx
mov    %ebx,%esi
call   10b0 <isValidSet@plt>
cmp    $0x1,%eax
jne    12fd <main+0x14d>
mov    0x10(%rsp),%edx
mov    %r14,%rdi
mov    %ebx,%esi
call   1080 <subsetSum@plt>
mov    0x10(%rsp),%edx
lea    0xd4b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1309 <main+0x159>
lea    0xd6d(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    12e5 <main+0x135>
lea    0xd64(%rip),%rdi
call   1040 <puts@plt>
mov    0x2cec(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd27(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x2cb8(%rip),%rax
jmp    12ec <main+0x13c>

LLVM IR (-O0):
@.str = [22 x i8] c"Need input file name\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"fopen fail\0A\00"
@SEEK_SET = global i32 0
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [14 x i8] c"fscanf error\0A\00"
@.str.5 = [40 x i8] c"There are %d subsets whose sums are %d\0A\00"
@.str.6 = [13 x i8] c"Invalid set\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
store i32 %16, i32* %3
br label %91
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i32*, i32** %6
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
store i32 %26, i32* %3
br label %91
27: ; preds = %17
%28 = load i32*, i32** %6
%29 = call i32 @countInteger(i32* %28)
store i32 %29, i32* %7
%30 = load i32*, i32** %6
%31 = load i32, i32* @SEEK_SET
%32 = call i32 @fseek(i32* %30, i32 0, i32 %31)
%33 = load i32*, i32** %6
%34 = call i32 @fscanf(i32* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %8)
%35 = icmp ne i32 %34, 1
br i1 %35, label %36, label %41
36: ; preds = %27
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%38 = load i32*, i32** %6
%39 = call i32 @fclose(i32* %38)
%40 = load i32, i32* @EXIT_FAILURE
store i32 %40, i32* %3
br label %91
41: ; preds = %27
%42 = load i32, i32* %7
%43 = add nsw i32 %42, -1
store i32 %43, i32* %7
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = mul i64 4, %45
%47 = trunc i64 %46 to i32
%48 = call i32* @malloc(i32 %47)
store i32* %48, i32** %9
store i32 0, i32* %10
store i32 0, i32* %10
br label %49
49: ; preds = %68, %41
%50 = load i32, i32* %10
%51 = load i32, i32* %7
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %71
53: ; preds = %49
%54 = load i32*, i32** %6
%55 = call i32 @fscanf(i32* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %11)
%56 = icmp ne i32 %55, 1
br i1 %56, label %57, label %62
57: ; preds = %53
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%59 = load i32*, i32** %6
%60 = call i32 @fclose(i32* %59)
%61 = load i32, i32* @EXIT_FAILURE
store i32 %61, i32* %3
br label %91
62: ; preds = %53
%63 = load i32, i32* %11
%64 = load i32*, i32** %9
%65 = load i32, i32* %10
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32, i32* %64, i64 %66
store i32 %63, i32* %67
br label %68
68: ; preds = %62
%69 = load i32, i32* %10
%70 = add nsw i32 %69, 1
store i32 %70, i32* %10
br label %49
71: ; preds = %49
%72 = load i32*, i32** %6
%73 = call i32 @fclose(i32* %72)
%74 = load i32*, i32** %9
%75 = load i32, i32* %7
%76 = call i32 @isValidSet(i32* %74, i32 %75)
%77 = icmp eq i32 %76, 1
br i1 %77, label %78, label %85
78: ; preds = %71
%79 = load i32*, i32** %9
%80 = load i32, i32* %7
%81 = load i32, i32* %8
%82 = call i32 @subsetSum(i32* %79, i32 %80, i32 %81)
%83 = load i32, i32* %8
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %82, i32 %83)
br label %87
85: ; preds = %71
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
br label %87
87: ; preds = %85, %78
%88 = load i32*, i32** %9
%89 = call i32 @free(i32* %88)
%90 = load i32, i32* @EXIT_SUCCESS
store i32 %90, i32* %3
br label %91
91: ; preds = %87, %57, %36, %24, %14
%92 = load i32, i32* %3
ret i32 %92
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@.str.3 = [3 x i8] c"%d\00"
@.str.5 = [40 x i8] c"There are %d subsets whose sums are %d\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [12 x i8] c"Invalid set\00"
@str.8 = [13 x i8] c"fscanf error\00"
@str.9 = [11 x i8] c"fopen fail\00"
@str.10 = [21 x i8] c"Need input file name\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.10, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
br label %65
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.9, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
br label %65
17: ; preds = %9
%18 = tail call i32 @countInteger(i32* %12)
%19 = load i32, i32* @SEEK_SET
%20 = tail call i32 @fseek(i32* %12, i32 0, i32 %19)
%21 = bitcast i32* %3 to i8*
%22 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%23 = icmp eq i32 %22, 1
br i1 %23, label %28, label %24
24: ; preds = %17
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.8, i64 0, i64 0))
%26 = call i32 @fclose(i32* %12)
%27 = load i32, i32* @EXIT_FAILURE
br label %63
28: ; preds = %17
%29 = add nsw i32 %18, -1
%30 = shl i32 %29, 2
%31 = call i32* @malloc(i32 %30)
%32 = icmp sgt i32 %18, 1
br i1 %32, label %33, label %49
33: ; preds = %28
%34 = bitcast i32* %4 to i8*
%35 = zext i32 %29 to i64
br label %36
36: ; preds = %33, %44
%37 = phi i64 [ 0, %33 ], [ %47, %44 ]
%38 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%39 = icmp eq i32 %38, 1
br i1 %39, label %44, label %40
40: ; preds = %36
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.8, i64 0, i64 0))
%42 = call i32 @fclose(i32* %12)
%43 = load i32, i32* @EXIT_FAILURE
br label %63
44: ; preds = %36
%45 = load i32, i32* %4
%46 = getelementptr inbounds i32, i32* %31, i64 %37
store i32 %45, i32* %46
%47 = add nuw nsw i64 %37, 1
%48 = icmp eq i64 %47, %35
br i1 %48, label %49, label %36
49: ; preds = %44, %28
%50 = call i32 @fclose(i32* %12)
%51 = call i32 @isValidSet(i32* %31, i32 %29)
%52 = icmp eq i32 %51, 1
br i1 %52, label %53, label %58
53: ; preds = %49
%54 = load i32, i32* %3
%55 = call i32 @subsetSum(i32* %31, i32 %29, i32 %54)
%56 = load i32, i32* %3
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %55, i32 %56)
br label %60
58: ; preds = %49
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %60
60: ; preds = %58, %53
%61 = call i32 @free(i32* %31)
%62 = load i32, i32* @EXIT_SUCCESS
br label %63
63: ; preds = %40, %60, %24
%64 = phi i32 [ %27, %24 ], [ %43, %40 ], [ %62, %60 ]
br label %65
65: ; preds = %14, %63, %6
%66 = phi i32 [ %8, %6 ], [ %16, %14 ], [ %64, %63 ]
ret i32 %66
}