#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 */
scalar_t__ contains(unsigned int, unsigned int *, unsigned int);
double distance(unsigned int, unsigned int, double **, unsigned int,
                unsigned int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, double, ...);
int /*<<< orphan*/ halt(char *);
int /*<<< orphan*/ stderr;
void checkCache(unsigned nNeighbors, unsigned neighborsCache[nNeighbors],
                unsigned queryIndex, unsigned nObs, unsigned nDims,
                double inputs[nObs][nDims]) {
  if (queryIndex != 2)
    return;
  fprintf(stderr, "checkCache: nNeighbors %u queryIndex %u nObs %u nDims %u\n",
          nNeighbors, queryIndex, nObs, nDims);
  unsigned underThreshold = 0;
  double threshold = 0.2813;
  fprintf(stderr, "threshold %f\n", threshold);
  for (unsigned obsIndex = 0; obsIndex < nObs; obsIndex++) {
    double d = distance(nObs, nDims, inputs, obsIndex, queryIndex);
    if (d < threshold) {
      underThreshold++;
      if (contains(nNeighbors, neighborsCache, obsIndex))
        fprintf(stderr,
                "numUnderThreshold %u obsIndex %u is in neighborsCache\n",
                underThreshold, obsIndex);
    }
  }
  fprintf(stderr, "threshold %f generates %u under threshold\n", threshold,
          underThreshold);
  halt("check for 256 indices under Threshold");
}


