int NormTwoSquareRealDenseVector(x_p, nz_p, xtx)
double *x_p;
double *xtx;
int *nz_p;
{
  static double *x_ps;
  *xtx = 0.0;
  x_ps = x_p + *nz_p;
  for (; x_p < x_ps; x_p++)
    *xtx += *x_p * *x_p;
  return 0;
}


x86 assembly (clang, -O0):
<NormTwoSquareRealDenseVector>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,0x2ef4(%rip)
mov    -0x8(%rbp),%rax
cmp    0x2ee9(%rip),%rax
jae    117a <NormTwoSquareRealDenseVector+0x7a>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
jmp    1134 <NormTwoSquareRealDenseVector+0x34>
xor    %eax,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<NormTwoSquareRealDenseVector>:
movq   $0x0,(%rdx)
movslq (%rsi),%rcx
lea    (%rdi,%rcx,8),%rax
mov    %rax,0x2f13(%rip)
test   %rcx,%rcx
jle    1139 <NormTwoSquareRealDenseVector+0x39>
xorpd  %xmm0,%xmm0
xchg   %ax,%ax
movsd  (%rdi),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rdx)
add    $0x8,%rdi
cmp    %rax,%rdi
jb     1120 <NormTwoSquareRealDenseVector+0x20>
xor    %eax,%eax
ret

LLVM IR (-O0):
@NormTwoSquareRealDenseVector.x_ps = internal global double* null
define i32 @NormTwoSquareRealDenseVector(double* %0, i32* %1, double* %2) {
%4 = alloca double*
%5 = alloca i32*
%6 = alloca double*
store double* %0, double** %4
store i32* %1, i32** %5
store double* %2, double** %6
%7 = load double*, double** %6
store double 0.000000e+00, double* %7
%8 = load double*, double** %4
%9 = load i32*, i32** %5
%10 = load i32, i32* %9
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds double, double* %8, i64 %11
store double* %12, double** @NormTwoSquareRealDenseVector.x_ps
br label %13
13: ; preds = %25, %3
%14 = load double*, double** %4
%15 = load double*, double** @NormTwoSquareRealDenseVector.x_ps
%16 = icmp ult double* %14, %15
br i1 %16, label %17, label %28
17: ; preds = %13
%18 = load double*, double** %4
%19 = load double, double* %18
%20 = load double*, double** %4
%21 = load double, double* %20
%22 = load double*, double** %6
%23 = load double, double* %22
%24 = call double @llvm.fmuladd.f64(double %19, double %21, double %23)
store double %24, double* %22
br label %25
25: ; preds = %17
%26 = load double*, double** %4
%27 = getelementptr inbounds double, double* %26, i32 1
store double* %27, double** %4
br label %13
28: ; preds = %13
ret i32 0
}

LLVM IR (-O2):
@NormTwoSquareRealDenseVector.x_ps = internal unnamed_addr global double* null
define i32 @NormTwoSquareRealDenseVector(double* %0, i32* nocapture %1, double* nocapture %2) {
store double 0.000000e+00, double* %2
%4 = load i32, i32* %1
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds double, double* %0, i64 %5
store double* %6, double** @NormTwoSquareRealDenseVector.x_ps
%7 = icmp sgt i32 %4, 0
br i1 %7, label %8, label %15
8: ; preds = %3, %8
%9 = phi double [ %12, %8 ], [ 0.000000e+00, %3 ]
%10 = phi double* [ %13, %8 ], [ %0, %3 ]
%11 = load double, double* %10
%12 = tail call double @llvm.fmuladd.f64(double %11, double %11, double %9)
store double %12, double* %2
%13 = getelementptr inbounds double, double* %10, i64 1
%14 = icmp ult double* %13, %6
br i1 %14, label %8, label %15
15: ; preds = %8, %3
ret i32 0
}