#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 */
float calc_dist_float(float *, float *, size_t);
int /*<<< orphan*/ insert_point_float(size_t *, float *, size_t, float, size_t);
void search_leaf_float_mask(float *restrict pa, uint32_t *restrict pidx,
                            int8_t no_dims, uint32_t start_idx, uint32_t n,
                            float *restrict point_coord, uint32_t k,
                            uint8_t *mask, uint32_t *restrict closest_idx,
                            float *restrict closest_dist) {
  float cur_dist;
  uint32_t i;
  for (i = 0; i < n; i++) {
    if (mask[start_idx + i]) {
      continue;
    }
    cur_dist = calc_dist_float(&(pa[no_dims * pidx[start_idx + i] + 0]),
                               point_coord, no_dims);
    if (cur_dist < closest_dist[k - 1]) {
      insert_point_float(closest_idx, closest_dist, pidx[start_idx + i],
                         cur_dist, k);
    }
  }
}


x86 assembly (clang, -O0):
<search_leaf_float_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    1213 <search_leaf_float_mask+0xf3>
mov    0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    -0x40(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1182 <search_leaf_float_mask+0x62>
jmp    1202 <search_leaf_float_mask+0xe2>
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    $0x2,%rax
add    %rax,%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <calc_dist_float@plt>
movss  %xmm0,-0x34(%rbp)
movss  -0x34(%rbp),%xmm1
mov    0x28(%rbp),%rax
mov    0x10(%rbp),%rcx
sub    $0x1,%rcx
movss  (%rax,%rcx,4),%xmm0
ucomiss %xmm1,%xmm0
jbe    11fd <search_leaf_float_mask+0xdd>
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
movss  -0x34(%rbp),%xmm0
mov    0x10(%rbp),%rcx
call   1030 <insert_point_float@plt>
jmp    1202 <search_leaf_float_mask+0xe2>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1158 <search_leaf_float_mask+0x38>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search_leaf_float_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     11c0 <search_leaf_float_mask+0xa0>
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_float_mask+0x49>
nopl   0x0(%rax)
add    $0x1,%r12
cmp    %r12,%rbx
je     11c0 <search_leaf_float_mask+0xa0>
cmpq   $0x0,(%r14,%r12,8)
jne    1160 <search_leaf_float_mask+0x40>
mov    0x0(%rbp,%r12,8),%r13
mov    %r13,%rax
imul   %r15,%rax
mov    0x8(%rsp),%rcx
lea    (%rcx,%rax,4),%rdi
mov    0x10(%rsp),%rsi
mov    %r15,%rdx
call   1040 <calc_dist_float@plt>
mov    0x68(%rsp),%rax
mov    0x50(%rsp),%rcx
movss  -0x4(%rax,%rcx,4),%xmm1
ucomiss %xmm0,%xmm1
jbe    1160 <search_leaf_float_mask+0x40>
mov    0x60(%rsp),%rdi
mov    0x68(%rsp),%rsi
mov    %r13,%rdx
mov    0x50(%rsp),%rcx
call   1030 <insert_point_float@plt>
jmp    1160 <search_leaf_float_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_float_mask(float* noalias %0, i64* noalias %1, i64 %2, i64 %3, i64 %4, float* noalias %5, i64 %6, i64* %7, i64* noalias %8, float* noalias %9) {
%11 = alloca float*
%12 = alloca i64*
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca float*
%17 = alloca i64
%18 = alloca i64*
%19 = alloca i64*
%20 = alloca float*
%21 = alloca float
%22 = alloca i64
store float* %0, float** %11
store i64* %1, i64** %12
store i64 %2, i64* %13
store i64 %3, i64* %14
store i64 %4, i64* %15
store float* %5, float** %16
store i64 %6, i64* %17
store i64* %7, i64** %18
store i64* %8, i64** %19
store float* %9, float** %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 float*, float** %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 float, float* %37, i64 %46
%48 = load float*, float** %16
%49 = load i64, i64* %13
%50 = call float @calc_dist_float(float* %47, float* %48, i64 %49)
store float %50, float* %21
%51 = load float, float* %21
%52 = load float*, float** %20
%53 = load i64, i64* %17
%54 = sub i64 %53, 1
%55 = getelementptr inbounds float, float* %52, i64 %54
%56 = load float, float* %55
%57 = fcmp olt float %51, %56
br i1 %57, label %58, label %70
58: ; preds = %36
%59 = load i64*, i64** %19
%60 = load float*, float** %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 float, float* %21
%68 = load i64, i64* %17
%69 = call i32 @insert_point_float(i64* %59, float* %60, i64 %66, float %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_float_mask(float* noalias %0, i64* noalias nocapture %1, i64 %2, i64 %3, i64 %4, float* noalias %5, i64 %6, i64* nocapture %7, i64* noalias %8, float* 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 float, float* %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 float, float* %0, i64 %24
%26 = tail call float @calc_dist_float(float* %25, float* %5, i64 %2)
%27 = load float, float* %14
%28 = fcmp olt float %26, %27
br i1 %28, label %29, label %31
29: ; preds = %21
%30 = tail call i32 @insert_point_float(i64* %8, float* %9, i64 %23, float %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
}