#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 *fvec_new(int);
int /*<<< orphan*/ knn_full(int, int, int, int, int, float const *,
                            float const *, int /*<<< orphan*/ *, int *, float *,
                            void (*)(void *, double), void *);
float *knn(int npt, int nclust, int d, int k, const float *codebook,
           const float *coords, int *vw,
           void (*peek_fun)(void *arg, double frac), void *peek_arg) {
  float *vwdis = fvec_new(npt * k);
  knn_full(2, npt, nclust, d, k, codebook, coords, NULL, vw, vwdis, peek_fun,
           peek_arg);
  return vwdis;
}


x86 assembly (clang, -O0):
<knn>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x1c(%rbp)
mov    %esi,-0x20(%rbp)
mov    %edx,-0x24(%rbp)
mov    %ecx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x1c(%rbp),%edi
imul   -0x28(%rbp),%edi
call   1040 <fvec_new@plt>
mov    %rax,-0x40(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x30(%rbp),%r9
mov    -0x38(%rbp),%r14
mov    0x10(%rbp),%rbx
mov    -0x40(%rbp),%r11
mov    0x18(%rbp),%r10
mov    0x20(%rbp),%rax
mov    $0x2,%edi
xor    %r15d,%r15d
mov    %r14,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rbx,0x10(%rsp)
mov    %r11,0x18(%rsp)
mov    %r10,0x20(%rsp)
mov    %rax,0x28(%rsp)
call   1030 <knn_full@plt>
mov    -0x40(%rbp),%rax
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<knn>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,%r13
mov    %r8,0x30(%rsp)
mov    %ecx,%ebp
mov    %edx,%r15d
mov    %esi,%r12d
mov    %edi,%ebx
mov    %ecx,%edi
imul   %ebx,%edi
call   1040 <fvec_new@plt>
mov    %rax,%r14
movups 0x78(%rsp),%xmm0
movups %xmm0,0x20(%rsp)
mov    %rax,0x18(%rsp)
mov    0x70(%rsp),%rax
mov    %rax,0x10(%rsp)
mov    %r13,(%rsp)
movq   $0x0,0x8(%rsp)
mov    $0x2,%edi
mov    %ebx,%esi
mov    %r12d,%edx
mov    %r15d,%ecx
mov    %ebp,%r8d
mov    0x30(%rsp),%r9
call   1030 <knn_full@plt>
mov    %r14,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define float* @knn(i32 %0, i32 %1, i32 %2, i32 %3, float* %4, float* %5, i32* %6, void (i8*, double)* %7, i8* %8) {
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca float*
%15 = alloca float*
%16 = alloca i32*
%17 = alloca void (i8*, double)*
%18 = alloca i8*
%19 = alloca float*
store i32 %0, i32* %10
store i32 %1, i32* %11
store i32 %2, i32* %12
store i32 %3, i32* %13
store float* %4, float** %14
store float* %5, float** %15
store i32* %6, i32** %16
store void (i8*, double)* %7, void (i8*, double)** %17
store i8* %8, i8** %18
%20 = load i32, i32* %10
%21 = load i32, i32* %13
%22 = mul nsw i32 %20, %21
%23 = call float* @fvec_new(i32 %22)
store float* %23, float** %19
%24 = load i32, i32* %10
%25 = load i32, i32* %11
%26 = load i32, i32* %12
%27 = load i32, i32* %13
%28 = load float*, float** %14
%29 = load float*, float** %15
%30 = load i32*, i32** %16
%31 = load float*, float** %19
%32 = load void (i8*, double)*, void (i8*, double)** %17
%33 = load i8*, i8** %18
%34 = call i32 @knn_full(i32 2, i32 %24, i32 %25, i32 %26, i32 %27, float* %28, float* %29, i32* null, i32* %30, float* %31, void (i8*, double)* %32, i8* %33)
%35 = load float*, float** %19
ret float* %35
}

LLVM IR (-O2):
define float* @knn(i32 %0, i32 %1, i32 %2, i32 %3, float* %4, float* %5, i32* %6, void (i8*, double)* %7, i8* %8) {
%10 = mul nsw i32 %3, %0
%11 = tail call float* @fvec_new(i32 %10)
%12 = tail call i32 @knn_full(i32 2, i32 %0, i32 %1, i32 %2, i32 %3, float* %4, float* %5, i32* null, i32* %6, float* %11, void (i8*, double)* %7, i8* %8)
ret float* %11
}