#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 */
unsigned int *copy_unsigned_array(unsigned int *, int);
int /*<<< orphan*/ free(unsigned int *);
int /*<<< orphan*/ swap(unsigned int *, int, unsigned int);
void permute(unsigned int **p, unsigned int *pi, unsigned int *a, int fi,
             int s) {
  if (fi < s - 1) {
    unsigned int i;
    fi++;
    for (i = fi; i < s; i++) {
      unsigned int *c = copy_unsigned_array(a, s);
      swap(c, fi, i);
      permute(p, pi, c, fi, s);
      if (fi < s - 1)
        free(c);
    }
  } else
    p[(*pi)++] = a;
}


x86 assembly (clang, -O0):
<permute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11f0 <permute+0xb0>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jae    11eb <permute+0xab>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1050 <copy_unsigned_array@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1060 <swap@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
call   1040 <permute@plt>
mov    -0x1c(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11d8 <permute+0x98>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    11dd <permute+0x9d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117b <permute+0x3b>
jmp    120b <permute+0xcb>
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rsi
mov    (%rsi),%ecx
mov    %ecx,%edi
add    $0x1,%edi
mov    %edi,(%rsi)
mov    %ecx,%ecx
mov    %rdx,(%rax,%rcx,8)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<permute>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r13d
lea    -0x1(%r13),%r15d
cmp    %ecx,%r15d
jle    11ce <permute+0x8e>
mov    %ecx,%ebx
mov    %rsi,0x8(%rsp)
mov    %rdi,0x10(%rsp)
add    $0x1,%ebx
cmp    %r13d,%ebx
jae    11d9 <permute+0x99>
mov    %ebx,%ebp
jmp    118b <permute+0x4b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%ebp
cmp    %ebp,%r13d
mov    %r12,%rdx
je     11d9 <permute+0x99>
mov    %rdx,%r12
mov    %rdx,%rdi
mov    %r13d,%esi
call   1050 <copy_unsigned_array@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1060 <swap@plt>
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    %r14,%rdx
mov    %ebx,%ecx
mov    %r13d,%r8d
call   1040 <permute@plt>
cmp    %r15d,%ebx
jge    1180 <permute+0x40>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    1180 <permute+0x40>
mov    (%rsi),%eax
lea    0x1(%rax),%ecx
mov    %ecx,(%rsi)
mov    %rdx,(%rdi,%rax,8)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @permute(i32** %0, i32* %1, i32* %2, i32 %3, i32 %4) {
%6 = alloca i32**
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
store i32** %0, i32*** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%13 = load i32, i32* %9
%14 = load i32, i32* %10
%15 = sub nsw i32 %14, 1
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %50
17: ; preds = %5
%18 = load i32, i32* %9
%19 = add nsw i32 %18, 1
store i32 %19, i32* %9
%20 = load i32, i32* %9
store i32 %20, i32* %11
br label %21
21: ; preds = %46, %17
%22 = load i32, i32* %11
%23 = load i32, i32* %10
%24 = icmp ult i32 %22, %23
br i1 %24, label %25, label %49
25: ; preds = %21
%26 = load i32*, i32** %8
%27 = load i32, i32* %10
%28 = call i32* @copy_unsigned_array(i32* %26, i32 %27)
store i32* %28, i32** %12
%29 = load i32*, i32** %12
%30 = load i32, i32* %9
%31 = load i32, i32* %11
%32 = call i32 @swap(i32* %29, i32 %30, i32 %31)
%33 = load i32**, i32*** %6
%34 = load i32*, i32** %7
%35 = load i32*, i32** %12
%36 = load i32, i32* %9
%37 = load i32, i32* %10
%38 = load i32, i32* %9
%39 = load i32, i32* %10
%40 = sub nsw i32 %39, 1
%41 = icmp slt i32 %38, %40
br i1 %41, label %42, label %45
42: ; preds = %25
%43 = load i32*, i32** %12
%44 = call i32 @free(i32* %43)
br label %45
45: ; preds = %42, %25
br label %46
46: ; preds = %45
%47 = load i32, i32* %11
%48 = add i32 %47, 1
store i32 %48, i32* %11
br label %21
49: ; preds = %21
br label %58
50: ; preds = %5
%51 = load i32*, i32** %8
%52 = load i32**, i32*** %6
%53 = load i32*, i32** %7
%54 = load i32, i32* %53
%55 = add i32 %54, 1
store i32 %55, i32* %53
%56 = zext i32 %54 to i64
%57 = getelementptr inbounds i32*, i32** %52, i64 %56
store i32* %51, i32** %57
br label %58
58: ; preds = %50, %49
ret void
}

LLVM IR (-O2):
define void @permute(i32** nocapture writeonly %0, i32* nocapture %1, i32* %2, i32 %3, i32 %4) {
%6 = add nsw i32 %4, -1
%7 = icmp sgt i32 %6, %3
br i1 %7, label %8, label %22
8: ; preds = %5
%9 = add nsw i32 %3, 1
%10 = icmp ult i32 %9, %4
br i1 %10, label %11, label %27
11: ; preds = %8
%12 = icmp slt i32 %9, %6
br label %13
13: ; preds = %11, %19
%14 = phi i32 [ %9, %11 ], [ %20, %19 ]
%15 = tail call i32* @copy_unsigned_array(i32* %2, i32 %4)
%16 = tail call i32 @swap(i32* %15, i32 %9, i32 %14)
tail call void @permute(i32** %0, i32* %1, i32* %15, i32 %9, i32 %4)
br i1 %12, label %17, label %19
17: ; preds = %13
%18 = tail call i32 @free(i32* %15)
br label %19
19: ; preds = %17, %13
%20 = add i32 %14, 1
%21 = icmp eq i32 %20, %4
br i1 %21, label %27, label %13
22: ; preds = %5
%23 = load i32, i32* %1
%24 = add i32 %23, 1
store i32 %24, i32* %1
%25 = zext i32 %23 to i64
%26 = getelementptr inbounds i32*, i32** %0, i64 %25
store i32* %2, i32** %26
br label %27
27: ; preds = %19, %8, %22
ret void
}