#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 */
scalar_t__ sqr(double);
double sqrt(double);
double distance(double *points, int n, int m, int ndim) {
  int i, o = n * ndim, p = m * ndim;
  double sum = 0.0;
  for (i = 0; i < ndim; ++i)
    sum += sqr(points[o + i] - points[p + i]);
  return sqrt(sum);
}


x86 assembly (clang, -O0):
<distance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0xc(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11aa <distance+0x8a>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm0
call   1030 <sqr@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1158 <distance+0x38>
movsd  -0x28(%rbp),%xmm0
call   1040 <sqrt@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<distance>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xorpd  %xmm0,%xmm0
test   %ecx,%ecx
jle    118a <distance+0x6a>
imul   %ecx,%edx
imul   %ecx,%esi
movslq %esi,%rax
movslq %edx,%rdx
mov    %ecx,%r14d
lea    (%rdi,%rdx,8),%r15
lea    (%rdi,%rax,8),%r12
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
nopl   (%rax)
movsd  %xmm0,(%rsp)
movsd  (%r12,%rbx,8),%xmm0
subsd  (%r15,%rbx,8),%xmm0
call   1030 <sqr@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1150 <distance+0x30>
ucomisd 0xe6e(%rip),%xmm0
jb     11a4 <distance+0x84>
sqrtsd %xmm0,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <sqrt@plt>

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

LLVM IR (-O2):
define double @distance(double* nocapture %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %27
6: ; preds = %4
%7 = mul nsw i32 %3, %2
%8 = mul nsw i32 %3, %1
%9 = sext i32 %8 to i64
%10 = sext i32 %7 to i64
%11 = zext i32 %3 to i64
br label %12
12: ; preds = %6, %12
%13 = phi i64 [ 0, %6 ], [ %25, %12 ]
%14 = phi double [ 0.000000e+00, %6 ], [ %24, %12 ]
%15 = add nsw i64 %13, %9
%16 = getelementptr inbounds double, double* %0, i64 %15
%17 = load double, double* %16
%18 = add nsw i64 %13, %10
%19 = getelementptr inbounds double, double* %0, i64 %18
%20 = load double, double* %19
%21 = fsub double %17, %20
%22 = tail call i64 @sqr(double %21)
%23 = sitofp i64 %22 to double
%24 = fadd double %14, %23
%25 = add nuw nsw i64 %13, 1
%26 = icmp eq i64 %25, %11
br i1 %26, label %27, label %12
27: ; preds = %12, %4
%28 = phi double [ 0.000000e+00, %4 ], [ %24, %12 ]
%29 = tail call double @sqrt(double %28)
ret double %29
}