#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*/ factorial(int);
int /*<<< orphan*/ free_matrix(unsigned int **, int /*<<< orphan*/);
unsigned int **permutations(unsigned int *, int);
int /*<<< orphan*/ print_matrix(unsigned int **, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
void test_permutations() {
  printf("Testing permutations...\n");
  unsigned int array[] = {1, 2, 3, 4, 5};
  unsigned int **p = permutations(array, 5);
  print_matrix(p, factorial(5), 5);
  free_matrix(p, factorial(5));
}


x86 assembly (clang, -O0):
<test_permutations>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xea1(%rip),%rdi
call   1050 <printf@plt>
mov    0xeb5(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb2(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xeb0(%rip),%eax
mov    %eax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x5,%esi
call   1070 <permutations@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x5,%edi
call   1030 <factorial@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
mov    $0x5,%edx
call   1060 <print_matrix@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x5,%edi
call   1030 <factorial@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1040 <free_matrix@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_permutations>:
push   %rbx
sub    $0x20,%rsp
lea    0xeb8(%rip),%rdi
call   1030 <puts@plt>
mov    0xea9(%rip),%eax
mov    %eax,0x10(%rsp)
movaps 0xe8e(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0x5,%esi
call   1070 <permutations@plt>
mov    %rax,%rbx
mov    $0x5,%edi
call   1040 <factorial@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x5,%edx
call   1060 <print_matrix@plt>
mov    $0x5,%edi
call   1040 <factorial@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <free_matrix@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Testing permutations...\0A\00"
@__const.test_permutations.array = [5 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5]
define void @test_permutations() {
%1 = alloca [5 x i32]
%2 = alloca i32**
%3 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%4 = bitcast [5 x i32]* %1 to i8*
%5 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 0
%6 = call i32** @permutations(i32* %5, i32 5)
store i32** %6, i32*** %2
%7 = load i32**, i32*** %2
%8 = call i32 @factorial(i32 5)
%9 = call i32 @print_matrix(i32** %7, i32 %8, i32 5)
%10 = load i32**, i32*** %2
%11 = call i32 @factorial(i32 5)
%12 = call i32 @free_matrix(i32** %10, i32 %11)
ret void
}

LLVM IR (-O2):
@__const.test_permutations.array = [5 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5]
@str = [24 x i8] c"Testing permutations...\00"
define void @test_permutations() {
%1 = alloca [5 x i32]
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%3 = bitcast [5 x i32]* %1 to i8*
%4 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 0
%5 = call i32** @permutations(i32* %4, i32 5)
%6 = call i32 @factorial(i32 5)
%7 = call i32 @print_matrix(i32** %5, i32 %6, i32 5)
%8 = call i32 @factorial(i32 5)
%9 = call i32 @free_matrix(i32** %5, i32 %8)
ret void
}