#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*/ delchar(char *, char);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
char *setstr(char *);
int /*<<< orphan*/ strcat(char *, char *);
char *strdup(char *);
int strlen(char *);
void RecursivePermute3(char *prefix, char *substr) {
  char *set = setstr(substr);
  int i;
  if (strlen(set) == 1) {
    char rbuf[10];
    memset(rbuf, 0, 10);
    strcat(rbuf, prefix);
    strcat(rbuf, substr);
    printf("%s\n", rbuf);
  } else {
    for (i = 0; i < strlen(set); i++) {
      char buf[2];
      char *tmp = NULL;
      int j;
      buf[0] = set[i];
      buf[1] = 0;
      strcat(prefix, buf);
      tmp = strdup(substr);
      delchar(tmp, set[i]);
      RecursivePermute3(prefix, tmp);
      prefix[strlen(prefix) - 1] = 0;
      free(tmp);
    }
  }
  free(set);
}


x86 assembly (clang, -O0):
<RecursivePermute3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <setstr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jne    11fe <RecursivePermute3+0x6e>
lea    -0x26(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1080 <memset@plt>
lea    -0x26(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10a0 <strcat@plt>
lea    -0x26(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <strcat@plt>
lea    -0x26(%rbp),%rsi
lea    0xe0c(%rip),%rdi
call   1060 <printf@plt>
jmp    12b4 <RecursivePermute3+0x124>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
cmp    %ecx,%eax
jge    12af <RecursivePermute3+0x11f>
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x28(%rbp)
movb   $0x0,-0x27(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x10(%rbp),%rdi
call   10b0 <strdup@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   1070 <delchar@plt>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1090 <RecursivePermute3@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1205 <RecursivePermute3+0x75>
jmp    12b4 <RecursivePermute3+0x124>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RecursivePermute3>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r13
mov    %rsi,%rdi
call   1050 <setstr@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jne    11fa <RecursivePermute3+0x6a>
lea    0xe(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1080 <memset@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   10a0 <strcat@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   10a0 <strcat@plt>
lea    0xe13(%rip),%rdi
mov    %r12,%rsi
call   1060 <printf@plt>
jmp    1277 <RecursivePermute3+0xe7>
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1277 <RecursivePermute3+0xe7>
xor    %ebp,%ebp
lea    0xc(%rsp),%r12
nopl   (%rax)
movzbl (%r15,%rbp,1),%eax
mov    %al,0xc(%rsp)
movb   $0x0,0xd(%rsp)
mov    %r13,%rdi
mov    %r12,%rsi
call   10a0 <strcat@plt>
mov    %r14,%rdi
call   10b0 <strdup@plt>
mov    %rax,%rbx
movsbl (%r15,%rbp,1),%esi
mov    %rax,%rdi
call   1070 <delchar@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1090 <RecursivePermute3@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r13,1)
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x1,%rbp
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1210 <RecursivePermute3+0x80>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x18,%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 @RecursivePermute3(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [10 x i8]
%8 = alloca [2 x i8]
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%11 = load i8*, i8** %4
%12 = call i8* @setstr(i8* %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = call i32 @strlen(i8* %13)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %27
16: ; preds = %2
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%18 = call i32 @memset(i8* %17, i32 0, i32 10)
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%20 = load i8*, i8** %3
%21 = call i32 @strcat(i8* %19, i8* %20)
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%23 = load i8*, i8** %4
%24 = call i32 @strcat(i8* %22, i8* %23)
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %25)
br label %67
27: ; preds = %2
store i32 0, i32* %6
br label %28
28: ; preds = %63, %27
%29 = load i32, i32* %6
%30 = load i8*, i8** %5
%31 = call i32 @strlen(i8* %30)
%32 = icmp slt i32 %29, %31
br i1 %32, label %33, label %66
33: ; preds = %28
store i8* null, i8** %9
%34 = load i8*, i8** %5
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
store i8 %38, i8* %39
%40 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 1
store i8 0, i8* %40
%41 = load i8*, i8** %3
%42 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%43 = call i32 @strcat(i8* %41, i8* %42)
%44 = load i8*, i8** %4
%45 = call i8* @strdup(i8* %44)
store i8* %45, i8** %9
%46 = load i8*, i8** %9
%47 = load i8*, i8** %5
%48 = load i32, i32* %6
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
%51 = load i8, i8* %50
%52 = call i32 @delchar(i8* %46, i8 signext %51)
%53 = load i8*, i8** %3
%54 = load i8*, i8** %9
%55 = load i8*, i8** %3
%56 = load i8*, i8** %3
%57 = call i32 @strlen(i8* %56)
%58 = sub nsw i32 %57, 1
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %55, i64 %59
store i8 0, i8* %60
%61 = load i8*, i8** %9
%62 = call i32 @free(i8* %61)
br label %63
63: ; preds = %33
%64 = load i32, i32* %6
%65 = add nsw i32 %64, 1
store i32 %65, i32* %6
br label %28
66: ; preds = %28
br label %67
67: ; preds = %66, %16
%68 = load i8*, i8** %5
%69 = call i32 @free(i8* %68)
ret void
}

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