#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 */
double DBL_MAX;
double squared_dist(double *, double *, int);
int /*<<< orphan*/ vectors_are_equal(double *, double *, int);
double dist_nearest_point(double *X, int vlen, double **front, int frontlen) {
  int i;
  double dist, mindist;
  mindist = DBL_MAX;
  for (i = 0; i < frontlen; i++) {
    if (!vectors_are_equal(X, front[i], vlen)) {
      dist = squared_dist(X, front[i], vlen);
      if (dist < mindist)
        mindist = dist;
    }
  }
  return mindist;
}


x86 assembly (clang, -O0):
<dist_nearest_point>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    0x2ea3(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11cd <dist_nearest_point+0xad>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0xc(%rbp),%edx
call   1030 <vectors_are_equal@plt>
cmp    $0x0,%eax
jne    11ba <dist_nearest_point+0x9a>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0xc(%rbp),%edx
call   1040 <squared_dist@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11b5 <dist_nearest_point+0x95>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11ba <dist_nearest_point+0x9a>
jmp    11bf <dist_nearest_point+0x9f>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    114d <dist_nearest_point+0x2d>
movsd  -0x30(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dist_nearest_point>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2ead(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,0x8(%rsp)
test   %ecx,%ecx
jle    119f <dist_nearest_point+0x7f>
mov    %rdx,%r14
mov    %esi,%r12d
mov    %rdi,%rbx
mov    %ecx,%r15d
xor    %ebp,%ebp
jmp    1169 <dist_nearest_point+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%r15
je     119f <dist_nearest_point+0x7f>
mov    (%r14,%rbp,8),%rsi
mov    %rbx,%rdi
mov    %r12d,%edx
call   1030 <vectors_are_equal@plt>
test   %eax,%eax
jne    1160 <dist_nearest_point+0x40>
mov    (%r14,%rbp,8),%rsi
mov    %rbx,%rdi
mov    %r12d,%edx
call   1040 <squared_dist@plt>
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jbe    1160 <dist_nearest_point+0x40>
movsd  %xmm0,0x8(%rsp)
jmp    1160 <dist_nearest_point+0x40>
movsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@DBL_MAX = global double 0.000000e+00
define double @dist_nearest_point(double* %0, i32 %1, double** %2, i32 %3) {
%5 = alloca double*
%6 = alloca i32
%7 = alloca double**
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca double
store double* %0, double** %5
store i32 %1, i32* %6
store double** %2, double*** %7
store i32 %3, i32* %8
%12 = load double, double* @DBL_MAX
store double %12, double* %11
store i32 0, i32* %9
br label %13
13: ; preds = %43, %4
%14 = load i32, i32* %9
%15 = load i32, i32* %8
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %46
17: ; preds = %13
%18 = load double*, double** %5
%19 = load double**, double*** %7
%20 = load i32, i32* %9
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double*, double** %19, i64 %21
%23 = load double*, double** %22
%24 = load i32, i32* %6
%25 = call i32 @vectors_are_equal(double* %18, double* %23, i32 %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %42, label %27
27: ; preds = %17
%28 = load double*, double** %5
%29 = load double**, double*** %7
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double*, double** %29, i64 %31
%33 = load double*, double** %32
%34 = load i32, i32* %6
%35 = call double @squared_dist(double* %28, double* %33, i32 %34)
store double %35, double* %10
%36 = load double, double* %10
%37 = load double, double* %11
%38 = fcmp olt double %36, %37
br i1 %38, label %39, label %41
39: ; preds = %27
%40 = load double, double* %10
store double %40, double* %11
br label %41
41: ; preds = %39, %27
br label %42
42: ; preds = %41, %17
br label %43
43: ; preds = %42
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
store i32 %45, i32* %9
br label %13
46: ; preds = %13
%47 = load double, double* %11
ret double %47
}

LLVM IR (-O2):
@DBL_MAX = global double 0.000000e+00
define double @dist_nearest_point(double* %0, i32 %1, double** nocapture %2, i32 %3) {
%5 = load double, double* @DBL_MAX
%6 = icmp sgt i32 %3, 0
br i1 %6, label %7, label %25
7: ; preds = %4
%8 = zext i32 %3 to i64
br label %9
9: ; preds = %7, %21
%10 = phi i64 [ 0, %7 ], [ %23, %21 ]
%11 = phi double [ %5, %7 ], [ %22, %21 ]
%12 = getelementptr inbounds double*, double** %2, i64 %10
%13 = load double*, double** %12
%14 = tail call i32 @vectors_are_equal(double* %0, double* %13, i32 %1)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %9
%17 = load double*, double** %12
%18 = tail call double @squared_dist(double* %0, double* %17, i32 %1)
%19 = fcmp olt double %18, %11
br i1 %19, label %20, label %21
20: ; preds = %16
br label %21
21: ; preds = %9, %20, %16
%22 = phi double [ %11, %9 ], [ %18, %20 ], [ %11, %16 ]
%23 = add nuw nsw i64 %10, 1
%24 = icmp eq i64 %23, %8
br i1 %24, label %25, label %9
25: ; preds = %21, %4
%26 = phi double [ %5, %4 ], [ %22, %21 ]
ret double %26
}