#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 *, ...);
int /*<<< orphan*/ swap(char *, char *);
void permutations(char *arr, int k, int n) {
  int i, j, temp;
  if (k == n - 1) {
    for (i = 0; i < n; i++)
      printf("%c ", arr[i]);
    printf("\n");
  } else
    for (i = k; i < n; i++) {
      swap(&arr[k], &arr[i]);
      permutations(arr, k + 1, n);
      swap(&arr[k], &arr[i]);
    }
}


x86 assembly (clang, -O0):
<permutations>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    11a1 <permutations+0x71>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    118e <permutations+0x5e>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115a <permutations+0x2a>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120e <permutations+0xde>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1209 <permutations+0xd9>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
call   1040 <swap@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1050 <permutations@plt>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
call   1040 <swap@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a7 <permutations+0x77>
jmp    120e <permutations+0xde>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<permutations>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rdi,%r14
lea    -0x1(%r15),%eax
cmp    %esi,%eax
jne    11a0 <permutations+0x60>
test   %r15d,%r15d
jle    1188 <permutations+0x48>
mov    %r15d,%ebp
lea    0xe98(%rip),%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsbl (%r14,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <permutations+0x30>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>
mov    %esi,%ebx
cmp    %r15d,%esi
jge    11f0 <permutations+0xb0>
movslq %ebx,%r12
add    %r14,%r12
lea    0x1(%rbx),%r13d
mov    %r12,%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
mov    %rbp,%rsi
call   1050 <swap@plt>
mov    %r14,%rdi
mov    %r13d,%esi
mov    %r15d,%edx
call   1060 <permutations@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
call   1050 <swap@plt>
add    $0x1,%rbp
add    $0x1,%ebx
cmp    %ebx,%r15d
jne    11c0 <permutations+0x80>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%c \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @permutations(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = sub nsw i32 %11, 1
%13 = icmp eq i32 %10, %12
br i1 %13, label %14, label %32
14: ; preds = %3
store i32 0, i32* %7
br label %15
15: ; preds = %27, %14
%16 = load i32, i32* %7
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %30
19: ; preds = %15
%20 = load i8*, i8** %4
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %19
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
br label %15
30: ; preds = %15
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %65
32: ; preds = %3
%33 = load i32, i32* %5
store i32 %33, i32* %7
br label %34
34: ; preds = %61, %32
%35 = load i32, i32* %7
%36 = load i32, i32* %6
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %64
38: ; preds = %34
%39 = load i8*, i8** %4
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8*, i8** %4
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = call i32 @swap(i8* %42, i8* %46)
%48 = load i8*, i8** %4
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
%51 = load i32, i32* %6
%52 = load i8*, i8** %4
%53 = load i32, i32* %5
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
%56 = load i8*, i8** %4
%57 = load i32, i32* %7
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = call i32 @swap(i8* %55, i8* %59)
br label %61
61: ; preds = %38
%62 = load i32, i32* %7
%63 = add nsw i32 %62, 1
store i32 %63, i32* %7
br label %34
64: ; preds = %34
br label %65
65: ; preds = %64, %30
ret void
}

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