#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*/ free(int *);
scalar_t__ has_overlap_with_same_type(double *, double *, int const, int const,
                                      double **, double const);
scalar_t__ malloc(int const);
int check_total_overlap_for_sorted(double lattice[3][3],
                                   double (*pos_original)[3],
                                   double (*pos_rotated)[3],
                                   const int types_original[],
                                   const int types_rotated[], const int num_pos,
                                   const double symprec) {
  int *found;
  int i, i_orig, i_rot;
  int search_start;
  found = NULL;
  if ((found = (int *)malloc(num_pos * sizeof(int))) == NULL) {
    ;
    return -1;
  }
  for (i = 0; i < num_pos; i++) {
    found[i] = 0;
  }
  search_start = 0;
  for (i_orig = 0; i_orig < num_pos; i_orig++) {
    while (found[search_start]) {
      search_start++;
    }
    for (i_rot = search_start; i_rot < num_pos; i_rot++) {
      if (found[i_rot]) {
        continue;
      }
      if (has_overlap_with_same_type(pos_original[i_orig], pos_rotated[i_rot],
                                     types_original[i_orig],
                                     types_rotated[i_rot], lattice, symprec)) {
        found[i_rot] = 1;
        break;
      }
    }
    if (i_rot == num_pos) {
      free(found);
      found = NULL;
      return 0;
    }
  }
  free(found);
  found = NULL;
  return 1;
}


