double project(double *u, double *Re, double *Im, int n, double step) {
  int i, j, k;
  double dotprod, dotr, doti;
  dotprod = 0.0;
  dotr = 0.0;
  doti = 0.0;
  for (i = 0; i < n; i++) {
    dotr = dotr + u[i] * Re[i] * step;
    doti = doti + u[i] * Im[i] * step;
  }
  dotprod = dotr * dotr + doti * doti;
  return dotprod;
}


x86 assembly (clang, -O0):
<project>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11b3 <project+0xb3>
movsd  -0x48(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x50(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1137 <project+0x37>
movsd  -0x48(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm1
mulsd  -0x50(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<project>:
test   %ecx,%ecx
jle    1121 <project+0x21>
mov    %ecx,%r8d
unpcklpd %xmm0,%xmm0
cmp    $0x1,%ecx
jne    112a <project+0x2a>
xorpd  %xmm2,%xmm2
xor    %ecx,%ecx
test   $0x1,%r8b
jne    1198 <project+0x98>
jmp    11b7 <project+0xb7>
xorpd  %xmm1,%xmm1
jmp    11b7 <project+0xb7>
mov    %r8d,%eax
and    $0xfffffffe,%eax
xorpd  %xmm2,%xmm2
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
movsd  (%rdi,%rcx,8),%xmm4
movsd  0x8(%rdi,%rcx,8),%xmm5
unpcklpd %xmm4,%xmm4
movsd  (%rsi,%rcx,8),%xmm3
movhpd (%rdx,%rcx,8),%xmm3
movsd  0x8(%rsi,%rcx,8),%xmm1
mulpd  %xmm4,%xmm3
mulpd  %xmm0,%xmm3
addpd  %xmm2,%xmm3
unpcklpd %xmm5,%xmm5
movhpd 0x8(%rdx,%rcx,8),%xmm1
mulpd  %xmm5,%xmm1
mulpd  %xmm0,%xmm1
movapd %xmm1,%xmm2
addpd  %xmm3,%xmm2
add    $0x2,%rcx
cmp    %rcx,%rax
jne    1140 <project+0x40>
addpd  %xmm3,%xmm1
test   $0x1,%r8b
je     11b7 <project+0xb7>
movsd  (%rdi,%rcx,8),%xmm3
movsd  (%rsi,%rcx,8),%xmm1
movhpd (%rdx,%rcx,8),%xmm1
unpcklpd %xmm3,%xmm3
mulpd  %xmm3,%xmm1
mulpd  %xmm0,%xmm1
addpd  %xmm2,%xmm1
movapd %xmm1,%xmm0
mulpd  %xmm1,%xmm0
unpckhpd %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
ret

LLVM IR (-O0):
define double @project(double* %0, double* %1, double* %2, i32 %3, double %4) {
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca double
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca double
%15 = alloca double
%16 = alloca double
store double* %0, double** %6
store double* %1, double** %7
store double* %2, double** %8
store i32 %3, i32* %9
store double %4, double* %10
store double 0.000000e+00, double* %14
store double 0.000000e+00, double* %15
store double 0.000000e+00, double* %16
store i32 0, i32* %11
br label %17
17: ; preds = %50, %5
%18 = load i32, i32* %11
%19 = load i32, i32* %9
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %53
21: ; preds = %17
%22 = load double, double* %15
%23 = load double*, double** %6
%24 = load i32, i32* %11
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
%27 = load double, double* %26
%28 = load double*, double** %7
%29 = load i32, i32* %11
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
%32 = load double, double* %31
%33 = fmul double %27, %32
%34 = load double, double* %10
%35 = call double @llvm.fmuladd.f64(double %33, double %34, double %22)
store double %35, double* %15
%36 = load double, double* %16
%37 = load double*, double** %6
%38 = load i32, i32* %11
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %37, i64 %39
%41 = load double, double* %40
%42 = load double*, double** %8
%43 = load i32, i32* %11
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %42, i64 %44
%46 = load double, double* %45
%47 = fmul double %41, %46
%48 = load double, double* %10
%49 = call double @llvm.fmuladd.f64(double %47, double %48, double %36)
store double %49, double* %16
br label %50
50: ; preds = %21
%51 = load i32, i32* %11
%52 = add nsw i32 %51, 1
store i32 %52, i32* %11
br label %17
53: ; preds = %17
%54 = load double, double* %15
%55 = load double, double* %15
%56 = load double, double* %16
%57 = load double, double* %16
%58 = fmul double %56, %57
%59 = call double @llvm.fmuladd.f64(double %54, double %55, double %58)
store double %59, double* %14
%60 = load double, double* %14
ret double %60
}

LLVM IR (-O2):
define double @project(double* nocapture %0, double* nocapture %1, double* nocapture %2, i32 %3, double %4) {
%6 = icmp sgt i32 %3, 0
br i1 %6, label %7, label %69
7: ; preds = %5
%8 = zext i32 %3 to i64
%9 = insertelement <2 x double> poison, double %4, i64 0
%10 = shufflevector <2 x double> %9, <2 x double> poison, <2 x i32> zeroinitializer
%11 = insertelement <2 x double> poison, double %4, i64 0
%12 = shufflevector <2 x double> %11, <2 x double> poison, <2 x i32> zeroinitializer
%13 = and i64 %8, 1
%14 = icmp eq i32 %3, 1
br i1 %14, label %51, label %15
15: ; preds = %7
%16 = and i64 %8, 4294967294
br label %17
17: ; preds = %17, %15
%18 = phi i64 [ 0, %15 ], [ %46, %17 ]
%19 = phi <2 x double> [ zeroinitializer, %15 ], [ %45, %17 ]
%20 = phi i64 [ 0, %15 ], [ %47, %17 ]
%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 = getelementptr inbounds double, double* %2, i64 %18
%26 = load double, double* %25
%27 = insertelement <2 x double> poison, double %22, i64 0
%28 = shufflevector <2 x double> %27, <2 x double> poison, <2 x i32> zeroinitializer
%29 = insertelement <2 x double> poison, double %24, i64 0
%30 = insertelement <2 x double> %29, double %26, i64 1
%31 = fmul <2 x double> %28, %30
%32 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %31, <2 x double> %12, <2 x double> %19)
%33 = or i64 %18, 1
%34 = getelementptr inbounds double, double* %0, i64 %33
%35 = load double, double* %34
%36 = getelementptr inbounds double, double* %1, i64 %33
%37 = load double, double* %36
%38 = getelementptr inbounds double, double* %2, i64 %33
%39 = load double, double* %38
%40 = insertelement <2 x double> poison, double %35, i64 0
%41 = shufflevector <2 x double> %40, <2 x double> poison, <2 x i32> zeroinitializer
%42 = insertelement <2 x double> poison, double %37, i64 0
%43 = insertelement <2 x double> %42, double %39, i64 1
%44 = fmul <2 x double> %41, %43
%45 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %44, <2 x double> %12, <2 x double> %32)
%46 = add nuw nsw i64 %18, 2
%47 = add i64 %20, 2
%48 = icmp eq i64 %47, %16
br i1 %48, label %49, label %17
49: ; preds = %17
%50 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %44, <2 x double> %10, <2 x double> %32)
br label %51
51: ; preds = %49, %7
%52 = phi <2 x double> [ undef, %7 ], [ %50, %49 ]
%53 = phi i64 [ 0, %7 ], [ %46, %49 ]
%54 = phi <2 x double> [ zeroinitializer, %7 ], [ %45, %49 ]
%55 = icmp eq i64 %13, 0
br i1 %55, label %69, label %56
56: ; preds = %51
%57 = getelementptr inbounds double, double* %0, i64 %53
%58 = load double, double* %57
%59 = getelementptr inbounds double, double* %1, i64 %53
%60 = load double, double* %59
%61 = getelementptr inbounds double, double* %2, i64 %53
%62 = load double, double* %61
%63 = insertelement <2 x double> poison, double %58, i64 0
%64 = shufflevector <2 x double> %63, <2 x double> poison, <2 x i32> zeroinitializer
%65 = insertelement <2 x double> poison, double %60, i64 0
%66 = insertelement <2 x double> %65, double %62, i64 1
%67 = fmul <2 x double> %64, %66
%68 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %67, <2 x double> %10, <2 x double> %54)
br label %69
69: ; preds = %56, %51, %5
%70 = phi <2 x double> [ zeroinitializer, %5 ], [ %52, %51 ], [ %68, %56 ]
%71 = fmul <2 x double> %70, %70
%72 = extractelement <2 x double> %71, i64 1
%73 = extractelement <2 x double> %70, i64 0
%74 = tail call double @llvm.fmuladd.f64(double %73, double %73, double %72)
ret double %74
}