#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 */
int /*<<< orphan*/ assert(int);
double sqrt(double);
double compute_distance(const double *vec1, const double *vec2,
                        const unsigned int dim) {
  double d = 0.0;
  for (unsigned int k = 0; k < dim; k++) {
    double df = (vec1[k] - vec2[k]);
    d += df * df;
  }
  assert(d >= 0.0);
  d = sqrt(d);
  return d;
}


x86 assembly (clang, -O0):
<compute_distance>:
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
jae    1195 <compute_distance+0x75>
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%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    1142 <compute_distance+0x22>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movsd  -0x20(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_distance>:
push   %rax
xorpd  %xmm2,%xmm2
xorpd  %xmm3,%xmm3
test   %edx,%edx
je     11eb <compute_distance+0xcb>
mov    %edx,%edx
lea    -0x1(%rdx),%rcx
mov    %edx,%eax
and    $0x3,%eax
cmp    $0x3,%rcx
jae    114a <compute_distance+0x2a>
xorpd  %xmm3,%xmm3
xor    %ecx,%ecx
jmp    11b7 <compute_distance+0x97>
and    $0xfffffffc,%edx
xorpd  %xmm3,%xmm3
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  (%rdi,%rcx,8),%xmm0
movsd  0x8(%rdi,%rcx,8),%xmm1
subsd  (%rsi,%rcx,8),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm3,%xmm0
subsd  0x8(%rsi,%rcx,8),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0x10(%rdi,%rcx,8),%xmm0
subsd  0x10(%rsi,%rcx,8),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0x18(%rdi,%rcx,8),%xmm3
subsd  0x18(%rsi,%rcx,8),%xmm3
mulsd  %xmm3,%xmm3
addsd  %xmm0,%xmm3
add    $0x4,%rcx
cmp    %rcx,%rdx
jne    1160 <compute_distance+0x40>
test   %rax,%rax
je     11eb <compute_distance+0xcb>
lea    (%rsi,%rcx,8),%rdx
lea    (%rdi,%rcx,8),%rcx
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
movsd  (%rcx,%rsi,8),%xmm0
subsd  (%rdx,%rsi,8),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm0,%xmm3
add    $0x1,%rsi
cmp    %rsi,%rax
jne    11d0 <compute_distance+0xb0>
movsd  %xmm3,(%rsp)
xor    %edi,%edi
ucomisd %xmm2,%xmm3
setae  %dil
call   1030 <assert@plt>
movsd  (%rsp),%xmm0
ucomisd 0xdf4(%rip),%xmm0
jb     1214 <compute_distance+0xf4>
sqrtsd %xmm0,%xmm0
pop    %rax
ret
pop    %rax
jmp    1040 <sqrt@plt>

LLVM IR (-O0):
define double @compute_distance(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca double
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 %10
10: ; preds = %30, %3
%11 = load i32, i32* %8
%12 = load i32, i32* %6
%13 = icmp ult i32 %11, %12
br i1 %13, label %14, label %33
14: ; preds = %10
%15 = load double*, double** %4
%16 = load i32, i32* %8
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds double, double* %15, i64 %17
%19 = load double, double* %18
%20 = load double*, double** %5
%21 = load i32, i32* %8
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
%24 = load double, double* %23
%25 = fsub double %19, %24
store double %25, double* %9
%26 = load double, double* %9
%27 = load double, double* %9
%28 = load double, double* %7
%29 = call double @llvm.fmuladd.f64(double %26, double %27, double %28)
store double %29, double* %7
br label %30
30: ; preds = %14
%31 = load i32, i32* %8
%32 = add i32 %31, 1
store i32 %32, i32* %8
br label %10
33: ; preds = %10
%34 = load double, double* %7
%35 = fcmp oge double %34, 0.000000e+00
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = load double, double* %7
%39 = call double @sqrt(double %38)
store double %39, double* %7
%40 = load double, double* %7
ret double %40
}

LLVM IR (-O2):
define double @compute_distance(double* nocapture %0, double* nocapture %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %30, label %5
5: ; preds = %3
%6 = zext i32 %2 to i64
%7 = add nsw i64 %6, -1
%8 = and i64 %6, 3
%9 = icmp ult i64 %7, 3
br i1 %9, label %12, label %10
10: ; preds = %5
%11 = and i64 %6, 4294967292
br label %36
12: ; preds = %36, %5
%13 = phi double [ undef, %5 ], [ %66, %36 ]
%14 = phi i64 [ 0, %5 ], [ %67, %36 ]
%15 = phi double [ 0.000000e+00, %5 ], [ %66, %36 ]
%16 = icmp eq i64 %8, 0
br i1 %16, label %30, label %17
17: ; preds = %12, %17
%18 = phi i64 [ %27, %17 ], [ %14, %12 ]
%19 = phi double [ %26, %17 ], [ %15, %12 ]
%20 = phi i64 [ %28, %17 ], [ 0, %12 ]
%21 = getelementptr inbounds double, double* %0, i64 %18
%22 = load double, double* %21
%23 = getelementptr inbounds double, double* %1, i64 %18
%24 = load double, double* %23
%25 = fsub double %22, %24
%26 = tail call double @llvm.fmuladd.f64(double %25, double %25, double %19)
%27 = add nuw nsw i64 %18, 1
%28 = add i64 %20, 1
%29 = icmp eq i64 %28, %8
br i1 %29, label %30, label %17
30: ; preds = %12, %17, %3
%31 = phi double [ 0.000000e+00, %3 ], [ %13, %12 ], [ %26, %17 ]
%32 = fcmp oge double %31, 0.000000e+00
%33 = zext i1 %32 to i32
%34 = tail call i32 @assert(i32 %33)
%35 = tail call double @sqrt(double %31)
ret double %35
36: ; preds = %36, %10
%37 = phi i64 [ 0, %10 ], [ %67, %36 ]
%38 = phi double [ 0.000000e+00, %10 ], [ %66, %36 ]
%39 = phi i64 [ 0, %10 ], [ %68, %36 ]
%40 = getelementptr inbounds double, double* %0, i64 %37
%41 = load double, double* %40
%42 = getelementptr inbounds double, double* %1, i64 %37
%43 = load double, double* %42
%44 = fsub double %41, %43
%45 = tail call double @llvm.fmuladd.f64(double %44, double %44, double %38)
%46 = or i64 %37, 1
%47 = getelementptr inbounds double, double* %0, i64 %46
%48 = load double, double* %47
%49 = getelementptr inbounds double, double* %1, i64 %46
%50 = load double, double* %49
%51 = fsub double %48, %50
%52 = tail call double @llvm.fmuladd.f64(double %51, double %51, double %45)
%53 = or i64 %37, 2
%54 = getelementptr inbounds double, double* %0, i64 %53
%55 = load double, double* %54
%56 = getelementptr inbounds double, double* %1, i64 %53
%57 = load double, double* %56
%58 = fsub double %55, %57
%59 = tail call double @llvm.fmuladd.f64(double %58, double %58, double %52)
%60 = or i64 %37, 3
%61 = getelementptr inbounds double, double* %0, i64 %60
%62 = load double, double* %61
%63 = getelementptr inbounds double, double* %1, i64 %60
%64 = load double, double* %63
%65 = fsub double %62, %64
%66 = tail call double @llvm.fmuladd.f64(double %65, double %65, double %59)
%67 = add nuw nsw i64 %37, 4
%68 = add i64 %39, 4
%69 = icmp eq i64 %68, %11
br i1 %69, label %12, label %36
}