void init_array_double(double *array, int length, double val) {
  unsigned int i;
  for (i = 0; i < length; ++i)
    array[i] = val;
}


x86 assembly (clang, -O0):
<init_array_double>:
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    1142 <init_array_double+0x42>
movsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1117 <init_array_double+0x17>
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_array_double>:
test   %esi,%esi
je     120e <init_array_double+0x10e>
mov    %esi,%eax
cmp    $0x4,%esi
jae    1116 <init_array_double+0x16>
xor    %ecx,%ecx
jmp    1200 <init_array_double+0x100>
mov    %eax,%ecx
and    $0xfffffffc,%ecx
movaps %xmm0,%xmm1
movlhps %xmm0,%xmm1
lea    -0x4(%rcx),%rdx
mov    %rdx,%rsi
shr    $0x2,%rsi
add    $0x1,%rsi
mov    %esi,%r8d
and    $0x7,%r8d
cmp    $0x1c,%rdx
jae    1144 <init_array_double+0x44>
xor    %edx,%edx
jmp    11c1 <init_array_double+0xc1>
and    $0xfffffffffffffff8,%rsi
xor    %edx,%edx
nopw   0x0(%rax,%rax,1)
movups %xmm1,(%rdi,%rdx,8)
movups %xmm1,0x10(%rdi,%rdx,8)
movups %xmm1,0x20(%rdi,%rdx,8)
movups %xmm1,0x30(%rdi,%rdx,8)
movups %xmm1,0x40(%rdi,%rdx,8)
movups %xmm1,0x50(%rdi,%rdx,8)
movups %xmm1,0x60(%rdi,%rdx,8)
movups %xmm1,0x70(%rdi,%rdx,8)
movups %xmm1,0x80(%rdi,%rdx,8)
movups %xmm1,0x90(%rdi,%rdx,8)
movups %xmm1,0xa0(%rdi,%rdx,8)
movups %xmm1,0xb0(%rdi,%rdx,8)
movups %xmm1,0xc0(%rdi,%rdx,8)
movups %xmm1,0xd0(%rdi,%rdx,8)
movups %xmm1,0xe0(%rdi,%rdx,8)
movups %xmm1,0xf0(%rdi,%rdx,8)
add    $0x20,%rdx
add    $0xfffffffffffffff8,%rsi
jne    1150 <init_array_double+0x50>
test   %r8,%r8
je     11f2 <init_array_double+0xf2>
lea    (%rdi,%rdx,8),%rdx
add    $0x10,%rdx
shl    $0x5,%r8
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movups %xmm1,-0x10(%rdx,%rsi,1)
movups %xmm1,(%rdx,%rsi,1)
add    $0x20,%rsi
cmp    %rsi,%r8
jne    11e0 <init_array_double+0xe0>
cmp    %rax,%rcx
je     120e <init_array_double+0x10e>
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,(%rdi,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1200 <init_array_double+0x100>
ret

LLVM IR (-O0):
define void @init_array_double(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 = %18, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %5
%11 = icmp ult i32 %9, %10
br i1 %11, label %12, label %21
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
store double %13, double* %17
br label %18
18: ; preds = %12
%19 = load i32, i32* %7
%20 = add i32 %19, 1
store i32 %20, i32* %7
br label %8
21: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @init_array_double(double* nocapture writeonly %0, i32 %1, double %2) {
%4 = icmp eq i32 %1, 0
br i1 %4, label %88, label %5
5: ; preds = %3
%6 = zext i32 %1 to i64
%7 = icmp ult i32 %1, 4
br i1 %7, label %81, 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, 7
%18 = icmp ult i64 %14, 28
br i1 %18, label %66, label %19
19: ; preds = %8
%20 = and i64 %16, 9223372036854775800
br label %21
21: ; preds = %21, %19
%22 = phi i64 [ 0, %19 ], [ %63, %21 ]
%23 = phi i64 [ 0, %19 ], [ %64, %21 ]
%24 = getelementptr inbounds double, double* %0, i64 %22
%25 = bitcast double* %24 to <2 x double>*
store <2 x double> %11, <2 x double>* %25
%26 = getelementptr inbounds double, double* %24, i64 2
%27 = bitcast double* %26 to <2 x double>*
store <2 x double> %13, <2 x double>* %27
%28 = or i64 %22, 4
%29 = getelementptr inbounds double, double* %0, i64 %28
%30 = bitcast double* %29 to <2 x double>*
store <2 x double> %11, <2 x double>* %30
%31 = getelementptr inbounds double, double* %29, i64 2
%32 = bitcast double* %31 to <2 x double>*
store <2 x double> %13, <2 x double>* %32
%33 = or i64 %22, 8
%34 = getelementptr inbounds double, double* %0, i64 %33
%35 = bitcast double* %34 to <2 x double>*
store <2 x double> %11, <2 x double>* %35
%36 = getelementptr inbounds double, double* %34, i64 2
%37 = bitcast double* %36 to <2 x double>*
store <2 x double> %13, <2 x double>* %37
%38 = or i64 %22, 12
%39 = getelementptr inbounds double, double* %0, i64 %38
%40 = bitcast double* %39 to <2 x double>*
store <2 x double> %11, <2 x double>* %40
%41 = getelementptr inbounds double, double* %39, i64 2
%42 = bitcast double* %41 to <2 x double>*
store <2 x double> %13, <2 x double>* %42
%43 = or i64 %22, 16
%44 = getelementptr inbounds double, double* %0, i64 %43
%45 = bitcast double* %44 to <2 x double>*
store <2 x double> %11, <2 x double>* %45
%46 = getelementptr inbounds double, double* %44, i64 2
%47 = bitcast double* %46 to <2 x double>*
store <2 x double> %13, <2 x double>* %47
%48 = or i64 %22, 20
%49 = getelementptr inbounds double, double* %0, i64 %48
%50 = bitcast double* %49 to <2 x double>*
store <2 x double> %11, <2 x double>* %50
%51 = getelementptr inbounds double, double* %49, i64 2
%52 = bitcast double* %51 to <2 x double>*
store <2 x double> %13, <2 x double>* %52
%53 = or i64 %22, 24
%54 = getelementptr inbounds double, double* %0, i64 %53
%55 = bitcast double* %54 to <2 x double>*
store <2 x double> %11, <2 x double>* %55
%56 = getelementptr inbounds double, double* %54, i64 2
%57 = bitcast double* %56 to <2 x double>*
store <2 x double> %13, <2 x double>* %57
%58 = or i64 %22, 28
%59 = getelementptr inbounds double, double* %0, i64 %58
%60 = bitcast double* %59 to <2 x double>*
store <2 x double> %11, <2 x double>* %60
%61 = getelementptr inbounds double, double* %59, i64 2
%62 = bitcast double* %61 to <2 x double>*
store <2 x double> %13, <2 x double>* %62
%63 = add nuw i64 %22, 32
%64 = add i64 %23, 8
%65 = icmp eq i64 %64, %20
br i1 %65, label %66, label %21
66: ; preds = %21, %8
%67 = phi i64 [ 0, %8 ], [ %63, %21 ]
%68 = icmp eq i64 %17, 0
br i1 %68, label %79, label %69
69: ; preds = %66, %69
%70 = phi i64 [ %76, %69 ], [ %67, %66 ]
%71 = phi i64 [ %77, %69 ], [ 0, %66 ]
%72 = getelementptr inbounds double, double* %0, i64 %70
%73 = bitcast double* %72 to <2 x double>*
store <2 x double> %11, <2 x double>* %73
%74 = getelementptr inbounds double, double* %72, i64 2
%75 = bitcast double* %74 to <2 x double>*
store <2 x double> %13, <2 x double>* %75
%76 = add nuw i64 %70, 4
%77 = add i64 %71, 1
%78 = icmp eq i64 %77, %17
br i1 %78, label %79, label %69
79: ; preds = %69, %66
%80 = icmp eq i64 %9, %6
br i1 %80, label %88, label %81
81: ; preds = %5, %79
%82 = phi i64 [ 0, %5 ], [ %9, %79 ]
br label %83
83: ; preds = %81, %83
%84 = phi i64 [ %86, %83 ], [ %82, %81 ]
%85 = getelementptr inbounds double, double* %0, i64 %84
store double %2, double* %85
%86 = add nuw nsw i64 %84, 1
%87 = icmp eq i64 %86, %6
br i1 %87, label %88, label %83
88: ; preds = %83, %79, %3
ret void
}