#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);
int /*<<< orphan*/ swap_char(int *, int, int);
void permute(int a[], int beg, int _end) {
  int i;
  if (beg == _end) {
    printf("\n%d", a[beg]);
    return;
  }
  for (i = beg; i <= _end; i++) {
    swap_char(a, beg, i);
    permute(a, beg + 1, _end);
    swap_char(a, beg, i);
  }
}


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    116a <permute+0x3a>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xea0(%rip),%rdi
call   1040 <printf@plt>
jmp    11ba <permute+0x8a>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11ba <permute+0x8a>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1050 <swap_char@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1030 <permute@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1050 <swap_char@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1170 <permute+0x40>
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    %esi,%r14d
mov    %rdi,%rbx
cmp    %edx,%esi
jne    1165 <permute+0x35>
movslq %r14d,%rax
mov    (%rbx,%rax,4),%esi
lea    0xeae(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
jg     11b0 <permute+0x80>
mov    %edx,%r15d
lea    0x1(%r14),%r12d
lea    0x1(%r15),%r13d
mov    %r14d,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1050 <swap_char@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r15d,%edx
call   1030 <permute@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1050 <swap_char@plt>
add    $0x1,%ebp
cmp    %ebp,%r13d
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"\0A%d\00"
define void @permute(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 %18
11: ; preds = %3
%12 = load i32*, i32** %4
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %12, i64 %14
%16 = load i32, i32* %15
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %40
18: ; preds = %3
%19 = load i32, i32* %5
store i32 %19, i32* %7
br label %20
20: ; preds = %37, %18
%21 = load i32, i32* %7
%22 = load i32, i32* %6
%23 = icmp sle i32 %21, %22
br i1 %23, label %24, label %40
24: ; preds = %20
%25 = load i32*, i32** %4
%26 = load i32, i32* %5
%27 = load i32, i32* %7
%28 = call i32 @swap_char(i32* %25, i32 %26, i32 %27)
%29 = load i32*, i32** %4
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
%32 = load i32, i32* %6
%33 = load i32*, i32** %4
%34 = load i32, i32* %5
%35 = load i32, i32* %7
%36 = call i32 @swap_char(i32* %33, i32 %34, i32 %35)
br label %37
37: ; preds = %24
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %20
40: ; preds = %11, %20
ret void
}

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