void PT_mac_scale(double *sum, double *p1, double p2, int n) {
  int i;
  for (i = 0; i < n; i++) {
    sum[i] += p1[i] * p2;
  }
}


x86 assembly (clang, -O0):
<PT_mac_scale>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1161 <PT_mac_scale+0x61>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  -0x18(%rbp),%xmm2
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    111b <PT_mac_scale+0x1b>
pop    %rbp
ret

x86 assembly (clang, -O2):
<PT_mac_scale>:
test   %edx,%edx
jle    126f <PT_mac_scale+0x16f>
mov    %edx,%r9d
cmp    $0x4,%edx
jb     1122 <PT_mac_scale+0x22>
lea    (%rsi,%r9,8),%rax
cmp    %rdi,%rax
jbe    1187 <PT_mac_scale+0x87>
lea    (%rdi,%r9,8),%rax
cmp    %rsi,%rax
jbe    1187 <PT_mac_scale+0x87>
xor    %ecx,%ecx
mov    %rcx,%rax
not    %rax
test   $0x1,%r9b
je     1147 <PT_mac_scale+0x47>
movsd  (%rsi,%rcx,8),%xmm1
mulsd  %xmm0,%xmm1
addsd  (%rdi,%rcx,8),%xmm1
movsd  %xmm1,(%rdi,%rcx,8)
or     $0x1,%rcx
add    %r9,%rax
je     126f <PT_mac_scale+0x16f>
movsd  (%rsi,%rcx,8),%xmm1
mulsd  %xmm0,%xmm1
addsd  (%rdi,%rcx,8),%xmm1
movsd  %xmm1,(%rdi,%rcx,8)
movsd  0x8(%rsi,%rcx,8),%xmm1
mulsd  %xmm0,%xmm1
addsd  0x8(%rdi,%rcx,8),%xmm1
movsd  %xmm1,0x8(%rdi,%rcx,8)
add    $0x2,%rcx
cmp    %rcx,%r9
jne    1150 <PT_mac_scale+0x50>
jmp    126f <PT_mac_scale+0x16f>
mov    %r9d,%ecx
and    $0xfffffffc,%ecx
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
lea    -0x4(%rcx),%rax
mov    %rax,%r8
shr    $0x2,%r8
add    $0x1,%r8
test   %rax,%rax
je     1270 <PT_mac_scale+0x170>
mov    %r8,%rax
and    $0xfffffffffffffffe,%rax
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
movupd (%rsi,%rdx,8),%xmm2
movupd 0x10(%rsi,%rdx,8),%xmm3
mulpd  %xmm1,%xmm2
movupd (%rdi,%rdx,8),%xmm4
addpd  %xmm2,%xmm4
movupd 0x10(%rdi,%rdx,8),%xmm2
movupd 0x20(%rdi,%rdx,8),%xmm5
movupd 0x30(%rdi,%rdx,8),%xmm6
mulpd  %xmm1,%xmm3
addpd  %xmm2,%xmm3
movupd %xmm4,(%rdi,%rdx,8)
movupd %xmm3,0x10(%rdi,%rdx,8)
movupd 0x20(%rsi,%rdx,8),%xmm2
movupd 0x30(%rsi,%rdx,8),%xmm3
mulpd  %xmm1,%xmm2
addpd  %xmm5,%xmm2
mulpd  %xmm1,%xmm3
addpd  %xmm6,%xmm3
movupd %xmm2,0x20(%rdi,%rdx,8)
movupd %xmm3,0x30(%rdi,%rdx,8)
add    $0x8,%rdx
add    $0xfffffffffffffffe,%rax
jne    11c0 <PT_mac_scale+0xc0>
test   $0x1,%r8b
je     1266 <PT_mac_scale+0x166>
movupd (%rsi,%rdx,8),%xmm2
movupd 0x10(%rsi,%rdx,8),%xmm3
movupd (%rdi,%rdx,8),%xmm4
movupd 0x10(%rdi,%rdx,8),%xmm5
mulpd  %xmm1,%xmm2
addpd  %xmm4,%xmm2
mulpd  %xmm1,%xmm3
addpd  %xmm5,%xmm3
movupd %xmm2,(%rdi,%rdx,8)
movupd %xmm3,0x10(%rdi,%rdx,8)
cmp    %r9,%rcx
jne    1124 <PT_mac_scale+0x24>
ret
xor    %edx,%edx
test   $0x1,%r8b
jne    1235 <PT_mac_scale+0x135>
jmp    1266 <PT_mac_scale+0x166>

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

