#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 *);
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("Permutation: %s\n", str);
    return;
  }
  size_t i;
  for (i = str_i; i < str_sz; i++) {
    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    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1167 <str_permutations_aux+0x37>
mov    -0x8(%rbp),%rsi
lea    0xea3(%rip),%rdi
call   1040 <printf@plt>
jmp    11c5 <str_permutations_aux+0x95>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11c5 <str_permutations_aux+0x95>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <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    -0x20(%rbp),%rdx
call   1050 <swap@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    116f <str_permutations_aux+0x3f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_permutations_aux>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r13
cmp    %rsi,%rdx
jne    1159 <str_permutations_aux+0x29>
lea    0xeb8(%rip),%rdi
mov    %r13,%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <printf@plt>
jae    11a3 <str_permutations_aux+0x73>
mov    %rdx,%r14
mov    %rsi,%r15
lea    0x1(%rdx),%r12
mov    %rdx,%rbx
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <swap@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <str_permutations_aux@plt>
mov    %r13,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <swap@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1170 <str_permutations_aux+0x40>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [17 x i8] c"Permutation: %s\0A\00"
define void @str_permutations_aux(i8* %0, i64 %1, i64 %2) {
%4 = icmp eq i64 %2, %1
br i1 %4, label %9, label %5
5: ; preds = %3
%6 = icmp ult i64 %2, %1
br i1 %6, label %7, label %17
7: ; preds = %5
%8 = add nuw i64 %2, 1
br label %11
9: ; preds = %3
%10 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %17
11: ; preds = %7, %11
%12 = phi i64 [ %2, %7 ], [ %15, %11 ]
%13 = tail call i32 @swap(i8* %0, i64 %2, i64 %12)
tail call void @str_permutations_aux(i8* %0, i64 %1, i64 %8)
%14 = tail call i32 @swap(i8* %0, i64 %2, i64 %12)
%15 = add i64 %12, 1
%16 = icmp eq i64 %15, %1
br i1 %16, label %17, label %11
17: ; preds = %11, %5, %9
ret void
}