int Permute(char inString[]) {
  int length, i, *used;
  char *out;
  length = strlen(inString);
  out = (char *)malloc(length + 1);
  if (!out)
    return 0;
  out[length] = '\0';
  used = (int *)malloc(sizeof(int) * length);
  if (!used)
    return 0;
  for (i = 0; i < length; i++)
    used[i] = 0;
  DoPermute(inString, out, used, length, 0);
  free(out);
  free(used);
  return 1;
}


x86 assembly (clang, -O0):
<Permute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1181 <Permute+0x41>
movl   $0x0,-0x4(%rbp)
jmp    1217 <Permute+0xd7>
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movslq -0x14(%rbp),%rdi
shl    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b5 <Permute+0x75>
movl   $0x0,-0x4(%rbp)
jmp    1217 <Permute+0xd7>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e5 <Permute+0xa5>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11bc <Permute+0x7c>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x14(%rbp),%ecx
xor    %r8d,%r8d
mov    $0x0,%al
call   1060 <DoPermute@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Permute>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %rax,%rbx
shl    $0x20,%rbx
movabs $0x100000000,%rdi
add    %rbx,%rdi
sar    $0x20,%rdi
call   1060 <malloc@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11ef <Permute+0x9f>
mov    %rax,%r13
mov    %rbx,%rax
sar    $0x20,%rax
movb   $0x0,0x0(%r13,%rax,1)
sar    $0x1e,%rbx
mov    %rbx,%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     11ef <Permute+0x9f>
mov    %rax,%r12
test   %r15d,%r15d
jle    11c4 <Permute+0x74>
mov    %r15d,%edx
shl    $0x2,%rdx
mov    %r12,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15d,%ecx
xor    %r8d,%r8d
xor    %eax,%eax
call   1070 <DoPermute@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @Permute(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i64 @strlen(i8* %8)
%10 = trunc i64 %9 to i32
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = call i8* @malloc(i64 %13)
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = icmp ne i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %1
store i32 0, i32* %2
br label %53
18: ; preds = %1
%19 = load i8*, i8** %7
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8 0, i8* %22
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = mul i64 4, %24
%26 = call i8* @malloc(i64 %25)
%27 = bitcast i8* %26 to i32*
store i32* %27, i32** %6
%28 = load i32*, i32** %6
%29 = icmp ne i32* %28, null
br i1 %29, label %31, label %30
30: ; preds = %18
store i32 0, i32* %2
br label %53
31: ; preds = %18
store i32 0, i32* %5
br label %32
32: ; preds = %41, %31
%33 = load i32, i32* %5
%34 = load i32, i32* %4
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %44
36: ; preds = %32
%37 = load i32*, i32** %6
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
store i32 0, i32* %40
br label %41
41: ; preds = %36
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
br label %32
44: ; preds = %32
%45 = load i8*, i8** %3
%46 = load i8*, i8** %7
%47 = load i32*, i32** %6
%48 = load i32, i32* %4
%49 = call i32 (i8*, i8*, i32*, i32, i32, ...) bitcast (i32 (...)* @DoPermute to i32 (i8*, i8*, i32*, i32, i32, ...)*)(i8* %45, i8* %46, i32* %47, i32 %48, i32 0)
%50 = load i8*, i8** %7
%51 = load i32*, i32** %6
%52 = bitcast i32* %51 to i8*
store i32 1, i32* %2
br label %53
53: ; preds = %44, %30, %17
%54 = load i32, i32* %2
ret i32 %54
}

LLVM IR (-O2):
define i32 @Permute(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = trunc i64 %2 to i32
%4 = shl i64 %2, 32
%5 = add i64 %4, 4294967296
%6 = ashr exact i64 %5, 32
%7 = tail call i8* @malloc(i64 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %23, label %9
9: ; preds = %1
%10 = ashr exact i64 %4, 32
%11 = getelementptr inbounds i8, i8* %7, i64 %10
store i8 0, i8* %11
%12 = ashr exact i64 %4, 30
%13 = tail call i8* @malloc(i64 %12)
%14 = bitcast i8* %13 to i32*
%15 = icmp eq i8* %13, null
br i1 %15, label %23, label %16
16: ; preds = %9
%17 = icmp sgt i32 %3, 0
br i1 %17, label %18, label %21
18: ; preds = %16
%19 = shl i64 %2, 2
%20 = and i64 %19, 17179869180
br label %21
21: ; preds = %18, %16
%22 = tail call i32 (i8*, i8*, i32*, i32, i32, ...) bitcast (i32 (...)* @DoPermute to i32 (i8*, i8*, i32*, i32, i32, ...)*)(i8* %0, i8* %7, i32* %14, i32 %3, i32 0)
tail call void @free(i8* %7)
tail call void @free(i8* %13)
br label %23
23: ; preds = %9, %1, %21
%24 = phi i32 [ 1, %21 ], [ 0, %1 ], [ 0, %9 ]
ret i32 %24
}