#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[pidx[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    121c <search_leaf_double_mask+0xfc>
mov    0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%rdx
add    -0x40(%rbp),%rdx
mov    (%rcx,%rdx,8),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     118a <search_leaf_double_mask+0x6a>
jmp    120b <search_leaf_double_mask+0xeb>
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    1206 <search_leaf_double_mask+0xe6>
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    120b <search_leaf_double_mask+0xeb>
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),%rbp
lea    (%rsi,%rcx,8),%r14
xor    %r12d,%r12d
jmp    1169 <search_leaf_double_mask+0x49>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r12
cmp    %r12,%rbx
je     11c1 <search_leaf_double_mask+0xa1>
mov    (%r14,%r12,8),%r13
cmpq   $0x0,0x0(%rbp,%r13,8)
jne    1160 <search_leaf_double_mask+0x40>
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 = %74, %10
%24 = load i64, i64* %22
%25 = load i64, i64* %15
%26 = icmp ult i64 %24, %25
br i1 %26, label %27, label %77
27: ; preds = %23
%28 = load i64*, i64** %18
%29 = load i64*, i64** %12
%30 = load i64, i64* %14
%31 = load i64, i64* %22
%32 = add i64 %30, %31
%33 = getelementptr inbounds i64, i64* %29, i64 %32
%34 = load i64, i64* %33
%35 = getelementptr inbounds i64, i64* %28, i64 %34
%36 = load i64, i64* %35
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %27
br label %74
39: ; preds = %27
%40 = load double*, double** %11
%41 = load i64, i64* %13
%42 = load i64*, i64** %12
%43 = load i64, i64* %14
%44 = load i64, i64* %22
%45 = add i64 %43, %44
%46 = getelementptr inbounds i64, i64* %42, i64 %45
%47 = load i64, i64* %46
%48 = mul i64 %41, %47
%49 = add i64 %48, 0
%50 = getelementptr inbounds double, double* %40, i64 %49
%51 = load double*, double** %16
%52 = load i64, i64* %13
%53 = call double @calc_dist_double(double* %50, double* %51, i64 %52)
store double %53, double* %21
%54 = load double, double* %21
%55 = load double*, double** %20
%56 = load i64, i64* %17
%57 = sub i64 %56, 1
%58 = getelementptr inbounds double, double* %55, i64 %57
%59 = load double, double* %58
%60 = fcmp olt double %54, %59
br i1 %60, label %61, label %73
61: ; preds = %39
%62 = load i64*, i64** %19
%63 = load double*, double** %20
%64 = load i64*, i64** %12
%65 = load i64, i64* %14
%66 = load i64, i64* %22
%67 = add i64 %65, %66
%68 = getelementptr inbounds i64, i64* %64, i64 %67
%69 = load i64, i64* %68
%70 = load double, double* %21
%71 = load i64, i64* %17
%72 = call i32 @insert_point_double(i64* %62, double* %63, i64 %69, double %70, i64 %71)
br label %73
73: ; preds = %61, %39
br label %74
74: ; preds = %73, %38
%75 = load i64, i64* %22
%76 = add i64 %75, 1
store i64 %76, i64* %22
br label %23
77: ; 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* %1, i64 %17
%19 = load i64, i64* %18
%20 = getelementptr inbounds i64, i64* %7, i64 %19
%21 = load i64, i64* %20
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %15
%24 = mul i64 %19, %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 = %23
%30 = tail call i32 @insert_point_double(i64* %8, double* %9, i64 %19, double %26, i64 %6)
br label %31
31: ; preds = %23, %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
}