#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 */

/* Variables and functions */
float kd_tree_dist(float *, float *, int);
int /*<<< orphan*/ kd_tree_insert(float, int, float *, int *, int);
void kd_tree_brute_force_leaf(void *XI, int dim, int fr_idx, int to_idx,
                              float *test_pattern, float *d_min, int *idx_min,
                              int K) {
  int i;
  for (i = fr_idx; i < to_idx; i++) {
    float *patt = (float *)(XI + i * (dim * sizeof(float) + sizeof(int)));
    float d = kd_tree_dist(patt, test_pattern, dim);
    kd_tree_insert(d, i, d_min, idx_min, K);
  }
}


x86 assembly (clang, -O0):
<kd_tree_brute_force_leaf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b0 <kd_tree_brute_force_leaf+0x90>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movslq -0xc(%rbp),%rdx
shl    $0x2,%rdx
add    $0x4,%rdx
imul   %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <kd_tree_dist@plt>
movss  %xmm0,-0x3c(%rbp)
movss  -0x3c(%rbp),%xmm0
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    0x10(%rbp),%rdx
mov    0x18(%rbp),%ecx
call   1030 <kd_tree_insert@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    114a <kd_tree_brute_force_leaf+0x2a>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kd_tree_brute_force_leaf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,(%rsp)
cmp    %ecx,%edx
jge    118d <kd_tree_brute_force_leaf+0x6d>
mov    %r8,%r15
mov    %ecx,%r12d
mov    %edx,%ebx
mov    %esi,%r13d
mov    %rdi,%rbp
movslq %esi,%rax
lea    0x4(,%rax,4),%r14
movslq %edx,%rax
imul   %r14,%rax
add    %rax,%rbp
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
call   1040 <kd_tree_dist@plt>
mov    %ebx,%edi
mov    (%rsp),%rsi
mov    0x40(%rsp),%rdx
mov    0x48(%rsp),%ecx
call   1030 <kd_tree_insert@plt>
add    $0x1,%ebx
add    %r14,%rbp
cmp    %ebx,%r12d
jne    1160 <kd_tree_brute_force_leaf+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @kd_tree_brute_force_leaf(i8* %0, i32 %1, i32 %2, i32 %3, float* %4, float* %5, i32* %6, i32 %7) {
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca float*
%14 = alloca float*
%15 = alloca i32*
%16 = alloca i32
%17 = alloca i32
%18 = alloca float*
%19 = alloca float
store i8* %0, i8** %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store i32 %3, i32* %12
store float* %4, float** %13
store float* %5, float** %14
store i32* %6, i32** %15
store i32 %7, i32* %16
%20 = load i32, i32* %11
store i32 %20, i32* %17
br label %21
21: ; preds = %46, %8
%22 = load i32, i32* %17
%23 = load i32, i32* %12
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %49
25: ; preds = %21
%26 = load i8*, i8** %9
%27 = load i32, i32* %17
%28 = sext i32 %27 to i64
%29 = load i32, i32* %10
%30 = sext i32 %29 to i64
%31 = mul i64 %30, 4
%32 = add i64 %31, 4
%33 = mul i64 %28, %32
%34 = getelementptr i8, i8* %26, i64 %33
%35 = bitcast i8* %34 to float*
store float* %35, float** %18
%36 = load float*, float** %18
%37 = load float*, float** %13
%38 = load i32, i32* %10
%39 = call float @kd_tree_dist(float* %36, float* %37, i32 %38)
store float %39, float* %19
%40 = load float, float* %19
%41 = load i32, i32* %17
%42 = load float*, float** %14
%43 = load i32*, i32** %15
%44 = load i32, i32* %16
%45 = call i32 @kd_tree_insert(float %40, i32 %41, float* %42, i32* %43, i32 %44)
br label %46
46: ; preds = %25
%47 = load i32, i32* %17
%48 = add nsw i32 %47, 1
store i32 %48, i32* %17
br label %21
49: ; preds = %21
ret void
}

LLVM IR (-O2):
define void @kd_tree_brute_force_leaf(i8* %0, i32 %1, i32 %2, i32 %3, float* %4, float* %5, i32* %6, i32 %7) {
%9 = icmp slt i32 %2, %3
br i1 %9, label %10, label %26
10: ; preds = %8
%11 = sext i32 %1 to i64
%12 = shl nsw i64 %11, 2
%13 = add nsw i64 %12, 4
%14 = sext i32 %2 to i64
br label %15
15: ; preds = %10, %15
%16 = phi i64 [ %14, %10 ], [ %23, %15 ]
%17 = mul i64 %13, %16
%18 = getelementptr i8, i8* %0, i64 %17
%19 = bitcast i8* %18 to float*
%20 = tail call float @kd_tree_dist(float* %19, float* %4, i32 %1)
%21 = trunc i64 %16 to i32
%22 = tail call i32 @kd_tree_insert(float %20, i32 %21, float* %5, i32* %6, i32 %7)
%23 = add nsw i64 %16, 1
%24 = trunc i64 %23 to i32
%25 = icmp eq i32 %24, %3
br i1 %25, label %26, label %15
26: ; preds = %15, %8
ret void
}