#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 */
typedef struct TYPE_12__ TYPE_1__;

/* Type definitions */
struct TYPE_12__ {
  int /*<<< orphan*/ member_1;
  int /*<<< orphan*/ member_0;
};
typedef TYPE_1__ __m128d;

/* Variables and functions */
TYPE_1__ _mm_add_pd(TYPE_1__, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_mul_pd(TYPE_1__, TYPE_1__);
int /*<<< orphan*/ _mm_store_pd(double *, TYPE_1__);
TYPE_1__ _mm_sub_pd(TYPE_1__, TYPE_1__);
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};
  double fsum[2];
  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));
  }
  _mm_store_pd(fsum, sum);
  ret = fsum[0] + fsum[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    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x64(%rbp),%eax
cmp    %ecx,%eax
jge    1222 <distance_l2_m128d+0xb2>
mov    -0x8(%rbp),%rdx
movslq -0x44(%rbp),%rsi
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rdx,%rsi,8),%rdi
mov    (%rax,%rcx,8),%rsi
call   1040 <_mm_sub_pd@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   1080 <_mm_mul_pd@plt>
mov    %eax,%esi
mov    -0x28(%rbp),%rdi
call   1060 <_mm_add_pd@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11a9 <distance_l2_m128d+0x39>
lea    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <_mm_store_pd@plt>
movsd  -0x40(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x44(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1294 <distance_l2_m128d+0x124>
mov    -0x8(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    $0x2,%edi
call   1070 <pow@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1247 <distance_l2_m128d+0xd7>
movsd  -0x20(%rbp),%xmm0
call   1090 <sqrt@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<distance_l2_m128d>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r13
cmp    $0x2,%edx
jl     11d5 <distance_l2_m128d+0x75>
mov    %ebx,%r12d
shr    $0x1f,%r12d
mov    %ebx,0x8(%rsp)
add    %ebx,%r12d
sar    %r12d
mov    %r12d,%ebx
xor    %r15d,%r15d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x0(%r13,%r15,8),%rdi
mov    (%r14,%r15,8),%rsi
call   1040 <_mm_sub_pd@plt>
mov    %rax,%rdi
mov    %rax,%rsi
call   1070 <_mm_mul_pd@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1050 <_mm_add_pd@plt>
mov    %rax,%rbp
add    $0x1,%r15
cmp    %r15,%rbx
jne    11a0 <distance_l2_m128d+0x40>
mov    0x8(%rsp),%ebx
jmp    11da <distance_l2_m128d+0x7a>
xor    %r12d,%r12d
xor    %ebp,%ebp
lea    0x10(%rsp),%rdi
mov    %rbp,%rsi
call   1030 <_mm_store_pd@plt>
movsd  0x10(%rsp),%xmm1
addsd  0x18(%rsp),%xmm1
lea    (%r12,%r12,1),%eax
cmp    %ebx,%eax
jge    12b0 <distance_l2_m128d+0x150>
mov    %r12d,%ebp
add    %rbp,%rbp
mov    %ebx,%r15d
mov    %rbp,%rbx
not    %rbx
test   $0x1,%r15b
je     1247 <distance_l2_m128d+0xe7>
movsd  0x0(%r13,%rbp,8),%xmm0
subsd  (%r14,%rbp,8),%xmm0
mov    $0x2,%edi
movsd  %xmm1,0x8(%rsp)
call   1060 <pow@plt>
movsd  0x8(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  %xmm0,%xmm1
or     $0x1,%rbp
add    %r15,%rbx
je     12b0 <distance_l2_m128d+0x150>
nopl   0x0(%rax)
movsd  %xmm1,0x8(%rsp)
movsd  0x0(%r13,%rbp,8),%xmm0
subsd  (%r14,%rbp,8),%xmm0
mov    $0x2,%edi
call   1060 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%r13,%rbp,8),%xmm0
subsd  0x8(%r14,%rbp,8),%xmm0
mov    $0x2,%edi
call   1060 <pow@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
addsd  0x8(%rsp),%xmm1
add    $0x2,%rbp
cmp    %rbp,%r15
jne    1250 <distance_l2_m128d+0xf0>
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jb     12c3 <distance_l2_m128d+0x163>
xorps  %xmm0,%xmm0
sqrtsd %xmm1,%xmm0
jmp    12cc <distance_l2_m128d+0x16c>
movapd %xmm1,%xmm0
call   1080 <sqrt@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_12__ = type { i32, i32 }
define double @distance_l2_m128d(%struct.TYPE_12__* %0, %struct.TYPE_12__* %1, i32 %2) {
%4 = alloca %struct.TYPE_12__*
%5 = alloca %struct.TYPE_12__*
%6 = alloca i32
%7 = alloca double
%8 = alloca %struct.TYPE_12__
%9 = alloca [2 x double]
%10 = alloca i32
%11 = alloca %struct.TYPE_12__
%12 = alloca %struct.TYPE_12__
%13 = alloca %struct.TYPE_12__
store %struct.TYPE_12__* %0, %struct.TYPE_12__** %4
store %struct.TYPE_12__* %1, %struct.TYPE_12__** %5
store i32 %2, i32* %6
store double 0.000000e+00, double* %7
%14 = bitcast %struct.TYPE_12__* %8 to i8*
store i32 0, i32* %10
store i32 0, i32* %10
br label %15
15: ; preds = %48, %3
%16 = load i32, i32* %10
%17 = load i32, i32* %6
%18 = sdiv i32 %17, 2
%19 = icmp slt i32 %16, %18
br i1 %19, label %20, label %51
20: ; preds = %15
%21 = load %struct.TYPE_12__*, %struct.TYPE_12__** %4
%22 = load i32, i32* %10
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds %struct.TYPE_12__, %struct.TYPE_12__* %21, i64 %23
%25 = load %struct.TYPE_12__*, %struct.TYPE_12__** %5
%26 = load i32, i32* %10
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds %struct.TYPE_12__, %struct.TYPE_12__* %25, i64 %27
%29 = bitcast %struct.TYPE_12__* %24 to i64*
%30 = load i64, i64* %29
%31 = bitcast %struct.TYPE_12__* %28 to i64*
%32 = load i64, i64* %31
%33 = call i64 @_mm_sub_pd(i64 %30, i64 %32)
%34 = bitcast %struct.TYPE_12__* %12 to i64*
store i64 %33, i64* %34
%35 = bitcast %struct.TYPE_12__* %11 to i8*
%36 = bitcast %struct.TYPE_12__* %12 to i8*
%37 = bitcast %struct.TYPE_12__* %11 to i64*
%38 = load i64, i64* %37
%39 = bitcast %struct.TYPE_12__* %11 to i64*
%40 = load i64, i64* %39
%41 = call i32 @_mm_mul_pd(i64 %38, i64 %40)
%42 = bitcast %struct.TYPE_12__* %8 to i64*
%43 = load i64, i64* %42
%44 = call i64 @_mm_add_pd(i64 %43, i32 %41)
%45 = bitcast %struct.TYPE_12__* %13 to i64*
store i64 %44, i64* %45
%46 = bitcast %struct.TYPE_12__* %8 to i8*
%47 = bitcast %struct.TYPE_12__* %13 to i8*
br label %48
48: ; preds = %20
%49 = load i32, i32* %10
%50 = add nsw i32 %49, 1
store i32 %50, i32* %10
br label %15
51: ; preds = %15
%52 = getelementptr inbounds [2 x double], [2 x double]* %9, i64 0, i64 0
%53 = bitcast %struct.TYPE_12__* %8 to i64*
%54 = load i64, i64* %53
%55 = call i32 @_mm_store_pd(double* %52, i64 %54)
%56 = getelementptr inbounds [2 x double], [2 x double]* %9, i64 0, i64 0
%57 = load double, double* %56
%58 = getelementptr inbounds [2 x double], [2 x double]* %9, i64 0, i64 1
%59 = load double, double* %58
%60 = fadd double %57, %59
store double %60, double* %7
%61 = load i32, i32* %10
%62 = mul nsw i32 %61, 2
store i32 %62, i32* %10
br label %63
63: ; preds = %85, %51
%64 = load i32, i32* %10
%65 = load i32, i32* %6
%66 = icmp slt i32 %64, %65
br i1 %66, label %67, label %88
67: ; preds = %63
%68 = load %struct.TYPE_12__*, %struct.TYPE_12__** %4
%69 = bitcast %struct.TYPE_12__* %68 to double*
%70 = load i32, i32* %10
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds double, double* %69, i64 %71
%73 = load double, double* %72
%74 = load %struct.TYPE_12__*, %struct.TYPE_12__** %5
%75 = bitcast %struct.TYPE_12__* %74 to double*
%76 = load i32, i32* %10
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds double, double* %75, i64 %77
%79 = load double, double* %78
%80 = fsub double %73, %79
%81 = call i64 @pow(double %80, i32 2)
%82 = sitofp i64 %81 to double
%83 = load double, double* %7
%84 = fadd double %83, %82
store double %84, double* %7
br label %85
85: ; preds = %67
%86 = load i32, i32* %10
%87 = add nsw i32 %86, 1
store i32 %87, i32* %10
br label %63
88: ; preds = %63
%89 = load double, double* %7
%90 = call double @sqrt(double %89)
ret double %90
}

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