#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*/ print_error(int, int, char *, ...);
double sqrt(double);
double weighted_euclidean_distance_ASF(const double *x, const double *y,
                                       const double *weights, const double *max,
                                       const double *min, int dimension) {
  double check_sum = 0;
  for (int i = 0; i < dimension; i++) {
    if (weights[i] > 1 || weights[i] < 0)
      print_error(
          1, 3, "Weight  ", i,
          " exceeded bounds 0 to -1 at weighted_euclidean_distance_ASF");
    check_sum += weights[i];
  }
  if (check_sum > 1)
    print_error(
        1, 1,
        "Weights exceeded bounds 0 to -1 at weighted_euclidean_distance_ASF");
  double sum = 0;
  for (int i = 0; i < dimension; i++) {
    double frac = (x[i] - y[i]) / (max[i] - min[i]);
    sum += weights[i] * frac * frac;
  }
  return sqrt(sum);
}


x86 assembly (clang, -O0):
<weighted_euclidean_distance_ASF>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    11d7 <weighted_euclidean_distance_ASF+0xb7>
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xe90(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     1190 <weighted_euclidean_distance_ASF+0x70>
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
xorps  %xmm0,%xmm0
ucomisd (%rax,%rcx,8),%xmm0
jbe    11b2 <weighted_euclidean_distance_ASF+0x92>
mov    -0x3c(%rbp),%ecx
mov    $0x1,%edi
mov    $0x3,%esi
lea    0xe64(%rip),%rdx
lea    0xe6d(%rip),%r8
mov    $0x0,%al
call   1030 <print_error@plt>
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    114f <weighted_euclidean_distance_ASF+0x2f>
movsd  -0x38(%rbp),%xmm0
movsd  0xe1c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1203 <weighted_euclidean_distance_ASF+0xe3>
mov    $0x1,%esi
lea    0xe17(%rip),%rdx
mov    %esi,%edi
mov    $0x0,%al
call   1030 <print_error@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1292 <weighted_euclidean_distance_ASF+0x172>
mov    -0x8(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x4c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x28(%rbp),%rax
movslq -0x4c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mulsd  -0x58(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1212 <weighted_euclidean_distance_ASF+0xf2>
movsd  -0x48(%rbp),%xmm0
call   1040 <sqrt@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<weighted_euclidean_distance_ASF>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xorpd  %xmm0,%xmm0
test   %r9d,%r9d
jle    1246 <weighted_euclidean_distance_ASF+0x126>
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rdi,%r13
mov    %r8,0x8(%rsp)
mov    %r9d,0x4(%rsp)
mov    %r9d,%r14d
movsd  0xea4(%rip),%xmm2
xor    %ebp,%ebp
xorpd  %xmm3,%xmm3
jmp    11b7 <weighted_euclidean_distance_ASF+0x97>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x1,%edi
mov    $0x3,%esi
lea    0xe8f(%rip),%rdx
mov    %ebp,%ecx
lea    0xe96(%rip),%r8
xor    %eax,%eax
movsd  %xmm3,0x10(%rsp)
call   1030 <print_error@plt>
movsd  0x10(%rsp),%xmm3
movsd  0xe5b(%rip),%xmm2
movsd  (%rbx,%rbp,8),%xmm0
addsd  %xmm0,%xmm3
add    $0x1,%rbp
cmp    %rbp,%r14
je     11ce <weighted_euclidean_distance_ASF+0xae>
movsd  (%rbx,%rbp,8),%xmm0
ucomisd %xmm2,%xmm0
ja     1170 <weighted_euclidean_distance_ASF+0x50>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    11aa <weighted_euclidean_distance_ASF+0x8a>
jmp    1170 <weighted_euclidean_distance_ASF+0x50>
ucomisd 0xe2a(%rip),%xmm3
jbe    11f0 <weighted_euclidean_distance_ASF+0xd0>
lea    0xe3a(%rip),%rdx
mov    $0x1,%edi
mov    $0x1,%esi
xor    %eax,%eax
call   1030 <print_error@plt>
cmpl   $0x0,0x4(%rsp)
mov    0x8(%rsp),%rcx
xorpd  %xmm0,%xmm0
jle    1246 <weighted_euclidean_distance_ASF+0x126>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  0x0(%r13,%rax,8),%xmm1
subsd  (%r12,%rax,8),%xmm1
movsd  (%r15,%rax,8),%xmm2
subsd  (%rcx,%rax,8),%xmm2
divsd  %xmm2,%xmm1
movsd  (%rbx,%rax,8),%xmm2
mulsd  %xmm1,%xmm2
mulsd  %xmm1,%xmm2
addsd  %xmm2,%xmm0
add    $0x1,%rax
cmp    %rax,%r14
jne    1210 <weighted_euclidean_distance_ASF+0xf0>
ucomisd 0xdba(%rip),%xmm0
jb     1263 <weighted_euclidean_distance_ASF+0x143>
sqrtsd %xmm0,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <sqrt@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"Weight \00"
@.str.1 = [60 x i8] c" exceeded bounds 0 to -1 at weighted_euclidean_distance_ASF\00"
@.str.2 = [67 x i8] c"Weights exceeded bounds 0 to -1 at weighted_euclidean_distance_ASF\00"
define double @weighted_euclidean_distance_ASF(double* %0, double* %1, double* %2, double* %3, double* %4, i32 %5) {
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
%11 = alloca double*
%12 = alloca i32
%13 = alloca double
%14 = alloca i32
%15 = alloca double
%16 = alloca i32
%17 = alloca double
store double* %0, double** %7
store double* %1, double** %8
store double* %2, double** %9
store double* %3, double** %10
store double* %4, double** %11
store i32 %5, i32* %12
store double 0.000000e+00, double* %13
store i32 0, i32* %14
br label %18
18: ; preds = %47, %6
%19 = load i32, i32* %14
%20 = load i32, i32* %12
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %50
22: ; preds = %18
%23 = load double*, double** %9
%24 = load i32, i32* %14
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
%27 = load double, double* %26
%28 = fcmp ogt double %27, 1.000000e+00
br i1 %28, label %36, label %29
29: ; preds = %22
%30 = load double*, double** %9
%31 = load i32, i32* %14
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
%34 = load double, double* %33
%35 = fcmp olt double %34, 0.000000e+00
br i1 %35, label %36, label %39
36: ; preds = %29, %22
%37 = load i32, i32* %14
%38 = call i32 (i32, i32, i8*, ...) @print_error(i32 1, i32 3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %37, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0))
br label %39
39: ; preds = %36, %29
%40 = load double*, double** %9
%41 = load i32, i32* %14
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
%44 = load double, double* %43
%45 = load double, double* %13
%46 = fadd double %45, %44
store double %46, double* %13
br label %47
47: ; preds = %39
%48 = load i32, i32* %14
%49 = add nsw i32 %48, 1
store i32 %49, i32* %14
br label %18
50: ; preds = %18
%51 = load double, double* %13
%52 = fcmp ogt double %51, 1.000000e+00
br i1 %52, label %53, label %55
53: ; preds = %50
%54 = call i32 (i32, i32, i8*, ...) @print_error(i32 1, i32 1, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.2, i64 0, i64 0))
br label %55
55: ; preds = %53, %50
store double 0.000000e+00, double* %15
store i32 0, i32* %16
br label %56
56: ; preds = %94, %55
%57 = load i32, i32* %16
%58 = load i32, i32* %12
%59 = icmp slt i32 %57, %58
br i1 %59, label %60, label %97
60: ; preds = %56
%61 = load double*, double** %7
%62 = load i32, i32* %16
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds double, double* %61, i64 %63
%65 = load double, double* %64
%66 = load double*, double** %8
%67 = load i32, i32* %16
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds double, double* %66, i64 %68
%70 = load double, double* %69
%71 = fsub double %65, %70
%72 = load double*, double** %10
%73 = load i32, i32* %16
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds double, double* %72, i64 %74
%76 = load double, double* %75
%77 = load double*, double** %11
%78 = load i32, i32* %16
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds double, double* %77, i64 %79
%81 = load double, double* %80
%82 = fsub double %76, %81
%83 = fdiv double %71, %82
store double %83, double* %17
%84 = load double*, double** %9
%85 = load i32, i32* %16
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds double, double* %84, i64 %86
%88 = load double, double* %87
%89 = load double, double* %17
%90 = fmul double %88, %89
%91 = load double, double* %17
%92 = load double, double* %15
%93 = call double @llvm.fmuladd.f64(double %90, double %91, double %92)
store double %93, double* %15
br label %94
94: ; preds = %60
%95 = load i32, i32* %16
%96 = add nsw i32 %95, 1
store i32 %96, i32* %16
br label %56
97: ; preds = %56
%98 = load double, double* %15
%99 = call double @sqrt(double %98)
ret double %99
}

LLVM IR (-O2):
@.str = [9 x i8] c"Weight \00"
@.str.1 = [60 x i8] c" exceeded bounds 0 to -1 at weighted_euclidean_distance_ASF\00"
@.str.2 = [67 x i8] c"Weights exceeded bounds 0 to -1 at weighted_euclidean_distance_ASF\00"
define double @weighted_euclidean_distance_ASF(double* nocapture %0, double* nocapture %1, double* nocapture %2, double* nocapture %3, double* nocapture %4, i32 %5) {
%7 = icmp sgt i32 %5, 0
br i1 %7, label %8, label %34
8: ; preds = %6
%9 = zext i32 %5 to i64
br label %12
10: ; preds = %24
%11 = fcmp ogt double %26, 1.000000e+00
br i1 %11, label %29, label %31
12: ; preds = %8, %24
%13 = phi i64 [ 0, %8 ], [ %27, %24 ]
%14 = phi double [ 0.000000e+00, %8 ], [ %26, %24 ]
%15 = getelementptr inbounds double, double* %2, i64 %13
%16 = load double, double* %15
%17 = fcmp ogt double %16, 1.000000e+00
%18 = fcmp olt double %16, 0.000000e+00
%19 = or i1 %17, %18
br i1 %19, label %20, label %24
20: ; preds = %12
%21 = trunc i64 %13 to i32
%22 = tail call i32 (i32, i32, i8*, ...) @print_error(i32 1, i32 3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %21, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0))
%23 = load double, double* %15
br label %24
24: ; preds = %12, %20
%25 = phi double [ %16, %12 ], [ %23, %20 ]
%26 = fadd double %14, %25
%27 = add nuw nsw i64 %13, 1
%28 = icmp eq i64 %27, %9
br i1 %28, label %10, label %12
29: ; preds = %10
%30 = tail call i32 (i32, i32, i8*, ...) @print_error(i32 1, i32 1, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %29, %10
br i1 %7, label %32, label %34
32: ; preds = %31
%33 = zext i32 %5 to i64
br label %37
34: ; preds = %37, %6, %31
%35 = phi double [ 0.000000e+00, %31 ], [ 0.000000e+00, %6 ], [ %54, %37 ]
%36 = tail call double @sqrt(double %35)
ret double %36
37: ; preds = %32, %37
%38 = phi i64 [ 0, %32 ], [ %55, %37 ]
%39 = phi double [ 0.000000e+00, %32 ], [ %54, %37 ]
%40 = getelementptr inbounds double, double* %0, i64 %38
%41 = load double, double* %40
%42 = getelementptr inbounds double, double* %1, i64 %38
%43 = load double, double* %42
%44 = fsub double %41, %43
%45 = getelementptr inbounds double, double* %3, i64 %38
%46 = load double, double* %45
%47 = getelementptr inbounds double, double* %4, i64 %38
%48 = load double, double* %47
%49 = fsub double %46, %48
%50 = fdiv double %44, %49
%51 = getelementptr inbounds double, double* %2, i64 %38
%52 = load double, double* %51
%53 = fmul double %52, %50
%54 = tail call double @llvm.fmuladd.f64(double %53, double %50, double %39)
%55 = add nuw nsw i64 %38, 1
%56 = icmp eq i64 %55, %33
br i1 %56, label %34, label %37
}