#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*/ sort(char *);
void dic_all_sort(char *str, char *dest, int size, int cur) {
  sort(str);
  if (cur == size) {
    printf("%s\n", dest);
    return;
  }
  int i;
  for (i = 0; i < size; ++i) {
    dest[cur] = str[i];
    dic_all_sort(str, dest, size, cur + 1);
  }
}


x86 assembly (clang, -O0):
<dic_all_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <sort@plt>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1170 <dic_all_sort+0x40>
mov    -0x10(%rbp),%rsi
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
jmp    11bd <dic_all_sort+0x8d>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11bd <dic_all_sort+0x8d>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
call   1050 <dic_all_sort@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1177 <dic_all_sort+0x47>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dic_all_sort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %rsi,%rbx
mov    %rdi,%rbp
call   1040 <sort@plt>
mov    %r12d,0x4(%rsp)
cmp    %r12d,%r15d
jne    1173 <dic_all_sort+0x43>
lea    0xea3(%rip),%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>
cmpl   $0x0,0x4(%rsp)
jle    11b5 <dic_all_sort+0x85>
movslq %r15d,%r12
add    $0x1,%r15d
mov    0x4(%rsp),%r13d
xor    %r14d,%r14d
nopl   0x0(%rax)
movzbl 0x0(%rbp,%r14,1),%eax
mov    %al,(%rbx,%r12,1)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    0x4(%rsp),%edx
mov    %r15d,%ecx
call   1050 <dic_all_sort@plt>
add    $0x1,%r14
cmp    %r14,%r13
jne    1190 <dic_all_sort+0x60>
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 @dic_all_sort(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i8*, i8** %5
%11 = call i32 @sort(i8* %10)
%12 = load i32, i32* %8
%13 = load i32, i32* %7
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %4
%16 = load i8*, i8** %6
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %41
18: ; preds = %4
store i32 0, i32* %9
br label %19
19: ; preds = %38, %18
%20 = load i32, i32* %9
%21 = load i32, i32* %7
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %41
23: ; preds = %19
%24 = load i8*, i8** %5
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = load i8*, i8** %6
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 %28, i8* %32
%33 = load i8*, i8** %5
%34 = load i8*, i8** %6
%35 = load i32, i32* %7
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 1
br label %38
38: ; preds = %23
%39 = load i32, i32* %9
%40 = add nsw i32 %39, 1
store i32 %40, i32* %9
br label %19
41: ; preds = %15, %19
ret void
}

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