#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*/ print_list(int *, int);
int /*<<< orphan*/ swap(int *, int, int);
void permutation(int *list, int start, int len) {
  if (start == len) {
    print_list(list, len);
    return;
  }
  for (int i = start; i < len; i++) {
    swap(list, start, i);
    permutation(list, start + 1, len);
    swap(list, i, start);
  }
}


x86 assembly (clang, -O0):
<permutation>:
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    115f <permutation+0x2f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1030 <print_list@plt>
jmp    11af <permutation+0x7f>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11af <permutation+0x7f>
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 <permutation@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1050 <swap@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1165 <permutation+0x35>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<permutation>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r12d
mov    %rdi,%rbp
cmp    %edx,%esi
jne    1155 <permutation+0x25>
mov    %rbp,%rdi
mov    %r12d,%esi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <print_list@plt>
jge    11a0 <permutation+0x70>
mov    %edx,%r14d
lea    0x1(%r12),%r15d
mov    %r12d,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %r12d,%esi
mov    %ebx,%edx
call   1050 <swap@plt>
mov    %rbp,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
call   1040 <permutation@plt>
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r12d,%edx
call   1050 <swap@plt>
add    $0x1,%ebx
cmp    %ebx,%r14d
jne    1170 <permutation+0x40>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @permutation(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %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 %15
11: ; preds = %3
%12 = load i32*, i32** %4
%13 = load i32, i32* %6
%14 = call i32 @print_list(i32* %12, i32 %13)
br label %37
15: ; preds = %3
%16 = load i32, i32* %5
store i32 %16, i32* %7
br label %17
17: ; preds = %34, %15
%18 = load i32, i32* %7
%19 = load i32, i32* %6
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %37
21: ; preds = %17
%22 = load i32*, i32** %4
%23 = load i32, i32* %5
%24 = load i32, i32* %7
%25 = call i32 @swap(i32* %22, i32 %23, i32 %24)
%26 = load i32*, i32** %4
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
%29 = load i32, i32* %6
%30 = load i32*, i32** %4
%31 = load i32, i32* %7
%32 = load i32, i32* %5
%33 = call i32 @swap(i32* %30, i32 %31, i32 %32)
br label %34
34: ; preds = %21
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %17
37: ; preds = %11, %17
ret void
}

LLVM IR (-O2):
define void @permutation(i32* %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %1, %2
br i1 %4, label %9, label %5
5: ; preds = %3
%6 = icmp slt i32 %1, %2
br i1 %6, label %7, label %17
7: ; preds = %5
%8 = add nsw i32 %1, 1
br label %11
9: ; preds = %3
%10 = tail call i32 @print_list(i32* %0, i32 %1)
br label %17
11: ; preds = %7, %11
%12 = phi i32 [ %1, %7 ], [ %15, %11 ]
%13 = tail call i32 @swap(i32* %0, i32 %1, i32 %12)
tail call void @permutation(i32* %0, i32 %8, i32 %2)
%14 = tail call i32 @swap(i32* %0, i32 %12, i32 %1)
%15 = add i32 %12, 1
%16 = icmp eq i32 %15, %2
br i1 %16, label %17, label %11
17: ; preds = %11, %5, %9
ret void
}