#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 *, ...);
void UniquePermutation(int a[], int n, int depth, int b[], int flag[]) {
  if (depth < n) {
    int i;
    for (i = 0; i < n; i++) {
      if (flag[i] == 0) {
        b[depth] = a[i];
        flag[i] = 1;
        UniquePermutation(a, n, depth + 1, b, flag);
        flag[i] = 0;
      }
    }
  } else {
    int j;
    printf("\n");
    for (j = 0; j < n; j++) {
      printf("%d", b[j]);
    }
  }
}


x86 assembly (clang, -O0):
<UniquePermutation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d1 <UniquePermutation+0xb1>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11cc <UniquePermutation+0xac>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    11b9 <UniquePermutation+0x99>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
add    $0x1,%edx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1040 <UniquePermutation@plt>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
jmp    11be <UniquePermutation+0x9e>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114d <UniquePermutation+0x2d>
jmp    121e <UniquePermutation+0xfe>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1219 <UniquePermutation+0xf9>
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11e6 <UniquePermutation+0xc6>
jmp    121e <UniquePermutation+0xfe>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UniquePermutation>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r13
mov    %esi,%ebx
cmp    %esi,%edx
jge    11be <UniquePermutation+0x8e>
test   %ebx,%ebx
jle    11f8 <UniquePermutation+0xc8>
mov    %r8,%rbp
mov    %edx,%r12d
movslq %edx,%rax
mov    %rax,0x10(%rsp)
add    $0x1,%r12d
mov    %ebx,%eax
xor    %r14d,%r14d
mov    %rax,0x8(%rsp)
jmp    1179 <UniquePermutation+0x49>
nopl   (%rax)
add    $0x1,%r14
cmp    %r14,%rax
je     11f8 <UniquePermutation+0xc8>
cmpl   $0x0,0x0(%rbp,%r14,4)
jne    1170 <UniquePermutation+0x40>
mov    (%rdi,%r14,4),%eax
mov    0x10(%rsp),%rcx
mov    %eax,0x0(%r13,%rcx,4)
movl   $0x1,0x0(%rbp,%r14,4)
mov    %rdi,%r15
mov    %ebx,%esi
mov    %r12d,%edx
mov    %r13,%rcx
mov    %rbp,%r8
call   1050 <UniquePermutation@plt>
mov    0x8(%rsp),%rax
mov    %r15,%rdi
movl   $0x0,0x0(%rbp,%r14,4)
jmp    1170 <UniquePermutation+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %ebx,%ebx
jle    11f8 <UniquePermutation+0xc8>
mov    %ebx,%ebp
lea    0xe2b(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11e0 <UniquePermutation+0xb0>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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