#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 permutation(char str[], int begin, int end) {
  if (0 <= begin && begin <= end) {
    if (begin == end)
      printf("%s\n", str);
    else {
      int i;
      for (i = begin; i <= end; i++) {
        swap(str, begin, i);
        permutation(str, begin + 1, end);
        swap(str, begin, i);
      }
    }
  }
}


x86 assembly (clang, -O0):
<permutation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
jg     11d4 <permutation+0xa4>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11d4 <permutation+0xa4>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    117a <permutation+0x4a>
mov    -0x8(%rbp),%rsi
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
jmp    11cf <permutation+0x9f>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11ca <permutation+0x9a>
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 <permutation@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    1180 <permutation+0x50>
jmp    11cf <permutation+0x9f>
jmp    11d4 <permutation+0xa4>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<permutation>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
js     11b0 <permutation+0x80>
mov    %edx,%r14d
mov    %esi,%r15d
cmp    %edx,%esi
jg     11b0 <permutation+0x80>
mov    %rdi,%rbx
jne    116b <permutation+0x3b>
lea    0xeab(%rip),%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>
lea    0x1(%r15),%r12d
lea    0x1(%r14),%r13d
mov    %r15d,%ebp
cs nopw 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 <permutation@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
call   1050 <swap@plt>
add    $0x1,%ebp
cmp    %ebp,%r13d
jne    1180 <permutation+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 @permutation(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 = icmp sle i32 0, %8
br i1 %9, label %10, label %45
10: ; preds = %3
%11 = load i32, i32* %5
%12 = load i32, i32* %6
%13 = icmp sle i32 %11, %12
br i1 %13, label %14, label %45
14: ; preds = %10
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i8*, i8** %4
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %19)
br label %44
21: ; preds = %14
%22 = load i32, i32* %5
store i32 %22, i32* %7
br label %23
23: ; preds = %40, %21
%24 = load i32, i32* %7
%25 = load i32, i32* %6
%26 = icmp sle i32 %24, %25
br i1 %26, label %27, label %43
27: ; preds = %23
%28 = load i8*, i8** %4
%29 = load i32, i32* %5
%30 = load i32, i32* %7
%31 = call i32 @swap(i8* %28, i32 %29, i32 %30)
%32 = load i8*, i8** %4
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
%35 = load i32, i32* %6
%36 = load i8*, i8** %4
%37 = load i32, i32* %5
%38 = load i32, i32* %7
%39 = call i32 @swap(i8* %36, i32 %37, i32 %38)
br label %40
40: ; preds = %27
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %23
43: ; preds = %23
br label %44
44: ; preds = %43, %18
br label %45
45: ; preds = %44, %10, %3
ret void
}

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