#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*/ do_permute_letters(char const *, int, int *, char *,
                                      int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char const *);
void permute_letters(const char *letters, int len) {
  char buffer[len + 1];
  buffer[len] = '\0';
  strcpy(buffer, letters);
  bool used[len];
  for (int i = 0; i < len; i++) {
    used[i] = false;
  }
  do_permute_letters(letters, len, used, buffer, 0);
}


x86 assembly (clang, -O0):
<permute_letters>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
movslq -0xc(%rbp),%rax
movb   $0x0,(%rax,%rdi,1)
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0xc(%rbp),%eax
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b9 <permute_letters+0x99>
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1190 <permute_letters+0x70>
mov    -0x40(%rbp),%rcx
mov    -0x38(%rbp),%rdx
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
xor    %r8d,%r8d
call   1040 <do_permute_letters@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<permute_letters>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
lea    0x1(%r15),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
movslq %esi,%r13
movb   $0x0,0x0(%r13,%r12,1)
mov    %r12,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r13d,%edx
mov    %rsp,%rbx
lea    0xf(,%rdx,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
test   %r13d,%r13d
jle    1198 <permute_letters+0x68>
shl    $0x2,%rdx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %r14,%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
mov    %r12,%rcx
xor    %r8d,%r8d
call   1050 <do_permute_letters@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @permute_letters(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i32, i32* %4
%10 = add nsw i32 %9, 1
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %5
%13 = alloca i8, i64 %11
store i64 %11, i64* %6
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
store i8 0, i8* %16
%17 = load i8*, i8** %3
%18 = call i32 @strcpy(i8* %13, i8* %17)
%19 = load i32, i32* %4
%20 = zext i32 %19 to i64
%21 = alloca i32, i64 %20
store i64 %20, i64* %7
store i32 0, i32* %8
br label %22
22: ; preds = %30, %2
%23 = load i32, i32* %8
%24 = load i32, i32* %4
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %33
26: ; preds = %22
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %21, i64 %28
store i32 0, i32* %29
br label %30
30: ; preds = %26
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %22
33: ; preds = %22
%34 = load i8*, i8** %3
%35 = load i32, i32* %4
%36 = call i32 @do_permute_letters(i8* %34, i32 %35, i32* %21, i8* %13, i32 0)
%37 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
define void @permute_letters(i8* %0, i32 %1) {
%3 = add nsw i32 %1, 1
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = sext i32 %1 to i64
%7 = getelementptr inbounds i8, i8* %5, i64 %6
store i8 0, i8* %7
%8 = call i32 @strcpy(i8* %5, i8* %0)
%9 = zext i32 %1 to i64
%10 = alloca i32, i64 %9
%11 = icmp sgt i32 %1, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = bitcast i32* %10 to i8*
%14 = shl nuw nsw i64 %9, 2
br label %15
15: ; preds = %12, %2
%16 = call i32 @do_permute_letters(i8* %0, i32 %1, i32* %10, i8* %5, i32 0)
ret void
}