#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 int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ permutation(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int print_all_permutation(char *str, uint8_t length) {
  if (str == NULL) {
    return -1;
  }
  if (length < 2) {
    printf("%s\n", str);
  } else {
    permutation(str, 0, length - 1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<print_all_permutation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1146 <print_all_permutation+0x26>
movl   $0xffffffff,-0x4(%rbp)
jmp    117d <print_all_permutation+0x5d>
cmpl   $0x2,-0x14(%rbp)
jge    1165 <print_all_permutation+0x45>
mov    -0x10(%rbp),%rsi
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
jmp    1176 <print_all_permutation+0x56>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1040 <permutation@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_all_permutation>:
push   %rbx
test   %rdi,%rdi
je     1140 <print_all_permutation+0x20>
mov    %esi,%edx
mov    %rdi,%rsi
cmp    $0x1,%edx
jg     1147 <print_all_permutation+0x27>
lea    0xec9(%rip),%rdi
call   1030 <printf@plt>
xor    %ebx,%ebx
jmp    1156 <print_all_permutation+0x36>
mov    $0xffffffff,%ebx
jmp    1156 <print_all_permutation+0x36>
add    $0xffffffff,%edx
xor    %ebx,%ebx
mov    %rsi,%rdi
xor    %esi,%esi
call   1040 <permutation@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
define i32 @print_all_permutation(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%6 = load i8*, i8** %4
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %2
store i32 -1, i32* %3
br label %21
9: ; preds = %2
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i8*, i8** %4
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %20
15: ; preds = %9
%16 = load i8*, i8** %4
%17 = load i32, i32* %5
%18 = sub nsw i32 %17, 1
%19 = call i32 @permutation(i8* %16, i32 0, i32 %18)
br label %20
20: ; preds = %15, %12
store i32 0, i32* %3
br label %21
21: ; preds = %20, %8
%22 = load i32, i32* %3
ret i32 %22
}

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