void array_scale(double *a, int n, double scale_factor, double offset) {
  int i;
  for (i = 0; i < n; a[i] = a[i] * scale_factor + offset, i++)
    ;
}


x86 assembly (clang, -O0):
<array_scale>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1167 <array_scale+0x67>
jmp    112d <array_scale+0x2d>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    111c <array_scale+0x1c>
pop    %rbp
ret

x86 assembly (clang, -O2):
<array_scale>:
test   %esi,%esi
jle    11fb <array_scale+0xfb>
mov    %esi,%eax
cmp    $0x4,%esi
jae    1116 <array_scale+0x16>
xor    %ecx,%ecx
jmp    11e0 <array_scale+0xe0>
mov    %eax,%ecx
and    $0xfffffffc,%ecx
movapd %xmm0,%xmm2
unpcklpd %xmm0,%xmm2
movapd %xmm1,%xmm3
unpcklpd %xmm1,%xmm3
lea    -0x4(%rcx),%rdx
mov    %rdx,%r8
shr    $0x2,%r8
add    $0x1,%r8
test   %rdx,%rdx
je     11fc <array_scale+0xfc>
mov    %r8,%rsi
and    $0xfffffffffffffffe,%rsi
xor    %edx,%edx
nopl   0x0(%rax)
movupd (%rdi,%rdx,8),%xmm4
movupd 0x10(%rdi,%rdx,8),%xmm5
movupd 0x20(%rdi,%rdx,8),%xmm6
movupd 0x30(%rdi,%rdx,8),%xmm7
mulpd  %xmm2,%xmm4
addpd  %xmm3,%xmm4
mulpd  %xmm2,%xmm5
addpd  %xmm3,%xmm5
movupd %xmm4,(%rdi,%rdx,8)
movupd %xmm5,0x10(%rdi,%rdx,8)
mulpd  %xmm2,%xmm6
addpd  %xmm3,%xmm6
mulpd  %xmm2,%xmm7
addpd  %xmm3,%xmm7
movupd %xmm6,0x20(%rdi,%rdx,8)
movupd %xmm7,0x30(%rdi,%rdx,8)
add    $0x8,%rdx
add    $0xfffffffffffffffe,%rsi
jne    1150 <array_scale+0x50>
test   $0x1,%r8b
je     11d4 <array_scale+0xd4>
movupd (%rdi,%rdx,8),%xmm4
movupd 0x10(%rdi,%rdx,8),%xmm5
mulpd  %xmm2,%xmm4
addpd  %xmm3,%xmm4
mulpd  %xmm2,%xmm5
addpd  %xmm3,%xmm5
movupd %xmm4,(%rdi,%rdx,8)
movupd %xmm5,0x10(%rdi,%rdx,8)
cmp    %rax,%rcx
je     11fb <array_scale+0xfb>
nopl   0x0(%rax)
movsd  (%rdi,%rcx,8),%xmm2
mulsd  %xmm0,%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,(%rdi,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    11e0 <array_scale+0xe0>
ret
xor    %edx,%edx
test   $0x1,%r8b
jne    11ae <array_scale+0xae>
jmp    11d4 <array_scale+0xd4>

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