#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 int /*<<< orphan*/ __m128d;

/* Variables and functions */
int /*<<< orphan*/ _mm_add_pd(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_mul_pd(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_sqrt_pd(int /*<<< orphan*/);
double sqrtf(double);
void distance_vec(double *x, double *y, double *z, double *d, int n) {
  __m128d *xx = (__m128d *)x;
  __m128d *yy = (__m128d *)y;
  __m128d *zz = (__m128d *)z;
  __m128d *dd = (__m128d *)d;
  int k = n / 2;
  for (int i = 0; i < k; i++) {
    __m128d t1 = _mm_mul_pd(xx[i], xx[i]);
    __m128d t2 = _mm_mul_pd(yy[i], yy[i]);
    __m128d t3 = _mm_mul_pd(zz[i], zz[i]);
    t1 = _mm_add_pd(t1, t2);
    t1 = _mm_add_pd(t1, t3);
    dd[i] = _mm_sqrt_pd(t1);
  }
  for (int i = k * 2; i < n; i++) {
    d[i] = sqrtf(x[i] * x[i] + y[i] * y[i] + z[i] * z[i]);
  }
}


x86 assembly (clang, -O0):
<distance_vec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4c(%rbp)
movl   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jge    1236 <distance_vec+0xf6>
mov    -0x30(%rbp),%rax
movslq -0x50(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x30(%rbp),%rax
movslq -0x50(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1060 <_mm_mul_pd@plt>
mov    %eax,-0x54(%rbp)
mov    -0x38(%rbp),%rax
movslq -0x50(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x38(%rbp),%rax
movslq -0x50(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1060 <_mm_mul_pd@plt>
mov    %eax,-0x58(%rbp)
mov    -0x40(%rbp),%rax
movslq -0x50(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x40(%rbp),%rax
movslq -0x50(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1060 <_mm_mul_pd@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x54(%rbp),%edi
mov    -0x58(%rbp),%esi
call   1030 <_mm_add_pd@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%edi
mov    -0x5c(%rbp),%esi
call   1030 <_mm_add_pd@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%edi
call   1040 <_mm_sqrt_pd@plt>
mov    %eax,%edx
mov    -0x48(%rbp),%rax
movslq -0x50(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    1191 <distance_vec+0x51>
mov    -0x4c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x60(%rbp)
mov    -0x60(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    12c9 <distance_vec+0x189>
mov    -0x8(%rbp),%rax
movslq -0x60(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x8(%rbp),%rax
movslq -0x60(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x10(%rbp),%rax
movslq -0x60(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x60(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x18(%rbp),%rax
movslq -0x60(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x60(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1050 <sqrtf@plt>
mov    -0x20(%rbp),%rax
movslq -0x60(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    123f <distance_vec+0xff>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<distance_vec>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%rbp
mov    %r8d,%eax
shr    $0x1f,%eax
add    %r8d,%eax
sar    %eax
mov    %eax,0x4(%rsp)
mov    %r8d,0x14(%rsp)
cmp    $0x2,%r8d
jl     11f4 <distance_vec+0xb4>
mov    0x4(%rsp),%eax
mov    %rax,0x18(%rsp)
xor    %r12d,%r12d
mov    %rbx,0x20(%rsp)
nopl   0x0(%rax)
mov    0x0(%rbp,%r12,4),%edi
mov    %edi,%esi
call   1060 <_mm_mul_pd@plt>
mov    %eax,0x8(%rsp)
mov    0x0(%r13,%r12,4),%edi
mov    %edi,%esi
call   1060 <_mm_mul_pd@plt>
mov    %r13,%rbx
mov    %eax,%r13d
mov    (%r15,%r12,4),%edi
mov    %edi,%esi
call   1060 <_mm_mul_pd@plt>
mov    %eax,%r14d
mov    0x8(%rsp),%edi
mov    %r13d,%esi
mov    %rbx,%r13
mov    0x20(%rsp),%rbx
call   1030 <_mm_add_pd@plt>
mov    %eax,%edi
mov    %r14d,%esi
call   1030 <_mm_add_pd@plt>
mov    %eax,%edi
call   1040 <_mm_sqrt_pd@plt>
mov    %eax,(%rbx,%r12,4)
add    $0x1,%r12
cmp    %r12,0x18(%rsp)
jne    1190 <distance_vec+0x50>
mov    0x4(%rsp),%ecx
add    %ecx,%ecx
mov    0x14(%rsp),%eax
cmp    %eax,%ecx
jge    126f <distance_vec+0x12f>
mov    %r15,%r12
mov    %rbp,0x8(%rsp)
movslq %ecx,%rbp
movslq %eax,%r14
mov    %rbp,%r15
not    %r15
test   $0x1,%r14b
je     1265 <distance_vec+0x125>
mov    0x8(%rsp),%rax
movsd  (%rax,%rbp,8),%xmm1
movsd  0x0(%r13,%rbp,8),%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  (%r12,%rbp,8),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1257 <distance_vec+0x117>
sqrtsd %xmm0,%xmm0
jmp    125c <distance_vec+0x11c>
call   1050 <sqrtf@plt>
movsd  %xmm0,(%rbx,%rbp,8)
or     $0x1,%rbp
add    %r14,%r15
mov    0x8(%rsp),%r15
jne    127e <distance_vec+0x13e>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xorpd  %xmm2,%xmm2
jmp    12a8 <distance_vec+0x168>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
call   1050 <sqrtf@plt>
xorpd  %xmm2,%xmm2
movsd  %xmm0,0x8(%rbx,%rbp,8)
add    $0x2,%rbp
cmp    %rbp,%r14
je     126f <distance_vec+0x12f>
movsd  (%r15,%rbp,8),%xmm1
movsd  0x0(%r13,%rbp,8),%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  (%r12,%rbp,8),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
jb     12e0 <distance_vec+0x1a0>
sqrtsd %xmm0,%xmm0
jmp    12e9 <distance_vec+0x1a9>
nopl   0x0(%rax,%rax,1)
call   1050 <sqrtf@plt>
xorpd  %xmm2,%xmm2
movsd  %xmm0,(%rbx,%rbp,8)
movsd  0x8(%r15,%rbp,8),%xmm1
movsd  0x8(%r13,%rbp,8),%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0x8(%r12,%rbp,8),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
jb     1290 <distance_vec+0x150>
sqrtsd %xmm0,%xmm0
jmp    1299 <distance_vec+0x159>

LLVM IR (-O0):
define void @distance_vec(double* %0, double* %1, double* %2, double* %3, i32 %4) {
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store double* %0, double** %6
store double* %1, double** %7
store double* %2, double** %8
store double* %3, double** %9
store i32 %4, i32* %10
%21 = load double*, double** %6
%22 = bitcast double* %21 to i32*
store i32* %22, i32** %11
%23 = load double*, double** %7
%24 = bitcast double* %23 to i32*
store i32* %24, i32** %12
%25 = load double*, double** %8
%26 = bitcast double* %25 to i32*
store i32* %26, i32** %13
%27 = load double*, double** %9
%28 = bitcast double* %27 to i32*
store i32* %28, i32** %14
%29 = load i32, i32* %10
%30 = sdiv i32 %29, 2
store i32 %30, i32* %15
store i32 0, i32* %16
br label %31
31: ; preds = %81, %5
%32 = load i32, i32* %16
%33 = load i32, i32* %15
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %84
35: ; preds = %31
%36 = load i32*, i32** %11
%37 = load i32, i32* %16
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = load i32, i32* %39
%41 = load i32*, i32** %11
%42 = load i32, i32* %16
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
%45 = load i32, i32* %44
%46 = call i32 @_mm_mul_pd(i32 %40, i32 %45)
store i32 %46, i32* %17
%47 = load i32*, i32** %12
%48 = load i32, i32* %16
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %47, i64 %49
%51 = load i32, i32* %50
%52 = load i32*, i32** %12
%53 = load i32, i32* %16
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i32, i32* %52, i64 %54
%56 = load i32, i32* %55
%57 = call i32 @_mm_mul_pd(i32 %51, i32 %56)
store i32 %57, i32* %18
%58 = load i32*, i32** %13
%59 = load i32, i32* %16
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i32, i32* %58, i64 %60
%62 = load i32, i32* %61
%63 = load i32*, i32** %13
%64 = load i32, i32* %16
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i32, i32* %63, i64 %65
%67 = load i32, i32* %66
%68 = call i32 @_mm_mul_pd(i32 %62, i32 %67)
store i32 %68, i32* %19
%69 = load i32, i32* %17
%70 = load i32, i32* %18
%71 = call i32 @_mm_add_pd(i32 %69, i32 %70)
store i32 %71, i32* %17
%72 = load i32, i32* %17
%73 = load i32, i32* %19
%74 = call i32 @_mm_add_pd(i32 %72, i32 %73)
store i32 %74, i32* %17
%75 = load i32, i32* %17
%76 = call i32 @_mm_sqrt_pd(i32 %75)
%77 = load i32*, i32** %14
%78 = load i32, i32* %16
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i32, i32* %77, i64 %79
store i32 %76, i32* %80
br label %81
81: ; preds = %35
%82 = load i32, i32* %16
%83 = add nsw i32 %82, 1
store i32 %83, i32* %16
br label %31
84: ; preds = %31
%85 = load i32, i32* %15
%86 = mul nsw i32 %85, 2
store i32 %86, i32* %20
br label %87
87: ; preds = %130, %84
%88 = load i32, i32* %20
%89 = load i32, i32* %10
%90 = icmp slt i32 %88, %89
br i1 %90, label %91, label %133
91: ; preds = %87
%92 = load double*, double** %6
%93 = load i32, i32* %20
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds double, double* %92, i64 %94
%96 = load double, double* %95
%97 = load double*, double** %6
%98 = load i32, i32* %20
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds double, double* %97, i64 %99
%101 = load double, double* %100
%102 = load double*, double** %7
%103 = load i32, i32* %20
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds double, double* %102, i64 %104
%106 = load double, double* %105
%107 = load double*, double** %7
%108 = load i32, i32* %20
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds double, double* %107, i64 %109
%111 = load double, double* %110
%112 = fmul double %106, %111
%113 = call double @llvm.fmuladd.f64(double %96, double %101, double %112)
%114 = load double*, double** %8
%115 = load i32, i32* %20
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds double, double* %114, i64 %116
%118 = load double, double* %117
%119 = load double*, double** %8
%120 = load i32, i32* %20
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds double, double* %119, i64 %121
%123 = load double, double* %122
%124 = call double @llvm.fmuladd.f64(double %118, double %123, double %113)
%125 = call double @sqrtf(double %124)
%126 = load double*, double** %9
%127 = load i32, i32* %20
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds double, double* %126, i64 %128
store double %125, double* %129
br label %130
130: ; preds = %91
%131 = load i32, i32* %20
%132 = add nsw i32 %131, 1
store i32 %132, i32* %20
br label %87
133: ; preds = %87
ret void
}

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