void testKnnNearestIndices() {
  unsigned nObs;
  unsigned nDims;
  double *inputsP;
  double *targetsP;
  makeData(&nObs, &nDims, &inputsP, &targetsP);
  const unsigned nNeighbors = 2;
  unsigned nnIndices[nNeighbors];
  Knn_nearest_indices(nObs, nDims, inputsP, nNeighbors, nnIndices, 0);
  UnitTest_expect_eq_unsigned((1), (nnIndices[0]), __func__, 42);
  UnitTest_expect_eq_unsigned((2), (nnIndices[1]), __func__, 43);
  Knn_nearest_indices(nObs, nDims, inputsP, nNeighbors, nnIndices, 1);
  UnitTest_expect_eq_unsigned((0), (nnIndices[0]), __func__, 47);
  UnitTest_expect_eq_unsigned((2), (nnIndices[1]), __func__, 48);
  Knn_nearest_indices(nObs, nDims, inputsP, nNeighbors, nnIndices, 2);
  UnitTest_expect_eq_unsigned((1), (nnIndices[0]), __func__, 52);
  UnitTest_expect_eq_unsigned((3), (nnIndices[1]), __func__, 53);
  Knn_nearest_indices(nObs, nDims, inputsP, nNeighbors, nnIndices, 3);
  UnitTest_expect_eq_unsigned((2), (nnIndices[0]), __func__, 57);
  UnitTest_expect_eq_unsigned((1), (nnIndices[1]), __func__, 58);
}


