#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int permutation(char *string) {
  if (string == NULL) {
    return -1;
  }
  char lastChar = '\0';
  char tmpChar = '\0';
  char *pointer = NULL;
  char *tmpString = NULL;
  int lastPositon = 0;
  lastPositon = strlen(string) - 1;
  tmpString = (char *)malloc(strlen(string) + 1);
  strcpy(tmpString, string);
  lastChar = tmpString[lastPositon];
  pointer = tmpString;
  for (int i = 0; i < strlen(tmpString); ++i) {
    pointer = tmpString;
    while (pointer - tmpString != lastPositon) {
      puts(tmpString);
      tmpChar = *pointer;
      *pointer = *(pointer + 1);
      *(pointer + 1) = tmpChar;
      pointer = pointer + 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<permutation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1163 <permutation+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    1262 <permutation+0x122>
movb   $0x0,-0x11(%rbp)
movb   $0x0,-0x12(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    125b <permutation+0x11b>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
movslq -0x2c(%rbp),%rcx
cmp    %rcx,%rax
je     1248 <permutation+0x108>
mov    -0x28(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x12(%rbp)
mov    -0x20(%rbp),%rax
mov    0x1(%rax),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x12(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11f6 <permutation+0xb6>
jmp    124d <permutation+0x10d>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11d2 <permutation+0x92>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<permutation>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11dc <permutation+0x9c>
mov    %rdi,%rbp
call   1050 <strlen@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    11d8 <permutation+0x98>
add    $0xffffffff,%r14d
movslq %r14d,%r15
xor    %r14d,%r14d
jmp    11b1 <permutation+0x71>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14d
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    %eax,%r14d
jge    11d8 <permutation+0x98>
test   %r15d,%r15d
je     11a0 <permutation+0x60>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <puts@plt>
rolw   $0x8,(%rbx,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r15
jne    11c0 <permutation+0x80>
jmp    11a0 <permutation+0x60>
xor    %eax,%eax
jmp    11e1 <permutation+0xa1>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @permutation(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
%10 = load i8*, i8** %3
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 -1, i32* %2
br label %66
13: ; preds = %1
store i8 0, i8* %4
store i8 0, i8* %5
store i8* null, i8** %6
store i8* null, i8** %7
store i32 0, i32* %8
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
%16 = sub nsw i32 %15, 1
store i32 %16, i32* %8
%17 = load i8*, i8** %3
%18 = call i32 @strlen(i8* %17)
%19 = add nsw i32 %18, 1
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %7
%22 = load i8*, i8** %7
%23 = load i8*, i8** %3
%24 = call i32 @strcpy(i8* %22, i8* %23)
%25 = load i8*, i8** %7
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
store i8 %29, i8* %4
%30 = load i8*, i8** %7
store i8* %30, i8** %6
store i32 0, i32* %9
br label %31
31: ; preds = %62, %13
%32 = load i32, i32* %9
%33 = load i8*, i8** %7
%34 = call i32 @strlen(i8* %33)
%35 = icmp slt i32 %32, %34
br i1 %35, label %36, label %65
36: ; preds = %31
%37 = load i8*, i8** %7
store i8* %37, i8** %6
br label %38
38: ; preds = %47, %36
%39 = load i8*, i8** %6
%40 = load i8*, i8** %7
%41 = ptrtoint i8* %39 to i64
%42 = ptrtoint i8* %40 to i64
%43 = sub i64 %41, %42
%44 = load i32, i32* %8
%45 = sext i32 %44 to i64
%46 = icmp ne i64 %43, %45
br i1 %46, label %47, label %61
47: ; preds = %38
%48 = load i8*, i8** %7
%49 = call i32 @puts(i8* %48)
%50 = load i8*, i8** %6
%51 = load i8, i8* %50
store i8 %51, i8* %5
%52 = load i8*, i8** %6
%53 = getelementptr inbounds i8, i8* %52, i64 1
%54 = load i8, i8* %53
%55 = load i8*, i8** %6
store i8 %54, i8* %55
%56 = load i8, i8* %5
%57 = load i8*, i8** %6
%58 = getelementptr inbounds i8, i8* %57, i64 1
store i8 %56, i8* %58
%59 = load i8*, i8** %6
%60 = getelementptr inbounds i8, i8* %59, i64 1
store i8* %60, i8** %6
br label %38
61: ; preds = %38
br label %62
62: ; preds = %61
%63 = load i32, i32* %9
%64 = add nsw i32 %63, 1
store i32 %64, i32* %9
br label %31
65: ; preds = %31
store i32 0, i32* %2
br label %66
66: ; preds = %65, %12
%67 = load i32, i32* %2
ret i32 %67
}

LLVM IR (-O2):
define i32 @permutation(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %31, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %4, -1
%6 = tail call i32 @strlen(i8* %0)
%7 = add nsw i32 %6, 1
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 @strcpy(i8* %9, i8* %0)
%11 = sext i32 %5 to i64
%12 = tail call i32 @strlen(i8* %9)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %31
14: ; preds = %3
%15 = icmp eq i32 %5, 0
br label %16
16: ; preds = %14, %27
%17 = phi i32 [ 0, %14 ], [ %28, %27 ]
br i1 %15, label %27, label %18
18: ; preds = %16, %18
%19 = phi i8* [ %22, %18 ], [ %9, %16 ]
%20 = tail call i32 @puts(i8* dereferenceable(1) %9)
%21 = load i8, i8* %19
%22 = getelementptr inbounds i8, i8* %19, i64 1
%23 = load i8, i8* %22
store i8 %23, i8* %19
store i8 %21, i8* %22
%24 = ptrtoint i8* %22 to i64
%25 = sub i64 %24, %8
%26 = icmp eq i64 %25, %11
br i1 %26, label %27, label %18
27: ; preds = %18, %16
%28 = add nuw nsw i32 %17, 1
%29 = tail call i32 @strlen(i8* %9)
%30 = icmp slt i32 %28, %29
br i1 %30, label %16, label %31
31: ; preds = %27, %3, %1
%32 = phi i32 [ -1, %1 ], [ 0, %3 ], [ 0, %27 ]
ret i32 %32
}