int main() {
  unsigned pref_size;
  unsigned n = 10, N = 1 << n;
  unsigned i, j;
  int **prefm = preferd(n, &pref_size);
  for (i = 0; i < pref_size; i++) {
    printf("%2d: ", i);
    for (j = 0; j < N - 1; j++)
      printf("%d,", prefm[i][j]);
    printf("\n");
  }
  free(*prefm);
  free(prefm);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1050 <preferd@plt>
cltq
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    11ec <main+0xbc>
mov    -0x14(%rbp),%esi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jae    11d0 <main+0xa0>
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
mov    -0x18(%rbp),%ecx
mov    (%rax,%rcx,4),%esi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1192 <main+0x62>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116e <main+0x3e>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rsi
mov    $0xa,%edi
xor    %eax,%eax
call   1060 <preferd@plt>
movslq %eax,%r12
cmpl   $0x0,0xc(%rsp)
je     11c5 <main+0x85>
lea    0xe91(%rip),%r14
lea    0xe90(%rip),%r15
xor    %r13d,%r13d
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %ebx,%ebx
nop
mov    (%r12,%r13,8),%rax
mov    (%rax,%rbx,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    $0x3ff,%rbx
jne    1190 <main+0x50>
mov    $0xa,%edi
call   1040 <putchar@plt>
add    $0x1,%r13
mov    0xc(%rsp),%eax
cmp    %rax,%r13
jb     1180 <main+0x40>
mov    (%r12),%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%2d: \00"
@.str.1 = [4 x i8] c"%d,\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32**
store i32 0, i32* %1
store i32 10, i32* %3
%8 = load i32, i32* %3
%9 = shl i32 1, %8
store i32 %9, i32* %4
%10 = load i32, i32* %3
%11 = call i32 (i32, i32*, ...) bitcast (i32 (...)* @preferd to i32 (i32, i32*, ...)*)(i32 %10, i32* %2)
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i32**
store i32** %13, i32*** %7
store i32 0, i32* %5
br label %14
14: ; preds = %42, %0
%15 = load i32, i32* %5
%16 = load i32, i32* %2
%17 = icmp ult i32 %15, %16
br i1 %17, label %18, label %45
18: ; preds = %14
%19 = load i32, i32* %5
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %19)
store i32 0, i32* %6
br label %21
21: ; preds = %37, %18
%22 = load i32, i32* %6
%23 = load i32, i32* %4
%24 = sub i32 %23, 1
%25 = icmp ult i32 %22, %24
br i1 %25, label %26, label %40
26: ; preds = %21
%27 = load i32**, i32*** %7
%28 = load i32, i32* %5
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i32*, i32** %27, i64 %29
%31 = load i32*, i32** %30
%32 = load i32, i32* %6
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
%35 = load i32, i32* %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %26
%38 = load i32, i32* %6
%39 = add i32 %38, 1
store i32 %39, i32* %6
br label %21
40: ; preds = %21
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %40
%43 = load i32, i32* %5
%44 = add i32 %43, 1
store i32 %44, i32* %5
br label %14
45: ; preds = %14
%46 = load i32**, i32*** %7
%47 = load i32*, i32** %46
%48 = bitcast i32* %47 to i8*
%49 = load i32**, i32*** %7
%50 = bitcast i32** %49 to i8*
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"%2d: \00"
@.str.1 = [4 x i8] c"%d,\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 (i32, i32*, ...) bitcast (i32 (...)* @preferd to i32 (i32, i32*, ...)*)(i32 10, i32* %1)
%4 = sext i32 %3 to i64
%5 = inttoptr i64 %4 to i32**
%6 = load i32, i32* %1
%7 = icmp eq i32 %6, 0
br i1 %7, label %27, label %8
8: ; preds = %0, %21
%9 = phi i64 [ %23, %21 ], [ 0, %0 ]
%10 = trunc i64 %9 to i32
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds i32*, i32** %5, i64 %9
br label %13
13: ; preds = %8, %13
%14 = phi i64 [ 0, %8 ], [ %19, %13 ]
%15 = load i32*, i32** %12
%16 = getelementptr inbounds i32, i32* %15, i64 %14
%17 = load i32, i32* %16
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = add nuw nsw i64 %14, 1
%20 = icmp eq i64 %19, 1023
br i1 %20, label %21, label %13
21: ; preds = %13
%22 = call i32 @putchar(i32 10)
%23 = add nuw nsw i64 %9, 1
%24 = load i32, i32* %1
%25 = zext i32 %24 to i64
%26 = icmp ult i64 %23, %25
br i1 %26, label %8, label %27
27: ; preds = %21, %0
%28 = inttoptr i64 %4 to i8**
%29 = load i8*, i8** %28
%30 = inttoptr i64 %4 to i8*
ret i32 0
}