#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 */
typedef scalar_t__ uint8_t;
typedef size_t uint32_t;
typedef size_t int8_t;

/* Variables and functions */
double calc_dist_double(double *, double *, size_t);
int /*<<< orphan*/ insert_point_double(size_t *, double *, size_t, double,
                                       size_t);
void search_leaf_double_mask(double *restrict pa, uint32_t *restrict pidx,
                             int8_t no_dims, uint32_t start_idx, uint32_t n,
                             double *restrict point_coord, uint32_t k,
                             uint8_t *mask, uint32_t *restrict closest_idx,
                             double *restrict closest_dist) {
  double cur_dist;
  uint32_t i;
  for (i = 0; i < n; i++) {
    if (mask[start_idx + i]) {
      continue;
    }
    cur_dist = calc_dist_double(&(pa[no_dims * pidx[start_idx + i] + 0]),
                                point_coord, no_dims);
    if (cur_dist < closest_dist[k - 1]) {
      insert_point_double(closest_idx, closest_dist, pidx[start_idx + i],
                          cur_dist, k);
    }
  }
}


x86 assembly (clang, -O0):
<search_leaf_double_mask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x28(%rbp),%rax
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1214 <search_leaf_double_mask+0xf4>
mov    0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    -0x40(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1182 <search_leaf_double_mask+0x62>
jmp    1203 <search_leaf_double_mask+0xe3>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%rdx
add    -0x40(%rbp),%rdx
imul   (%rcx,%rdx,8),%rax
add    $0x0,%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <calc_dist_double@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
mov    0x28(%rbp),%rax
mov    0x10(%rbp),%rcx
sub    $0x1,%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    11fe <search_leaf_double_mask+0xde>
mov    0x20(%rbp),%rdi
mov    0x28(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    -0x40(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
movsd  -0x38(%rbp),%xmm0
mov    0x10(%rbp),%rcx
call   1040 <insert_point_double@plt>
jmp    1203 <search_leaf_double_mask+0xe3>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1158 <search_leaf_double_mask+0x38>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search_leaf_double_mask>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,0x10(%rsp)
mov    %rdi,0x8(%rsp)
test   %r8,%r8
je     11c1 <search_leaf_double_mask+0xa1>
mov    %r8,%rbx
mov    %rdx,%r15
mov    0x58(%rsp),%rax
lea    (%rsi,%rcx,8),%rbp
lea    (%rax,%rcx,8),%r14
xor    %r12d,%r12d
jmp    1169 <search_leaf_double_mask+0x49>
nopl   0x0(%rax)
add    $0x1,%r12
cmp    %r12,%rbx
je     11c1 <search_leaf_double_mask+0xa1>
cmpq   $0x0,(%r14,%r12,8)
jne    1160 <search_leaf_double_mask+0x40>
mov    0x0(%rbp,%r12,8),%r13
mov    %r13,%rax
imul   %r15,%rax
mov    0x8(%rsp),%rcx
lea    (%rcx,%rax,8),%rdi
mov    0x10(%rsp),%rsi
mov    %r15,%rdx
call   1030 <calc_dist_double@plt>
mov    0x68(%rsp),%rax
mov    0x50(%rsp),%rcx
movsd  -0x8(%rax,%rcx,8),%xmm1
ucomisd %xmm0,%xmm1
jbe    1160 <search_leaf_double_mask+0x40>
mov    0x60(%rsp),%rdi
mov    0x68(%rsp),%rsi
mov    %r13,%rdx
mov    0x50(%rsp),%rcx
call   1040 <insert_point_double@plt>
jmp    1160 <search_leaf_double_mask+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @search_leaf_double_mask(double* noalias %0, i64* noalias %1, i64 %2, i64 %3, i64 %4, double* noalias %5, i64 %6, i64* %7, i64* noalias %8, double* noalias %9) {
%11 = alloca double*
%12 = alloca i64*
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca double*
%17 = alloca i64
%18 = alloca i64*
%19 = alloca i64*
%20 = alloca double*
%21 = alloca double
%22 = alloca i64
store double* %0, double** %11
store i64* %1, i64** %12
store i64 %2, i64* %13
store i64 %3, i64* %14
store i64 %4, i64* %15
store double* %5, double** %16
store i64 %6, i64* %17
store i64* %7, i64** %18
store i64* %8, i64** %19
store double* %9, double** %20
store i64 0, i64* %22
br label %23
23: ; preds = %71, %10
%24 = load i64, i64* %22
%25 = load i64, i64* %15
%26 = icmp ult i64 %24, %25
br i1 %26, label %27, label %74
27: ; preds = %23
%28 = load i64*, i64** %18
%29 = load i64, i64* %14
%30 = load i64, i64* %22
%31 = add i64 %29, %30
%32 = getelementptr inbounds i64, i64* %28, i64 %31
%33 = load i64, i64* %32
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %27
br label %71
36: ; preds = %27
%37 = load double*, double** %11
%38 = load i64, i64* %13
%39 = load i64*, i64** %12
%40 = load i64, i64* %14
%41 = load i64, i64* %22
%42 = add i64 %40, %41
%43 = getelementptr inbounds i64, i64* %39, i64 %42
%44 = load i64, i64* %43
%45 = mul i64 %38, %44
%46 = add i64 %45, 0
%47 = getelementptr inbounds double, double* %37, i64 %46
%48 = load double*, double** %16
%49 = load i64, i64* %13
%50 = call double @calc_dist_double(double* %47, double* %48, i64 %49)
store double %50, double* %21
%51 = load double, double* %21
%52 = load double*, double** %20
%53 = load i64, i64* %17
%54 = sub i64 %53, 1
%55 = getelementptr inbounds double, double* %52, i64 %54
%56 = load double, double* %55
%57 = fcmp olt double %51, %56
br i1 %57, label %58, label %70
58: ; preds = %36
%59 = load i64*, i64** %19
%60 = load double*, double** %20
%61 = load i64*, i64** %12
%62 = load i64, i64* %14
%63 = load i64, i64* %22
%64 = add i64 %62, %63
%65 = getelementptr inbounds i64, i64* %61, i64 %64
%66 = load i64, i64* %65
%67 = load double, double* %21
%68 = load i64, i64* %17
%69 = call i32 @insert_point_double(i64* %59, double* %60, i64 %66, double %67, i64 %68)
br label %70
70: ; preds = %58, %36
br label %71
71: ; preds = %70, %35
%72 = load i64, i64* %22
%73 = add i64 %72, 1
store i64 %73, i64* %22
br label %23
74: ; preds = %23
ret void
}

LLVM IR (-O2):
define void @search_leaf_double_mask(double* noalias %0, i64* noalias nocapture %1, i64 %2, i64 %3, i64 %4, double* noalias %5, i64 %6, i64* nocapture %7, i64* noalias %8, double* noalias %9) {
%11 = icmp eq i64 %4, 0
br i1 %11, label %34, label %12
12: ; preds = %10
%13 = add i64 %6, -1
%14 = getelementptr inbounds double, double* %9, i64 %13
br label %15
15: ; preds = %12, %31
%16 = phi i64 [ 0, %12 ], [ %32, %31 ]
%17 = add i64 %16, %3
%18 = getelementptr inbounds i64, i64* %7, i64 %17
%19 = load i64, i64* %18
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %15
%22 = getelementptr inbounds i64, i64* %1, i64 %17
%23 = load i64, i64* %22
%24 = mul i64 %23, %2
%25 = getelementptr inbounds double, double* %0, i64 %24
%26 = tail call double @calc_dist_double(double* %25, double* %5, i64 %2)
%27 = load double, double* %14
%28 = fcmp olt double %26, %27
br i1 %28, label %29, label %31
29: ; preds = %21
%30 = tail call i32 @insert_point_double(i64* %8, double* %9, i64 %23, double %26, i64 %6)
br label %31
31: ; preds = %21, %29, %15
%32 = add nuw i64 %16, 1
%33 = icmp eq i64 %32, %4
br i1 %33, label %34, label %15
34: ; preds = %31, %10
ret void
}