x86 assembly (clang, -O0):
<checkCache>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9,-0x28(%rbp)
cmpl   $0x2,-0x14(%rbp)
je     116c <checkCache+0x2c>
jmp    128e <checkCache+0x14e>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%eax
cvtsi2sd %rax,%xmm0
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xe7a(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
movsd  0xe5c(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
movsd  -0x38(%rbp),%xmm0
lea    0xe84(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    1263 <checkCache+0x123>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x3c(%rbp),%ecx
mov    -0x14(%rbp),%r8d
call   1060 <distance@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1250 <checkCache+0x110>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x3c(%rbp),%edx
call   1030 <contains@plt>
cmp    $0x0,%rax
je     124b <checkCache+0x10b>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%eax
cvtsi2sd %rax,%xmm0
mov    -0x3c(%rbp),%edx
lea    0xe0c(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
jmp    1250 <checkCache+0x110>
jmp    1255 <checkCache+0x115>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11cc <checkCache+0x8c>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
movsd  -0x38(%rbp),%xmm0
mov    -0x2c(%rbp),%edx
lea    0xe0c(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
lea    0xe29(%rip),%rdi
call   1050 <halt@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkCache>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,(%rsp)
cmp    $0x2,%edx
jne    121a <checkCache+0xda>
mov    %r9,%r14
mov    %r8d,%r13d
mov    %ecx,%ebx
mov    %edi,%r12d
mov    0x2e76(%rip),%rbp
mov    0x0(%rbp),%edi
mov    %r12d,%eax
cvtsi2sd %rax,%xmm0
lea    0xe8c(%rip),%rsi
mov    $0x2,%edx
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xeb0(%rip),%rsi
movsd  0xe66(%rip),%xmm0
mov    $0x1,%al
call   1040 <fprintf@plt>
xor    %ebp,%ebp
test   %ebx,%ebx
je     1229 <checkCache+0xe9>
xor    %r15d,%r15d
jmp    11b9 <checkCache+0x79>
add    $0x1,%r15d
cmp    %r15d,%ebx
je     1229 <checkCache+0xe9>
mov    %ebx,%edi
mov    %r13d,%esi
mov    %r14,%rdx
mov    %r15d,%ecx
mov    $0x2,%r8d
call   1060 <distance@plt>
movsd  0xe29(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    11b0 <checkCache+0x70>
add    $0x1,%ebp
mov    %r12d,%edi
mov    (%rsp),%rsi
mov    %r15d,%edx
call   1030 <contains@plt>
test   %rax,%rax
je     11b0 <checkCache+0x70>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
mov    %ebp,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
lea    0xe42(%rip),%rsi
mov    %r15d,%edx
mov    $0x1,%al
call   1040 <fprintf@plt>
jmp    11b0 <checkCache+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
movsd  0xdbf(%rip),%xmm0
mov    %ebp,%edx
mov    $0x1,%al
call   1040 <fprintf@plt>
lea    0xe61(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <halt@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [58 x i8] c"checkCache: nNeighbors %u queryIndex %u nObs %u nDims %u\0A\00"
@.str.1 = [14 x i8] c"threshold %f\0A\00"
@.str.2 = [55 x i8] c"numUnderThreshold %u obsIndex %u is in neighborsCache\0A\00"
@.str.3 = [43 x i8] c"threshold %f generates %u under threshold\0A\00"
@.str.4 = [38 x i8] c"check for 256 indices under Threshold\00"
define void @checkCache(i32 %0, i32* %1, i32 %2, i32 %3, i32 %4, double* %5) {
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca double*
%13 = alloca i32
%14 = alloca double
%15 = alloca i32
%16 = alloca double
store i32 %0, i32* %7
store i32* %1, i32** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store double* %5, double** %12
%17 = load i32, i32* %7
%18 = zext i32 %17 to i64
%19 = load i32, i32* %10
%20 = zext i32 %19 to i64
%21 = load i32, i32* %11
%22 = zext i32 %21 to i64
%23 = load i32, i32* %9
%24 = icmp ne i32 %23, 2
br i1 %24, label %25, label %26
25: ; preds = %6
br label %77
26: ; preds = %6
%27 = load i32, i32* @stderr
%28 = load i32, i32* %7
%29 = uitofp i32 %28 to double
%30 = load i32, i32* %9
%31 = load i32, i32* %10
%32 = load i32, i32* %11
%33 = call i32 (i32, i8*, double, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), double %29, i32 %30, i32 %31, i32 %32)
store i32 0, i32* %13
store double 2.813000e-01, double* %14
%34 = load i32, i32* @stderr
%35 = load double, double* %14
%36 = call i32 (i32, i8*, double, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), double %35)
store i32 0, i32* %15
br label %37
37: ; preds = %68, %26
%38 = load i32, i32* %15
%39 = load i32, i32* %10
%40 = icmp ult i32 %38, %39
br i1 %40, label %41, label %71
41: ; preds = %37
%42 = load i32, i32* %10
%43 = load i32, i32* %11
%44 = load double*, double** %12
%45 = bitcast double* %44 to double**
%46 = load i32, i32* %15
%47 = load i32, i32* %9
%48 = call double @distance(i32 %42, i32 %43, double** %45, i32 %46, i32 %47)
store double %48, double* %16
%49 = load double, double* %16
%50 = load double, double* %14
%51 = fcmp olt double %49, %50
br i1 %51, label %52, label %67
52: ; preds = %41
%53 = load i32, i32* %13
%54 = add i32 %53, 1
store i32 %54, i32* %13
%55 = load i32, i32* %7
%56 = load i32*, i32** %8
%57 = load i32, i32* %15
%58 = call i64 @contains(i32 %55, i32* %56, i32 %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %66
60: ; preds = %52
%61 = load i32, i32* @stderr
%62 = load i32, i32* %13
%63 = uitofp i32 %62 to double
%64 = load i32, i32* %15
%65 = call i32 (i32, i8*, double, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), double %63, i32 %64)
br label %66
66: ; preds = %60, %52
br label %67
67: ; preds = %66, %41
br label %68
68: ; preds = %67
%69 = load i32, i32* %15
%70 = add i32 %69, 1
store i32 %70, i32* %15
br label %37
71: ; preds = %37
%72 = load i32, i32* @stderr
%73 = load double, double* %14
%74 = load i32, i32* %13
%75 = call i32 (i32, i8*, double, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), double %73, i32 %74)
%76 = call i32 @halt(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
br label %77
77: ; preds = %71, %25
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [58 x i8] c"checkCache: nNeighbors %u queryIndex %u nObs %u nDims %u\0A\00"
@.str.1 = [14 x i8] c"threshold %f\0A\00"
@.str.2 = [55 x i8] c"numUnderThreshold %u obsIndex %u is in neighborsCache\0A\00"
@.str.3 = [43 x i8] c"threshold %f generates %u under threshold\0A\00"
@.str.4 = [38 x i8] c"check for 256 indices under Threshold\00"
define void @checkCache(i32 %0, i32* %1, i32 %2, i32 %3, i32 %4, double* %5) {
%7 = icmp eq i32 %2, 2
br i1 %7, label %8, label %39
8: ; preds = %6
%9 = load i32, i32* @stderr
%10 = uitofp i32 %0 to double
%11 = tail call i32 (i32, i8*, double, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), double %10, i32 2, i32 %3, i32 %4)
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, double, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), double 2.813000e-01)
%14 = icmp eq i32 %3, 0
br i1 %14, label %17, label %15
15: ; preds = %8
%16 = bitcast double* %5 to double**
br label %22
17: ; preds = %35, %8
%18 = phi i32 [ 0, %8 ], [ %36, %35 ]
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, double, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), double 2.813000e-01, i32 %18)
%21 = tail call i32 @halt(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
br label %39
22: ; preds = %15, %35
%23 = phi i32 [ 0, %15 ], [ %36, %35 ]
%24 = phi i32 [ 0, %15 ], [ %37, %35 ]
%25 = tail call double @distance(i32 %3, i32 %4, double** %16, i32 %24, i32 2)
%26 = fcmp olt double %25, 2.813000e-01
br i1 %26, label %27, label %35
27: ; preds = %22
%28 = add i32 %23, 1
%29 = tail call i64 @contains(i32 %0, i32* %1, i32 %24)
%30 = icmp eq i64 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %27
%32 = load i32, i32* @stderr
%33 = uitofp i32 %28 to double
%34 = tail call i32 (i32, i8*, double, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), double %33, i32 %24)
br label %35
35: ; preds = %27, %31, %22
%36 = phi i32 [ %28, %31 ], [ %28, %27 ], [ %23, %22 ]
%37 = add nuw i32 %24, 1
%38 = icmp eq i32 %37, %3
br i1 %38, label %17, label %22
39: ; preds = %6, %17
ret void
}