x86 assembly (clang, -O0):
<check_total_overlap_for_sorted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9d,-0x34(%rbp)
movsd  %xmm0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movslq -0x34(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    1186 <check_total_overlap_for_sorted+0x56>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e5 <check_total_overlap_for_sorted+0x1b5>
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    11b6 <check_total_overlap_for_sorted+0x86>
mov    -0x48(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    118d <check_total_overlap_for_sorted+0x5d>
movl   $0x0,-0x58(%rbp)
movl   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    12cd <check_total_overlap_for_sorted+0x19d>
jmp    11d5 <check_total_overlap_for_sorted+0xa5>
mov    -0x48(%rbp),%rax
movslq -0x58(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     11f5 <check_total_overlap_for_sorted+0xc5>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    11d5 <check_total_overlap_for_sorted+0xa5>
mov    -0x58(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    1291 <check_total_overlap_for_sorted+0x161>
mov    -0x48(%rbp),%rax
movslq -0x54(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     121e <check_total_overlap_for_sorted+0xee>
jmp    1283 <check_total_overlap_for_sorted+0x153>
mov    -0x18(%rbp),%rdi
movslq -0x50(%rbp),%rax
imul   $0x18,%rax,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
movslq -0x54(%rbp),%rax
imul   $0x18,%rax,%rax
add    %rax,%rsi
mov    -0x28(%rbp),%rax
movslq -0x50(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x30(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x10(%rbp),%r8
movsd  -0x40(%rbp),%xmm0
call   1050 <has_overlap_with_same_type@plt>
cmp    $0x0,%rax
je     127e <check_total_overlap_for_sorted+0x14e>
mov    -0x48(%rbp),%rax
movslq -0x54(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
jmp    1291 <check_total_overlap_for_sorted+0x161>
jmp    1283 <check_total_overlap_for_sorted+0x153>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11fb <check_total_overlap_for_sorted+0xcb>
mov    -0x54(%rbp),%eax
cmp    -0x34(%rbp),%eax
jne    12ba <check_total_overlap_for_sorted+0x18a>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x48(%rbp)
movl   $0x0,-0x4(%rbp)
jmp    12e5 <check_total_overlap_for_sorted+0x1b5>
jmp    12bf <check_total_overlap_for_sorted+0x18f>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    11c4 <check_total_overlap_for_sorted+0x94>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x48(%rbp)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_total_overlap_for_sorted>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
movsd  %xmm0,0x40(%rsp)
mov    %r9d,%ebp
mov    %r8,0x38(%rsp)
mov    %rcx,0x30(%rsp)
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,0x28(%rsp)
lea    0x0(,%rbp,4),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     12ca <check_total_overlap_for_sorted+0x18a>
mov    %rax,%rbx
mov    $0x1,%r14d
test   %ebp,%ebp
jle    12d5 <check_total_overlap_for_sorted+0x195>
mov    %r12,0x10(%rsp)
mov    %ebp,%eax
mov    %rax,0x18(%rsp)
lea    0x0(,%rax,4),%rdx
xor    %eax,%eax
mov    %rax,(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
movabs $0xffffffff00000000,%rax
ff ff ff
movabs $0x100000000,%r13
xor    %r14d,%r14d
mov    %r15,0x8(%rsp)
mov    %r14,%r12
shl    $0x20,%r12
add    %rax,%r12
mov    %r14d,%ecx
movslq %r14d,%r14
add    $0xffffffffffffffff,%r14
cs nopw 0x0(%rax,%rax,1)
mov    %ecx,%eax
add    %r13,%r12
cmpl   $0x0,0x4(%rbx,%r14,4)
lea    0x1(%r14),%r14
lea    0x1(%rax),%ecx
jne    11f0 <check_total_overlap_for_sorted+0xb0>
mov    %r14d,%ecx
cmp    %ebp,%r14d
jge    129a <check_total_overlap_for_sorted+0x15a>
mov    (%rsp),%rcx
lea    (%rcx,%rcx,2),%rcx
mov    0x10(%rsp),%rdx
lea    (%rdx,%rcx,8),%rcx
mov    %rcx,0x20(%rsp)
sar    $0x20,%r12
cltq
lea    (%rax,%rax,2),%rax
lea    (%r15,%rax,8),%r15
jmp    1251 <check_total_overlap_for_sorted+0x111>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r12
add    $0x18,%r15
cmp    %r12d,%ebp
je     12d2 <check_total_overlap_for_sorted+0x192>
cmpl   $0x0,(%rbx,%r12,4)
jne    1240 <check_total_overlap_for_sorted+0x100>
mov    0x30(%rsp),%rax
mov    (%rsp),%rcx
mov    (%rax,%rcx,4),%edx
mov    0x38(%rsp),%rax
mov    (%rax,%r12,4),%ecx
mov    0x20(%rsp),%rdi
mov    %r15,%rsi
mov    0x28(%rsp),%r8
movsd  0x40(%rsp),%xmm0
call   1060 <has_overlap_with_same_type@plt>
test   %rax,%rax
je     1240 <check_total_overlap_for_sorted+0x100>
movl   $0x1,(%rbx,%r12,4)
mov    %r12d,%ecx
mov    0x8(%rsp),%r15
cmp    %ebp,%ecx
je     12d2 <check_total_overlap_for_sorted+0x192>
mov    (%rsp),%rcx
add    $0x1,%rcx
mov    %rcx,%rax
mov    %rcx,(%rsp)
cmp    0x18(%rsp),%rcx
movabs $0xffffffff00000000,%rax
ff ff ff
jne    11d2 <check_total_overlap_for_sorted+0x92>
mov    $0x1,%r14d
jmp    12d5 <check_total_overlap_for_sorted+0x195>
mov    $0xffffffff,%r14d
jmp    12dd <check_total_overlap_for_sorted+0x19d>
xor    %r14d,%r14d
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @check_total_overlap_for_sorted([3 x double]* %0, [3 x double]* %1, [3 x double]* %2, i32* %3, i32* %4, i32 %5, double %6) {
%8 = alloca i32
%9 = alloca [3 x double]*
%10 = alloca [3 x double]*
%11 = alloca [3 x double]*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca double
%16 = alloca i32*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store [3 x double]* %0, [3 x double]** %9
store [3 x double]* %1, [3 x double]** %10
store [3 x double]* %2, [3 x double]** %11
store i32* %3, i32** %12
store i32* %4, i32** %13
store i32 %5, i32* %14
store double %6, double* %15
store i32* null, i32** %16
%21 = load i32, i32* %14
%22 = sext i32 %21 to i64
%23 = mul i64 %22, 4
%24 = trunc i64 %23 to i32
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i32*
store i32* %26, i32** %16
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %29
28: ; preds = %7
store i32 -1, i32* %8
br label %121
29: ; preds = %7
store i32 0, i32* %17
br label %30
30: ; preds = %39, %29
%31 = load i32, i32* %17
%32 = load i32, i32* %14
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %42
34: ; preds = %30
%35 = load i32*, i32** %16
%36 = load i32, i32* %17
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
store i32 0, i32* %38
br label %39
39: ; preds = %34
%40 = load i32, i32* %17
%41 = add nsw i32 %40, 1
store i32 %41, i32* %17
br label %30
42: ; preds = %30
store i32 0, i32* %20
store i32 0, i32* %18
br label %43
43: ; preds = %115, %42
%44 = load i32, i32* %18
%45 = load i32, i32* %14
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %118
47: ; preds = %43
br label %48
48: ; preds = %55, %47
%49 = load i32*, i32** %16
%50 = load i32, i32* %20
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %49, i64 %51
%53 = load i32, i32* %52
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %48
%56 = load i32, i32* %20
%57 = add nsw i32 %56, 1
store i32 %57, i32* %20
br label %48
58: ; preds = %48
%59 = load i32, i32* %20
store i32 %59, i32* %19
br label %60
60: ; preds = %104, %58
%61 = load i32, i32* %19
%62 = load i32, i32* %14
%63 = icmp slt i32 %61, %62
br i1 %63, label %64, label %107
64: ; preds = %60
%65 = load i32*, i32** %16
%66 = load i32, i32* %19
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i32, i32* %65, i64 %67
%69 = load i32, i32* %68
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %64
br label %104
72: ; preds = %64
%73 = load [3 x double]*, [3 x double]** %10
%74 = load i32, i32* %18
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [3 x double], [3 x double]* %73, i64 %75
%77 = getelementptr inbounds [3 x double], [3 x double]* %76, i64 0, i64 0
%78 = load [3 x double]*, [3 x double]** %11
%79 = load i32, i32* %19
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [3 x double], [3 x double]* %78, i64 %80
%82 = getelementptr inbounds [3 x double], [3 x double]* %81, i64 0, i64 0
%83 = load i32*, i32** %12
%84 = load i32, i32* %18
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i32, i32* %83, i64 %85
%87 = load i32, i32* %86
%88 = load i32*, i32** %13
%89 = load i32, i32* %19
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i32, i32* %88, i64 %90
%92 = load i32, i32* %91
%93 = load [3 x double]*, [3 x double]** %9
%94 = bitcast [3 x double]* %93 to double**
%95 = load double, double* %15
%96 = call i64 @has_overlap_with_same_type(double* %77, double* %82, i32 %87, i32 %92, double** %94, double %95)
%97 = icmp ne i64 %96, 0
br i1 %97, label %98, label %103
98: ; preds = %72
%99 = load i32*, i32** %16
%100 = load i32, i32* %19
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds i32, i32* %99, i64 %101
store i32 1, i32* %102
br label %107
103: ; preds = %72
br label %104
104: ; preds = %103, %71
%105 = load i32, i32* %19
%106 = add nsw i32 %105, 1
store i32 %106, i32* %19
br label %60
107: ; preds = %98, %60
%108 = load i32, i32* %19
%109 = load i32, i32* %14
%110 = icmp eq i32 %108, %109
br i1 %110, label %111, label %114
111: ; preds = %107
%112 = load i32*, i32** %16
%113 = call i32 @free(i32* %112)
store i32* null, i32** %16
store i32 0, i32* %8
br label %121
114: ; preds = %107
br label %115
115: ; preds = %114
%116 = load i32, i32* %18
%117 = add nsw i32 %116, 1
store i32 %117, i32* %18
br label %43
118: ; preds = %43
%119 = load i32*, i32** %16
%120 = call i32 @free(i32* %119)
store i32* null, i32** %16
store i32 1, i32* %8
br label %121
121: ; preds = %118, %111, %28
%122 = load i32, i32* %8
ret i32 %122
}

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