#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*/ canonical_perm_ext(int *, int, int, int *, int, int *, int,
                                      int *, int, int *, int, int *, int, int *,
                                      int *, int /*<<< orphan*/, int *,
                                      int /*<<< orphan*/, int *);
int /*<<< orphan*/ copy_list(int *, int *, int);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ inverse(int *, int *, int);
scalar_t__ malloc(int);
int onpoints(int, int *, int);
void canonical_perm(int *PERM, int SGSQ, int *base, int bl, int *GS, int m,
                    int n, int *freeps, int fl, int *dummyps, int dpl, int ob,
                    int metricQ, int *CPERM) {
  int i;
  int vds;
  int mQ;
  int *repes = NULL;
  int *vrs = NULL;
  int *PERM1 = (int *)malloc(n * sizeof(int));
  int *PERM2 = (int *)malloc(n * sizeof(int));
  int *frees = (int *)malloc(fl * sizeof(int));
  int *dummies = (int *)malloc(2 * dpl * sizeof(int));
  vds = 2 * dpl;
  mQ = metricQ;
  inverse(PERM, PERM1, n);
  for (i = 0; i < fl; i++) {
    frees[i] = onpoints(freeps[i], PERM1, n);
  }
  for (i = 0; i < 2 * dpl; i++) {
    dummies[i] = onpoints(dummyps[i], PERM1, n);
  }
  canonical_perm_ext(PERM1, n, SGSQ, base, bl, GS, m, frees, fl, &vds, 1,
                     dummies, 2 * dpl, &mQ, vrs, 0, repes, 0, PERM2);
  if (PERM2[0] != 0)
    inverse(PERM2, CPERM, n);
  else
    copy_list(PERM2, CPERM, n);
  free(PERM1);
  free(PERM2);
  free(frees);
  free(dummies);
}


