void __attribute__((noipa))
f_sub_double(double *restrict dest, double *restrict cond, double limit,
             double *restrict src, double val, unsigned int n) {
  for (unsigned int i = 0; i < n; ++i) {
    double truev = ((src[i]) - (val));
    dest[i] = cond[i] < limit ? truev : src[i];
  }
}


x86 assembly (clang, -O0):
<f_sub_double>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
mov    %ecx,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jae    11a0 <f_sub_double+0xa0>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1170 <f_sub_double+0x70>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    1181 <f_sub_double+0x81>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%ecx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1124 <f_sub_double+0x24>
pop    %rbp
ret

x86 assembly (clang, -O2):
<f_sub_double>:
test   %ecx,%ecx
je     1245 <f_sub_double+0x145>
mov    %ecx,%r8d
cmp    $0x4,%ecx
jae    1117 <f_sub_double+0x17>
xor    %ecx,%ecx
jmp    1220 <f_sub_double+0x120>
mov    %r8d,%ecx
and    $0xfffffffc,%ecx
movapd %xmm0,%xmm3
unpcklpd %xmm0,%xmm3
movapd %xmm1,%xmm2
unpcklpd %xmm1,%xmm2
lea    -0x4(%rcx),%rax
mov    %rax,%r9
shr    $0x2,%r9
add    $0x1,%r9
test   %rax,%rax
je     1246 <f_sub_double+0x146>
mov    %r9,%r10
and    $0xfffffffffffffffe,%r10
xor    %eax,%eax
xchg   %ax,%ax
movupd (%rdx,%rax,8),%xmm4
movupd 0x10(%rdx,%rax,8),%xmm5
movupd (%rsi,%rax,8),%xmm6
movupd 0x10(%rsi,%rax,8),%xmm7
cmpltpd %xmm3,%xmm6
cmpltpd %xmm3,%xmm7
andpd  %xmm2,%xmm6
subpd  %xmm6,%xmm4
andpd  %xmm2,%xmm7
subpd  %xmm7,%xmm5
movupd %xmm4,(%rdi,%rax,8)
movupd %xmm5,0x10(%rdi,%rax,8)
movupd 0x20(%rdx,%rax,8),%xmm4
movupd 0x30(%rdx,%rax,8),%xmm5
movupd 0x20(%rsi,%rax,8),%xmm6
movupd 0x30(%rsi,%rax,8),%xmm7
cmpltpd %xmm3,%xmm6
cmpltpd %xmm3,%xmm7
andpd  %xmm2,%xmm6
subpd  %xmm6,%xmm4
andpd  %xmm2,%xmm7
subpd  %xmm7,%xmm5
movupd %xmm4,0x20(%rdi,%rax,8)
movupd %xmm5,0x30(%rdi,%rax,8)
add    $0x8,%rax
add    $0xfffffffffffffffe,%r10
jne    1150 <f_sub_double+0x50>
test   $0x1,%r9b
je     1218 <f_sub_double+0x118>
movupd (%rdx,%rax,8),%xmm4
movupd 0x10(%rdx,%rax,8),%xmm5
movupd (%rsi,%rax,8),%xmm6
movupd 0x10(%rsi,%rax,8),%xmm7
cmpltpd %xmm3,%xmm6
cmpltpd %xmm3,%xmm7
andpd  %xmm2,%xmm6
subpd  %xmm6,%xmm4
andpd  %xmm2,%xmm7
subpd  %xmm7,%xmm5
movupd %xmm4,(%rdi,%rax,8)
movupd %xmm5,0x10(%rdi,%rax,8)
cmp    %r8,%rcx
je     1245 <f_sub_double+0x145>
nopl   (%rax)
movsd  (%rdx,%rcx,8),%xmm2
movsd  (%rsi,%rcx,8),%xmm3
cmpltsd %xmm0,%xmm3
andpd  %xmm1,%xmm3
subsd  %xmm3,%xmm2
movsd  %xmm2,(%rdi,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%r8
jne    1220 <f_sub_double+0x120>
ret
xor    %eax,%eax
test   $0x1,%r9b
jne    11dd <f_sub_double+0xdd>
jmp    1218 <f_sub_double+0x118>

LLVM IR (-O0):
define void @f_sub_double(double* noalias %0, double* noalias %1, double %2, double* noalias %3, double %4, i32 %5) {
%7 = alloca double*
%8 = alloca double*
%9 = alloca double
%10 = alloca double*
%11 = alloca double
%12 = alloca i32
%13 = alloca i32
%14 = alloca double
store double* %0, double** %7
store double* %1, double** %8
store double %2, double* %9
store double* %3, double** %10
store double %4, double* %11
store i32 %5, i32* %12
store i32 0, i32* %13
br label %15
15: ; preds = %48, %6
%16 = load i32, i32* %13
%17 = load i32, i32* %12
%18 = icmp ult i32 %16, %17
br i1 %18, label %19, label %51
19: ; preds = %15
%20 = load double*, double** %10
%21 = load i32, i32* %13
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
%24 = load double, double* %23
%25 = load double, double* %11
%26 = fsub double %24, %25
store double %26, double* %14
%27 = load double*, double** %8
%28 = load i32, i32* %13
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
%31 = load double, double* %30
%32 = load double, double* %9
%33 = fcmp olt double %31, %32
br i1 %33, label %34, label %36
34: ; preds = %19
%35 = load double, double* %14
br label %42
36: ; preds = %19
%37 = load double*, double** %10
%38 = load i32, i32* %13
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds double, double* %37, i64 %39
%41 = load double, double* %40
br label %42
42: ; preds = %36, %34
%43 = phi double [ %35, %34 ], [ %41, %36 ]
%44 = load double*, double** %7
%45 = load i32, i32* %13
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds double, double* %44, i64 %46
store double %43, double* %47
br label %48
48: ; preds = %42
%49 = load i32, i32* %13
%50 = add i32 %49, 1
store i32 %50, i32* %13
br label %15
51: ; preds = %15
ret void
}

LLVM IR (-O2):
define void @f_sub_double(double* noalias nocapture writeonly %0, double* noalias nocapture %1, double %2, double* noalias nocapture %3, double %4, i32 %5) {
%7 = icmp eq i32 %5, 0
br i1 %7, label %109, label %8
8: ; preds = %6
%9 = zext i32 %5 to i64
%10 = icmp ult i32 %5, 4
br i1 %10, label %107, label %11
11: ; preds = %8
%12 = and i64 %9, 4294967292
%13 = insertelement <2 x double> poison, double %2, i64 0
%14 = shufflevector <2 x double> %13, <2 x double> poison, <2 x i32> zeroinitializer
%15 = insertelement <2 x double> poison, double %2, i64 0
%16 = shufflevector <2 x double> %15, <2 x double> poison, <2 x i32> zeroinitializer
%17 = insertelement <2 x double> poison, double %4, i64 0
%18 = shufflevector <2 x double> %17, <2 x double> poison, <2 x i32> zeroinitializer
%19 = insertelement <2 x double> poison, double %4, i64 0
%20 = shufflevector <2 x double> %19, <2 x double> poison, <2 x i32> zeroinitializer
%21 = add nsw i64 %12, -4
%22 = lshr exact i64 %21, 2
%23 = add nuw nsw i64 %22, 1
%24 = and i64 %23, 1
%25 = icmp eq i64 %21, 0
br i1 %25, label %79, label %26
26: ; preds = %11
%27 = and i64 %23, 9223372036854775806
br label %28
28: ; preds = %28, %26
%29 = phi i64 [ 0, %26 ], [ %76, %28 ]
%30 = phi i64 [ 0, %26 ], [ %77, %28 ]
%31 = getelementptr inbounds double, double* %3, i64 %29
%32 = bitcast double* %31 to <2 x double>*
%33 = load <2 x double>, <2 x double>* %32
%34 = getelementptr inbounds double, double* %31, i64 2
%35 = bitcast double* %34 to <2 x double>*
%36 = load <2 x double>, <2 x double>* %35
%37 = getelementptr inbounds double, double* %1, i64 %29
%38 = bitcast double* %37 to <2 x double>*
%39 = load <2 x double>, <2 x double>* %38
%40 = getelementptr inbounds double, double* %37, i64 2
%41 = bitcast double* %40 to <2 x double>*
%42 = load <2 x double>, <2 x double>* %41
%43 = fcmp olt <2 x double> %39, %14
%44 = fcmp olt <2 x double> %42, %16
%45 = select <2 x i1> %43, <2 x double> %18, <2 x double> zeroinitializer
%46 = select <2 x i1> %44, <2 x double> %20, <2 x double> zeroinitializer
%47 = fsub <2 x double> %33, %45
%48 = fsub <2 x double> %36, %46
%49 = getelementptr inbounds double, double* %0, i64 %29
%50 = bitcast double* %49 to <2 x double>*
store <2 x double> %47, <2 x double>* %50
%51 = getelementptr inbounds double, double* %49, i64 2
%52 = bitcast double* %51 to <2 x double>*
store <2 x double> %48, <2 x double>* %52
%53 = or i64 %29, 4
%54 = getelementptr inbounds double, double* %3, i64 %53
%55 = bitcast double* %54 to <2 x double>*
%56 = load <2 x double>, <2 x double>* %55
%57 = getelementptr inbounds double, double* %54, i64 2
%58 = bitcast double* %57 to <2 x double>*
%59 = load <2 x double>, <2 x double>* %58
%60 = getelementptr inbounds double, double* %1, i64 %53
%61 = bitcast double* %60 to <2 x double>*
%62 = load <2 x double>, <2 x double>* %61
%63 = getelementptr inbounds double, double* %60, i64 2
%64 = bitcast double* %63 to <2 x double>*
%65 = load <2 x double>, <2 x double>* %64
%66 = fcmp olt <2 x double> %62, %14
%67 = fcmp olt <2 x double> %65, %16
%68 = select <2 x i1> %66, <2 x double> %18, <2 x double> zeroinitializer
%69 = select <2 x i1> %67, <2 x double> %20, <2 x double> zeroinitializer
%70 = fsub <2 x double> %56, %68
%71 = fsub <2 x double> %59, %69
%72 = getelementptr inbounds double, double* %0, i64 %53
%73 = bitcast double* %72 to <2 x double>*
store <2 x double> %70, <2 x double>* %73
%74 = getelementptr inbounds double, double* %72, i64 2
%75 = bitcast double* %74 to <2 x double>*
store <2 x double> %71, <2 x double>* %75
%76 = add nuw i64 %29, 8
%77 = add i64 %30, 2
%78 = icmp eq i64 %77, %27
br i1 %78, label %79, label %28
79: ; preds = %28, %11
%80 = phi i64 [ 0, %11 ], [ %76, %28 ]
%81 = icmp eq i64 %24, 0
br i1 %81, label %105, label %82
82: ; preds = %79
%83 = getelementptr inbounds double, double* %3, i64 %80
%84 = bitcast double* %83 to <2 x double>*
%85 = load <2 x double>, <2 x double>* %84
%86 = getelementptr inbounds double, double* %83, i64 2
%87 = bitcast double* %86 to <2 x double>*
%88 = load <2 x double>, <2 x double>* %87
%89 = getelementptr inbounds double, double* %1, i64 %80
%90 = bitcast double* %89 to <2 x double>*
%91 = load <2 x double>, <2 x double>* %90
%92 = getelementptr inbounds double, double* %89, i64 2
%93 = bitcast double* %92 to <2 x double>*
%94 = load <2 x double>, <2 x double>* %93
%95 = fcmp olt <2 x double> %91, %14
%96 = fcmp olt <2 x double> %94, %16
%97 = select <2 x i1> %95, <2 x double> %18, <2 x double> zeroinitializer
%98 = select <2 x i1> %96, <2 x double> %20, <2 x double> zeroinitializer
%99 = fsub <2 x double> %85, %97
%100 = fsub <2 x double> %88, %98
%101 = getelementptr inbounds double, double* %0, i64 %80
%102 = bitcast double* %101 to <2 x double>*
store <2 x double> %99, <2 x double>* %102
%103 = getelementptr inbounds double, double* %101, i64 2
%104 = bitcast double* %103 to <2 x double>*
store <2 x double> %100, <2 x double>* %104
br label %105
105: ; preds = %79, %82
%106 = icmp eq i64 %12, %9
br i1 %106, label %109, label %107
107: ; preds = %8, %105
%108 = phi i64 [ 0, %8 ], [ %12, %105 ]
br label %110
109: ; preds = %110, %105, %6
ret void
110: ; preds = %107, %110
%111 = phi i64 [ %120, %110 ], [ %108, %107 ]
%112 = getelementptr inbounds double, double* %3, i64 %111
%113 = load double, double* %112
%114 = getelementptr inbounds double, double* %1, i64 %111
%115 = load double, double* %114
%116 = fcmp olt double %115, %2
%117 = select i1 %116, double %4, double 0.000000e+00
%118 = fsub double %113, %117
%119 = getelementptr inbounds double, double* %0, i64 %111
store double %118, double* %119
%120 = add nuw nsw i64 %111, 1
%121 = icmp eq i64 %120, %9
br i1 %121, label %109, label %110
}