#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 calc_distance(int *, int *);
double naive_solve(int pts[][2], int n) {
  double min_d = DBL_MAX, d = 0;
  if (n <= 1) {
    return min_d;
  } else if (n == 2) {
    min_d = calc_distance(pts[0], pts[1]);
  } else {
    for (int i = 0; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        d = calc_distance(pts[i], pts[j]);
        if (d < min_d) {
          min_d = d;
        }
      }
    }
  }
  return min_d;
}


x86 assembly (clang, -O0):
<naive_solve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    0x2eba(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x1,-0x14(%rbp)
jg     1150 <naive_solve+0x40>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    121d <naive_solve+0x10d>
cmpl   $0x2,-0x14(%rbp)
jne    1175 <naive_solve+0x65>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1030 <calc_distance@plt>
movsd  %xmm0,-0x20(%rbp)
jmp    120e <naive_solve+0xfe>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1209 <naive_solve+0xf9>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f6 <naive_solve+0xe6>
mov    -0x10(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
movslq -0x30(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
call   1030 <calc_distance@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11e3 <naive_solve+0xd3>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11e8 <naive_solve+0xd8>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1191 <naive_solve+0x81>
jmp    11fb <naive_solve+0xeb>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    117c <naive_solve+0x6c>
jmp    120e <naive_solve+0xfe>
jmp    1213 <naive_solve+0x103>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<naive_solve>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,(%rsp)
mov    0x2eb7(%rip),%rax
movsd  (%rax),%xmm1
cmp    $0x2,%esi
jge    1145 <naive_solve+0x35>
movapd %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
jne    1162 <naive_solve+0x52>
mov    (%rsp),%rdi
lea    0x8(%rdi),%rsi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <calc_distance@plt>
mov    %esi,%r12d
mov    (%rsp),%rax
lea    0x8(%rax),%r13
mov    $0x1,%ebp
xor    %r14d,%r14d
mov    %r12,0x8(%rsp)
jmp    119a <naive_solve+0x8a>
nopl   0x0(%rax)
movapd %xmm1,%xmm0
add    $0x1,%rbp
add    $0x8,%r13
movapd %xmm0,%xmm1
mov    0x8(%rsp),%r12
cmp    %r12,%r14
je     1136 <naive_solve+0x26>
mov    %r14,%rax
add    $0x1,%r14
cmp    %r12,%r14
jae    1180 <naive_solve+0x70>
mov    (%rsp),%rcx
lea    (%rcx,%rax,8),%r15
mov    %r13,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x10(%rsp)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <calc_distance@plt>
minsd  0x10(%rsp),%xmm0
add    $0x8,%rbx
add    $0xffffffffffffffff,%r12
movapd %xmm0,%xmm1
cmp    %r12,%rbp
jne    11c0 <naive_solve+0xb0>
jmp    1184 <naive_solve+0x74>

LLVM IR (-O0):
@DBL_MAX = global double 0.000000e+00
define double @naive_solve([2 x i32]* %0, i32 %1) {
%3 = alloca double
%4 = alloca [2 x i32]*
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
store [2 x i32]* %0, [2 x i32]** %4
store i32 %1, i32* %5
%10 = load double, double* @DBL_MAX
store double %10, double* %6
store double 0.000000e+00, double* %7
%11 = load i32, i32* %5
%12 = icmp sle i32 %11, 1
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load double, double* %6
store double %14, double* %3
br label %67
15: ; preds = %2
%16 = load i32, i32* %5
%17 = icmp eq i32 %16, 2
br i1 %17, label %18, label %26
18: ; preds = %15
%19 = load [2 x i32]*, [2 x i32]** %4
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %19, i64 0
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %20, i64 0, i64 0
%22 = load [2 x i32]*, [2 x i32]** %4
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %22, i64 1
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %23, i64 0, i64 0
%25 = call double @calc_distance(i32* %21, i32* %24)
store double %25, double* %6
br label %64
26: ; preds = %15
store i32 0, i32* %8
br label %27
27: ; preds = %60, %26
%28 = load i32, i32* %8
%29 = load i32, i32* %5
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %63
31: ; preds = %27
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
store i32 %33, i32* %9
br label %34
34: ; preds = %56, %31
%35 = load i32, i32* %9
%36 = load i32, i32* %5
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %59
38: ; preds = %34
%39 = load [2 x i32]*, [2 x i32]** %4
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [2 x i32], [2 x i32]* %39, i64 %41
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %42, i64 0, i64 0
%44 = load [2 x i32]*, [2 x i32]** %4
%45 = load i32, i32* %9
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [2 x i32], [2 x i32]* %44, i64 %46
%48 = getelementptr inbounds [2 x i32], [2 x i32]* %47, i64 0, i64 0
%49 = call double @calc_distance(i32* %43, i32* %48)
store double %49, double* %7
%50 = load double, double* %7
%51 = load double, double* %6
%52 = fcmp olt double %50, %51
br i1 %52, label %53, label %55
53: ; preds = %38
%54 = load double, double* %7
store double %54, double* %6
br label %55
55: ; preds = %53, %38
br label %56
56: ; preds = %55
%57 = load i32, i32* %9
%58 = add nsw i32 %57, 1
store i32 %58, i32* %9
br label %34
59: ; preds = %34
br label %60
60: ; preds = %59
%61 = load i32, i32* %8
%62 = add nsw i32 %61, 1
store i32 %62, i32* %8
br label %27
63: ; preds = %27
br label %64
64: ; preds = %63, %18
br label %65
65: ; preds = %64
%66 = load double, double* %6
store double %66, double* %3
br label %67
67: ; preds = %65, %13
%68 = load double, double* %3
ret double %68
}

LLVM IR (-O2):
@DBL_MAX = global double 0.000000e+00
define double @naive_solve([2 x i32]* %0, i32 %1) {
%3 = load double, double* @DBL_MAX
%4 = icmp slt i32 %1, 2
br i1 %4, label %35, label %5
5: ; preds = %2
%6 = icmp eq i32 %1, 2
br i1 %6, label %10, label %7
7: ; preds = %5
%8 = zext i32 %1 to i64
%9 = zext i32 %1 to i64
br label %18
10: ; preds = %5
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %0, i64 0, i64 0
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %0, i64 1, i64 0
%13 = tail call double @calc_distance(i32* %11, i32* %12)
br label %35
14: ; preds = %26, %18
%15 = phi double [ %21, %18 ], [ %32, %26 ]
%16 = add nuw nsw i64 %20, 1
%17 = icmp eq i64 %22, %9
br i1 %17, label %35, label %18
18: ; preds = %7, %14
%19 = phi i64 [ 0, %7 ], [ %22, %14 ]
%20 = phi i64 [ 1, %7 ], [ %16, %14 ]
%21 = phi double [ %3, %7 ], [ %15, %14 ]
%22 = add nuw nsw i64 %19, 1
%23 = icmp ult i64 %22, %8
br i1 %23, label %24, label %14
24: ; preds = %18
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %0, i64 %19, i64 0
br label %26
26: ; preds = %24, %26
%27 = phi i64 [ %20, %24 ], [ %33, %26 ]
%28 = phi double [ %21, %24 ], [ %32, %26 ]
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %0, i64 %27, i64 0
%30 = tail call double @calc_distance(i32* %25, i32* %29)
%31 = fcmp olt double %30, %28
%32 = select i1 %31, double %30, double %28
%33 = add nuw nsw i64 %27, 1
%34 = icmp eq i64 %33, %9
br i1 %34, label %14, label %26
35: ; preds = %14, %10, %2
%36 = phi double [ %3, %2 ], [ %13, %10 ], [ %15, %14 ]
ret double %36
}