#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 *, int, int);
void string_permutation(char *s, int from, int to) {
  if (from < 0 || to < from)
    return;
  if (from == to)
    printf("%s\n", s);
  else {
    int i;
    for (i = from; i <= to; i++) {
      if ((s[from] == s[i]) && from != i)
        continue;
      swap(s, from, i);
      string_permutation(s, from + 1, to);
      swap(s, from, i);
    }
  }
}


x86 assembly (clang, -O0):
<string_permutation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1158 <string_permutation+0x28>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    115d <string_permutation+0x2d>
jmp    1204 <string_permutation+0xd4>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    117e <string_permutation+0x4e>
mov    -0x8(%rbp),%rsi
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
jmp    1204 <string_permutation+0xd4>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11ff <string_permutation+0xcf>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x8(%rbp),%rcx
movslq -0x14(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    11c1 <string_permutation+0x91>
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     11c1 <string_permutation+0x91>
jmp    11f1 <string_permutation+0xc1>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1050 <swap@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1040 <string_permutation@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1050 <swap@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1184 <string_permutation+0x54>
jmp    1204 <string_permutation+0xd4>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_permutation>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,0x4(%rsp)
mov    %rsi,0x8(%rsp)
test   %esi,%esi
js     11fe <string_permutation+0xce>
mov    0x8(%rsp),%rax
cmp    %eax,0x4(%rsp)
jl     11fe <string_permutation+0xce>
mov    %rdi,%rbx
jne    1180 <string_permutation+0x50>
lea    0xe96(%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    0x8(%rsp),%rax
mov    %eax,%r13d
add    $0x1,%eax
mov    %eax,0x14(%rsp)
lea    (%rbx,%r13,1),%r12
mov    0x4(%rsp),%eax
mov    %eax,%r14d
not    %r14d
add    %r13,%r14
xor    %r15d,%r15d
jmp    11ec <string_permutation+0xbc>
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%r15,%r13,1),%ebp
mov    %rbx,%rdi
mov    %r13d,%esi
mov    %ebp,%edx
call   1050 <swap@plt>
mov    %rbx,%rdi
mov    0x14(%rsp),%esi
mov    0x4(%rsp),%edx
call   1040 <string_permutation@plt>
mov    %rbx,%rdi
mov    0x8(%rsp),%rsi
mov    %ebp,%edx
call   1050 <swap@plt>
add    $0x1,%r15
mov    %r14d,%eax
add    %r15d,%eax
je     11fe <string_permutation+0xce>
movzbl (%rbx,%r13,1),%eax
cmp    (%r12,%r15,1),%al
jne    11b0 <string_permutation+0x80>
test   %r15,%r15
jne    11e0 <string_permutation+0xb0>
jmp    11b0 <string_permutation+0x80>
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 @string_permutation(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %3
%11 = load i32, i32* %6
%12 = load i32, i32* %5
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %10, %3
br label %64
15: ; preds = %10
%16 = load i32, i32* %5
%17 = load i32, i32* %6
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i8*, i8** %4
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %20)
br label %64
22: ; preds = %15
%23 = load i32, i32* %5
store i32 %23, i32* %7
br label %24
24: ; preds = %60, %22
%25 = load i32, i32* %7
%26 = load i32, i32* %6
%27 = icmp sle i32 %25, %26
br i1 %27, label %28, label %63
28: ; preds = %24
%29 = load i8*, i8** %4
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = load i8*, i8** %4
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %34, %40
br i1 %41, label %42, label %47
42: ; preds = %28
%43 = load i32, i32* %5
%44 = load i32, i32* %7
%45 = icmp ne i32 %43, %44
br i1 %45, label %46, label %47
46: ; preds = %42
br label %60
47: ; preds = %42, %28
%48 = load i8*, i8** %4
%49 = load i32, i32* %5
%50 = load i32, i32* %7
%51 = call i32 @swap(i8* %48, i32 %49, i32 %50)
%52 = load i8*, i8** %4
%53 = load i32, i32* %5
%54 = add nsw i32 %53, 1
%55 = load i32, i32* %6
%56 = load i8*, i8** %4
%57 = load i32, i32* %5
%58 = load i32, i32* %7
%59 = call i32 @swap(i8* %56, i32 %57, i32 %58)
br label %60
60: ; preds = %47, %46
%61 = load i32, i32* %7
%62 = add nsw i32 %61, 1
store i32 %62, i32* %7
br label %24
63: ; preds = %24
br label %64
64: ; preds = %14, %63, %19
ret void
}

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