#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 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(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,
                       uint32_t *restrict closest_idx,
                       float *restrict closest_dist) {
  float cur_dist;
  for (uint32_t i = 0; i < n; i++) {
    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>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
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    11f3 <search_leaf_float+0xd3>
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    0x20(%rbp),%rax
mov    0x10(%rbp),%rcx
sub    $0x1,%rcx
movss  (%rax,%rcx,4),%xmm0
ucomiss %xmm1,%xmm0
jbe    11dd <search_leaf_float+0xbd>
mov    0x18(%rbp),%rdi
mov    0x20(%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    11e2 <search_leaf_float+0xc2>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1154 <search_leaf_float+0x34>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search_leaf_float>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,(%rsp)
test   %r8,%r8
je     11a3 <search_leaf_float+0x83>
mov    %r8,%r15
mov    %rdx,%rbx
mov    %rdi,%r12
lea    (%rsi,%rcx,8),%rbp
xor    %r14d,%r14d
jmp    1159 <search_leaf_float+0x39>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r14
cmp    %r14,%r15
je     11a3 <search_leaf_float+0x83>
mov    0x0(%rbp,%r14,8),%r13
mov    %r13,%rax
imul   %rbx,%rax
lea    (%r12,%rax,4),%rdi
mov    (%rsp),%rsi
mov    %rbx,%rdx
call   1040 <calc_dist_float@plt>
mov    0x50(%rsp),%rax
mov    0x40(%rsp),%rcx
movss  -0x4(%rax,%rcx,4),%xmm1
ucomiss %xmm0,%xmm1
jbe    1150 <search_leaf_float+0x30>
mov    0x48(%rsp),%rdi
mov    0x50(%rsp),%rsi
mov    %r13,%rdx
mov    0x40(%rsp),%rcx
call   1030 <insert_point_float@plt>
jmp    1150 <search_leaf_float+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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