#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 get_distance(double const *const, double const *const, int);
int index_of_nearest_point(const double *const *data, int I, int t, int n) {
  int J = (I + 1) % t;
  double minimum = get_distance(data[I], data[J], n);
  for (int i = 0; i < t; i++) {
    if (i == I)
      continue;
    double distance = get_distance(data[I], data[i], n);
    if (distance < minimum) {
      minimum = distance;
      J = i;
    }
  }
  return J;
}


x86 assembly (clang, -O0):
<index_of_nearest_point>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltd
idivl  -0x10(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x14(%rbp),%edx
call   1030 <get_distance@plt>
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11d7 <index_of_nearest_point+0xc7>
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    117b <index_of_nearest_point+0x6b>
jmp    11c9 <index_of_nearest_point+0xb9>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x14(%rbp),%edx
call   1030 <get_distance@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11c4 <index_of_nearest_point+0xb4>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11c9 <index_of_nearest_point+0xb9>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115e <index_of_nearest_point+0x4e>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<index_of_nearest_point>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebp
mov    %esi,%ebx
mov    %rdi,%r15
lea    0x1(%rbx),%eax
cltd
idiv   %ebp
mov    %edx,%r12d
movslq %esi,%r13
mov    (%rdi,%r13,8),%rdi
movslq %edx,%rax
mov    (%r15,%rax,8),%rsi
mov    %ecx,0xc(%rsp)
mov    %ecx,%edx
call   1030 <get_distance@plt>
test   %ebp,%ebp
jle    1199 <index_of_nearest_point+0x89>
mov    %ebx,%ebx
mov    %ebp,%ebp
xor    %r14d,%r14d
jmp    1169 <index_of_nearest_point+0x59>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r14
cmp    %r14,%rbp
je     1199 <index_of_nearest_point+0x89>
cmp    %r14,%rbx
je     1160 <index_of_nearest_point+0x50>
mov    (%r15,%r13,8),%rdi
mov    (%r15,%r14,8),%rsi
mov    0xc(%rsp),%edx
movsd  %xmm0,0x10(%rsp)
call   1030 <get_distance@plt>
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
minsd  %xmm1,%xmm0
cmova  %r14d,%r12d
jmp    1160 <index_of_nearest_point+0x50>
mov    %r12d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @index_of_nearest_point(double** nocapture %0, i32 %1, i32 %2, i32 %3) {
%5 = add nsw i32 %1, 1
%6 = srem i32 %5, %2
%7 = sext i32 %1 to i64
%8 = getelementptr inbounds double*, double** %0, i64 %7
%9 = load double*, double** %8
%10 = sext i32 %6 to i64
%11 = getelementptr inbounds double*, double** %0, i64 %10
%12 = load double*, double** %11
%13 = tail call double @get_distance(double* %9, double* %12, i32 %3)
%14 = icmp sgt i32 %2, 0
br i1 %14, label %15, label %18
15: ; preds = %4
%16 = zext i32 %1 to i64
%17 = zext i32 %2 to i64
br label %20
18: ; preds = %34, %4
%19 = phi i32 [ %6, %4 ], [ %36, %34 ]
ret i32 %19
20: ; preds = %15, %34
%21 = phi i64 [ 0, %15 ], [ %37, %34 ]
%22 = phi i32 [ %6, %15 ], [ %36, %34 ]
%23 = phi double [ %13, %15 ], [ %35, %34 ]
%24 = icmp eq i64 %21, %16
br i1 %24, label %34, label %25
25: ; preds = %20
%26 = load double*, double** %8
%27 = getelementptr inbounds double*, double** %0, i64 %21
%28 = load double*, double** %27
%29 = tail call double @get_distance(double* %26, double* %28, i32 %3)
%30 = fcmp olt double %29, %23
%31 = select i1 %30, double %29, double %23
%32 = trunc i64 %21 to i32
%33 = select i1 %30, i32 %32, i32 %22
br label %34
34: ; preds = %20, %25
%35 = phi double [ %23, %20 ], [ %31, %25 ]
%36 = phi i32 [ %22, %20 ], [ %33, %25 ]
%37 = add nuw nsw i64 %21, 1
%38 = icmp eq i64 %37, %17
br i1 %38, label %18, label %20
}