void mnm_darrscale(double *arr, const unsigned int n, const double scale) {
  unsigned int i;
  for (i = 0; i < n; i++)
    arr[i] *= scale;
}


x86 assembly (clang, -O0):
<mnm_darrscale>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1147 <mnm_darrscale+0x47>
movsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1117 <mnm_darrscale+0x17>
pop    %rbp
ret

x86 assembly (clang, -O2):
<mnm_darrscale>:
test   %esi,%esi
je     11e7 <mnm_darrscale+0xe7>
mov    %esi,%eax
cmp    $0x4,%esi
jae    1116 <mnm_darrscale+0x16>
xor    %ecx,%ecx
jmp    11d0 <mnm_darrscale+0xd0>
mov    %eax,%ecx
and    $0xfffffffc,%ecx
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
lea    -0x4(%rcx),%rdx
mov    %rdx,%r8
shr    $0x2,%r8
add    $0x1,%r8
test   %rdx,%rdx
je     11e8 <mnm_darrscale+0xe8>
mov    %r8,%rsi
and    $0xfffffffffffffffe,%rsi
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movupd (%rdi,%rdx,8),%xmm2
movupd 0x10(%rdi,%rdx,8),%xmm3
movupd 0x20(%rdi,%rdx,8),%xmm4
movupd 0x30(%rdi,%rdx,8),%xmm5
mulpd  %xmm1,%xmm2
mulpd  %xmm1,%xmm3
movupd %xmm2,(%rdi,%rdx,8)
movupd %xmm3,0x10(%rdi,%rdx,8)
mulpd  %xmm1,%xmm4
mulpd  %xmm1,%xmm5
movupd %xmm4,0x20(%rdi,%rdx,8)
movupd %xmm5,0x30(%rdi,%rdx,8)
add    $0x8,%rdx
add    $0xfffffffffffffffe,%rsi
jne    1150 <mnm_darrscale+0x50>
test   $0x1,%r8b
je     11bc <mnm_darrscale+0xbc>
movupd (%rdi,%rdx,8),%xmm2
movupd 0x10(%rdi,%rdx,8),%xmm3
mulpd  %xmm1,%xmm2
mulpd  %xmm1,%xmm3
movupd %xmm2,(%rdi,%rdx,8)
movupd %xmm3,0x10(%rdi,%rdx,8)
cmp    %rax,%rcx
je     11e7 <mnm_darrscale+0xe7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%rdi,%rcx,8),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%rdi,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    11d0 <mnm_darrscale+0xd0>
ret
xor    %edx,%edx
test   $0x1,%r8b
jne    119e <mnm_darrscale+0x9e>
jmp    11bc <mnm_darrscale+0xbc>

LLVM IR (-O0):
define void @mnm_darrscale(double* %0, i32 %1, double %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca double
%7 = alloca i32
store double* %0, double** %4
store i32 %1, i32* %5
store double %2, double* %6
store i32 0, i32* %7
br label %8
8: ; preds = %20, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %5
%11 = icmp ult i32 %9, %10
br i1 %11, label %12, label %23
12: ; preds = %8
%13 = load double, double* %6
%14 = load double*, double** %4
%15 = load i32, i32* %7
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds double, double* %14, i64 %16
%18 = load double, double* %17
%19 = fmul double %18, %13
store double %19, double* %17
br label %20
20: ; preds = %12
%21 = load i32, i32* %7
%22 = add i32 %21, 1
store i32 %22, i32* %7
br label %8
23: ; preds = %8
ret void
}

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