#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__ _gmm_pow2(double const);
double sqrt(double);
double _gmm_vec_l2_dist(const double *x, const double *y, int D) {
  double l2_dist_sq = 0;
  for (int i = 0; i < D; i++) {
    l2_dist_sq += _gmm_pow2(x[i] - y[i]);
  }
  return (sqrt(l2_dist_sq));
}


x86 assembly (clang, -O0):
<_gmm_vec_l2_dist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    118a <_gmm_vec_l2_dist+0x6a>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
call   1030 <_gmm_pow2@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1142 <_gmm_vec_l2_dist+0x22>
movsd  -0x20(%rbp),%xmm0
call   1040 <sqrt@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_gmm_vec_l2_dist>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xorpd  %xmm0,%xmm0
test   %edx,%edx
jle    117a <_gmm_vec_l2_dist+0x5a>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r12d
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
nop
movsd  %xmm0,(%rsp)
movsd  (%r15,%rbx,8),%xmm0
subsd  (%r14,%rbx,8),%xmm0
call   1030 <_gmm_pow2@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1140 <_gmm_vec_l2_dist+0x20>
ucomisd 0xe7e(%rip),%xmm0
jb     1194 <_gmm_vec_l2_dist+0x74>
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 @_gmm_vec_l2_dist(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
store double 0.000000e+00, double* %7
store i32 0, i32* %8
br label %9
9: ; preds = %29, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %32
13: ; preds = %9
%14 = load double*, double** %4
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds double, double* %14, i64 %16
%18 = load double, double* %17
%19 = load double*, double** %5
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %19, i64 %21
%23 = load double, double* %22
%24 = fsub double %18, %23
%25 = call i64 @_gmm_pow2(double %24)
%26 = sitofp i64 %25 to double
%27 = load double, double* %7
%28 = fadd double %27, %26
store double %28, double* %7
br label %29
29: ; preds = %13
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
store i32 %31, i32* %8
br label %9
32: ; preds = %9
%33 = load double, double* %7
%34 = call double @sqrt(double %33)
ret double %34
}

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