#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*/ printf(char *, int, char *);
int /*<<< orphan*/ rotate(char *, int);
int perm_rec(char *A, int len, char *str, int count) {
  int j;
  if (len == 1) {
    printf("%3d. %s\n", ++count, str);
    return count;
  }
  for (j = 0; j < len; ++j) {
    count = perm_rec(A + 1, len - 1, str, count);
    rotate(A, len);
  }
  return count;
}


x86 assembly (clang, -O0):
<perm_rec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    1174 <perm_rec+0x44>
mov    -0x24(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
mov    -0x20(%rbp),%rdx
lea    0xe9c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c4 <perm_rec+0x94>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11be <perm_rec+0x8e>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1050 <perm_rec@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <rotate@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    117b <perm_rec+0x4b>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<perm_rec>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %rdx,%r12
cmp    $0x1,%esi
jne    115b <perm_rec+0x2b>
add    $0x1,%ebx
lea    0xeb1(%rip),%rdi
mov    %ebx,%esi
mov    %r12,%rdx
call   1030 <printf@plt>
jmp    11a3 <perm_rec+0x73>
jl     11a3 <perm_rec+0x73>
mov    %esi,%r15d
lea    0x1(%rdi),%rax
mov    %rax,(%rsp)
lea    -0x1(%r15),%ebp
mov    %esi,%r14d
mov    %rdi,%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rsp),%rdi
mov    %ebp,%esi
mov    %r12,%rdx
mov    %ebx,%ecx
call   1050 <perm_rec@plt>
mov    %eax,%ebx
mov    %r13,%rdi
mov    %r15d,%esi
call   1040 <rotate@plt>
add    $0xffffffff,%r14d
jne    1180 <perm_rec+0x50>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%3d. %s\0A\00"
define i32 @perm_rec(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%11 = load i32, i32* %7
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %19
13: ; preds = %4
%14 = load i32, i32* %9
%15 = add nsw i32 %14, 1
store i32 %15, i32* %9
%16 = load i8*, i8** %8
%17 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %15, i8* %16)
%18 = load i32, i32* %9
store i32 %18, i32* %5
br label %40
19: ; preds = %4
store i32 0, i32* %10
br label %20
20: ; preds = %35, %19
%21 = load i32, i32* %10
%22 = load i32, i32* %7
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %38
24: ; preds = %20
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = load i32, i32* %7
%28 = sub nsw i32 %27, 1
%29 = load i8*, i8** %8
%30 = load i32, i32* %9
%31 = call i32 @perm_rec(i8* %26, i32 %28, i8* %29, i32 %30)
store i32 %31, i32* %9
%32 = load i8*, i8** %6
%33 = load i32, i32* %7
%34 = call i32 @rotate(i8* %32, i32 %33)
br label %35
35: ; preds = %24
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 1
store i32 %37, i32* %10
br label %20
38: ; preds = %20
%39 = load i32, i32* %9
store i32 %39, i32* %5
br label %40
40: ; preds = %38, %13
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
@.str = [9 x i8] c"%3d. %s\0A\00"
define i32 @perm_rec(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = icmp eq i32 %1, 1
br i1 %5, label %11, label %6
6: ; preds = %4
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %21
8: ; preds = %6
%9 = getelementptr inbounds i8, i8* %0, i64 1
%10 = add nsw i32 %1, -1
br label %14
11: ; preds = %4
%12 = add nsw i32 %3, 1
%13 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %12, i8* %2)
br label %21
14: ; preds = %8, %14
%15 = phi i32 [ 0, %8 ], [ %19, %14 ]
%16 = phi i32 [ %3, %8 ], [ %17, %14 ]
%17 = tail call i32 @perm_rec(i8* %9, i32 %10, i8* %2, i32 %16)
%18 = tail call i32 @rotate(i8* %0, i32 %1)
%19 = add nuw nsw i32 %15, 1
%20 = icmp eq i32 %19, %1
br i1 %20, label %21, label %14
21: ; preds = %14, %6, %11
%22 = phi i32 [ %12, %11 ], [ %3, %6 ], [ %17, %14 ]
ret i32 %22
}