#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 checkThePositions(int *);
int /*<<< orphan*/ swap(int *, int, int);
void permute(int arr[8], int index, int length, int *count) {
  if (index == length) {
    if (checkThePositions(arr) == 1)
      (*count)++;
  } else {
    for (int i = index; i < length; i++) {
      swap(arr, index, i);
      permute(arr, index + 1, length, count);
      swap(arr, index, 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    %rcx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    1174 <permute+0x44>
mov    -0x8(%rbp),%rdi
call   1040 <checkThePositions@plt>
cmp    $0x1,%eax
jne    116f <permute+0x3f>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    11cd <permute+0x9d>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11c8 <permute+0x98>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1050 <swap@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1030 <permute@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1050 <swap@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117a <permute+0x4a>
jmp    11cd <permute+0x9d>
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    %rcx,%r14
mov    %rdi,%rbx
cmp    %edx,%esi
jne    1158 <permute+0x28>
mov    %rbx,%rdi
call   1040 <checkThePositions@plt>
cmp    $0x1,%eax
jne    11a3 <permute+0x73>
addl   $0x1,(%r14)
jmp    11a3 <permute+0x73>
jge    11a3 <permute+0x73>
mov    %edx,%r15d
mov    %esi,%r13d
lea    0x1(%r13),%r12d
mov    %esi,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r13d,%esi
mov    %ebp,%edx
call   1050 <swap@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r15d,%edx
mov    %r14,%rcx
call   1030 <permute@plt>
mov    %rbx,%rdi
mov    %r13d,%esi
mov    %ebp,%edx
call   1050 <swap@plt>
add    $0x1,%ebp
cmp    %ebp,%r15d
jne    1170 <permute+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @permute(i32* %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%10 = load i32, i32* %6
%11 = load i32, i32* %7
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %22
13: ; preds = %4
%14 = load i32*, i32** %5
%15 = call i32 @checkThePositions(i32* %14)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i32*, i32** %8
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1
store i32 %20, i32* %18
br label %21
21: ; preds = %17, %13
br label %46
22: ; preds = %4
%23 = load i32, i32* %6
store i32 %23, i32* %9
br label %24
24: ; preds = %42, %22
%25 = load i32, i32* %9
%26 = load i32, i32* %7
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %45
28: ; preds = %24
%29 = load i32*, i32** %5
%30 = load i32, i32* %6
%31 = load i32, i32* %9
%32 = call i32 @swap(i32* %29, i32 %30, i32 %31)
%33 = load i32*, i32** %5
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
%36 = load i32, i32* %7
%37 = load i32*, i32** %8
%38 = load i32*, i32** %5
%39 = load i32, i32* %6
%40 = load i32, i32* %9
%41 = call i32 @swap(i32* %38, i32 %39, i32 %40)
br label %42
42: ; preds = %28
%43 = load i32, i32* %9
%44 = add nsw i32 %43, 1
store i32 %44, i32* %9
br label %24
45: ; preds = %24
br label %46
46: ; preds = %45, %21
ret void
}

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