int constantR(double *pval, int rn, double *rp) {

  int k;
  double val = *pval;
  for (k = 0; k < rn; k++) {
    rp[k] = val;
  }
  return 0;
}


x86 assembly (clang, -O0):
<constantR>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    114f <constantR+0x4f>
movsd  -0x28(%rbp),%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    1123 <constantR+0x23>
xor    %eax,%eax
pop    %rbp
ret

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

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

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