#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*/ swap(int *, int, int /*<<< orphan*/);
void perms(int *a, int n, int r, int *z, int zi, void f(int *, int, void *),
           void *p) {
  int i;
  if (r == 0) {
    f(z, zi, p);
    return;
  } else {
    for (i = 0; i < n; i++) {
      z[zi] = a[i];
      swap(a, i, 0);
      perms(a + 1, n - 1, r - 1, z, zi + 1, f, p);
      swap(a, i, 0);
    }
  }
}


x86 assembly (clang, -O0):
<perms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9,-0x28(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1162 <perms+0x42>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    0x10(%rbp),%rdx
call   *%rax
jmp    11eb <perms+0xcb>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e6 <perms+0xc6>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rdi
mov    -0x2c(%rbp),%esi
xor    %edx,%edx
call   1040 <swap@plt>
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
add    $0x1,%r8d
mov    -0x28(%rbp),%r9
mov    0x10(%rbp),%rax
mov    %rax,(%rsp)
call   1030 <perms@plt>
mov    -0x8(%rbp),%rdi
mov    -0x2c(%rbp),%esi
xor    %edx,%edx
call   1040 <swap@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1169 <perms+0x49>
jmp    11eb <perms+0xcb>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<perms>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rcx,%rbx
mov    %edx,%r12d
mov    0x70(%rsp),%rdx
test   %r12d,%r12d
je     11f4 <perms+0xd4>
test   %esi,%esi
mov    %r9,0x30(%rsp)
mov    %rdx,0x28(%rsp)
mov    %r12d,0x14(%rsp)
jle    11e5 <perms+0xc5>
mov    %rdi,%rbp
movslq %r8d,%rcx
lea    0x4(%rdi),%rax
mov    %rax,0x18(%rsp)
addl   $0xffffffff,0x14(%rsp)
mov    %rcx,%rax
mov    %rcx,0x20(%rsp)
lea    0x1(%rcx),%r14d
mov    %esi,%r12d
mov    %esi,%r15d
add    $0xffffffff,%r12d
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%rbp,%r13,4),%eax
mov    0x20(%rsp),%rcx
mov    %eax,(%rbx,%rcx,4)
mov    %rbp,%rdi
mov    %r13d,%esi
xor    %edx,%edx
call   1040 <swap@plt>
mov    0x28(%rsp),%rax
mov    %rax,(%rsp)
mov    0x18(%rsp),%rdi
mov    %r12d,%esi
mov    0x14(%rsp),%edx
mov    %rbx,%rcx
mov    %r14d,%r8d
mov    0x30(%rsp),%r9
call   1030 <perms@plt>
mov    %rbp,%rdi
mov    %r13d,%esi
xor    %edx,%edx
call   1040 <swap@plt>
add    $0x1,%r13
cmp    %r13,%r15
jne    1190 <perms+0x70>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
mov    %r8d,%esi
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    *%r9

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

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