void doubles_scale_self(double *v, int len, double scale) {
  for (int i = 0; i < len; i++)
    v[i] = (double)(v[i] * scale);
}


x86 assembly (clang, -O0):
<doubles_scale_self>:
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
jge    1150 <doubles_scale_self+0x50>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mulsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1117 <doubles_scale_self+0x17>
pop    %rbp
ret

x86 assembly (clang, -O2):
<doubles_scale_self>:
test   %esi,%esi
jle    11e7 <doubles_scale_self+0xe7>
mov    %esi,%eax
cmp    $0x4,%esi
jae    1116 <doubles_scale_self+0x16>
xor    %ecx,%ecx
jmp    11d0 <doubles_scale_self+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 <doubles_scale_self+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 <doubles_scale_self+0x50>
test   $0x1,%r8b
je     11bc <doubles_scale_self+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 <doubles_scale_self+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 <doubles_scale_self+0xd0>
ret
xor    %edx,%edx
test   $0x1,%r8b
jne    119e <doubles_scale_self+0x9e>
jmp    11bc <doubles_scale_self+0xbc>

LLVM IR (-O0):
define void @doubles_scale_self(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 = %24, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %5
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %27
12: ; preds = %8
%13 = load double*, double** %4
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds double, double* %13, i64 %15
%17 = load double, double* %16
%18 = load double, double* %6
%19 = fmul double %17, %18
%20 = load double*, double** %4
%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 @doubles_scale_self(double* nocapture %0, i32 %1, double %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %66
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 %66, label %64
64: ; preds = %5, %62
%65 = phi i64 [ 0, %5 ], [ %9, %62 ]
br label %67
66: ; preds = %67, %62, %3
ret void
67: ; preds = %64, %67
%68 = phi i64 [ %72, %67 ], [ %65, %64 ]
%69 = getelementptr inbounds double, double* %0, i64 %68
%70 = load double, double* %69
%71 = fmul double %70, %2
store double %71, double* %69
%72 = add nuw nsw i64 %68, 1
%73 = icmp eq i64 %72, %6
br i1 %73, label %66, label %67
}