LLVM IR (-O2):
define void @PT_mac_scale(double* nocapture %0, double* nocapture %1, double %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %120
6: ; preds = %4
%7 = zext i32 %3 to i64
%8 = icmp ult i32 %3, 4
br i1 %8, label %89, label %9
9: ; preds = %6
%10 = getelementptr double, double* %0, i64 %7
%11 = getelementptr double, double* %1, i64 %7
%12 = icmp ugt double* %11, %0
%13 = icmp ugt double* %10, %1
%14 = and i1 %12, %13
br i1 %14, label %89, label %15
15: ; preds = %9
%16 = and i64 %7, 4294967292
%17 = insertelement <2 x double> poison, double %2, i64 0
%18 = shufflevector <2 x double> %17, <2 x double> poison, <2 x i32> zeroinitializer
%19 = insertelement <2 x double> poison, double %2, i64 0
%20 = shufflevector <2 x double> %19, <2 x double> poison, <2 x i32> zeroinitializer
%21 = add nsw i64 %16, -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 %67, label %26
26: ; preds = %15
%27 = and i64 %23, 9223372036854775806
br label %28
28: ; preds = %28, %26
%29 = phi i64 [ 0, %26 ], [ %64, %28 ]
%30 = phi i64 [ 0, %26 ], [ %65, %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* %0, 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 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %33, <2 x double> %18, <2 x double> %39)
%44 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %36, <2 x double> %20, <2 x double> %42)
%45 = bitcast double* %37 to <2 x double>*
store <2 x double> %43, <2 x double>* %45
%46 = bitcast double* %40 to <2 x double>*
store <2 x double> %44, <2 x double>* %46
%47 = or i64 %29, 4
%48 = getelementptr inbounds double, double* %1, i64 %47
%49 = bitcast double* %48 to <2 x double>*
%50 = load <2 x double>, <2 x double>* %49
%51 = getelementptr inbounds double, double* %48, i64 2
%52 = bitcast double* %51 to <2 x double>*
%53 = load <2 x double>, <2 x double>* %52
%54 = getelementptr inbounds double, double* %0, i64 %47
%55 = bitcast double* %54 to <2 x double>*
%56 = load <2 x double>, <2 x double>* %55
%57 = getelementptr inbounds double, double* %54, i64 2
%58 = bitcast double* %57 to <2 x double>*
%59 = load <2 x double>, <2 x double>* %58
%60 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %50, <2 x double> %18, <2 x double> %56)
%61 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %53, <2 x double> %20, <2 x double> %59)
%62 = bitcast double* %54 to <2 x double>*
store <2 x double> %60, <2 x double>* %62
%63 = bitcast double* %57 to <2 x double>*
store <2 x double> %61, <2 x double>* %63
%64 = add nuw i64 %29, 8
%65 = add i64 %30, 2
%66 = icmp eq i64 %65, %27
br i1 %66, label %67, label %28
67: ; preds = %28, %15
%68 = phi i64 [ 0, %15 ], [ %64, %28 ]
%69 = icmp eq i64 %24, 0
br i1 %69, label %87, label %70
70: ; preds = %67
%71 = getelementptr inbounds double, double* %1, i64 %68
%72 = bitcast double* %71 to <2 x double>*
%73 = load <2 x double>, <2 x double>* %72
%74 = getelementptr inbounds double, double* %71, i64 2
%75 = bitcast double* %74 to <2 x double>*
%76 = load <2 x double>, <2 x double>* %75
%77 = getelementptr inbounds double, double* %0, i64 %68
%78 = bitcast double* %77 to <2 x double>*
%79 = load <2 x double>, <2 x double>* %78
%80 = getelementptr inbounds double, double* %77, i64 2
%81 = bitcast double* %80 to <2 x double>*
%82 = load <2 x double>, <2 x double>* %81
%83 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %73, <2 x double> %18, <2 x double> %79)
%84 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %76, <2 x double> %20, <2 x double> %82)
%85 = bitcast double* %77 to <2 x double>*
store <2 x double> %83, <2 x double>* %85
%86 = bitcast double* %80 to <2 x double>*
store <2 x double> %84, <2 x double>* %86
br label %87
87: ; preds = %67, %70
%88 = icmp eq i64 %16, %7
br i1 %88, label %120, label %89
89: ; preds = %9, %6, %87
%90 = phi i64 [ 0, %9 ], [ 0, %6 ], [ %16, %87 ]
%91 = xor i64 %90, -1
%92 = and i64 %7, 1
%93 = icmp eq i64 %92, 0
br i1 %93, label %101, label %94
94: ; preds = %89
%95 = getelementptr inbounds double, double* %1, i64 %90
%96 = load double, double* %95
%97 = getelementptr inbounds double, double* %0, i64 %90
%98 = load double, double* %97
%99 = tail call double @llvm.fmuladd.f64(double %96, double %2, double %98)
store double %99, double* %97
%100 = or i64 %90, 1
br label %101
101: ; preds = %94, %89
%102 = phi i64 [ %90, %89 ], [ %100, %94 ]
%103 = sub nsw i64 0, %7
%104 = icmp eq i64 %91, %103
br i1 %104, label %120, label %105
105: ; preds = %101, %105
%106 = phi i64 [ %118, %105 ], [ %102, %101 ]
%107 = getelementptr inbounds double, double* %1, i64 %106
%108 = load double, double* %107
%109 = getelementptr inbounds double, double* %0, i64 %106
%110 = load double, double* %109
%111 = tail call double @llvm.fmuladd.f64(double %108, double %2, double %110)
store double %111, double* %109
%112 = add nuw nsw i64 %106, 1
%113 = getelementptr inbounds double, double* %1, i64 %112
%114 = load double, double* %113
%115 = getelementptr inbounds double, double* %0, i64 %112
%116 = load double, double* %115
%117 = tail call double @llvm.fmuladd.f64(double %114, double %2, double %116)
store double %117, double* %115
%118 = add nuw nsw i64 %106, 2
%119 = icmp eq i64 %118, %7
br i1 %119, label %120, label %105
120: ; preds = %101, %105, %87, %4
ret void
}