#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*/ permutation_set_permutation_array(int *, int *, int);
void permutation_visit(int *permutation_array, int *value_array, int *level,
                       int N, int k) {
  int i;
  (*level)++;
  value_array[k] = *level;
  if (*level == N) {
    permutation_set_permutation_array(permutation_array, value_array, N);
  } else {
    for (i = 0; i < N; i++) {
      if (value_array[i] == 0)
        permutation_visit(permutation_array, value_array, level, N, i);
    }
  }
  (*level)--;
  value_array[k] = 0;
}


x86 assembly (clang, -O0):
<permutation_visit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
cmp    -0x1c(%rbp),%eax
jne    117b <permutation_visit+0x5b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <permutation_set_permutation_array@plt>
jmp    11d0 <permutation_visit+0xb0>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11cb <permutation_visit+0xab>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    11b8 <permutation_visit+0x98>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x24(%rbp),%r8d
call   1040 <permutation_visit@plt>
jmp    11bd <permutation_visit+0x9d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1182 <permutation_visit+0x62>
jmp    11d0 <permutation_visit+0xb0>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<permutation_visit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
mov    (%rdx),%eax
add    $0x1,%eax
mov    %eax,(%rdx)
movslq %r8d,%rbp
mov    %eax,(%rsi,%rbp,4)
cmp    %ecx,(%rdx)
jne    1154 <permutation_visit+0x34>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %ecx,%edx
call   1030 <permutation_set_permutation_array@plt>
jmp    1186 <permutation_visit+0x66>
test   %ecx,%ecx
jle    1186 <permutation_visit+0x66>
mov    %ecx,%r13d
xor    %ebx,%ebx
jmp    1169 <permutation_visit+0x49>
nop
add    $0x1,%rbx
cmp    %rbx,%r13
je     1186 <permutation_visit+0x66>
cmpl   $0x0,(%r12,%rbx,4)
jne    1160 <permutation_visit+0x40>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    %r13d,%ecx
mov    %ebx,%r8d
call   1040 <permutation_visit@plt>
jmp    1160 <permutation_visit+0x40>
addl   $0xffffffff,(%r14)
movl   $0x0,(%r12,%rbp,4)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @permutation_visit(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
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
%12 = load i32*, i32** %8
%13 = load i32, i32* %12
%14 = add nsw i32 %13, 1
store i32 %14, i32* %12
%15 = load i32*, i32** %8
%16 = load i32, i32* %15
%17 = load i32*, i32** %7
%18 = load i32, i32* %10
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
store i32 %16, i32* %20
%21 = load i32*, i32** %8
%22 = load i32, i32* %21
%23 = load i32, i32* %9
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %30
25: ; preds = %5
%26 = load i32*, i32** %6
%27 = load i32*, i32** %7
%28 = load i32, i32* %9
%29 = call i32 @permutation_set_permutation_array(i32* %26, i32* %27, i32 %28)
br label %53
30: ; preds = %5
store i32 0, i32* %11
br label %31
31: ; preds = %49, %30
%32 = load i32, i32* %11
%33 = load i32, i32* %9
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %52
35: ; preds = %31
%36 = load i32*, i32** %7
%37 = load i32, i32* %11
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = load i32, i32* %39
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %35
%43 = load i32*, i32** %6
%44 = load i32*, i32** %7
%45 = load i32*, i32** %8
%46 = load i32, i32* %9
%47 = load i32, i32* %11
br label %48
48: ; preds = %42, %35
br label %49
49: ; preds = %48
%50 = load i32, i32* %11
%51 = add nsw i32 %50, 1
store i32 %51, i32* %11
br label %31
52: ; preds = %31
br label %53
53: ; preds = %52, %25
%54 = load i32*, i32** %8
%55 = load i32, i32* %54
%56 = add nsw i32 %55, -1
store i32 %56, i32* %54
%57 = load i32*, i32** %7
%58 = load i32, i32* %10
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %57, i64 %59
store i32 0, i32* %60
ret void
}

LLVM IR (-O2):
define void @permutation_visit(i32* %0, i32* %1, i32* nocapture %2, i32 %3, i32 %4) {
%6 = load i32, i32* %2
%7 = add nsw i32 %6, 1
store i32 %7, i32* %2
%8 = sext i32 %4 to i64
%9 = getelementptr inbounds i32, i32* %1, i64 %8
store i32 %7, i32* %9
%10 = load i32, i32* %2
%11 = icmp eq i32 %10, %3
br i1 %11, label %16, label %12
12: ; preds = %5
%13 = icmp sgt i32 %3, 0
br i1 %13, label %14, label %28
14: ; preds = %12
%15 = zext i32 %3 to i64
br label %18
16: ; preds = %5
%17 = tail call i32 @permutation_set_permutation_array(i32* %0, i32* %1, i32 %3)
br label %28
18: ; preds = %14, %25
%19 = phi i64 [ 0, %14 ], [ %26, %25 ]
%20 = getelementptr inbounds i32, i32* %1, i64 %19
%21 = load i32, i32* %20
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = trunc i64 %19 to i32
tail call void @permutation_visit(i32* %0, i32* %1, i32* %2, i32 %3, i32 %24)
br label %25
25: ; preds = %18, %23
%26 = add nuw nsw i64 %19, 1
%27 = icmp eq i64 %26, %15
br i1 %27, label %28, label %18
28: ; preds = %25, %12, %16
%29 = load i32, i32* %2
%30 = add nsw i32 %29, -1
store i32 %30, i32* %2
store i32 0, i32* %9
ret void
}