#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 */
typedef scalar_t__ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ swap(char *, char *);
int permutation(char *str, uint8_t left, uint8_t right) {
  uint8_t i;
  if (str == NULL) {
    return -1;
  }
  if (left == right)
    printf("%s\n", str);
  else {
    for (i = left; i <= right; i += 1) {
      swap(str + left, str + i);
      permutation(str, left + 1, right);
      swap(str + left, str + i);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<permutation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115b <permutation+0x2b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f0 <permutation+0xc0>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    117e <permutation+0x4e>
mov    -0x10(%rbp),%rsi
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
jmp    11e9 <permutation+0xb9>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jg     11e4 <permutation+0xb4>
mov    -0x10(%rbp),%rdi
add    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    -0x28(%rbp),%rsi
call   1050 <swap@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
mov    -0x20(%rbp),%rdx
call   1040 <permutation@plt>
mov    -0x10(%rbp),%rdi
add    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    -0x28(%rbp),%rsi
call   1050 <swap@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1186 <permutation+0x56>
jmp    11e9 <permutation+0xb9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<permutation>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     115f <permutation+0x2f>
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%r12
cmp    %rdx,%rsi
jne    1166 <permutation+0x36>
lea    0xeab(%rip),%rdi
mov    %r12,%rsi
call   1030 <printf@plt>
jmp    11b2 <permutation+0x82>
mov    $0xffffffff,%eax
jmp    11b4 <permutation+0x84>
xor    %eax,%eax
cmp    %r15,%rbp
jg     11b4 <permutation+0x84>
lea    (%r12,%rbp,1),%rbx
lea    0x1(%rbp),%rax
mov    %rax,(%rsp)
lea    0x1(%r15),%r13
nopl   (%rax)
lea    (%r12,%rbp,1),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <swap@plt>
mov    %r12,%rdi
mov    (%rsp),%rsi
mov    %r15,%rdx
call   1040 <permutation@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <swap@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1180 <permutation+0x50>
xor    %eax,%eax
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 i32 @permutation(i8* %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%9 = load i8*, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %12
11: ; preds = %3
store i32 -1, i32* %4
br label %50
12: ; preds = %3
%13 = load i64, i64* %6
%14 = load i64, i64* %7
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i8*, i8** %5
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %49
19: ; preds = %12
%20 = load i64, i64* %6
store i64 %20, i64* %8
br label %21
21: ; preds = %45, %19
%22 = load i64, i64* %8
%23 = load i64, i64* %7
%24 = icmp sle i64 %22, %23
br i1 %24, label %25, label %48
25: ; preds = %21
%26 = load i8*, i8** %5
%27 = load i64, i64* %6
%28 = getelementptr inbounds i8, i8* %26, i64 %27
%29 = load i8*, i8** %5
%30 = load i64, i64* %8
%31 = getelementptr inbounds i8, i8* %29, i64 %30
%32 = call i32 @swap(i8* %28, i8* %31)
%33 = load i8*, i8** %5
%34 = load i64, i64* %6
%35 = add nsw i64 %34, 1
%36 = load i64, i64* %7
%37 = call i32 @permutation(i8* %33, i64 %35, i64 %36)
%38 = load i8*, i8** %5
%39 = load i64, i64* %6
%40 = getelementptr inbounds i8, i8* %38, i64 %39
%41 = load i8*, i8** %5
%42 = load i64, i64* %8
%43 = getelementptr inbounds i8, i8* %41, i64 %42
%44 = call i32 @swap(i8* %40, i8* %43)
br label %45
45: ; preds = %25
%46 = load i64, i64* %8
%47 = add nsw i64 %46, 1
store i64 %47, i64* %8
br label %21
48: ; preds = %21
br label %49
49: ; preds = %48, %16
store i32 0, i32* %4
br label %50
50: ; preds = %49, %11
%51 = load i32, i32* %4
ret i32 %51
}

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