#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 */
scalar_t__ dist_closed_point(double *, int, double **, int);
int /*<<< orphan*/ free_matrix(void **, int);
int /*<<< orphan*/ free_vector(double *);
double *get_max_values(double **, int, int);
double *get_min_values(double **, int, int);
double **normalize_front(double **, int, int, double *, double *);
int sqrt(double);
double inverted_generational_distance(double **front, int frontlen,
                                      double **truefront, int truefrontlen,
                                      int vlen) {
  size_t i;
  double res, sum;
  double *min_values, *max_values;
  double **norm_front, **norm_truefront;
  min_values = get_min_values(truefront, truefrontlen, vlen);
  max_values = get_max_values(truefront, truefrontlen, vlen);
  norm_front = normalize_front(front, frontlen, vlen, min_values, max_values);
  norm_truefront =
      normalize_front(truefront, truefrontlen, vlen, min_values, max_values);
  sum = 0;
  for (i = 0; i < truefrontlen; i++) {
    sum += dist_closed_point(norm_truefront[i], vlen, norm_front, frontlen);
  }
  res = (sqrt(sum)) / truefrontlen;
  free_matrix((void **)norm_front, frontlen);
  free_matrix((void **)norm_truefront, truefrontlen);
  free_vector(min_values);
  free_vector(max_values);
  return (res);
}


