void vec_power(double *P, double *re, double *im, unsigned long N) {
  long j;
  for (j = 0; j < N; j++) {
    *(P + j) = (*(re + j) * *(re + j)) + (*(im + j) * *(im + j));
  }
}


x86 assembly (clang, -O0):
<vec_power>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1184 <vec_power+0x84>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    111c <vec_power+0x1c>
pop    %rbp
ret

x86 assembly (clang, -O2):
<vec_power>:
test   %rcx,%rcx
je     12dd <vec_power+0x1dd>
cmp    $0x4,%rcx
jae    1197 <vec_power+0x97>
xor    %eax,%eax
mov    %rax,%r8
not    %r8
test   $0x1,%cl
je     113f <vec_power+0x3f>
movsd  (%rsi,%rax,8),%xmm0
movsd  (%rdx,%rax,8),%xmm1
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rdi,%rax,8)
or     $0x1,%rax
add    %rcx,%r8
je     12dd <vec_power+0x1dd>
nopl   0x0(%rax,%rax,1)
movsd  (%rsi,%rax,8),%xmm0
movsd  (%rdx,%rax,8),%xmm1
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rdi,%rax,8)
movsd  0x8(%rsi,%rax,8),%xmm0
movsd  0x8(%rdx,%rax,8),%xmm1
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rdi,%rax,8)
add    $0x2,%rax
cmp    %rax,%rcx
jne    1150 <vec_power+0x50>
jmp    12dd <vec_power+0x1dd>
lea    (%rdi,%rcx,8),%r9
lea    (%rsi,%rcx,8),%rax
cmp    %rdi,%rax
seta   %r10b
lea    (%rdx,%rcx,8),%rax
cmp    %rsi,%r9
seta   %r11b
cmp    %rdi,%rax
seta   %r8b
cmp    %rdx,%r9
seta   %r9b
xor    %eax,%eax
test   %r11b,%r10b
jne    1115 <vec_power+0x15>
and    %r9b,%r8b
jne    1115 <vec_power+0x15>
mov    %rcx,%rax
and    $0xfffffffffffffffc,%rax
lea    -0x4(%rax),%r8
mov    %r8,%r9
shr    $0x2,%r9
add    $0x1,%r9
test   %r8,%r8
je     12de <vec_power+0x1de>
mov    %r9,%r10
and    $0xfffffffffffffffe,%r10
xor    %r8d,%r8d
nopl   0x0(%rax)
movupd (%rsi,%r8,8),%xmm0
movupd 0x10(%rsi,%r8,8),%xmm1
movupd (%rdx,%r8,8),%xmm2
movupd 0x10(%rdx,%r8,8),%xmm3
mulpd  %xmm2,%xmm2
mulpd  %xmm3,%xmm3
mulpd  %xmm0,%xmm0
addpd  %xmm2,%xmm0
mulpd  %xmm1,%xmm1
addpd  %xmm3,%xmm1
movupd %xmm0,(%rdi,%r8,8)
movupd %xmm1,0x10(%rdi,%r8,8)
movupd 0x20(%rsi,%r8,8),%xmm0
movupd 0x30(%rsi,%r8,8),%xmm1
movupd 0x20(%rdx,%r8,8),%xmm2
movupd 0x30(%rdx,%r8,8),%xmm3
mulpd  %xmm2,%xmm2
mulpd  %xmm3,%xmm3
mulpd  %xmm0,%xmm0
addpd  %xmm2,%xmm0
mulpd  %xmm1,%xmm1
addpd  %xmm3,%xmm1
movupd %xmm0,0x20(%rdi,%r8,8)
movupd %xmm1,0x30(%rdi,%r8,8)
add    $0x8,%r8
add    $0xfffffffffffffffe,%r10
jne    1200 <vec_power+0x100>
test   $0x1,%r9b
je     12d4 <vec_power+0x1d4>
movupd (%rsi,%r8,8),%xmm0
movupd 0x10(%rsi,%r8,8),%xmm1
movupd (%rdx,%r8,8),%xmm2
movupd 0x10(%rdx,%r8,8),%xmm3
mulpd  %xmm2,%xmm2
mulpd  %xmm3,%xmm3
mulpd  %xmm0,%xmm0
addpd  %xmm2,%xmm0
mulpd  %xmm1,%xmm1
addpd  %xmm3,%xmm1
movupd %xmm0,(%rdi,%r8,8)
movupd %xmm1,0x10(%rdi,%r8,8)
cmp    %rcx,%rax
jne    1115 <vec_power+0x15>
ret
xor    %r8d,%r8d
test   $0x1,%r9b
jne    1295 <vec_power+0x195>
jmp    12d4 <vec_power+0x1d4>

LLVM IR (-O0):
define void @vec_power(double* %0, double* %1, double* %2, i64 %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca i64
%9 = alloca i64
store double* %0, double** %5
store double* %1, double** %6
store double* %2, double** %7
store i64 %3, i64* %8
store i64 0, i64* %9
br label %10
10: ; preds = %36, %4
%11 = load i64, i64* %9
%12 = load i64, i64* %8
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %39
14: ; preds = %10
%15 = load double*, double** %6
%16 = load i64, i64* %9
%17 = getelementptr inbounds double, double* %15, i64 %16
%18 = load double, double* %17
%19 = load double*, double** %6
%20 = load i64, i64* %9
%21 = getelementptr inbounds double, double* %19, i64 %20
%22 = load double, double* %21
%23 = load double*, double** %7
%24 = load i64, i64* %9
%25 = getelementptr inbounds double, double* %23, i64 %24
%26 = load double, double* %25
%27 = load double*, double** %7
%28 = load i64, i64* %9
%29 = getelementptr inbounds double, double* %27, i64 %28
%30 = load double, double* %29
%31 = fmul double %26, %30
%32 = call double @llvm.fmuladd.f64(double %18, double %22, double %31)
%33 = load double*, double** %5
%34 = load i64, i64* %9
%35 = getelementptr inbounds double, double* %33, i64 %34
store double %32, double* %35
br label %36
36: ; preds = %14
%37 = load i64, i64* %9
%38 = add nsw i64 %37, 1
store i64 %38, i64* %9
br label %10
39: ; preds = %10
ret void
}

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