#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 *, char *);
int /*<<< orphan*/ swap(char *, int, int);
void printAllPermutation(char *perm, int from, int to) {
  if (from == to) {
    printf("%s\n", perm);
    return;
  }
  for (int i = from; i <= to; ++i) {
    swap(perm, from, i);
    printAllPermutation(perm, from + 1, to);
    swap(perm, from, i);
  }
}


x86 assembly (clang, -O0):
<printAllPermutation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    1163 <printAllPermutation+0x33>
mov    -0x8(%rbp),%rsi
lea    0xea7(%rip),%rdi
call   1030 <printf@plt>
jmp    11b3 <printAllPermutation+0x83>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11b3 <printAllPermutation+0x83>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1050 <swap@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1040 <printAllPermutation@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1050 <swap@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1169 <printAllPermutation+0x39>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printAllPermutation>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
cmp    %edx,%esi
jne    115f <printAllPermutation+0x2f>
lea    0xeb7(%rip),%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>
jg     11b0 <printAllPermutation+0x80>
mov    %edx,%r14d
mov    %esi,%r15d
lea    0x1(%r15),%r12d
lea    0x1(%r14),%r13d
mov    %esi,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
call   1050 <swap@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r14d,%edx
call   1040 <printAllPermutation@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
call   1050 <swap@plt>
add    $0x1,%ebp
cmp    %ebp,%r13d
jne    1180 <printAllPermutation+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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