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


x86 assembly (clang, -O0):
<dist_closed_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    0x2eb3(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1197 <dist_closed_point+0x87>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0xc(%rbp),%edx
call   1030 <squared_dist@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1184 <dist_closed_point+0x74>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1189 <dist_closed_point+0x79>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    113d <dist_closed_point+0x2d>
movsd  -0x30(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dist_closed_point>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2ebd(%rip),%rax
movsd  (%rax),%xmm1
test   %ecx,%ecx
jle    116a <dist_closed_point+0x5a>
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%r12
mov    %ecx,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x8(%rsp)
mov    (%r14,%rbx,8),%rsi
mov    %r12,%rdi
mov    %r15d,%edx
call   1030 <squared_dist@plt>
minsd  0x8(%rsp),%xmm0
add    $0x1,%rbx
movapd %xmm0,%xmm1
cmp    %rbx,%rbp
jne    1140 <dist_closed_point+0x30>
jmp    116e <dist_closed_point+0x5e>
movapd %xmm1,%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_closed_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 = %32, %4
%14 = load i32, i32* %9
%15 = load i32, i32* %8
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %35
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 double @squared_dist(double* %18, double* %23, i32 %24)
store double %25, double* %10
%26 = load double, double* %10
%27 = load double, double* %11
%28 = fcmp olt double %26, %27
br i1 %28, label %29, label %31
29: ; preds = %17
%30 = load double, double* %10
store double %30, double* %11
br label %31
31: ; preds = %29, %17
br label %32
32: ; preds = %31
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
br label %13
35: ; preds = %13
%36 = load double, double* %11
ret double %36
}

LLVM IR (-O2):
@DBL_MAX = global double 0.000000e+00
define double @dist_closed_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 %19
7: ; preds = %4
%8 = zext i32 %3 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %17, %9 ]
%11 = phi double [ %5, %7 ], [ %16, %9 ]
%12 = getelementptr inbounds double*, double** %2, i64 %10
%13 = load double*, double** %12
%14 = tail call double @squared_dist(double* %0, double* %13, i32 %1)
%15 = fcmp olt double %14, %11
%16 = select i1 %15, double %14, double %11
%17 = add nuw nsw i64 %10, 1
%18 = icmp eq i64 %17, %8
br i1 %18, label %19, label %9
19: ; preds = %9, %4
%20 = phi double [ %5, %4 ], [ %16, %9 ]
ret double %20
}