#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 int int64_t;

/* Variables and functions */
double _distance2(float *p1, float *p2) {
  double dx, r2 = 0;
  for (int64_t k = 0; k < 3; k++) {
    dx = p1[k] - p2[k];
    r2 += dx * dx;
  }
  return (r2);
}


x86 assembly (clang, -O0):
<_distance2>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jge    1172 <_distance2+0x72>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
subss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    111b <_distance2+0x1b>
movsd  -0x20(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<_distance2>:
movss  (%rdi),%xmm0
subss  (%rsi),%xmm0
movss  0x4(%rdi),%xmm1
cvtss2sd %xmm0,%xmm0
mulsd  %xmm0,%xmm0
xorpd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
subss  0x4(%rsi),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm1
movss  0x8(%rdi),%xmm0
subss  0x8(%rsi),%xmm0
addsd  %xmm2,%xmm1
cvtss2sd %xmm0,%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
ret

LLVM IR (-O0):
define double @_distance2(float* %0, float* %1) {
%3 = alloca float*
%4 = alloca float*
%5 = alloca double
%6 = alloca double
%7 = alloca i32
store float* %0, float** %3
store float* %1, float** %4
store double 0.000000e+00, double* %6
store i32 0, i32* %7
br label %8
8: ; preds = %28, %2
%9 = load i32, i32* %7
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %31
11: ; preds = %8
%12 = load float*, float** %3
%13 = load i32, i32* %7
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds float, float* %12, i64 %14
%16 = load float, float* %15
%17 = load float*, float** %4
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds float, float* %17, i64 %19
%21 = load float, float* %20
%22 = fsub float %16, %21
%23 = fpext float %22 to double
store double %23, double* %5
%24 = load double, double* %5
%25 = load double, double* %5
%26 = load double, double* %6
%27 = call double @llvm.fmuladd.f64(double %24, double %25, double %26)
store double %27, double* %6
br label %28
28: ; preds = %11
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %8
31: ; preds = %8
%32 = load double, double* %6
ret double %32
}

LLVM IR (-O2):
define double @_distance2(float* nocapture %0, float* nocapture %1) {
%3 = load float, float* %0
%4 = load float, float* %1
%5 = fsub float %3, %4
%6 = fpext float %5 to double
%7 = tail call double @llvm.fmuladd.f64(double %6, double %6, double 0.000000e+00)
%8 = getelementptr inbounds float, float* %0, i64 1
%9 = load float, float* %8
%10 = getelementptr inbounds float, float* %1, i64 1
%11 = load float, float* %10
%12 = fsub float %9, %11
%13 = fpext float %12 to double
%14 = tail call double @llvm.fmuladd.f64(double %13, double %13, double %7)
%15 = getelementptr inbounds float, float* %0, i64 2
%16 = load float, float* %15
%17 = getelementptr inbounds float, float* %1, i64 2
%18 = load float, float* %17
%19 = fsub float %16, %18
%20 = fpext float %19 to double
%21 = tail call double @llvm.fmuladd.f64(double %20, double %20, double %14)
ret double %21
}