void mms_dscal(int m, double value, double *vector) {
  int i = 0;
  for (i = 0; i < m; i++) {
    vector[i] = value * vector[i];
  }
}


x86 assembly (clang, -O0):
<mms_dscal>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1157 <mms_dscal+0x57>
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    111e <mms_dscal+0x1e>
pop    %rbp
ret

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

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

LLVM IR (-O2):
define void @mms_dscal(i32 %0, double %1, double* nocapture %2) {
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %73
5: ; preds = %3
%6 = zext i32 %0 to i64
%7 = icmp ult i32 %0, 4
br i1 %7, label %64, label %8
8: ; preds = %5
%9 = and i64 %6, 4294967292
%10 = insertelement <2 x double> poison, double %1, i64 0
%11 = shufflevector <2 x double> %10, <2 x double> poison, <2 x i32> zeroinitializer
%12 = insertelement <2 x double> poison, double %1, 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* %2, 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* %2, 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* %2, 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* %2, i64 %67
%69 = load double, double* %68
%70 = fmul double %69, %1
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
}