#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 */
double edist(double *, double *, int const);
int vq(double *x, double *cb, const int l, const int cbsize) {
  int i, index = 0;
  double min = 1e23, dist;
  for (i = 0; i < cbsize; i++) {
    dist = edist(x, cb, l);
    if (dist < min) {
      index = i;
      min = dist;
    }
    cb += l;
  }
  return (index);
}


x86 assembly (clang, -O0):
<vq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movsd  0xecb(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11a9 <vq+0x99>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <edist@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1186 <vq+0x76>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1141 <vq+0x31>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vq>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,0xc(%rsp)
test   %ecx,%ecx
jle    1185 <vq+0x75>
mov    %ecx,%r12d
mov    %rsi,%rbp
mov    %rdi,%r15
movslq 0xc(%rsp),%r13
shl    $0x3,%r13
xor    %ebx,%ebx
movsd  0xebe(%rip),%xmm0
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nop
movsd  %xmm0,0x10(%rsp)
mov    %r15,%rdi
mov    %rbp,%rsi
mov    0xc(%rsp),%edx
call   1030 <edist@plt>
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
cmova  %r14d,%ebx
minsd  %xmm1,%xmm0
add    $0x1,%r14d
add    %r13,%rbp
cmp    %r14d,%r12d
jne    1150 <vq+0x40>
jmp    1187 <vq+0x77>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @vq(double* %0, double* %1, i32 %2, i32 %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca double
store double* %0, double** %5
store double* %1, double** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %10
store double 0x44B52D02C7E14AF6, double* %11
store i32 0, i32* %9
br label %13
13: ; preds = %33, %4
%14 = load i32, i32* %9
%15 = load i32, i32* %8
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %36
17: ; preds = %13
%18 = load double*, double** %5
%19 = load double*, double** %6
%20 = load i32, i32* %7
%21 = call double @edist(double* %18, double* %19, i32 %20)
store double %21, double* %12
%22 = load double, double* %12
%23 = load double, double* %11
%24 = fcmp olt double %22, %23
br i1 %24, label %25, label %28
25: ; preds = %17
%26 = load i32, i32* %9
store i32 %26, i32* %10
%27 = load double, double* %12
store double %27, double* %11
br label %28
28: ; preds = %25, %17
%29 = load i32, i32* %7
%30 = load double*, double** %6
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds double, double* %30, i64 %31
store double* %32, double** %6
br label %33
33: ; preds = %28
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 1
store i32 %35, i32* %9
br label %13
36: ; preds = %13
%37 = load i32, i32* %10
ret i32 %37
}

LLVM IR (-O2):
define i32 @vq(double* %0, double* %1, i32 %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %20
6: ; preds = %4
%7 = sext i32 %2 to i64
br label %8
8: ; preds = %6, %8
%9 = phi double* [ %1, %6 ], [ %17, %8 ]
%10 = phi double [ 0x44B52D02C7E14AF6, %6 ], [ %16, %8 ]
%11 = phi i32 [ 0, %6 ], [ %15, %8 ]
%12 = phi i32 [ 0, %6 ], [ %18, %8 ]
%13 = tail call double @edist(double* %0, double* %9, i32 %2)
%14 = fcmp olt double %13, %10
%15 = select i1 %14, i32 %12, i32 %11
%16 = select i1 %14, double %13, double %10
%17 = getelementptr inbounds double, double* %9, i64 %7
%18 = add nuw nsw i32 %12, 1
%19 = icmp eq i32 %18, %3
br i1 %19, label %20, label %8
20: ; preds = %8, %4
%21 = phi i32 [ 0, %4 ], [ %15, %8 ]
ret i32 %21
}