#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 *);
void permute(char str1[], char str2[], int pos, int len) {
  if (pos == len) {
    printf("%s\n", str2);
    return;
  }
  for (int i = 0; i < len; i++) {
    str2[pos] = str1[i];
    permute(str1, str2, pos + 1, len);
  }
}


x86 assembly (clang, -O0):
<permute>:
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    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    1157 <permute+0x37>
mov    -0x10(%rbp),%rsi
lea    0xeb3(%rip),%rdi
call   1040 <printf@plt>
jmp    11a4 <permute+0x84>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11a4 <permute+0x84>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
mov    -0x18(%rbp),%ecx
call   1030 <permute@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115e <permute+0x3e>
add    $0x20,%rsp
pop    %rbp
ret

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

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