#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*/ swapCharacters(char *, char *);
void permutation(char *input, int startPosition, int endPosition) {
  int j;
  if (startPosition == endPosition) {
    printf("%s\n", input);
  } else {
    for (j = startPosition; j <= endPosition; j++) {
      swapCharacters((input + startPosition), (input + j));
      permutation(input, startPosition + 1, endPosition);
      swapCharacters((input + startPosition), (input + j));
    }
  }
}


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)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    1163 <permutation+0x33>
mov    -0x8(%rbp),%rsi
lea    0xea7(%rip),%rdi
call   1030 <printf@plt>
jmp    11d0 <permutation+0xa0>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11cb <permutation+0x9b>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
call   1040 <swapCharacters@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1050 <permutation@plt>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
call   1040 <swapCharacters@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1169 <permutation+0x39>
jmp    11d0 <permutation+0xa0>
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
mov    %rdi,%r14
cmp    %edx,%esi
jne    115f <permutation+0x2f>
lea    0xeb7(%rip),%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>
jg     11b0 <permutation+0x80>
mov    %edx,%r15d
mov    %esi,%ebx
movslq %esi,%r13
add    %r14,%r13
lea    0x1(%rbx),%r12d
add    $0xffffffff,%ebx
mov    %r13,%rbp
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbp,%rsi
call   1040 <swapCharacters@plt>
mov    %r14,%rdi
mov    %r12d,%esi
mov    %r15d,%edx
call   1050 <permutation@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1040 <swapCharacters@plt>
add    $0x1,%rbp
add    $0x1,%ebx
cmp    %ebx,%r15d
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 = 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 %47
14: ; preds = %3
%15 = load i32, i32* %5
store i32 %15, i32* %7
br label %16
16: ; preds = %43, %14
%17 = load i32, i32* %7
%18 = load i32, i32* %6
%19 = icmp sle i32 %17, %18
br i1 %19, label %20, label %46
20: ; preds = %16
%21 = load i8*, i8** %4
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8*, i8** %4
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = call i32 @swapCharacters(i8* %24, i8* %28)
%30 = load i8*, i8** %4
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
%33 = load i32, i32* %6
%34 = load i8*, i8** %4
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8*, i8** %4
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = call i32 @swapCharacters(i8* %37, i8* %41)
br label %43
43: ; preds = %20
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %16
46: ; preds = %16
br label %47
47: ; preds = %46, %11
ret void
}

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