x86 assembly (clang, -O0):
<testKnnNearestIndices>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x4(%rbp),%rdi
lea    -0x8(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rcx
mov    $0x0,%al
call   1030 <makeData@plt>
movl   $0x2,-0x1c(%rbp)
mov    %rsp,%rax
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    $0x2,%ecx
lea    -0x30(%rbp),%r8
xor    %r9d,%r9d
mov    $0x0,%al
call   1050 <Knn_nearest_indices@plt>
mov    -0x30(%rbp),%esi
mov    $0x1,%edi
lea    0xe77(%rip),%rdx
mov    $0x2a,%ecx
mov    $0x0,%al
call   1040 <UnitTest_expect_eq_unsigned@plt>
mov    -0x2c(%rbp),%esi
mov    $0x2,%edi
lea    0xe5c(%rip),%rdx
mov    $0x2b,%ecx
mov    $0x0,%al
call   1040 <UnitTest_expect_eq_unsigned@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    $0x2,%ecx
lea    -0x30(%rbp),%r8
mov    $0x1,%r9d
mov    $0x0,%al
call   1050 <Knn_nearest_indices@plt>
mov    -0x30(%rbp),%esi
xor    %edi,%edi
lea    0xe24(%rip),%rdx
mov    $0x2f,%ecx
mov    $0x0,%al
call   1040 <UnitTest_expect_eq_unsigned@plt>
mov    -0x2c(%rbp),%esi
mov    $0x2,%edi
lea    0xe09(%rip),%rdx
mov    $0x30,%ecx
mov    $0x0,%al
call   1040 <UnitTest_expect_eq_unsigned@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    $0x2,%r9d
lea    -0x30(%rbp),%r8
mov    %r9d,%ecx
mov    $0x0,%al
call   1050 <Knn_nearest_indices@plt>
mov    -0x30(%rbp),%esi
mov    $0x1,%edi
lea    0xdd0(%rip),%rdx
mov    $0x34,%ecx
mov    $0x0,%al
call   1040 <UnitTest_expect_eq_unsigned@plt>
mov    -0x2c(%rbp),%esi
mov    $0x3,%edi
lea    0xdb5(%rip),%rdx
mov    $0x35,%ecx
mov    $0x0,%al
call   1040 <UnitTest_expect_eq_unsigned@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    $0x2,%ecx
lea    -0x30(%rbp),%r8
mov    $0x3,%r9d
mov    $0x0,%al
call   1050 <Knn_nearest_indices@plt>
mov    -0x30(%rbp),%esi
mov    $0x2,%edi
lea    0xd7a(%rip),%rdx
mov    $0x39,%ecx
mov    $0x0,%al
call   1040 <UnitTest_expect_eq_unsigned@plt>
mov    -0x2c(%rbp),%esi
mov    $0x1,%edi
lea    0xd5f(%rip),%rdx
mov    $0x3a,%ecx
mov    $0x0,%al
call   1040 <UnitTest_expect_eq_unsigned@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testKnnNearestIndices>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
lea    0x20(%rsp),%rdx
lea    0x28(%rsp),%rcx
xor    %eax,%eax
call   1030 <makeData@plt>
mov    %rsp,%r15
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
mov    0x20(%rsp),%rdx
lea    0x10(%rsp),%r14
mov    $0x2,%ecx
mov    %r14,%r8
xor    %r9d,%r9d
xor    %eax,%eax
call   1050 <Knn_nearest_indices@plt>
mov    0x10(%rsp),%esi
lea    0xe7a(%rip),%rbx
mov    $0x1,%edi
mov    %rbx,%rdx
mov    $0x2a,%ecx
xor    %eax,%eax
call   1040 <UnitTest_expect_eq_unsigned@plt>
mov    0x14(%rsp),%esi
mov    $0x2,%edi
mov    %rbx,%rdx
mov    $0x2b,%ecx
xor    %eax,%eax
call   1040 <UnitTest_expect_eq_unsigned@plt>
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
mov    0x20(%rsp),%rdx
mov    $0x2,%ecx
mov    %r14,%r8
mov    $0x1,%r9d
xor    %eax,%eax
call   1050 <Knn_nearest_indices@plt>
mov    0x10(%rsp),%esi
xor    %edi,%edi
mov    %rbx,%rdx
mov    $0x2f,%ecx
xor    %eax,%eax
call   1040 <UnitTest_expect_eq_unsigned@plt>
mov    0x14(%rsp),%esi
mov    $0x2,%edi
mov    %rbx,%rdx
mov    $0x30,%ecx
xor    %eax,%eax
call   1040 <UnitTest_expect_eq_unsigned@plt>
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
mov    0x20(%rsp),%rdx
mov    $0x2,%ecx
mov    %r14,%r8
mov    $0x2,%r9d
xor    %eax,%eax
call   1050 <Knn_nearest_indices@plt>
mov    0x10(%rsp),%esi
mov    $0x1,%edi
mov    %rbx,%rdx
mov    $0x34,%ecx
xor    %eax,%eax
call   1040 <UnitTest_expect_eq_unsigned@plt>
mov    0x14(%rsp),%esi
mov    $0x3,%edi
mov    %rbx,%rdx
mov    $0x35,%ecx
xor    %eax,%eax
call   1040 <UnitTest_expect_eq_unsigned@plt>
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
mov    0x20(%rsp),%rdx
mov    $0x2,%ecx
mov    %r14,%r8
mov    $0x3,%r9d
xor    %eax,%eax
call   1050 <Knn_nearest_indices@plt>
mov    0x10(%rsp),%esi
mov    $0x2,%edi
mov    %rbx,%rdx
mov    $0x39,%ecx
xor    %eax,%eax
call   1040 <UnitTest_expect_eq_unsigned@plt>
mov    0x14(%rsp),%esi
mov    $0x1,%edi
mov    %rbx,%rdx
mov    $0x3a,%ecx
xor    %eax,%eax
call   1040 <UnitTest_expect_eq_unsigned@plt>
mov    %r15,%rsp
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__func__.testKnnNearestIndices = [22 x i8] c"testKnnNearestIndices\00"
define void @testKnnNearestIndices() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double*
%4 = alloca double*
%5 = alloca i32
%6 = alloca i8*
%7 = call i32 (i32*, i32*, double**, double**, ...) bitcast (i32 (...)* @makeData to i32 (i32*, i32*, double**, double**, ...)*)(i32* %1, i32* %2, double** %3, double** %4)
store i32 2, i32* %5
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %6
%9 = alloca i32, i64 2
%10 = load i32, i32* %1
%11 = load i32, i32* %2
%12 = load double*, double** %3
%13 = call i32 (i32, i32, double*, i32, i32*, i32, ...) bitcast (i32 (...)* @Knn_nearest_indices to i32 (i32, i32, double*, i32, i32*, i32, ...)*)(i32 %10, i32 %11, double* %12, i32 2, i32* %9, i32 0)
%14 = getelementptr inbounds i32, i32* %9, i64 0
%15 = load i32, i32* %14
%16 = call i32 (i32, i32, i8*, i32, ...) bitcast (i32 (...)* @UnitTest_expect_eq_unsigned to i32 (i32, i32, i8*, i32, ...)*)(i32 1, i32 %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @__func__.testKnnNearestIndices, i64 0, i64 0), i32 42)
%17 = getelementptr inbounds i32, i32* %9, i64 1
%18 = load i32, i32* %17
%19 = call i32 (i32, i32, i8*, i32, ...) bitcast (i32 (...)* @UnitTest_expect_eq_unsigned to i32 (i32, i32, i8*, i32, ...)*)(i32 2, i32 %18, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @__func__.testKnnNearestIndices, i64 0, i64 0), i32 43)
%20 = load i32, i32* %1
%21 = load i32, i32* %2
%22 = load double*, double** %3
%23 = call i32 (i32, i32, double*, i32, i32*, i32, ...) bitcast (i32 (...)* @Knn_nearest_indices to i32 (i32, i32, double*, i32, i32*, i32, ...)*)(i32 %20, i32 %21, double* %22, i32 2, i32* %9, i32 1)
%24 = getelementptr inbounds i32, i32* %9, i64 0
%25 = load i32, i32* %24
%26 = call i32 (i32, i32, i8*, i32, ...) bitcast (i32 (...)* @UnitTest_expect_eq_unsigned to i32 (i32, i32, i8*, i32, ...)*)(i32 0, i32 %25, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @__func__.testKnnNearestIndices, i64 0, i64 0), i32 47)
%27 = getelementptr inbounds i32, i32* %9, i64 1
%28 = load i32, i32* %27
%29 = call i32 (i32, i32, i8*, i32, ...) bitcast (i32 (...)* @UnitTest_expect_eq_unsigned to i32 (i32, i32, i8*, i32, ...)*)(i32 2, i32 %28, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @__func__.testKnnNearestIndices, i64 0, i64 0), i32 48)
%30 = load i32, i32* %1
%31 = load i32, i32* %2
%32 = load double*, double** %3
%33 = call i32 (i32, i32, double*, i32, i32*, i32, ...) bitcast (i32 (...)* @Knn_nearest_indices to i32 (i32, i32, double*, i32, i32*, i32, ...)*)(i32 %30, i32 %31, double* %32, i32 2, i32* %9, i32 2)
%34 = getelementptr inbounds i32, i32* %9, i64 0
%35 = load i32, i32* %34
%36 = call i32 (i32, i32, i8*, i32, ...) bitcast (i32 (...)* @UnitTest_expect_eq_unsigned to i32 (i32, i32, i8*, i32, ...)*)(i32 1, i32 %35, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @__func__.testKnnNearestIndices, i64 0, i64 0), i32 52)
%37 = getelementptr inbounds i32, i32* %9, i64 1
%38 = load i32, i32* %37
%39 = call i32 (i32, i32, i8*, i32, ...) bitcast (i32 (...)* @UnitTest_expect_eq_unsigned to i32 (i32, i32, i8*, i32, ...)*)(i32 3, i32 %38, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @__func__.testKnnNearestIndices, i64 0, i64 0), i32 53)
%40 = load i32, i32* %1
%41 = load i32, i32* %2
%42 = load double*, double** %3
%43 = call i32 (i32, i32, double*, i32, i32*, i32, ...) bitcast (i32 (...)* @Knn_nearest_indices to i32 (i32, i32, double*, i32, i32*, i32, ...)*)(i32 %40, i32 %41, double* %42, i32 2, i32* %9, i32 3)
%44 = getelementptr inbounds i32, i32* %9, i64 0
%45 = load i32, i32* %44
%46 = call i32 (i32, i32, i8*, i32, ...) bitcast (i32 (...)* @UnitTest_expect_eq_unsigned to i32 (i32, i32, i8*, i32, ...)*)(i32 2, i32 %45, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @__func__.testKnnNearestIndices, i64 0, i64 0), i32 57)
%47 = getelementptr inbounds i32, i32* %9, i64 1
%48 = load i32, i32* %47
%49 = call i32 (i32, i32, i8*, i32, ...) bitcast (i32 (...)* @UnitTest_expect_eq_unsigned to i32 (i32, i32, i8*, i32, ...)*)(i32 1, i32 %48, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @__func__.testKnnNearestIndices, i64 0, i64 0), i32 58)
%50 = load i8*, i8** %6
ret void
}

