double vec_scale_mask(int no, double *vp, double *zp, double cut) {
  register int i;
  register double scale, tmp;
  scale = 0;
  for (i = 0; i < no; i++) {
    if (zp[i] < cut) {
      vp[2 * i] = vp[2 * i + 1] = 0;
    } else {
      tmp = sqrt(((vp[2 * i]) * (vp[2 * i])) +
                 ((vp[2 * i + 1]) * (vp[2 * i + 1])));
      if (scale < tmp)
        scale = tmp;
    }
  }
  return scale;
}


x86 assembly (clang, -O0):
<vec_scale_mask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1227 <vec_scale_mask+0x117>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1191 <vec_scale_mask+0x81>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    1214 <vec_scale_mask+0x104>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mulsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    120f <vec_scale_mask+0xff>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1214 <vec_scale_mask+0x104>
jmp    1219 <vec_scale_mask+0x109>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1137 <vec_scale_mask+0x27>
movsd  -0x30(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vec_scale_mask>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %edi,%edi
jle    11ca <vec_scale_mask+0xba>
movapd %xmm0,%xmm2
mov    %rdx,%r14
mov    %rsi,%r12
mov    %edi,%r15d
shl    $0x3,%r15
xorpd  %xmm3,%xmm3
xor    %ebx,%ebx
xorps  %xmm5,%xmm5
xorpd  %xmm4,%xmm4
movsd  %xmm0,0x8(%rsp)
jmp    115e <vec_scale_mask+0x4e>
nopl   0x0(%rax)
movups %xmm5,(%r12,%rbx,2)
add    $0x8,%rbx
cmp    %rbx,%r15
je     11ce <vec_scale_mask+0xbe>
ucomisd (%r14,%rbx,1),%xmm2
ja     1150 <vec_scale_mask+0x40>
movsd  (%r12,%rbx,2),%xmm0
movsd  0x8(%r12,%rbx,2),%xmm1
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
ucomisd %xmm3,%xmm0
jb     11a0 <vec_scale_mask+0x90>
sqrtsd %xmm0,%xmm0
ucomisd %xmm4,%xmm0
jbe    1155 <vec_scale_mask+0x45>
jmp    11c4 <vec_scale_mask+0xb4>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  %xmm4,0x10(%rsp)
call   1030 <sqrt@plt>
xorps  %xmm5,%xmm5
movsd  0x10(%rsp),%xmm4
xorpd  %xmm3,%xmm3
movsd  0x8(%rsp),%xmm2
ucomisd %xmm4,%xmm0
jbe    1155 <vec_scale_mask+0x45>
movapd %xmm0,%xmm4
jmp    1155 <vec_scale_mask+0x45>
xorpd  %xmm4,%xmm4
movapd %xmm4,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @vec_scale_mask(i32 %0, double* %1, double* %2, double %3) {
%5 = alloca i32
%6 = alloca double*
%7 = alloca double*
%8 = alloca double
%9 = alloca i32
%10 = alloca double
%11 = alloca double
store i32 %0, i32* %5
store double* %1, double** %6
store double* %2, double** %7
store double %3, double* %8
store double 0.000000e+00, double* %10
store i32 0, i32* %9
br label %12
12: ; preds = %73, %4
%13 = load i32, i32* %9
%14 = load i32, i32* %5
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %76
16: ; preds = %12
%17 = load double*, double** %7
%18 = load i32, i32* %9
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds double, double* %17, i64 %19
%21 = load double, double* %20
%22 = load double, double* %8
%23 = fcmp olt double %21, %22
br i1 %23, label %24, label %36
24: ; preds = %16
%25 = load double*, double** %6
%26 = load i32, i32* %9
%27 = mul nsw i32 2, %26
%28 = add nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %25, i64 %29
store double 0.000000e+00, double* %30
%31 = load double*, double** %6
%32 = load i32, i32* %9
%33 = mul nsw i32 2, %32
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %31, i64 %34
store double 0.000000e+00, double* %35
br label %72
36: ; preds = %16
%37 = load double*, double** %6
%38 = load i32, i32* %9
%39 = mul nsw i32 2, %38
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %37, i64 %40
%42 = load double, double* %41
%43 = load double*, double** %6
%44 = load i32, i32* %9
%45 = mul nsw i32 2, %44
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %43, i64 %46
%48 = load double, double* %47
%49 = load double*, double** %6
%50 = load i32, i32* %9
%51 = mul nsw i32 2, %50
%52 = add nsw i32 %51, 1
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds double, double* %49, i64 %53
%55 = load double, double* %54
%56 = load double*, double** %6
%57 = load i32, i32* %9
%58 = mul nsw i32 2, %57
%59 = add nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %56, i64 %60
%62 = load double, double* %61
%63 = fmul double %55, %62
%64 = call double @llvm.fmuladd.f64(double %42, double %48, double %63)
%65 = call double @sqrt(double %64)
store double %65, double* %11
%66 = load double, double* %10
%67 = load double, double* %11
%68 = fcmp olt double %66, %67
br i1 %68, label %69, label %71
69: ; preds = %36
%70 = load double, double* %11
store double %70, double* %10
br label %71
71: ; preds = %69, %36
br label %72
72: ; preds = %71, %24
br label %73
73: ; preds = %72
%74 = load i32, i32* %9
%75 = add nsw i32 %74, 1
store i32 %75, i32* %9
br label %12
76: ; preds = %12
%77 = load double, double* %10
ret double %77
}

LLVM IR (-O2):
define double @vec_scale_mask(i32 %0, double* nocapture %1, double* nocapture %2, double %3) {
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %33
6: ; preds = %4
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %6, %29
%9 = phi i64 [ 0, %6 ], [ %31, %29 ]
%10 = phi double [ 0.000000e+00, %6 ], [ %30, %29 ]
%11 = getelementptr inbounds double, double* %2, i64 %9
%12 = load double, double* %11
%13 = fcmp olt double %12, %3
%14 = shl nuw nsw i64 %9, 1
br i1 %13, label %15, label %18
15: ; preds = %8
%16 = getelementptr inbounds double, double* %1, i64 %14
%17 = bitcast double* %16 to <2 x double>*
store <2 x double> zeroinitializer, <2 x double>* %17
br label %29
18: ; preds = %8
%19 = getelementptr inbounds double, double* %1, i64 %14
%20 = load double, double* %19
%21 = or i64 %14, 1
%22 = getelementptr inbounds double, double* %1, i64 %21
%23 = load double, double* %22
%24 = fmul double %23, %23
%25 = tail call double @llvm.fmuladd.f64(double %20, double %20, double %24)
%26 = tail call double @sqrt(double %25)
%27 = fcmp olt double %10, %26
br i1 %27, label %28, label %29
28: ; preds = %18
br label %29
29: ; preds = %15, %28, %18
%30 = phi double [ %10, %15 ], [ %26, %28 ], [ %10, %18 ]
%31 = add nuw nsw i64 %9, 1
%32 = icmp eq i64 %31, %7
br i1 %32, label %33, label %8
33: ; preds = %29, %4
%34 = phi double [ 0.000000e+00, %4 ], [ %30, %29 ]
ret double %34
}