#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*/ ExchangeChar(char *, int, int);
int /*<<< orphan*/ printf(char *, char *);
int strlen(char *);
void RecursivePermute(char *str, int k) {
  int i;
  if (strlen(str) == k) {
    printf("%s\n", str);
  } else {
    for (i = k; i < strlen(str); i++) {
      ExchangeChar(str, k, i);
      RecursivePermute(str, k + 1);
      ExchangeChar(str, k, i);
    }
  }
}


x86 assembly (clang, -O0):
<RecursivePermute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    -0xc(%rbp),%eax
jne    1176 <RecursivePermute+0x36>
mov    -0x8(%rbp),%rsi
lea    0xe94(%rip),%rdi
call   1050 <printf@plt>
jmp    11d8 <RecursivePermute+0x98>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jge    11d3 <RecursivePermute+0x93>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <ExchangeChar@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x1,%esi
call   1060 <RecursivePermute@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <ExchangeChar@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117c <RecursivePermute+0x3c>
jmp    11d8 <RecursivePermute+0x98>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RecursivePermute>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
call   1040 <strlen@plt>
cmp    %r14d,%eax
jne    1170 <RecursivePermute+0x30>
lea    0xea2(%rip),%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %r14d,%eax
jle    11c4 <RecursivePermute+0x84>
lea    0x1(%r14),%r15d
mov    %r14d,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1030 <ExchangeChar@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1060 <RecursivePermute@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1030 <ExchangeChar@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %eax,%ebp
jl     1190 <RecursivePermute+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
define void @RecursivePermute(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
%8 = load i32, i32* %4
%9 = icmp eq i32 %7, %8
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %36
13: ; preds = %2
%14 = load i32, i32* %4
store i32 %14, i32* %5
br label %15
15: ; preds = %32, %13
%16 = load i32, i32* %5
%17 = load i8*, i8** %3
%18 = call i32 @strlen(i8* %17)
%19 = icmp slt i32 %16, %18
br i1 %19, label %20, label %35
20: ; preds = %15
%21 = load i8*, i8** %3
%22 = load i32, i32* %4
%23 = load i32, i32* %5
%24 = call i32 @ExchangeChar(i8* %21, i32 %22, i32 %23)
%25 = load i8*, i8** %3
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
%28 = load i8*, i8** %3
%29 = load i32, i32* %4
%30 = load i32, i32* %5
%31 = call i32 @ExchangeChar(i8* %28, i32 %29, i32 %30)
br label %32
32: ; preds = %20
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %15
35: ; preds = %15
br label %36
36: ; preds = %35, %10
ret void
}

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