x86 assembly (clang, -O0):
<canonical_perm>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe8,%rsp
mov    0x48(%rbp),%rax
mov    0x40(%rbp),%eax
mov    0x38(%rbp),%eax
mov    0x30(%rbp),%eax
mov    0x28(%rbp),%rax
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %rdi,-0x30(%rbp)
mov    %esi,-0x34(%rbp)
mov    %rdx,-0x40(%rbp)
mov    %ecx,-0x44(%rbp)
mov    %r8,-0x50(%rbp)
mov    %r9d,-0x54(%rbp)
movq   $0x0,-0x68(%rbp)
movq   $0x0,-0x70(%rbp)
movslq 0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x78(%rbp)
movslq 0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x80(%rbp)
movslq 0x20(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x88(%rbp)
mov    0x30(%rbp),%eax
shl    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x90(%rbp)
mov    0x30(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x5c(%rbp)
mov    0x40(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x78(%rbp),%rsi
mov    0x10(%rbp),%edx
call   1050 <inverse@plt>
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    0x20(%rbp),%eax
jge    1272 <canonical_perm+0x112>
mov    0x18(%rbp),%rax
movslq -0x58(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x78(%rbp),%rsi
mov    0x10(%rbp),%edx
call   1080 <onpoints@plt>
mov    %eax,%edx
mov    -0x88(%rbp),%rax
movslq -0x58(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1231 <canonical_perm+0xd1>
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    0x30(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jge    12bf <canonical_perm+0x15f>
mov    0x28(%rbp),%rax
movslq -0x58(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x78(%rbp),%rsi
mov    0x10(%rbp),%edx
call   1080 <onpoints@plt>
mov    %eax,%edx
mov    -0x90(%rbp),%rax
movslq -0x58(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1279 <canonical_perm+0x119>
mov    -0x78(%rbp),%rdi
mov    0x10(%rbp),%esi
mov    -0x34(%rbp),%edx
mov    -0x40(%rbp),%rcx
mov    -0x44(%rbp),%r8d
mov    -0x50(%rbp),%r9
mov    -0x54(%rbp),%eax
mov    %eax,-0xa4(%rbp)
mov    -0x88(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    0x20(%rbp),%r13d
mov    -0x90(%rbp),%r15
mov    0x30(%rbp),%r14d
shl    $0x1,%r14d
mov    -0x70(%rbp),%r11
mov    -0x68(%rbp),%r10
mov    -0x80(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x5c(%rbp),%r12
lea    -0x60(%rbp),%rbx
xor    %eax,%eax
mov    -0xa4(%rbp),%eax
mov    %eax,(%rsp)
mov    -0xa0(%rbp),%rax
mov    %rax,0x8(%rsp)
mov    -0x98(%rbp),%rax
mov    %r13d,0x10(%rsp)
mov    %r12,0x18(%rsp)
movl   $0x1,0x20(%rsp)
mov    %r15,0x28(%rsp)
mov    %r14d,0x30(%rsp)
mov    %rbx,0x38(%rsp)
mov    %r11,0x40(%rsp)
movl   $0x0,0x48(%rsp)
mov    %r10,0x50(%rsp)
movl   $0x0,0x58(%rsp)
mov    %rax,0x60(%rsp)
call   1060 <canonical_perm_ext@plt>
mov    -0x80(%rbp),%rax
cmpl   $0x0,(%rax)
je     139f <canonical_perm+0x23f>
mov    -0x80(%rbp),%rdi
mov    0x48(%rbp),%rsi
mov    0x10(%rbp),%edx
call   1050 <inverse@plt>
jmp    13af <canonical_perm+0x24f>
mov    -0x80(%rbp),%rdi
mov    0x48(%rbp),%rsi
mov    0x10(%rbp),%edx
call   1070 <copy_list@plt>
mov    -0x78(%rbp),%rdi
call   1030 <free@plt>
mov    -0x80(%rbp),%rdi
call   1030 <free@plt>
mov    -0x88(%rbp),%rdi
call   1030 <free@plt>
mov    -0x90(%rbp),%rdi
call   1030 <free@plt>
add    $0xe8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<canonical_perm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r9,0x38(%rsp)
mov    %r8,0x28(%rsp)
mov    %ecx,0xc(%rsp)
mov    %rdx,0x20(%rsp)
mov    %esi,0x8(%rsp)
mov    %rdi,(%rsp)
mov    0xa0(%rsp),%r13d
mov    0x90(%rsp),%r15d
mov    0x80(%rsp),%r14d
lea    0x0(,%r14,4),%ebp
mov    %ebp,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1040 <malloc@plt>
mov    %rax,0x40(%rsp)
lea    0x0(,%r15,4),%edi
call   1040 <malloc@plt>
mov    %rax,%r12
lea    0x0(%r13,%r13,1),%ebp
lea    0x0(,%r13,8),%edi
call   1040 <malloc@plt>
mov    %rax,0x30(%rsp)
mov    %rbp,0x18(%rsp)
mov    %ebp,0x14(%rsp)
mov    0xb0(%rsp),%eax
mov    %eax,0x10(%rsp)
mov    (%rsp),%rdi
mov    %rbx,%rsi
mov    %r14,%r13
mov    %r14d,%edx
call   1050 <inverse@plt>
test   %r15d,%r15d
jle    124c <canonical_perm+0xec>
mov    0x88(%rsp),%r15
mov    0x90(%rsp),%eax
mov    %eax,%ebp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15,%r14,4),%edi
mov    %rbx,%rsi
mov    %r13d,%edx
call   1080 <onpoints@plt>
mov    %eax,(%r12,%r14,4)
add    $0x1,%r14
cmp    %r14,%rbp
jne    1230 <canonical_perm+0xd0>
mov    %r12,(%rsp)
mov    0xa0(%rsp),%eax
test   %eax,%eax
mov    0x30(%rsp),%r12
jle    129c <canonical_perm+0x13c>
mov    0x98(%rsp),%r14
mov    0x18(%rsp),%rax
cmp    $0x2,%eax
mov    $0x1,%r15d
cmovge %eax,%r15d
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    (%r14,%rbp,4),%edi
mov    %rbx,%rsi
mov    %r13d,%edx
call   1080 <onpoints@plt>
mov    %eax,(%r12,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1280 <canonical_perm+0x120>
sub    $0x8,%rsp
lea    0x18(%rsp),%rax
lea    0x1c(%rsp),%r10
mov    %rbx,%rdi
mov    %r13d,%esi
mov    0x10(%rsp),%edx
mov    0x28(%rsp),%rcx
mov    0x14(%rsp),%r8d
mov    0x30(%rsp),%r9
mov    0x48(%rsp),%rbp
push   %rbp
push   $0x0
push   $0x0
push   $0x0
push   $0x0
push   %rax
push   0x50(%rsp)
push   %r12
push   $0x1
push   %r10
mov    0xe8(%rsp),%eax
push   %rax
mov    0x60(%rsp),%r14
push   %r14
push   0xa0(%rsp)
call   1060 <canonical_perm_ext@plt>
add    $0x70,%rsp
cmpl   $0x0,0x0(%rbp)
je     1316 <canonical_perm+0x1b6>
mov    %rbp,%rdi
mov    0xb8(%rsp),%rsi
mov    %r13d,%edx
call   1050 <inverse@plt>
jmp    1329 <canonical_perm+0x1c9>
mov    %rbp,%rdi
mov    0xb8(%rsp),%rsi
mov    %r13d,%edx
call   1070 <copy_list@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @canonical_perm(i32* %0, i32 %1, i32* %2, i32 %3, i32* %4, i32 %5, i32 %6, i32* %7, i32 %8, i32* %9, i32 %10, i32 %11, i32 %12, i32* %13) {
%15 = alloca i32*
%16 = alloca i32
%17 = alloca i32*
%18 = alloca i32
%19 = alloca i32*
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32*
%23 = alloca i32
%24 = alloca i32*
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
%28 = alloca i32*
%29 = alloca i32
%30 = alloca i32
%31 = alloca i32
%32 = alloca i32*
%33 = alloca i32*
%34 = alloca i32*
%35 = alloca i32*
%36 = alloca i32*
%37 = alloca i32*
store i32* %0, i32** %15
store i32 %1, i32* %16
store i32* %2, i32** %17
store i32 %3, i32* %18
store i32* %4, i32** %19
store i32 %5, i32* %20
store i32 %6, i32* %21
store i32* %7, i32** %22
store i32 %8, i32* %23
store i32* %9, i32** %24
store i32 %10, i32* %25
store i32 %11, i32* %26
store i32 %12, i32* %27
store i32* %13, i32** %28
store i32* null, i32** %32
store i32* null, i32** %33
%38 = load i32, i32* %21
%39 = sext i32 %38 to i64
%40 = mul i64 %39, 4
%41 = trunc i64 %40 to i32
%42 = call i64 @malloc(i32 %41)
%43 = inttoptr i64 %42 to i32*
store i32* %43, i32** %34
%44 = load i32, i32* %21
%45 = sext i32 %44 to i64
%46 = mul i64 %45, 4
%47 = trunc i64 %46 to i32
%48 = call i64 @malloc(i32 %47)
%49 = inttoptr i64 %48 to i32*
store i32* %49, i32** %35
%50 = load i32, i32* %23
%51 = sext i32 %50 to i64
%52 = mul i64 %51, 4
%53 = trunc i64 %52 to i32
%54 = call i64 @malloc(i32 %53)
%55 = inttoptr i64 %54 to i32*
store i32* %55, i32** %36
%56 = load i32, i32* %25
%57 = mul nsw i32 2, %56
%58 = sext i32 %57 to i64
%59 = mul i64 %58, 4
%60 = trunc i64 %59 to i32
%61 = call i64 @malloc(i32 %60)
%62 = inttoptr i64 %61 to i32*
store i32* %62, i32** %37
%63 = load i32, i32* %25
%64 = mul nsw i32 2, %63
store i32 %64, i32* %30
%65 = load i32, i32* %27
store i32 %65, i32* %31
%66 = load i32*, i32** %15
%67 = load i32*, i32** %34
%68 = load i32, i32* %21
%69 = call i32 @inverse(i32* %66, i32* %67, i32 %68)
store i32 0, i32* %29
br label %70
70: ; preds = %87, %14
%71 = load i32, i32* %29
%72 = load i32, i32* %23
%73 = icmp slt i32 %71, %72
br i1 %73, label %74, label %90
74: ; preds = %70
%75 = load i32*, i32** %22
%76 = load i32, i32* %29
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i32, i32* %75, i64 %77
%79 = load i32, i32* %78
%80 = load i32*, i32** %34
%81 = load i32, i32* %21
%82 = call i32 @onpoints(i32 %79, i32* %80, i32 %81)
%83 = load i32*, i32** %36
%84 = load i32, i32* %29
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i32, i32* %83, i64 %85
store i32 %82, i32* %86
br label %87
87: ; preds = %74
%88 = load i32, i32* %29
%89 = add nsw i32 %88, 1
store i32 %89, i32* %29
br label %70
90: ; preds = %70
store i32 0, i32* %29
br label %91
91: ; preds = %109, %90
%92 = load i32, i32* %29
%93 = load i32, i32* %25
%94 = mul nsw i32 2, %93
%95 = icmp slt i32 %92, %94
br i1 %95, label %96, label %112
96: ; preds = %91
%97 = load i32*, i32** %24
%98 = load i32, i32* %29
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds i32, i32* %97, i64 %99
%101 = load i32, i32* %100
%102 = load i32*, i32** %34
%103 = load i32, i32* %21
%104 = call i32 @onpoints(i32 %101, i32* %102, i32 %103)
%105 = load i32*, i32** %37
%106 = load i32, i32* %29
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds i32, i32* %105, i64 %107
store i32 %104, i32* %108
br label %109
109: ; preds = %96
%110 = load i32, i32* %29
%111 = add nsw i32 %110, 1
store i32 %111, i32* %29
br label %91
112: ; preds = %91
%113 = load i32*, i32** %34
%114 = load i32, i32* %21
%115 = load i32, i32* %16
%116 = load i32*, i32** %17
%117 = load i32, i32* %18
%118 = load i32*, i32** %19
%119 = load i32, i32* %20
%120 = load i32*, i32** %36
%121 = load i32, i32* %23
%122 = load i32*, i32** %37
%123 = load i32, i32* %25
%124 = mul nsw i32 2, %123
%125 = load i32*, i32** %33
%126 = load i32*, i32** %32
%127 = load i32*, i32** %35
%128 = call i32 @canonical_perm_ext(i32* %113, i32 %114, i32 %115, i32* %116, i32 %117, i32* %118, i32 %119, i32* %120, i32 %121, i32* %30, i32 1, i32* %122, i32 %124, i32* %31, i32* %125, i32 0, i32* %126, i32 0, i32* %127)
%129 = load i32*, i32** %35
%130 = getelementptr inbounds i32, i32* %129, i64 0
%131 = load i32, i32* %130
%132 = icmp ne i32 %131, 0
br i1 %132, label %133, label %138
133: ; preds = %112
%134 = load i32*, i32** %35
%135 = load i32*, i32** %28
%136 = load i32, i32* %21
%137 = call i32 @inverse(i32* %134, i32* %135, i32 %136)
br label %143
138: ; preds = %112
%139 = load i32*, i32** %35
%140 = load i32*, i32** %28
%141 = load i32, i32* %21
%142 = call i32 @copy_list(i32* %139, i32* %140, i32 %141)
br label %143
143: ; preds = %138, %133
%144 = load i32*, i32** %34
%145 = call i32 @free(i32* %144)
%146 = load i32*, i32** %35
%147 = call i32 @free(i32* %146)
%148 = load i32*, i32** %36
%149 = call i32 @free(i32* %148)
%150 = load i32*, i32** %37
%151 = call i32 @free(i32* %150)
ret void
}

LLVM IR (-O2):
define void @canonical_perm(i32* %0, i32 %1, i32* %2, i32 %3, i32* %4, i32 %5, i32 %6, i32* nocapture %7, i32 %8, i32* nocapture %9, i32 %10, i32 %11, i32 %12, i32* %13) {
%15 = alloca i32
%16 = alloca i32
%17 = bitcast i32* %15 to i8*
%18 = bitcast i32* %16 to i8*
%19 = shl i32 %6, 2
%20 = tail call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i32*
%22 = tail call i64 @malloc(i32 %19)
%23 = inttoptr i64 %22 to i32*
%24 = shl i32 %8, 2
%25 = tail call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i32*
%27 = shl i32 %10, 1
%28 = shl i32 %10, 3
%29 = tail call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to i32*
store i32 %27, i32* %15
store i32 %12, i32* %16
%31 = tail call i32 @inverse(i32* %0, i32* %21, i32 %6)
%32 = icmp sgt i32 %8, 0
br i1 %32, label %33, label %35
33: ; preds = %14
%34 = zext i32 %8 to i64
br label %40
35: ; preds = %40, %14
%36 = icmp sgt i32 %10, 0
br i1 %36, label %37, label %56
37: ; preds = %35
%38 = call i32 @llvm.smax.i32(i32 %27, i32 1)
%39 = zext i32 %38 to i64
br label %48
40: ; preds = %33, %40
%41 = phi i64 [ 0, %33 ], [ %46, %40 ]
%42 = getelementptr inbounds i32, i32* %7, i64 %41
%43 = load i32, i32* %42
%44 = tail call i32 @onpoints(i32 %43, i32* %21, i32 %6)
%45 = getelementptr inbounds i32, i32* %26, i64 %41
store i32 %44, i32* %45
%46 = add nuw nsw i64 %41, 1
%47 = icmp eq i64 %46, %34
br i1 %47, label %35, label %40
48: ; preds = %37, %48
%49 = phi i64 [ 0, %37 ], [ %54, %48 ]
%50 = getelementptr inbounds i32, i32* %9, i64 %49
%51 = load i32, i32* %50
%52 = tail call i32 @onpoints(i32 %51, i32* %21, i32 %6)
%53 = getelementptr inbounds i32, i32* %30, i64 %49
store i32 %52, i32* %53
%54 = add nuw nsw i64 %49, 1
%55 = icmp eq i64 %54, %39
br i1 %55, label %56, label %48
56: ; preds = %48, %35
%57 = call i32 @canonical_perm_ext(i32* %21, i32 %6, i32 %1, i32* %2, i32 %3, i32* %4, i32 %5, i32* %26, i32 %8, i32* %15, i32 1, i32* %30, i32 %27, i32* %16, i32* null, i32 0, i32* null, i32 0, i32* %23)
%58 = load i32, i32* %23
%59 = icmp eq i32 %58, 0
br i1 %59, label %62, label %60
60: ; preds = %56
%61 = call i32 @inverse(i32* %23, i32* %13, i32 %6)
br label %64
62: ; preds = %56
%63 = call i32 @copy_list(i32* %23, i32* %13, i32 %6)
br label %64
64: ; preds = %62, %60
%65 = call i32 @free(i32* %21)
%66 = call i32 @free(i32* %23)
%67 = call i32 @free(i32* %26)
%68 = call i32 @free(i32* %30)
ret void
}