#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[pidx[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    121b <search_leaf_float_mask+0xfb>
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_float_mask+0x6a>
jmp    120a <search_leaf_float_mask+0xea>
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    1205 <search_leaf_float_mask+0xe5>
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    120a <search_leaf_float_mask+0xea>
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),%rbp
lea    (%rsi,%rcx,8),%r14
xor    %r12d,%r12d
jmp    1169 <search_leaf_float_mask+0x49>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r12
cmp    %r12,%rbx
je     11c0 <search_leaf_float_mask+0xa0>
mov    (%r14,%r12,8),%r13
cmpq   $0x0,0x0(%rbp,%r13,8)
jne    1160 <search_leaf_float_mask+0x40>
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 = %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 float*, float** %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 float, float* %40, i64 %49
%51 = load float*, float** %16
%52 = load i64, i64* %13
%53 = call float @calc_dist_float(float* %50, float* %51, i64 %52)
store float %53, float* %21
%54 = load float, float* %21
%55 = load float*, float** %20
%56 = load i64, i64* %17
%57 = sub i64 %56, 1
%58 = getelementptr inbounds float, float* %55, i64 %57
%59 = load float, float* %58
%60 = fcmp olt float %54, %59
br i1 %60, label %61, label %73
61: ; preds = %39
%62 = load i64*, i64** %19
%63 = load float*, float** %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 float, float* %21
%71 = load i64, i64* %17
%72 = call i32 @insert_point_float(i64* %62, float* %63, i64 %69, float %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_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* %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 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 = %23
%30 = tail call i32 @insert_point_float(i64* %8, float* %9, i64 %19, float %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
}