#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 double *__m128d;

/* Variables and functions */
double *_mm_add_pd(double *, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_mul_pd(double *, double *);
double *_mm_sub_pd(double *, double *);
scalar_t__ pow(double, int);
double sqrt(double);
double distance_l2_m128d(__m128d *p1, __m128d *p2, int len) {
  double ret = 0;
  __m128d sum = {0, 0};
  int i = 0;
  for (i = 0; i < len / 2; i++) {
    __m128d diff;
    diff = _mm_sub_pd(p1[i], p2[i]);
    sum = _mm_add_pd(sum, _mm_mul_pd(diff, diff));
  }
  ret = sum[0] + sum[1];
  for (i *= 2; i < len; i++) {
    ret += pow(((double *)p1)[i] - ((double *)p2)[i], 2);
  }
  return sqrt(ret);
}


x86 assembly (clang, -O0):
<distance_l2_m128d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
cmp    %ecx,%eax
jge    11f2 <distance_l2_m128d+0xa2>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <_mm_sub_pd@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1060 <_mm_mul_pd@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
call   1040 <_mm_add_pd@plt>
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1181 <distance_l2_m128d+0x31>
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x28(%rbp),%rax
addsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    125e <distance_l2_m128d+0x10e>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    $0x2,%edi
call   1050 <pow@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1211 <distance_l2_m128d+0xc1>
movsd  -0x20(%rbp),%xmm0
call   1070 <sqrt@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<distance_l2_m128d>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%r12
mov    %edx,%r13d
shr    %r13d
xor    %ebx,%ebx
xor    %ebp,%ebp
xchg   %ax,%ax
mov    (%r12,%rbx,8),%rdi
mov    (%r14,%rbx,8),%rsi
call   1030 <_mm_sub_pd@plt>
mov    %rax,%rdi
mov    %rax,%rsi
call   1060 <_mm_mul_pd@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1040 <_mm_add_pd@plt>
mov    %rax,%rbp
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1170 <distance_l2_m128d+0x20>
movsd  0x0(%rbp),%xmm1
addsd  0x8(%rbp),%xmm1
mov    %r15d,%eax
and    $0x7ffffffe,%eax
cmp    %r15d,%eax
jae    125b <distance_l2_m128d+0x10b>
add    %r13,%r13
mov    %r15d,%ebp
mov    %r13,%rbx
not    %rbx
test   $0x1,%bpl
je     11fb <distance_l2_m128d+0xab>
movsd  (%r12,%r13,8),%xmm0
subsd  (%r14,%r13,8),%xmm0
mov    $0x2,%edi
movsd  %xmm1,(%rsp)
call   1050 <pow@plt>
movsd  (%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  %xmm0,%xmm1
or     $0x1,%r13
add    %rbp,%rbx
je     125b <distance_l2_m128d+0x10b>
movsd  %xmm1,(%rsp)
movsd  (%r12,%r13,8),%xmm0
subsd  (%r14,%r13,8),%xmm0
mov    $0x2,%edi
call   1050 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%r12,%r13,8),%xmm0
subsd  0x8(%r14,%r13,8),%xmm0
mov    $0x2,%edi
call   1050 <pow@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
addsd  (%rsp),%xmm1
add    $0x2,%r13
cmp    %r13,%rbp
jne    1200 <distance_l2_m128d+0xb0>
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jb     127b <distance_l2_m128d+0x12b>
xorps  %xmm0,%xmm0
sqrtsd %xmm1,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movapd %xmm1,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <sqrt@plt>

LLVM IR (-O0):
define double @distance_l2_m128d(double** %0, double** %1, i32 %2) {
%4 = alloca double**
%5 = alloca double**
%6 = alloca i32
%7 = alloca double
%8 = alloca double*
%9 = alloca i32
%10 = 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 double* null, double** %8
store i32 0, i32* %9
store i32 0, i32* %9
br label %11
11: ; preds = %33, %3
%12 = load i32, i32* %9
%13 = load i32, i32* %6
%14 = sdiv i32 %13, 2
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %36
16: ; preds = %11
%17 = load double**, double*** %4
%18 = load i32, i32* %9
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds double*, double** %17, i64 %19
%21 = load double*, double** %20
%22 = load double**, double*** %5
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double*, double** %22, i64 %24
%26 = load double*, double** %25
%27 = call double* @_mm_sub_pd(double* %21, double* %26)
store double* %27, double** %10
%28 = load double*, double** %8
%29 = load double*, double** %10
%30 = load double*, double** %10
%31 = call i32 @_mm_mul_pd(double* %29, double* %30)
%32 = call double* @_mm_add_pd(double* %28, i32 %31)
store double* %32, double** %8
br label %33
33: ; preds = %16
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 1
store i32 %35, i32* %9
br label %11
36: ; preds = %11
%37 = load double*, double** %8
%38 = getelementptr inbounds double, double* %37, i64 0
%39 = load double, double* %38
%40 = load double*, double** %8
%41 = getelementptr inbounds double, double* %40, i64 1
%42 = load double, double* %41
%43 = fadd double %39, %42
store double %43, double* %7
%44 = load i32, i32* %9
%45 = mul nsw i32 %44, 2
store i32 %45, i32* %9
br label %46
46: ; preds = %68, %36
%47 = load i32, i32* %9
%48 = load i32, i32* %6
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %71
50: ; preds = %46
%51 = load double**, double*** %4
%52 = bitcast double** %51 to double*
%53 = load i32, i32* %9
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %52, i64 %54
%56 = load double, double* %55
%57 = load double**, double*** %5
%58 = bitcast double** %57 to double*
%59 = load i32, i32* %9
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %58, i64 %60
%62 = load double, double* %61
%63 = fsub double %56, %62
%64 = call i64 @pow(double %63, i32 2)
%65 = sitofp i64 %64 to double
%66 = load double, double* %7
%67 = fadd double %66, %65
store double %67, double* %7
br label %68
68: ; preds = %50
%69 = load i32, i32* %9
%70 = add nsw i32 %69, 1
store i32 %70, i32* %9
br label %46
71: ; preds = %46
%72 = load double, double* %7
%73 = call double @sqrt(double %72)
ret double %73
}

LLVM IR (-O2):
define double @distance_l2_m128d(double** nocapture %0, double** nocapture %1, i32 %2) {
%4 = lshr i32 %2, 1
%5 = icmp sgt i32 %2, 1
%6 = zext i32 %4 to i64
br label %7
7: ; preds = %3, %7
%8 = phi i64 [ 0, %3 ], [ %17, %7 ]
%9 = phi double* [ null, %3 ], [ %16, %7 ]
%10 = getelementptr inbounds double*, double** %0, i64 %8
%11 = load double*, double** %10
%12 = getelementptr inbounds double*, double** %1, i64 %8
%13 = load double*, double** %12
%14 = tail call double* @_mm_sub_pd(double* %11, double* %13)
%15 = tail call i32 @_mm_mul_pd(double* %14, double* %14)
%16 = tail call double* @_mm_add_pd(double* %9, i32 %15)
%17 = add nuw nsw i64 %8, 1
%18 = icmp eq i64 %17, %6
br i1 %18, label %19, label %7
19: ; preds = %7
%20 = load double, double* %16
%21 = getelementptr inbounds double, double* %16, i64 1
%22 = load double, double* %21
%23 = fadd double %20, %22
%24 = and i32 %2, 2147483646
%25 = icmp ult i32 %24, %2
br i1 %25, label %26, label %76
26: ; preds = %19
%27 = shl nuw nsw i64 %6, 1
%28 = zext i32 %2 to i64
%29 = xor i64 %27, -1
%30 = and i64 %28, 1
%31 = icmp eq i64 %30, 0
br i1 %31, label %44, label %32
32: ; preds = %26
%33 = getelementptr inbounds double*, double** %0, i64 %27
%34 = bitcast double** %33 to double*
%35 = load double, double* %34
%36 = getelementptr inbounds double*, double** %1, i64 %27
%37 = bitcast double** %36 to double*
%38 = load double, double* %37
%39 = fsub double %35, %38
%40 = tail call i64 @pow(double %39, i32 2)
%41 = sitofp i64 %40 to double
%42 = fadd double %23, %41
%43 = or i64 %27, 1
br label %44
44: ; preds = %32, %26
%45 = phi double [ undef, %26 ], [ %42, %32 ]
%46 = phi i64 [ %27, %26 ], [ %43, %32 ]
%47 = phi double [ %23, %26 ], [ %42, %32 ]
%48 = sub nsw i64 0, %28
%49 = icmp eq i64 %29, %48
br i1 %49, label %76, label %50
50: ; preds = %44, %50
%51 = phi i64 [ %74, %50 ], [ %46, %44 ]
%52 = phi double [ %73, %50 ], [ %47, %44 ]
%53 = getelementptr inbounds double*, double** %0, i64 %51
%54 = bitcast double** %53 to double*
%55 = load double, double* %54
%56 = getelementptr inbounds double*, double** %1, i64 %51
%57 = bitcast double** %56 to double*
%58 = load double, double* %57
%59 = fsub double %55, %58
%60 = tail call i64 @pow(double %59, i32 2)
%61 = sitofp i64 %60 to double
%62 = fadd double %52, %61
%63 = add nuw nsw i64 %51, 1
%64 = getelementptr inbounds double*, double** %0, i64 %63
%65 = bitcast double** %64 to double*
%66 = load double, double* %65
%67 = getelementptr inbounds double*, double** %1, i64 %63
%68 = bitcast double** %67 to double*
%69 = load double, double* %68
%70 = fsub double %66, %69
%71 = tail call i64 @pow(double %70, i32 2)
%72 = sitofp i64 %71 to double
%73 = fadd double %62, %72
%74 = add nuw nsw i64 %51, 2
%75 = icmp eq i64 %74, %28
br i1 %75, label %76, label %50
76: ; preds = %44, %50, %19
%77 = phi double [ %23, %19 ], [ %45, %44 ], [ %73, %50 ]
%78 = tail call double @sqrt(double %77)
ret double %78
}