#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 */
typedef int /*<<< orphan*/ used;

/* Variables and functions */
int UCHAR_MAX;
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ swap(char *, size_t, size_t);
void str_permutations_aux(char *str, size_t str_sz, size_t str_i) {
  if (str_i == str_sz) {
    printf("%s\n", str);
    return;
  }
  unsigned char used[UCHAR_MAX];
  memset(used, 0, sizeof(used));
  size_t i;
  for (i = str_i; i < str_sz; i++) {
    if (used[(unsigned char)str[i]]) {
      continue;
    }
    used[(unsigned char)str[i]] = 1;
    swap(str, str_i, i);
    str_permutations_aux(str, str_sz, str_i + 1);
    swap(str, str_i, i);
  }
}


x86 assembly (clang, -O0):
<str_permutations_aux>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1177 <str_permutations_aux+0x37>
mov    -0x8(%rbp),%rsi
lea    0xe93(%rip),%rdi
call   1040 <printf@plt>
jmp    1244 <str_permutations_aux+0x104>
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    123d <str_permutations_aux+0xfd>
mov    -0x38(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    -0x30(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
cmpb   $0x0,(%rax,%rcx,1)
je     11e1 <str_permutations_aux+0xa1>
jmp    122c <str_permutations_aux+0xec>
mov    -0x38(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    -0x30(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
movb   $0x1,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1060 <swap@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
add    $0x1,%rdx
call   1030 <str_permutations_aux@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1060 <swap@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11b4 <str_permutations_aux+0x74>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_permutations_aux>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
cmp    %rsi,%rdx
jne    1176 <str_permutations_aux+0x36>
lea    0xea0(%rip),%rdi
mov    %rbx,%rsi
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rsp,-0x30(%rbp)
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%r12
mov    %rdx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %r12,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
cmp    %r15,%r13
jae    1207 <str_permutations_aux+0xc7>
lea    0x1(%r13),%rax
mov    %rax,-0x38(%rbp)
mov    %r13,%r14
jmp    11c9 <str_permutations_aux+0x89>
nopl   0x0(%rax)
add    $0x1,%r14
cmp    %r14,%r15
je     1207 <str_permutations_aux+0xc7>
movzbl (%rbx,%r14,1),%eax
cmpb   $0x0,(%r12,%rax,1)
jne    11c0 <str_permutations_aux+0x80>
movb   $0x1,(%r12,%rax,1)
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   1060 <swap@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    -0x38(%rbp),%rdx
call   1030 <str_permutations_aux@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   1060 <swap@plt>
jmp    11c0 <str_permutations_aux+0x80>
mov    -0x30(%rbp),%rsp
lea    -0x28(%rbp),%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"
@UCHAR_MAX = global i32 0
define void @str_permutations_aux(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%10 = load i64, i64* %6
%11 = load i64, i64* %5
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = load i8*, i8** %4
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %62
16: ; preds = %3
%17 = load i32, i32* @UCHAR_MAX
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %7
%20 = alloca i8, i64 %18
store i64 %18, i64* %8
%21 = trunc i64 %18 to i32
%22 = call i32 @memset(i8* %20, i32 0, i32 %21)
%23 = load i64, i64* %6
store i64 %23, i64* %9
br label %24
24: ; preds = %57, %16
%25 = load i64, i64* %9
%26 = load i64, i64* %5
%27 = icmp ult i64 %25, %26
br i1 %27, label %28, label %60
28: ; preds = %24
%29 = load i8*, i8** %4
%30 = load i64, i64* %9
%31 = getelementptr inbounds i8, i8* %29, i64 %30
%32 = load i8, i8* %31
%33 = zext i8 %32 to i64
%34 = getelementptr inbounds i8, i8* %20, i64 %33
%35 = load i8, i8* %34
%36 = icmp ne i8 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %28
br label %57
38: ; preds = %28
%39 = load i8*, i8** %4
%40 = load i64, i64* %9
%41 = getelementptr inbounds i8, i8* %39, i64 %40
%42 = load i8, i8* %41
%43 = zext i8 %42 to i64
%44 = getelementptr inbounds i8, i8* %20, i64 %43
store i8 1, i8* %44
%45 = load i8*, i8** %4
%46 = load i64, i64* %6
%47 = load i64, i64* %9
%48 = call i32 @swap(i8* %45, i64 %46, i64 %47)
%49 = load i8*, i8** %4
%50 = load i64, i64* %5
%51 = load i64, i64* %6
%52 = add i64 %51, 1
%53 = load i8*, i8** %4
%54 = load i64, i64* %6
%55 = load i64, i64* %9
%56 = call i32 @swap(i8* %53, i64 %54, i64 %55)
br label %57
57: ; preds = %38, %37
%58 = load i64, i64* %9
%59 = add i64 %58, 1
store i64 %59, i64* %9
br label %24
60: ; preds = %24
%61 = load i8*, i8** %7
br label %62
62: ; preds = %60, %13
ret void
}

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