int wcsutil_dblEq(int nelem, double tol, const double *darr1,
                  const double *darr2) {
  if (nelem == 0)
    return 1;
  if (nelem < 0)
    return 0;
  if (darr1 == 0x0 && darr2 == 0x0)
    return 1;
  if (tol == 0.0) {
    for (int i = 0; i < nelem; i++) {
      double dval1 = (darr1 ? darr1[i] : 987654321.0e99);
      double dval2 = (darr2 ? darr2[i] : 987654321.0e99);
      if (dval1 == 987654321.0e99 && dval2 != 987654321.0e99)
        return 0;
      if (dval1 != 987654321.0e99 && dval2 == 987654321.0e99)
        return 0;
      if (dval1 != dval2)
        return 0;
    }
  } else {
    for (int i = 0; i < nelem; i++) {
      double dval1 = (darr1 ? darr1[i] : 987654321.0e99);
      double dval2 = (darr2 ? darr2[i] : 987654321.0e99);
      if (dval1 == 987654321.0e99 && dval2 != 987654321.0e99)
        return 0;
      if (dval1 != 987654321.0e99 && dval2 == 987654321.0e99)
        return 0;
      if (fabs(dval1 - dval2) > 0.5 * tol)
        return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<wcsutil_dblEq>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    112a <wcsutil_dblEq+0x2a>
movl   $0x1,-0x4(%rbp)
jmp    145a <wcsutil_dblEq+0x35a>
cmpl   $0x0,-0x8(%rbp)
jge    1140 <wcsutil_dblEq+0x40>
movl   $0x0,-0x4(%rbp)
jmp    145a <wcsutil_dblEq+0x35a>
cmpq   $0x0,-0x18(%rbp)
jne    1162 <wcsutil_dblEq+0x62>
cmpq   $0x0,-0x20(%rbp)
jne    1162 <wcsutil_dblEq+0x62>
movl   $0x1,-0x4(%rbp)
jmp    145a <wcsutil_dblEq+0x35a>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12de <wcsutil_dblEq+0x1de>
jp     12de <wcsutil_dblEq+0x1de>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12d9 <wcsutil_dblEq+0x1d9>
cmpq   $0x0,-0x18(%rbp)
je     11af <wcsutil_dblEq+0xaf>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    11c1 <wcsutil_dblEq+0xc1>
movsd  0xe49(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    11c1 <wcsutil_dblEq+0xc1>
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ed <wcsutil_dblEq+0xed>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    11ff <wcsutil_dblEq+0xff>
movsd  0xe0b(%rip),%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    11ff <wcsutil_dblEq+0xff>
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xdea(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1254 <wcsutil_dblEq+0x154>
jp     1254 <wcsutil_dblEq+0x154>
movsd  -0x38(%rbp),%xmm0
movsd  0xdcd(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1248 <wcsutil_dblEq+0x148>
jp     1248 <wcsutil_dblEq+0x148>
jmp    1254 <wcsutil_dblEq+0x154>
movl   $0x0,-0x4(%rbp)
jmp    145a <wcsutil_dblEq+0x35a>
movsd  -0x30(%rbp),%xmm0
movsd  0xd9f(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1276 <wcsutil_dblEq+0x176>
jp     1276 <wcsutil_dblEq+0x176>
jmp    129f <wcsutil_dblEq+0x19f>
movsd  -0x38(%rbp),%xmm0
movsd  0xd7d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    129f <wcsutil_dblEq+0x19f>
jp     129f <wcsutil_dblEq+0x19f>
movl   $0x0,-0x4(%rbp)
jmp    145a <wcsutil_dblEq+0x35a>
movsd  -0x30(%rbp),%xmm0
ucomisd -0x38(%rbp),%xmm0
jne    12ba <wcsutil_dblEq+0x1ba>
jp     12ba <wcsutil_dblEq+0x1ba>
jmp    12c6 <wcsutil_dblEq+0x1c6>
movl   $0x0,-0x4(%rbp)
jmp    145a <wcsutil_dblEq+0x35a>
jmp    12cb <wcsutil_dblEq+0x1cb>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1181 <wcsutil_dblEq+0x81>
jmp    1453 <wcsutil_dblEq+0x353>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    144e <wcsutil_dblEq+0x34e>
cmpq   $0x0,-0x18(%rbp)
je     1313 <wcsutil_dblEq+0x213>
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x68(%rbp)
jmp    1325 <wcsutil_dblEq+0x225>
movsd  0xce5(%rip),%xmm0
movsd  %xmm0,-0x68(%rbp)
jmp    1325 <wcsutil_dblEq+0x225>
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1351 <wcsutil_dblEq+0x251>
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x70(%rbp)
jmp    1363 <wcsutil_dblEq+0x263>
movsd  0xca7(%rip),%xmm0
movsd  %xmm0,-0x70(%rbp)
jmp    1363 <wcsutil_dblEq+0x263>
movsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  0xc86(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    13b8 <wcsutil_dblEq+0x2b8>
jp     13b8 <wcsutil_dblEq+0x2b8>
movsd  -0x50(%rbp),%xmm0
movsd  0xc69(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    13ac <wcsutil_dblEq+0x2ac>
jp     13ac <wcsutil_dblEq+0x2ac>
jmp    13b8 <wcsutil_dblEq+0x2b8>
movl   $0x0,-0x4(%rbp)
jmp    145a <wcsutil_dblEq+0x35a>
movsd  -0x48(%rbp),%xmm0
movsd  0xc3b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    13da <wcsutil_dblEq+0x2da>
jp     13da <wcsutil_dblEq+0x2da>
jmp    1403 <wcsutil_dblEq+0x303>
movsd  -0x50(%rbp),%xmm0
movsd  0xc19(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1403 <wcsutil_dblEq+0x303>
jp     1403 <wcsutil_dblEq+0x303>
movl   $0x0,-0x4(%rbp)
jmp    145a <wcsutil_dblEq+0x35a>
movsd  -0x48(%rbp),%xmm0
subsd  -0x50(%rbp),%xmm0
movaps 0xbfc(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xbe8(%rip),%xmm1
mulsd  -0x10(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jbe    143b <wcsutil_dblEq+0x33b>
movl   $0x0,-0x4(%rbp)
jmp    145a <wcsutil_dblEq+0x35a>
jmp    1440 <wcsutil_dblEq+0x340>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    12e5 <wcsutil_dblEq+0x1e5>
jmp    1453 <wcsutil_dblEq+0x353>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcsutil_dblEq>:
test   %edi,%edi
je     1112 <wcsutil_dblEq+0x12>
js     1238 <wcsutil_dblEq+0x138>
mov    %rsi,%rax
or     %rdx,%rax
jne    1118 <wcsutil_dblEq+0x18>
mov    $0x1,%eax
ret
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11b9 <wcsutil_dblEq+0xb9>
jp     11b9 <wcsutil_dblEq+0xb9>
mov    %edi,%r8d
xor    %edi,%edi
movsd  0xecf(%rip),%xmm0
nopl   0x0(%rax)
movapd %xmm0,%xmm1
test   %rsi,%rsi
je     114e <wcsutil_dblEq+0x4e>
movsd  (%rsi,%rdi,8),%xmm1
movapd %xmm0,%xmm2
test   %rdx,%rdx
je     1174 <wcsutil_dblEq+0x74>
movsd  (%rdx,%rdi,8),%xmm2
ucomisd %xmm0,%xmm1
jne    1174 <wcsutil_dblEq+0x74>
jp     1174 <wcsutil_dblEq+0x74>
ucomisd %xmm0,%xmm2
jne    1238 <wcsutil_dblEq+0x138>
jp     1238 <wcsutil_dblEq+0x138>
ucomisd %xmm0,%xmm1
setnp  %cl
sete   %al
and    %cl,%al
ucomisd %xmm0,%xmm2
setp   %r9b
setne  %cl
or     %r9b,%cl
or     %al,%cl
xor    %eax,%eax
cmp    $0x1,%cl
jne    123b <wcsutil_dblEq+0x13b>
ucomisd %xmm2,%xmm1
jne    123b <wcsutil_dblEq+0x13b>
jp     123b <wcsutil_dblEq+0x13b>
add    $0x1,%rdi
cmp    %rdi,%r8
jne    1140 <wcsutil_dblEq+0x40>
jmp    1112 <wcsutil_dblEq+0x12>
mulsd  0xe3f(%rip),%xmm0
mov    %edi,%ecx
xor    %edi,%edi
movsd  0xe3b(%rip),%xmm1
movapd 0xe3b(%rip),%xmm2
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
movapd %xmm1,%xmm3
test   %rsi,%rsi
je     11ee <wcsutil_dblEq+0xee>
movsd  (%rsi,%rdi,8),%xmm3
movapd %xmm1,%xmm4
test   %rdx,%rdx
je     120c <wcsutil_dblEq+0x10c>
movsd  (%rdx,%rdi,8),%xmm4
ucomisd %xmm1,%xmm3
jne    120c <wcsutil_dblEq+0x10c>
jp     120c <wcsutil_dblEq+0x10c>
ucomisd %xmm1,%xmm4
jne    1238 <wcsutil_dblEq+0x138>
jp     1238 <wcsutil_dblEq+0x138>
ucomisd %xmm1,%xmm3
jne    1214 <wcsutil_dblEq+0x114>
jnp    121c <wcsutil_dblEq+0x11c>
ucomisd %xmm1,%xmm4
jne    121c <wcsutil_dblEq+0x11c>
jnp    123b <wcsutil_dblEq+0x13b>
subsd  %xmm4,%xmm3
andpd  %xmm2,%xmm3
ucomisd %xmm0,%xmm3
ja     123b <wcsutil_dblEq+0x13b>
add    $0x1,%rdi
cmp    %rdi,%rcx
jne    11e0 <wcsutil_dblEq+0xe0>
jmp    1112 <wcsutil_dblEq+0x12>
xor    %eax,%eax
ret
ret

LLVM IR (-O0):
define i32 @wcsutil_dblEq(i32 %0, double %1, double* %2, double* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca double*
%9 = alloca double*
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca i32
%14 = alloca double
%15 = alloca double
store i32 %0, i32* %6
store double %1, double* %7
store double* %2, double** %8
store double* %3, double** %9
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %4
store i32 1, i32* %5
br label %140
19: ; preds = %4
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 0, i32* %5
br label %140
23: ; preds = %19
%24 = load double*, double** %8
%25 = icmp eq double* %24, null
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load double*, double** %9
%28 = icmp eq double* %27, null
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 1, i32* %5
br label %140
30: ; preds = %26, %23
%31 = load double, double* %7
%32 = fcmp oeq double %31, 0.000000e+00
br i1 %32, label %33, label %84
33: ; preds = %30
store i32 0, i32* %10
br label %34
34: ; preds = %80, %33
%35 = load i32, i32* %10
%36 = load i32, i32* %6
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %83
38: ; preds = %34
%39 = load double*, double** %8
%40 = icmp ne double* %39, null
br i1 %40, label %41, label %47
41: ; preds = %38
%42 = load double*, double** %8
%43 = load i32, i32* %10
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %42, i64 %44
%46 = load double, double* %45
br label %48
47: ; preds = %38
br label %48
48: ; preds = %47, %41
%49 = phi double [ %46, %41 ], [ 0x565AEA1D6E56E1C8, %47 ]
store double %49, double* %11
%50 = load double*, double** %9
%51 = icmp ne double* %50, null
br i1 %51, label %52, label %58
52: ; preds = %48
%53 = load double*, double** %9
%54 = load i32, i32* %10
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %53, i64 %55
%57 = load double, double* %56
br label %59
58: ; preds = %48
br label %59
59: ; preds = %58, %52
%60 = phi double [ %57, %52 ], [ 0x565AEA1D6E56E1C8, %58 ]
store double %60, double* %12
%61 = load double, double* %11
%62 = fcmp oeq double %61, 0x565AEA1D6E56E1C8
br i1 %62, label %63, label %67
63: ; preds = %59
%64 = load double, double* %12
%65 = fcmp une double %64, 0x565AEA1D6E56E1C8
br i1 %65, label %66, label %67
66: ; preds = %63
store i32 0, i32* %5
br label %140
67: ; preds = %63, %59
%68 = load double, double* %11
%69 = fcmp une double %68, 0x565AEA1D6E56E1C8
br i1 %69, label %70, label %74
70: ; preds = %67
%71 = load double, double* %12
%72 = fcmp oeq double %71, 0x565AEA1D6E56E1C8
br i1 %72, label %73, label %74
73: ; preds = %70
store i32 0, i32* %5
br label %140
74: ; preds = %70, %67
%75 = load double, double* %11
%76 = load double, double* %12
%77 = fcmp une double %75, %76
br i1 %77, label %78, label %79
78: ; preds = %74
store i32 0, i32* %5
br label %140
79: ; preds = %74
br label %80
80: ; preds = %79
%81 = load i32, i32* %10
%82 = add nsw i32 %81, 1
store i32 %82, i32* %10
br label %34
83: ; preds = %34
br label %139
84: ; preds = %30
store i32 0, i32* %13
br label %85
85: ; preds = %135, %84
%86 = load i32, i32* %13
%87 = load i32, i32* %6
%88 = icmp slt i32 %86, %87
br i1 %88, label %89, label %138
89: ; preds = %85
%90 = load double*, double** %8
%91 = icmp ne double* %90, null
br i1 %91, label %92, label %98
92: ; preds = %89
%93 = load double*, double** %8
%94 = load i32, i32* %13
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds double, double* %93, i64 %95
%97 = load double, double* %96
br label %99
98: ; preds = %89
br label %99
99: ; preds = %98, %92
%100 = phi double [ %97, %92 ], [ 0x565AEA1D6E56E1C8, %98 ]
store double %100, double* %14
%101 = load double*, double** %9
%102 = icmp ne double* %101, null
br i1 %102, label %103, label %109
103: ; preds = %99
%104 = load double*, double** %9
%105 = load i32, i32* %13
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds double, double* %104, i64 %106
%108 = load double, double* %107
br label %110
109: ; preds = %99
br label %110
110: ; preds = %109, %103
%111 = phi double [ %108, %103 ], [ 0x565AEA1D6E56E1C8, %109 ]
store double %111, double* %15
%112 = load double, double* %14
%113 = fcmp oeq double %112, 0x565AEA1D6E56E1C8
br i1 %113, label %114, label %118
114: ; preds = %110
%115 = load double, double* %15
%116 = fcmp une double %115, 0x565AEA1D6E56E1C8
br i1 %116, label %117, label %118
117: ; preds = %114
store i32 0, i32* %5
br label %140
118: ; preds = %114, %110
%119 = load double, double* %14
%120 = fcmp une double %119, 0x565AEA1D6E56E1C8
br i1 %120, label %121, label %125
121: ; preds = %118
%122 = load double, double* %15
%123 = fcmp oeq double %122, 0x565AEA1D6E56E1C8
br i1 %123, label %124, label %125
124: ; preds = %121
store i32 0, i32* %5
br label %140
125: ; preds = %121, %118
%126 = load double, double* %14
%127 = load double, double* %15
%128 = fsub double %126, %127
%129 = call double @llvm.fabs.f64(double %128)
%130 = load double, double* %7
%131 = fmul double 5.000000e-01, %130
%132 = fcmp ogt double %129, %131
br i1 %132, label %133, label %134
133: ; preds = %125
store i32 0, i32* %5
br label %140
134: ; preds = %125
br label %135
135: ; preds = %134
%136 = load i32, i32* %13
%137 = add nsw i32 %136, 1
store i32 %137, i32* %13
br label %85
138: ; preds = %85
br label %139
139: ; preds = %138, %83
store i32 1, i32* %5
br label %140
140: ; preds = %139, %133, %124, %117, %78, %73, %66, %29, %22, %18
%141 = load i32, i32* %5
ret i32 %141
}

LLVM IR (-O2):
define i32 @wcsutil_dblEq(i32 %0, double %1, double* %2, double* %3) {
%5 = icmp eq i32 %0, 0
br i1 %5, label %67, label %6
6: ; preds = %4
%7 = icmp slt i32 %0, 0
br i1 %7, label %67, label %8
8: ; preds = %6
%9 = icmp eq double* %2, null
%10 = icmp eq double* %3, null
%11 = and i1 %9, %10
br i1 %11, label %67, label %12
12: ; preds = %8
%13 = fcmp oeq double %1, 0.000000e+00
br i1 %13, label %17, label %14
14: ; preds = %12
%15 = fmul double %1, 5.000000e-01
%16 = zext i32 %0 to i64
br label %44
17: ; preds = %12
%18 = zext i32 %0 to i64
br label %21
19: ; preds = %34
%20 = icmp eq i64 %41, %18
br i1 %20, label %67, label %21
21: ; preds = %17, %19
%22 = phi i64 [ 0, %17 ], [ %41, %19 ]
br i1 %9, label %26, label %23
23: ; preds = %21
%24 = getelementptr inbounds double, double* %2, i64 %22
%25 = load double, double* %24
br label %26
26: ; preds = %21, %23
%27 = phi double [ %25, %23 ], [ 0x565AEA1D6E56E1C8, %21 ]
br i1 %10, label %34, label %28
28: ; preds = %26
%29 = getelementptr inbounds double, double* %3, i64 %22
%30 = load double, double* %29
%31 = fcmp oeq double %27, 0x565AEA1D6E56E1C8
%32 = fcmp une double %30, 0x565AEA1D6E56E1C8
%33 = select i1 %31, i1 %32, i1 false
br i1 %33, label %67, label %34
34: ; preds = %26, %28
%35 = phi double [ %30, %28 ], [ 0x565AEA1D6E56E1C8, %26 ]
%36 = fcmp oeq double %27, 0x565AEA1D6E56E1C8
%37 = fcmp une double %35, 0x565AEA1D6E56E1C8
%38 = select i1 %36, i1 true, i1 %37
%39 = fcmp oeq double %27, %35
%40 = select i1 %38, i1 %39, i1 false
%41 = add nuw nsw i64 %22, 1
br i1 %40, label %19, label %67
42: ; preds = %62
%43 = icmp eq i64 %66, %16
br i1 %43, label %67, label %44
44: ; preds = %14, %42
%45 = phi i64 [ 0, %14 ], [ %66, %42 ]
br i1 %9, label %49, label %46
46: ; preds = %44
%47 = getelementptr inbounds double, double* %2, i64 %45
%48 = load double, double* %47
br label %49
49: ; preds = %44, %46
%50 = phi double [ %48, %46 ], [ 0x565AEA1D6E56E1C8, %44 ]
br i1 %10, label %57, label %51
51: ; preds = %49
%52 = getelementptr inbounds double, double* %3, i64 %45
%53 = load double, double* %52
%54 = fcmp oeq double %50, 0x565AEA1D6E56E1C8
%55 = fcmp une double %53, 0x565AEA1D6E56E1C8
%56 = select i1 %54, i1 %55, i1 false
br i1 %56, label %67, label %57
57: ; preds = %49, %51
%58 = phi double [ %53, %51 ], [ 0x565AEA1D6E56E1C8, %49 ]
%59 = fcmp une double %50, 0x565AEA1D6E56E1C8
%60 = fcmp oeq double %58, 0x565AEA1D6E56E1C8
%61 = select i1 %59, i1 %60, i1 false
br i1 %61, label %67, label %62
62: ; preds = %57
%63 = fsub double %50, %58
%64 = tail call double @llvm.fabs.f64(double %63)
%65 = fcmp ule double %64, %15
%66 = add nuw nsw i64 %45, 1
br i1 %65, label %42, label %67
67: ; preds = %62, %51, %57, %42, %28, %34, %19, %8, %6, %4
%68 = phi i32 [ 1, %4 ], [ 0, %6 ], [ 1, %8 ], [ 0, %28 ], [ 0, %34 ], [ 1, %19 ], [ 0, %62 ], [ 0, %51 ], [ 0, %57 ], [ 1, %42 ]
ret i32 %68
}