#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*/ free(int *);
int /*<<< orphan*/ free_mat(int **, int /*<<< orphan*/, int);
int **get_combs(int *, int, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ num_combs(int, int);
int /*<<< orphan*/ print_mat(int **, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int num_items;
  int *items;
  int i, k;
  int **combs;
  printf("How many items do you have: ");
  scanf("%d", &num_items);
  items = (int *)malloc(num_items * sizeof(int));
  printf("Enter your items: ");
  for (i = 0; i < num_items; i++) {
    scanf("%d", &items[i]);
  }
  printf("Enter k: ");
  scanf("%d", &k);
  combs = get_combs(items, k, num_items);
  print_mat(combs, num_combs(num_items, k), k);
  free(items);
  free_mat(combs, num_combs(num_items, k), k);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rdi
call   1050 <printf@plt>
lea    0xe7b(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1080 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xe5b(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1206 <main+0x86>
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe2a(%rip),%rdi
call   1080 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d1 <main+0x51>
lea    0xe26(%rip),%rdi
call   1050 <printf@plt>
lea    0xe04(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <scanf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x8(%rbp),%edx
call   10a0 <get_combs@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1040 <num_combs@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
mov    -0x18(%rbp),%edx
call   1060 <print_mat@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1040 <num_combs@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
mov    -0x18(%rbp),%edx
call   1090 <free_mat@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xe71(%rip),%rdi
call   1050 <printf@plt>
lea    0xe82(%rip),%rdi
mov    %rsp,%rsi
call   1080 <scanf@plt>
mov    (%rsp),%edi
shl    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
lea    0xe68(%rip),%rdi
call   1050 <printf@plt>
cmpl   $0x0,(%rsp)
jle    11ec <main+0x6c>
xor    %r12d,%r12d
lea    0xe50(%rip),%r15
mov    %r14,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
add    $0x1,%r12
movslq (%rsp),%rax
add    $0x4,%rbx
cmp    %rax,%r12
jl     11d0 <main+0x50>
lea    0xe40(%rip),%rdi
call   1050 <printf@plt>
lea    0xe1e(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1080 <scanf@plt>
mov    0x4(%rsp),%esi
mov    (%rsp),%edx
mov    %r14,%rdi
call   10a0 <get_combs@plt>
mov    %rax,%rbx
mov    (%rsp),%edi
mov    0x4(%rsp),%esi
call   1040 <num_combs@plt>
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <print_mat@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    (%rsp),%edi
mov    0x4(%rsp),%esi
call   1040 <num_combs@plt>
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
mov    %eax,%esi
call   1090 <free_mat@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [29 x i8] c"How many items do you have: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [19 x i8] c"Enter your items: \00"
@.str.3 = [10 x i8] c"Enter k: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32**
store i32 0, i32* %1
%7 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 4
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i32*
store i32* %14, i32** %3
%15 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %16
16: ; preds = %26, %0
%17 = load i32, i32* %4
%18 = load i32, i32* %2
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %29
20: ; preds = %16
%21 = load i32*, i32** %3
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %24)
br label %26
26: ; preds = %20
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %16
29: ; preds = %16
%30 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%32 = load i32*, i32** %3
%33 = load i32, i32* %5
%34 = load i32, i32* %2
%35 = call i32** @get_combs(i32* %32, i32 %33, i32 %34)
store i32** %35, i32*** %6
%36 = load i32**, i32*** %6
%37 = load i32, i32* %2
%38 = load i32, i32* %5
%39 = call i32 @num_combs(i32 %37, i32 %38)
%40 = load i32, i32* %5
%41 = call i32 @print_mat(i32** %36, i32 %39, i32 %40)
%42 = load i32*, i32** %3
%43 = call i32 @free(i32* %42)
%44 = load i32**, i32*** %6
%45 = load i32, i32* %2
%46 = load i32, i32* %5
%47 = call i32 @num_combs(i32 %45, i32 %46)
%48 = load i32, i32* %5
%49 = call i32 @free_mat(i32** %44, i32 %47, i32 %48)
ret i32 0
}

LLVM IR (-O2):
@.str = [29 x i8] c"How many items do you have: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [19 x i8] c"Enter your items: \00"
@.str.3 = [10 x i8] c"Enter k: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = shl i32 %7, 2
%9 = call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i32*
%11 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* %1
%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 i32, i32* %10, i64 %15
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %16)
%18 = add nuw nsw i64 %15, 1
%19 = load i32, i32* %1
%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 @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%25 = load i32, i32* %2
%26 = load i32, i32* %1
%27 = call i32** @get_combs(i32* %10, i32 %25, i32 %26)
%28 = load i32, i32* %1
%29 = load i32, i32* %2
%30 = call i32 @num_combs(i32 %28, i32 %29)
%31 = load i32, i32* %2
%32 = call i32 @print_mat(i32** %27, i32 %30, i32 %31)
%33 = call i32 @free(i32* %10)
%34 = load i32, i32* %1
%35 = load i32, i32* %2
%36 = call i32 @num_combs(i32 %34, i32 %35)
%37 = load i32, i32* %2
%38 = call i32 @free_mat(i32** %27, i32 %36, i32 %37)
ret i32 0
}