LLVM IR (-O2):
@__func__.testKnnNearestIndices = [22 x i8] c"testKnnNearestIndices\00"
define void @testKnnNearestIndices() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double*
%4 = alloca double*
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast double** %3 to i8*
%8 = bitcast double** %4 to i8*
%9 = call i32 (i32*, i32*, double**, double**, ...) bitcast (i32 (...)* @makeData to i32 (i32*, i32*, double**, double**, ...)*)(i32* %1, i32* %2, double** %3, double** %4)
%10 = call i8* @llvm.stacksave()
%11 = alloca [2 x i32]
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%13 = load i32, i32* %1
%14 = load i32, i32* %2
%15 = load double*, double** %3
%16 = call i32 (i32, i32, double*, i32, i32*, i32, ...) bitcast (i32 (...)* @Knn_nearest_indices to i32 (i32, i32, double*, i32, i32*, i32, ...)*)(i32 %13, i32 %14, double* %15, i32 2, i32* %12, i32 0)
%17 = load i32, i32* %12
%18 = call i32 (i32, i32, i8*, i32, ...) bitcast (i32 (...)* @UnitTest_expect_eq_unsigned to i32 (i32, i32, i8*, i32, ...)*)(i32 1, i32 %17, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @__func__.testKnnNearestIndices, i64 0, i64 0), i32 42)
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 1
%20 = load i32, i32* %19
%21 = call i32 (i32, i32, i8*, i32, ...) bitcast (i32 (...)* @UnitTest_expect_eq_unsigned to i32 (i32, i32, i8*, i32, ...)*)(i32 2, i32 %20, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @__func__.testKnnNearestIndices, i64 0, i64 0), i32 43)
%22 = load i32, i32* %1
%23 = load i32, i32* %2
%24 = load double*, double** %3
%25 = call i32 (i32, i32, double*, i32, i32*, i32, ...) bitcast (i32 (...)* @Knn_nearest_indices to i32 (i32, i32, double*, i32, i32*, i32, ...)*)(i32 %22, i32 %23, double* %24, i32 2, i32* %12, i32 1)
%26 = load i32, i32* %12
%27 = call i32 (i32, i32, i8*, i32, ...) bitcast (i32 (...)* @UnitTest_expect_eq_unsigned to i32 (i32, i32, i8*, i32, ...)*)(i32 0, i32 %26, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @__func__.testKnnNearestIndices, i64 0, i64 0), i32 47)
%28 = load i32, i32* %19
%29 = call i32 (i32, i32, i8*, i32, ...) bitcast (i32 (...)* @UnitTest_expect_eq_unsigned to i32 (i32, i32, i8*, i32, ...)*)(i32 2, i32 %28, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @__func__.testKnnNearestIndices, i64 0, i64 0), i32 48)
%30 = load i32, i32* %1
%31 = load i32, i32* %2
%32 = load double*, double** %3
%33 = call i32 (i32, i32, double*, i32, i32*, i32, ...) bitcast (i32 (...)* @Knn_nearest_indices to i32 (i32, i32, double*, i32, i32*, i32, ...)*)(i32 %30, i32 %31, double* %32, i32 2, i32* %12, i32 2)
%34 = load i32, i32* %12
%35 = call i32 (i32, i32, i8*, i32, ...) bitcast (i32 (...)* @UnitTest_expect_eq_unsigned to i32 (i32, i32, i8*, i32, ...)*)(i32 1, i32 %34, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @__func__.testKnnNearestIndices, i64 0, i64 0), i32 52)
%36 = load i32, i32* %19
%37 = call i32 (i32, i32, i8*, i32, ...) bitcast (i32 (...)* @UnitTest_expect_eq_unsigned to i32 (i32, i32, i8*, i32, ...)*)(i32 3, i32 %36, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @__func__.testKnnNearestIndices, i64 0, i64 0), i32 53)
%38 = load i32, i32* %1
%39 = load i32, i32* %2
%40 = load double*, double** %3
%41 = call i32 (i32, i32, double*, i32, i32*, i32, ...) bitcast (i32 (...)* @Knn_nearest_indices to i32 (i32, i32, double*, i32, i32*, i32, ...)*)(i32 %38, i32 %39, double* %40, i32 2, i32* %12, i32 3)
%42 = load i32, i32* %12
%43 = call i32 (i32, i32, i8*, i32, ...) bitcast (i32 (...)* @UnitTest_expect_eq_unsigned to i32 (i32, i32, i8*, i32, ...)*)(i32 2, i32 %42, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @__func__.testKnnNearestIndices, i64 0, i64 0), i32 57)
%44 = load i32, i32* %19
%45 = call i32 (i32, i32, i8*, i32, ...) bitcast (i32 (...)* @UnitTest_expect_eq_unsigned to i32 (i32, i32, i8*, i32, ...)*)(i32 1, i32 %44, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @__func__.testKnnNearestIndices, i64 0, i64 0), i32 58)
ret void
}