void projectConstants(int n, double x[], const double xscale[]) {
  int i;
  for (i = 0; i < n; i++) {
    if (xscale[i] == 0.0) {
      x[i] = 0.0;
    }
  }
}


x86 assembly (clang, -O0):
<projectConstants>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1165 <projectConstants+0x65>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1152 <projectConstants+0x52>
jp     1152 <projectConstants+0x52>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    1157 <projectConstants+0x57>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1116 <projectConstants+0x16>
pop    %rbp
ret

x86 assembly (clang, -O2):
<projectConstants>:
test   %edi,%edi
jle    112b <projectConstants+0x2b>
mov    %edi,%ecx
cmp    $0x1,%edi
jne    112c <projectConstants+0x2c>
xor    %eax,%eax
test   $0x1,%cl
je     112b <projectConstants+0x2b>
movsd  (%rdx,%rax,8),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    112b <projectConstants+0x2b>
jp     112b <projectConstants+0x2b>
movq   $0x0,(%rsi,%rax,8)
ret
mov    %ecx,%edi
and    $0xfffffffe,%edi
xor    %eax,%eax
xorpd  %xmm0,%xmm0
jmp    1149 <projectConstants+0x49>
nopl   0x0(%rax)
add    $0x2,%rax
cmp    %rax,%rdi
je     110d <projectConstants+0xd>
movsd  (%rdx,%rax,8),%xmm1
ucomisd %xmm0,%xmm1
jne    115e <projectConstants+0x5e>
jp     115e <projectConstants+0x5e>
movq   $0x0,(%rsi,%rax,8)
movsd  0x8(%rdx,%rax,8),%xmm1
ucomisd %xmm0,%xmm1
jne    1140 <projectConstants+0x40>
jp     1140 <projectConstants+0x40>
movq   $0x0,0x8(%rsi,%rax,8)
jmp    1140 <projectConstants+0x40>

LLVM IR (-O0):
define void @projectConstants(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
br label %8
8: ; preds = %25, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %28
12: ; preds = %8
%13 = load double*, double** %6
%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 = fcmp oeq double %17, 0.000000e+00
br i1 %18, label %19, label %24
19: ; preds = %12
%20 = load double*, double** %5
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
store double 0.000000e+00, double* %23
br label %24
24: ; preds = %19, %12
br label %25
25: ; preds = %24
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
br label %8
28: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @projectConstants(i32 %0, double* nocapture writeonly %1, double* nocapture %2) {
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %39
5: ; preds = %3
%6 = zext i32 %0 to i64
%7 = and i64 %6, 1
%8 = icmp eq i32 %0, 1
br i1 %8, label %30, label %9
9: ; preds = %5
%10 = and i64 %6, 4294967294
br label %11
11: ; preds = %26, %9
%12 = phi i64 [ 0, %9 ], [ %27, %26 ]
%13 = phi i64 [ 0, %9 ], [ %28, %26 ]
%14 = getelementptr inbounds double, double* %2, i64 %12
%15 = load double, double* %14
%16 = fcmp oeq double %15, 0.000000e+00
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = getelementptr inbounds double, double* %1, i64 %12
store double 0.000000e+00, double* %18
br label %19
19: ; preds = %11, %17
%20 = or i64 %12, 1
%21 = getelementptr inbounds double, double* %2, i64 %20
%22 = load double, double* %21
%23 = fcmp oeq double %22, 0.000000e+00
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = getelementptr inbounds double, double* %1, i64 %20
store double 0.000000e+00, double* %25
br label %26
26: ; preds = %24, %19
%27 = add nuw nsw i64 %12, 2
%28 = add i64 %13, 2
%29 = icmp eq i64 %28, %10
br i1 %29, label %30, label %11
30: ; preds = %26, %5
%31 = phi i64 [ 0, %5 ], [ %27, %26 ]
%32 = icmp eq i64 %7, 0
br i1 %32, label %39, label %33
33: ; preds = %30
%34 = getelementptr inbounds double, double* %2, i64 %31
%35 = load double, double* %34
%36 = fcmp oeq double %35, 0.000000e+00
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = getelementptr inbounds double, double* %1, i64 %31
store double 0.000000e+00, double* %38
br label %39
39: ; preds = %30, %37, %33, %3
ret void
}