x86 assembly (clang, -O0):
<inverted_generational_distance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1050 <get_min_values@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1060 <get_max_values@plt>
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x40(%rbp),%rcx
mov    -0x48(%rbp),%r8
call   1090 <normalize_front@plt>
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x40(%rbp),%rcx
mov    -0x48(%rbp),%r8
call   1090 <normalize_front@plt>
mov    %rax,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmp    %rcx,%rax
jae    1242 <inverted_generational_distance+0xd2>
mov    -0x58(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%esi
mov    -0x50(%rbp),%rdx
mov    -0xc(%rbp),%ecx
call   1080 <dist_closed_point@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11f6 <inverted_generational_distance+0x86>
movsd  -0x38(%rbp),%xmm0
call   1070 <sqrt@plt>
cltd
idivl  -0x1c(%rbp)
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <free_matrix@plt>
mov    -0x58(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <free_matrix@plt>
mov    -0x40(%rbp),%rdi
call   1040 <free_vector@plt>
mov    -0x48(%rbp),%rdi
call   1040 <free_vector@plt>
movsd  -0x30(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inverted_generational_distance>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,%ebx
mov    %ecx,%r15d
mov    %rdx,%rbp
mov    %rdx,0x10(%rsp)
mov    %esi,%r13d
mov    %rdi,0x8(%rsp)
mov    %rdx,%rdi
mov    %ecx,%esi
mov    %r8d,%edx
call   1050 <get_min_values@plt>
mov    %rax,%r12
mov    %rbp,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
call   1060 <get_max_values@plt>
mov    %rax,%r14
mov    0x8(%rsp),%rdi
mov    %r13d,%esi
mov    %ebx,%edx
mov    %r12,%rcx
mov    %rax,%r8
call   1090 <normalize_front@plt>
mov    %rax,%rbp
mov    0x10(%rsp),%rdi
mov    %r15d,%esi
mov    %ebx,%edx
mov    %r12,0x10(%rsp)
mov    %r12,%rcx
mov    %r14,0x20(%rsp)
mov    %r14,%r8
call   1090 <normalize_front@plt>
mov    %rax,%r14
test   %r15d,%r15d
mov    %r15d,0x1c(%rsp)
je     1250 <inverted_generational_distance+0xe0>
movslq %r15d,%r15
xorps  %xmm0,%xmm0
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,0x8(%rsp)
mov    (%r14,%r12,8),%rdi
mov    %ebx,%esi
mov    %rbp,%rdx
mov    %r13d,%ecx
call   1080 <dist_closed_point@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
add    $0x1,%r12
cmp    %r12,%r15
jne    1210 <inverted_generational_distance+0xa0>
jmp    1253 <inverted_generational_distance+0xe3>
xorps  %xmm0,%xmm0
call   1070 <sqrt@plt>
cltd
mov    0x1c(%rsp),%ebx
idiv   %ebx
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %rbp,%rdi
mov    %r13d,%esi
call   1030 <free_matrix@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <free_matrix@plt>
mov    0x10(%rsp),%rdi
call   1040 <free_vector@plt>
mov    0x20(%rsp),%rdi
call   1040 <free_vector@plt>
movsd  0x8(%rsp),%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @inverted_generational_distance(double** %0, i32 %1, double** %2, i32 %3, i32 %4) {
%6 = alloca double**
%7 = alloca i32
%8 = alloca double**
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
%12 = alloca double
%13 = alloca double
%14 = alloca double*
%15 = alloca double*
%16 = alloca double**
%17 = alloca double**
store double** %0, double*** %6
store i32 %1, i32* %7
store double** %2, double*** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%18 = load double**, double*** %8
%19 = load i32, i32* %9
%20 = load i32, i32* %10
%21 = call double* @get_min_values(double** %18, i32 %19, i32 %20)
store double* %21, double** %14
%22 = load double**, double*** %8
%23 = load i32, i32* %9
%24 = load i32, i32* %10
%25 = call double* @get_max_values(double** %22, i32 %23, i32 %24)
store double* %25, double** %15
%26 = load double**, double*** %6
%27 = load i32, i32* %7
%28 = load i32, i32* %10
%29 = load double*, double** %14
%30 = load double*, double** %15
%31 = call double** @normalize_front(double** %26, i32 %27, i32 %28, double* %29, double* %30)
store double** %31, double*** %16
%32 = load double**, double*** %8
%33 = load i32, i32* %9
%34 = load i32, i32* %10
%35 = load double*, double** %14
%36 = load double*, double** %15
%37 = call double** @normalize_front(double** %32, i32 %33, i32 %34, double* %35, double* %36)
store double** %37, double*** %17
store double 0.000000e+00, double* %13
store i64 0, i64* %11
br label %38
38: ; preds = %55, %5
%39 = load i64, i64* %11
%40 = load i32, i32* %9
%41 = sext i32 %40 to i64
%42 = icmp ult i64 %39, %41
br i1 %42, label %43, label %58
43: ; preds = %38
%44 = load double**, double*** %17
%45 = load i64, i64* %11
%46 = getelementptr inbounds double*, double** %44, i64 %45
%47 = load double*, double** %46
%48 = load i32, i32* %10
%49 = load double**, double*** %16
%50 = load i32, i32* %7
%51 = call i64 @dist_closed_point(double* %47, i32 %48, double** %49, i32 %50)
%52 = sitofp i64 %51 to double
%53 = load double, double* %13
%54 = fadd double %53, %52
store double %54, double* %13
br label %55
55: ; preds = %43
%56 = load i64, i64* %11
%57 = add i64 %56, 1
store i64 %57, i64* %11
br label %38
58: ; preds = %38
%59 = load double, double* %13
%60 = call i32 @sqrt(double %59)
%61 = load i32, i32* %9
%62 = sdiv i32 %60, %61
%63 = sitofp i32 %62 to double
store double %63, double* %12
%64 = load double**, double*** %16
%65 = bitcast double** %64 to i8**
%66 = load i32, i32* %7
%67 = call i32 @free_matrix(i8** %65, i32 %66)
%68 = load double**, double*** %17
%69 = bitcast double** %68 to i8**
%70 = load i32, i32* %9
%71 = call i32 @free_matrix(i8** %69, i32 %70)
%72 = load double*, double** %14
%73 = call i32 @free_vector(double* %72)
%74 = load double*, double** %15
%75 = call i32 @free_vector(double* %74)
%76 = load double, double* %12
ret double %76
}

LLVM IR (-O2):
define double @inverted_generational_distance(double** %0, i32 %1, double** %2, i32 %3, i32 %4) {
%6 = tail call double* @get_min_values(double** %2, i32 %3, i32 %4)
%7 = tail call double* @get_max_values(double** %2, i32 %3, i32 %4)
%8 = tail call double** @normalize_front(double** %0, i32 %1, i32 %4, double* %6, double* %7)
%9 = tail call double** @normalize_front(double** %2, i32 %3, i32 %4, double* %6, double* %7)
%10 = icmp eq i32 %3, 0
br i1 %10, label %23, label %11
11: ; preds = %5
%12 = sext i32 %3 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ %21, %13 ], [ 0, %11 ]
%15 = phi double [ %20, %13 ], [ 0.000000e+00, %11 ]
%16 = getelementptr inbounds double*, double** %9, i64 %14
%17 = load double*, double** %16
%18 = tail call i64 @dist_closed_point(double* %17, i32 %4, double** %8, i32 %1)
%19 = sitofp i64 %18 to double
%20 = fadd double %15, %19
%21 = add nuw i64 %14, 1
%22 = icmp eq i64 %21, %12
br i1 %22, label %23, label %13
23: ; preds = %13, %5
%24 = phi double [ 0.000000e+00, %5 ], [ %20, %13 ]
%25 = tail call i32 @sqrt(double %24)
%26 = sdiv i32 %25, %3
%27 = sitofp i32 %26 to double
%28 = bitcast double** %8 to i8**
%29 = tail call i32 @free_matrix(i8** %28, i32 %1)
%30 = bitcast double** %9 to i8**
%31 = tail call i32 @free_matrix(i8** %30, i32 %3)
%32 = tail call i32 @free_vector(double* %6)
%33 = tail call i32 @free_vector(double* %7)
ret double %27
}