#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 *, char *);
void print_permutations(char *str, int left, int right, int *counter) {
  int i;
  if (left == right) {
    printf("%s\n", str);
    *counter = *counter + 1;
  }
  for (i = left; i < right; i++) {
    swap((str + left), (str + i));
    print_permutations(str, left + 1, right, counter);
    swap((str + left), (str + i));
  }
}


x86 assembly (clang, -O0):
<print_permutations>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    1171 <print_permutations+0x41>
mov    -0x8(%rbp),%rsi
lea    0xea3(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11dd <print_permutations+0xad>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
call   1040 <swap@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1050 <print_permutations@plt>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
call   1040 <swap@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1177 <print_permutations+0x47>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_permutations>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %edx,%r12d
mov    %esi,%ebx
mov    %rdi,%rbp
cmp    %edx,%esi
jne    115d <print_permutations+0x2d>
lea    0xeaf(%rip),%rdi
mov    %rbp,%rsi
call   1030 <printf@plt>
addl   $0x1,(%r15)
cmp    %r12d,%ebx
mov    %r15,(%rsp)
jge    11b4 <print_permutations+0x84>
mov    %rbp,%r15
movslq %ebx,%r14
add    %rbp,%r14
lea    0x1(%rbx),%r13d
mov    %r14,%rbp
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbp,%rsi
call   1040 <swap@plt>
mov    %r15,%rdi
mov    %r13d,%esi
mov    %r12d,%edx
mov    (%rsp),%rcx
call   1050 <print_permutations@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1040 <swap@plt>
add    $0x1,%rbp
add    $0x1,%ebx
cmp    %ebx,%r12d
jne    1180 <print_permutations+0x50>
add    $0x8,%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 @print_permutations(i8* %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%10 = load i32, i32* %6
%11 = load i32, i32* %7
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %20
13: ; preds = %4
%14 = load i8*, i8** %5
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32*, i32** %8
%17 = load i32, i32* %16
%18 = add nsw i32 %17, 1
%19 = load i32*, i32** %8
store i32 %18, i32* %19
br label %20
20: ; preds = %13, %4
%21 = load i32, i32* %6
store i32 %21, i32* %9
br label %22
22: ; preds = %50, %20
%23 = load i32, i32* %9
%24 = load i32, i32* %7
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %53
26: ; preds = %22
%27 = load i8*, i8** %5
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8*, i8** %5
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = call i32 @swap(i8* %30, i8* %34)
%36 = load i8*, i8** %5
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
%39 = load i32, i32* %7
%40 = load i32*, i32** %8
%41 = load i8*, i8** %5
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i8*, i8** %5
%46 = load i32, i32* %9
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = call i32 @swap(i8* %44, i8* %48)
br label %50
50: ; preds = %26
%51 = load i32, i32* %9
%52 = add nsw i32 %51, 1
store i32 %52, i32* %9
br label %22
53: ; preds = %22
ret void
}

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