#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*/ copy(char *, char *, int);
int /*<<< orphan*/ swap(char *, char *);
void perm(char list[], int left, int right, void (*handle)(char *, int)) {
  if (left == right) {
    handle(list, right);
  }
  int i;
  for (i = left; i <= right; ++i) {
    char tmp[right];
    copy(tmp, list, right);
    swap(&tmp[left], &tmp[i]);
    perm(tmp, left + 1, right, handle);
  }
}


x86 assembly (clang, -O0):
<perm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    115f <perm+0x2f>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   *%rax
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11e8 <perm+0xb8>
mov    -0x10(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1030 <copy@plt>
mov    -0x38(%rbp),%rsi
movslq -0xc(%rbp),%rax
mov    %rsi,%rdi
add    %rax,%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
call   1050 <swap@plt>
mov    -0x38(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1040 <perm@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1165 <perm+0x35>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<perm>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r14
mov    %esi,%ebx
mov    %rdi,%r12
cmp    %edx,%esi
jne    115b <perm+0x2b>
mov    %r12,%rdi
mov    %ebx,%esi
mov    %edx,%r15d
call   *%r14
mov    %r15d,%edx
cmp    %edx,%ebx
jg     11e7 <perm+0xb7>
mov    %edx,%eax
movslq %ebx,%r13
lea    0x1(%rbx),%ecx
mov    %ecx,-0x2c(%rbp)
add    $0xffffffff,%ebx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rax,-0x40(%rbp)
mov    %r13,%rax
mov    %r13,-0x38(%rbp)
mov    %r14,-0x48(%rbp)
nopl   0x0(%rax,%rax,1)
mov    %rsp,-0x50(%rbp)
mov    %rsp,%r14
sub    -0x40(%rbp),%r14
mov    %r14,%rsp
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r12,%r15
mov    %edx,%r12d
call   1030 <copy@plt>
mov    -0x38(%rbp),%rax
lea    (%r14,%rax,1),%rdi
lea    (%r14,%r13,1),%rsi
call   1050 <swap@plt>
mov    %r14,%rdi
mov    -0x48(%rbp),%rcx
mov    -0x2c(%rbp),%esi
mov    %r12d,%edx
call   1040 <perm@plt>
mov    %r12d,%edx
mov    %r15,%r12
mov    -0x50(%rbp),%rsp
add    $0x1,%r13
add    $0x1,%ebx
cmp    %ebx,%edx
jne    1190 <perm+0x60>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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