#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*/ printf(char *, char *);
void DoPermute(char in[], char out[], int used[], int length, int recurLen) {
  int i;
  if (recurLen == length) {
    printf("%s\n", out);
    return;
  }
  for (i = 0; i < length; i++) {
    if (used[i])
      continue;
    out[recurLen] = in[i];
    used[i] = 1;
    DoPermute(in, out, used, length, recurLen + 1);
    used[i] = 0;
  }
}


x86 assembly (clang, -O0):
<DoPermute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    115c <DoPermute+0x3c>
mov    -0x10(%rbp),%rsi
lea    0xeae(%rip),%rdi
call   1030 <printf@plt>
jmp    11e4 <DoPermute+0xc4>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11e4 <DoPermute+0xc4>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     1186 <DoPermute+0x66>
jmp    11d6 <DoPermute+0xb6>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
add    $0x1,%r8d
call   1040 <DoPermute@plt>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1163 <DoPermute+0x43>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DoPermute>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    %ecx,%r8d
jne    1153 <DoPermute+0x33>
lea    0xec3(%rip),%rdi
mov    %rbx,%rsi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>
mov    %ecx,%r15d
test   %ecx,%ecx
jle    11cc <DoPermute+0xac>
mov    %r8d,%r12d
mov    %rdx,%rbp
mov    %rdi,%r13
movslq %r8d,%rax
mov    %rax,0x10(%rsp)
add    $0x1,%r12d
mov    %r15d,%eax
xor    %r14d,%r14d
mov    %rax,0x8(%rsp)
jmp    1189 <DoPermute+0x69>
nopl   0x0(%rax)
add    $0x1,%r14
cmp    %r14,%rax
je     11cc <DoPermute+0xac>
cmpl   $0x0,0x0(%rbp,%r14,4)
jne    1180 <DoPermute+0x60>
movzbl 0x0(%r13,%r14,1),%eax
mov    0x10(%rsp),%rdx
mov    %al,(%rbx,%rdx,1)
movl   $0x1,0x0(%rbp,%r14,4)
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %r15d,%ecx
mov    %r12d,%r8d
call   1040 <DoPermute@plt>
mov    0x8(%rsp),%rax
movl   $0x0,0x0(%rbp,%r14,4)
jmp    1180 <DoPermute+0x60>
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 @DoPermute(i8* %0, i8* %1, i32* %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%12 = load i32, i32* %10
%13 = load i32, i32* %9
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %5
%16 = load i8*, i8** %7
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %58
18: ; preds = %5
store i32 0, i32* %11
br label %19
19: ; preds = %55, %18
%20 = load i32, i32* %11
%21 = load i32, i32* %9
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %58
23: ; preds = %19
%24 = load i32*, i32** %8
%25 = load i32, i32* %11
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = load i32, i32* %27
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %23
br label %55
31: ; preds = %23
%32 = load i8*, i8** %6
%33 = load i32, i32* %11
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = load i8*, i8** %7
%38 = load i32, i32* %10
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 %36, i8* %40
%41 = load i32*, i32** %8
%42 = load i32, i32* %11
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
store i32 1, i32* %44
%45 = load i8*, i8** %6
%46 = load i8*, i8** %7
%47 = load i32*, i32** %8
%48 = load i32, i32* %9
%49 = load i32, i32* %10
%50 = add nsw i32 %49, 1
%51 = load i32*, i32** %8
%52 = load i32, i32* %11
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %51, i64 %53
store i32 0, i32* %54
br label %55
55: ; preds = %31, %30
%56 = load i32, i32* %11
%57 = add nsw i32 %56, 1
store i32 %57, i32* %11
br label %19
58: ; preds = %15, %19
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define void @DoPermute(i8* nocapture %0, i8* %1, i32* nocapture %2, i32 %3, i32 %4) {
%6 = icmp eq i32 %4, %3
br i1 %6, label %14, label %7
7: ; preds = %5
%8 = icmp sgt i32 %3, 0
br i1 %8, label %9, label %27
9: ; preds = %7
%10 = sext i32 %4 to i64
%11 = getelementptr inbounds i8, i8* %1, i64 %10
%12 = add nsw i32 %4, 1
%13 = zext i32 %3 to i64
br label %16
14: ; preds = %5
%15 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %27
16: ; preds = %9, %24
%17 = phi i64 [ 0, %9 ], [ %25, %24 ]
%18 = getelementptr inbounds i32, i32* %2, i64 %17
%19 = load i32, i32* %18
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = getelementptr inbounds i8, i8* %0, i64 %17
%23 = load i8, i8* %22
store i8 %23, i8* %11
store i32 1, i32* %18
tail call void @DoPermute(i8* %0, i8* %1, i32* %2, i32 %3, i32 %12)
store i32 0, i32* %18
br label %24
24: ; preds = %16, %21
%25 = add nuw nsw i64 %17, 1
%26 = icmp eq i64 %25, %13
br i1 %26, label %27, label %16
27: ; preds = %24, %7, %14
ret void
}