#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ display_tupples(int *, int, int);
scalar_t__ intersects(int *, int, int *, int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int *get_all_solutions(int *tupples, int num_ele, int cardinality,
                       int num_final_tupples) {
  int tupple_i = 0;
  int tupple_f = 0;
  int *final_tupples =
      (int *)calloc(cardinality * num_final_tupples, sizeof(int));
  int num_tupples_in_final = 0;
  int i = 0;
  for (tupple_i = 0; tupple_i < num_ele; tupple_i = tupple_i + cardinality) {
    int tupple_intersects = 0;
    for (tupple_f = 0; tupple_f < (num_tupples_in_final * cardinality);
         tupple_f = (tupple_f + cardinality)) {
      if (intersects(tupples + tupple_i, cardinality, final_tupples + tupple_f,
                     cardinality)) {
        tupple_intersects = 1;
        break;
      }
    }
    if (!tupple_intersects) {
      int i = 0;
      for (i = 0; i < cardinality; i++) {
        final_tupples[num_tupples_in_final * cardinality + i] =
            tupples[tupple_i + i];
        printf("%d,", final_tupples[num_tupples_in_final * cardinality + i]);
      }
      printf(")\n");
      num_tupples_in_final++;
    }
    if (num_tupples_in_final == num_final_tupples) {
      printf("Found Solution\n");
      display_tupples(final_tupples, num_final_tupples * cardinality,
                      cardinality);
      num_tupples_in_final = 0;
      memset(final_tupples, 0, cardinality * num_final_tupples * sizeof(int));
    }
  }
  return final_tupples;
}


x86 assembly (clang, -O0):
<get_all_solutions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%edi
imul   -0x14(%rbp),%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    130b <get_all_solutions+0x1bb>
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x2c(%rbp),%ecx
imul   -0x10(%rbp),%ecx
cmp    %ecx,%eax
jge    121b <get_all_solutions+0xcb>
mov    -0x8(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%esi
mov    -0x28(%rbp),%rdx
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
mov    -0x10(%rbp),%ecx
call   1060 <intersects@plt>
cmp    $0x0,%rax
je     1208 <get_all_solutions+0xb8>
movl   $0x1,-0x34(%rbp)
jmp    121b <get_all_solutions+0xcb>
jmp    120d <get_all_solutions+0xbd>
mov    -0x1c(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11b7 <get_all_solutions+0x67>
cmpl   $0x0,-0x34(%rbp)
jne    12aa <get_all_solutions+0x15a>
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1293 <get_all_solutions+0x143>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
imul   -0x10(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
imul   -0x10(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1233 <get_all_solutions+0xe3>
lea    0xd6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    12f8 <get_all_solutions+0x1a8>
lea    0xd4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
imul   -0x10(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1070 <display_tupples@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
jmp    12fd <get_all_solutions+0x1ad>
mov    -0x18(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    119d <get_all_solutions+0x4d>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_all_solutions>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %edx,%ebp
mov    %esi,%ebx
mov    %rdi,0x30(%rsp)
mov    %ecx,0x24(%rsp)
mov    %ecx,%edi
imul   %edx,%edi
mov    %rdi,0x28(%rsp)
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,0x10(%rsp)
test   %ebx,%ebx
jle    1303 <get_all_solutions+0x1a3>
mov    0x28(%rsp),%rax
lea    0x0(,%rax,4),%eax
mov    %eax,0x20(%rsp)
movslq %ebp,%rax
mov    %ebx,%ecx
mov    %rcx,0x50(%rsp)
mov    %eax,%r15d
mov    %rax,0x40(%rsp)
lea    0x0(,%rax,4),%rax
mov    %rax,0x38(%rsp)
mov    0x30(%rsp),%r12
xor    %eax,%eax
mov    %rax,0x18(%rsp)
xor    %ebx,%ebx
mov    %r15,0x48(%rsp)
jmp    1202 <get_all_solutions+0xa2>
mov    0x18(%rsp),%rcx
add    0x40(%rsp),%rcx
add    0x38(%rsp),%r12
mov    %rcx,%rax
mov    %rcx,0x18(%rsp)
cmp    0x50(%rsp),%rcx
jge    1303 <get_all_solutions+0x1a3>
mov    %ebx,0x8(%rsp)
imul   %ebp,%ebx
mov    %ebx,0xc(%rsp)
test   %ebx,%ebx
jle    1253 <get_all_solutions+0xf3>
mov    0x30(%rsp),%rax
mov    0x18(%rsp),%rcx
lea    (%rax,%rcx,4),%r14
mov    0xc(%rsp),%r13d
mov    0x10(%rsp),%rbx
xor    %r15d,%r15d
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   1070 <intersects@plt>
test   %rax,%rax
jne    12c0 <get_all_solutions+0x160>
add    0x40(%rsp),%r15
add    0x38(%rsp),%rbx
cmp    %r13,%r15
jl     1230 <get_all_solutions+0xd0>
mov    %ebp,%r14d
test   %ebp,%ebp
mov    0x48(%rsp),%r15
lea    0xd9c(%rip),%r13
jle    129a <get_all_solutions+0x13a>
movslq 0xc(%rsp),%rax
mov    0x10(%rsp),%rcx
lea    (%rcx,%rax,4),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    (%r12,%rbp,4),%esi
mov    %esi,(%rbx,%rbp,4)
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1280 <get_all_solutions+0x120>
lea    0xd63(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%ebx
add    $0x1,%ebx
mov    %r14d,%ebp
cmp    0x24(%rsp),%ebx
jne    11e0 <get_all_solutions+0x80>
jmp    12ce <get_all_solutions+0x16e>
nopl   0x0(%rax)
mov    0x8(%rsp),%ebx
cmp    0x24(%rsp),%ebx
jne    11e0 <get_all_solutions+0x80>
lea    0xd31(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%rsp),%r14
mov    %r14,%rdi
mov    0x28(%rsp),%rsi
mov    %ebp,%edx
call   1080 <display_tupples@plt>
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
mov    0x20(%rsp),%edx
call   1050 <memset@plt>
jmp    11e0 <get_all_solutions+0x80>
mov    0x10(%rsp),%rax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d,\00"
@.str.1 = [3 x i8] c")\0A\00"
@.str.2 = [16 x i8] c"Found Solution\0A\00"
define i32* @get_all_solutions(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%16 = load i32, i32* %7
%17 = load i32, i32* %8
%18 = mul nsw i32 %16, %17
%19 = call i64 @calloc(i32 %18, i32 4)
%20 = inttoptr i64 %19 to i32*
store i32* %20, i32** %11
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %9
br label %21
21: ; preds = %113, %4
%22 = load i32, i32* %9
%23 = load i32, i32* %6
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %117
25: ; preds = %21
store i32 0, i32* %14
store i32 0, i32* %10
br label %26
26: ; preds = %47, %25
%27 = load i32, i32* %10
%28 = load i32, i32* %12
%29 = load i32, i32* %7
%30 = mul nsw i32 %28, %29
%31 = icmp slt i32 %27, %30
br i1 %31, label %32, label %51
32: ; preds = %26
%33 = load i32*, i32** %5
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %7
%38 = load i32*, i32** %11
%39 = load i32, i32* %10
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
%42 = load i32, i32* %7
%43 = call i64 @intersects(i32* %36, i32 %37, i32* %41, i32 %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %32
store i32 1, i32* %14
br label %51
46: ; preds = %32
br label %47
47: ; preds = %46
%48 = load i32, i32* %10
%49 = load i32, i32* %7
%50 = add nsw i32 %48, %49
store i32 %50, i32* %10
br label %26
51: ; preds = %45, %26
%52 = load i32, i32* %14
%53 = icmp ne i32 %52, 0
br i1 %53, label %92, label %54
54: ; preds = %51
store i32 0, i32* %15
store i32 0, i32* %15
br label %55
55: ; preds = %85, %54
%56 = load i32, i32* %15
%57 = load i32, i32* %7
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %88
59: ; preds = %55
%60 = load i32*, i32** %5
%61 = load i32, i32* %9
%62 = load i32, i32* %15
%63 = add nsw i32 %61, %62
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i32, i32* %60, i64 %64
%66 = load i32, i32* %65
%67 = load i32*, i32** %11
%68 = load i32, i32* %12
%69 = load i32, i32* %7
%70 = mul nsw i32 %68, %69
%71 = load i32, i32* %15
%72 = add nsw i32 %70, %71
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i32, i32* %67, i64 %73
store i32 %66, i32* %74
%75 = load i32*, i32** %11
%76 = load i32, i32* %12
%77 = load i32, i32* %7
%78 = mul nsw i32 %76, %77
%79 = load i32, i32* %15
%80 = add nsw i32 %78, %79
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i32, i32* %75, i64 %81
%83 = load i32, i32* %82
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %83)
br label %85
85: ; preds = %59
%86 = load i32, i32* %15
%87 = add nsw i32 %86, 1
store i32 %87, i32* %15
br label %55
88: ; preds = %55
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%90 = load i32, i32* %12
%91 = add nsw i32 %90, 1
store i32 %91, i32* %12
br label %92
92: ; preds = %88, %51
%93 = load i32, i32* %12
%94 = load i32, i32* %8
%95 = icmp eq i32 %93, %94
br i1 %95, label %96, label %112
96: ; preds = %92
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%98 = load i32*, i32** %11
%99 = load i32, i32* %8
%100 = load i32, i32* %7
%101 = mul nsw i32 %99, %100
%102 = load i32, i32* %7
%103 = call i32 @display_tupples(i32* %98, i32 %101, i32 %102)
store i32 0, i32* %12
%104 = load i32*, i32** %11
%105 = load i32, i32* %7
%106 = load i32, i32* %8
%107 = mul nsw i32 %105, %106
%108 = sext i32 %107 to i64
%109 = mul i64 %108, 4
%110 = trunc i64 %109 to i32
%111 = call i32 @memset(i32* %104, i32 0, i32 %110)
br label %112
112: ; preds = %96, %92
br label %113
113: ; preds = %112
%114 = load i32, i32* %9
%115 = load i32, i32* %7
%116 = add nsw i32 %114, %115
store i32 %116, i32* %9
br label %21
117: ; preds = %21
%118 = load i32*, i32** %11
ret i32* %118
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d,\00"
@str = [2 x i8] c")\00"
@str.3 = [15 x i8] c"Found Solution\00"
define i32* @get_all_solutions(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = mul nsw i32 %3, %2
%6 = tail call i64 @calloc(i32 %5, i32 4)
%7 = inttoptr i64 %6 to i32*
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %58
9: ; preds = %4
%10 = icmp sgt i32 %2, 0
%11 = shl i32 %5, 2
%12 = sext i32 %2 to i64
%13 = zext i32 %1 to i64
%14 = zext i32 %2 to i64
br label %15
15: ; preds = %9, %54
%16 = phi i64 [ 0, %9 ], [ %56, %54 ]
%17 = phi i32 [ 0, %9 ], [ %55, %54 ]
%18 = mul nsw i32 %17, %2
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = getelementptr inbounds i32, i32* %0, i64 %16
%22 = zext i32 %18 to i64
br label %28
23: ; preds = %28
%24 = icmp slt i64 %33, %22
br i1 %24, label %28, label %25
25: ; preds = %23, %15
br i1 %10, label %26, label %44
26: ; preds = %25
%27 = sext i32 %18 to i64
br label %34
28: ; preds = %20, %23
%29 = phi i64 [ 0, %20 ], [ %33, %23 ]
%30 = getelementptr inbounds i32, i32* %7, i64 %29
%31 = tail call i64 @intersects(i32* %21, i32 %2, i32* %30, i32 %2)
%32 = icmp eq i64 %31, 0
%33 = add i64 %29, %12
br i1 %32, label %23, label %47
34: ; preds = %26, %34
%35 = phi i64 [ 0, %26 ], [ %42, %34 ]
%36 = add nsw i64 %35, %16
%37 = getelementptr inbounds i32, i32* %0, i64 %36
%38 = load i32, i32* %37
%39 = add nsw i64 %35, %27
%40 = getelementptr inbounds i32, i32* %7, i64 %39
store i32 %38, i32* %40
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %38)
%42 = add nuw nsw i64 %35, 1
%43 = icmp eq i64 %42, %14
br i1 %43, label %44, label %34
44: ; preds = %34, %25
%45 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%46 = add nsw i32 %17, 1
br label %47
47: ; preds = %28, %44
%48 = phi i32 [ %46, %44 ], [ %17, %28 ]
%49 = icmp eq i32 %48, %3
br i1 %49, label %50, label %54
50: ; preds = %47
%51 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.3, i64 0, i64 0))
%52 = tail call i32 @display_tupples(i32* %7, i32 %5, i32 %2)
%53 = tail call i32 @memset(i32* %7, i32 0, i32 %11)
br label %54
54: ; preds = %50, %47
%55 = phi i32 [ 0, %50 ], [ %48, %47 ]
%56 = add i64 %16, %12
%57 = icmp slt i64 %56, %13
br i1 %57, label %15, label %58
58: ; preds = %54, %4
ret i32* %7
}