#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 euclidean_distance(double *, double *, int);
void compute_distances(double *points, double *sample, double *distances,
                       int dims, int n_points) {
  if (!points || !sample || !distances || dims < 1 || n_points < 1) {
    return;
  }
  int i;
  for (i = 0; i < n_points; i++) {
    distances[i] = euclidean_distance(&points[dims * i], sample, dims);
  }
}


x86 assembly (clang, -O0):
<compute_distances>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1160 <compute_distances+0x50>
cmpq   $0x0,-0x10(%rbp)
je     1160 <compute_distances+0x50>
cmpq   $0x0,-0x18(%rbp)
je     1160 <compute_distances+0x50>
cmpl   $0x1,-0x1c(%rbp)
jl     1160 <compute_distances+0x50>
cmpl   $0x1,-0x20(%rbp)
jge    1165 <compute_distances+0x55>
jmp    11b3 <compute_distances+0xa3>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11b3 <compute_distances+0xa3>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%eax
imul   -0x24(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <euclidean_distance@plt>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116c <compute_distances+0x5c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_distances>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %ecx,%ecx
jle    1171 <compute_distances+0x61>
mov    %rdi,%rbx
test   %rdi,%rdi
je     1171 <compute_distances+0x61>
mov    %rsi,%r12
test   %rsi,%rsi
je     1171 <compute_distances+0x61>
mov    %rdx,%r15
test   %rdx,%rdx
je     1171 <compute_distances+0x61>
test   %r8d,%r8d
jle    1171 <compute_distances+0x61>
mov    %ecx,%r13d
mov    %ecx,%ebp
mov    %r8d,%eax
mov    %rax,(%rsp)
shl    $0x3,%rbp
xor    %r14d,%r14d
nop
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13d,%edx
call   1030 <euclidean_distance@plt>
movsd  %xmm0,(%r15,%r14,8)
add    $0x1,%r14
add    %rbp,%rbx
cmp    %r14,(%rsp)
jne    1150 <compute_distances+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @compute_distances(double* %0, double* %1, double* writeonly %2, i32 %3, i32 %4) {
%6 = icmp ne double* %0, null
%7 = icmp ne double* %1, null
%8 = and i1 %6, %7
%9 = icmp ne double* %2, null
%10 = and i1 %8, %9
%11 = xor i1 %10, true
%12 = icmp slt i32 %3, 1
%13 = or i1 %12, %11
%14 = icmp slt i32 %4, 1
%15 = or i1 %13, %14
br i1 %15, label %27, label %16
16: ; preds = %5
%17 = zext i32 %3 to i64
%18 = zext i32 %4 to i64
br label %19
19: ; preds = %16, %19
%20 = phi i64 [ 0, %16 ], [ %25, %19 ]
%21 = mul nsw i64 %20, %17
%22 = getelementptr inbounds double, double* %0, i64 %21
%23 = tail call double @euclidean_distance(double* %22, double* %1, i32 %3)
%24 = getelementptr inbounds double, double* %2, i64 %20
store double %23, double* %24
%25 = add nuw nsw i64 %20, 1
%26 = icmp eq i64 %25, %18
br i1 %26, label %27, label %19
27: ; preds = %19, %5
ret void
}