#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 permute(char *address, int i, int n) {
  int j;
  if (i == n)
    printf("%s\n", address);
  else {
    for (j = i; j <= n; j++) {
      swap((address + i), (address + j));
      permute(address, i + 1, n);
      swap((address + i), (address + j));
      printf("In backtrack: %s\n", address);
    }
  }
}


x86 assembly (clang, -O0):
<permute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    1163 <permute+0x33>
mov    -0x8(%rbp),%rsi
lea    0xeb5(%rip),%rdi
call   1040 <printf@plt>
jmp    11e0 <permute+0xb0>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11db <permute+0xab>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
call   1050 <swap@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1030 <permute@plt>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
call   1050 <swap@plt>
mov    -0x8(%rbp),%rsi
lea    0xe38(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1169 <permute+0x39>
jmp    11e0 <permute+0xb0>
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    %rdi,%r14
cmp    %edx,%esi
jne    115f <permute+0x2f>
lea    0xec5(%rip),%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
jg     11bf <permute+0x8f>
mov    %edx,%r15d
mov    %esi,%ebx
movslq %esi,%r13
add    %r14,%r13
lea    0x1(%rbx),%r12d
add    $0xffffffff,%ebx
mov    %r13,%rbp
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbp,%rsi
call   1050 <swap@plt>
mov    %r14,%rdi
mov    %r12d,%esi
mov    %r15d,%edx
call   1030 <permute@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1050 <swap@plt>
lea    0xe55(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
add    $0x1,%rbp
add    $0x1,%ebx
cmp    %ebx,%r15d
jne    1180 <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"
@.str.1 = [18 x i8] c"In backtrack: %s\0A\00"
define void @permute(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 = load i32, i32* %6
%10 = icmp eq i32 %8, %9
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i8*, i8** %4
%13 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %49
14: ; preds = %3
%15 = load i32, i32* %5
store i32 %15, i32* %7
br label %16
16: ; preds = %45, %14
%17 = load i32, i32* %7
%18 = load i32, i32* %6
%19 = icmp sle i32 %17, %18
br i1 %19, label %20, label %48
20: ; preds = %16
%21 = load i8*, i8** %4
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8*, i8** %4
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = call i32 @swap(i8* %24, i8* %28)
%30 = load i8*, i8** %4
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
%33 = load i32, i32* %6
%34 = load i8*, i8** %4
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8*, i8** %4
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = call i32 @swap(i8* %37, i8* %41)
%43 = load i8*, i8** %4
%44 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %43)
br label %45
45: ; preds = %20
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %7
br label %16
48: ; preds = %16
br label %49
49: ; preds = %48, %11
ret void
}

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