double calculateDecayPercentile(volatile unsigned int *pBaseAddress,
                                const unsigned int pExpectedValue) {
  unsigned int index;
  unsigned int failCount = 0;
  for (index = 0; index < (0x10000 * 1); index += 1) {
    if ((pBaseAddress[index] & 0xFFFF) != (pExpectedValue & 0xFFFF))
      failCount++;
    if ((pBaseAddress[index] & 0xFFFF0000) != (pExpectedValue & 0xFFFF0000))
      failCount++;
  }
  printf("Fail Count: %d\n\r", failCount);
  double decay = ((double)failCount) / (0x10000 * 1 * 2);
  printf("Decay percentile %e\n\r", decay);
  return decay;
}


x86 assembly (clang, -O0):
<calculateDecayPercentile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x10000,-0x10(%rbp)
jae    119f <calculateDecayPercentile+0x8f>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    (%rax,%rcx,4),%eax
and    $0xffff,%eax
mov    -0xc(%rbp),%ecx
and    $0xffff,%ecx
cmp    %ecx,%eax
je     1163 <calculateDecayPercentile+0x53>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    (%rax,%rcx,4),%eax
and    $0xffff0000,%eax
mov    -0xc(%rbp),%ecx
and    $0xffff0000,%ecx
cmp    %ecx,%eax
je     118c <calculateDecayPercentile+0x7c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1191 <calculateDecayPercentile+0x81>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112d <calculateDecayPercentile+0x1d>
mov    -0x14(%rbp),%esi
lea    0xe5f(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  0xe40(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    0xe44(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x20(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculateDecayPercentile>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%rdi,%rax,4),%ecx
xor    %edx,%edx
xor    %si,%cx
setne  %dl
add    %ebx,%edx
mov    (%rdi,%rax,4),%ecx
xor    %esi,%ecx
cmp    $0x10000,%ecx
sbb    $0xffffffff,%edx
mov    0x4(%rdi,%rax,4),%ecx
xor    %ebx,%ebx
xor    %si,%cx
setne  %bl
add    %edx,%ebx
mov    0x4(%rdi,%rax,4),%ecx
xor    %esi,%ecx
cmp    $0x10000,%ecx
sbb    $0xffffffff,%ebx
add    $0x2,%rax
cmp    $0x10000,%rax
jne    1120 <calculateDecayPercentile+0x10>
lea    0xe9d(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%eax
cvtsi2sd %rax,%xmm0
mulsd  0xe7d(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xe89(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Fail Count: %d\0A\0D\00"
@.str.1 = [22 x i8] c"Decay percentile %e\0A\0D\00"
define double @calculateDecayPercentile(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %6
store i32 0, i32* %5
br label %8
8: ; preds = %38, %2
%9 = load i32, i32* %5
%10 = icmp ult i32 %9, 65536
br i1 %10, label %11, label %41
11: ; preds = %8
%12 = load i32*, i32** %3
%13 = load i32, i32* %5
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %12, i64 %14
%16 = load volatile i32, i32* %15
%17 = and i32 %16, 65535
%18 = load i32, i32* %4
%19 = and i32 %18, 65535
%20 = icmp ne i32 %17, %19
br i1 %20, label %21, label %24
21: ; preds = %11
%22 = load i32, i32* %6
%23 = add i32 %22, 1
store i32 %23, i32* %6
br label %24
24: ; preds = %21, %11
%25 = load i32*, i32** %3
%26 = load i32, i32* %5
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = load volatile i32, i32* %28
%30 = and i32 %29, -65536
%31 = load i32, i32* %4
%32 = and i32 %31, -65536
%33 = icmp ne i32 %30, %32
br i1 %33, label %34, label %37
34: ; preds = %24
%35 = load i32, i32* %6
%36 = add i32 %35, 1
store i32 %36, i32* %6
br label %37
37: ; preds = %34, %24
br label %38
38: ; preds = %37
%39 = load i32, i32* %5
%40 = add i32 %39, 1
store i32 %40, i32* %5
br label %8
41: ; preds = %8
%42 = load i32, i32* %6
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %6
%45 = uitofp i32 %44 to double
%46 = fdiv double %45, 1.310720e+05
store double %46, double* %7
%47 = load double, double* %7
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), double %47)
%49 = load double, double* %7
ret double %49
}

LLVM IR (-O2):
@.str = [17 x i8] c"Fail Count: %d\0A\0D\00"
@.str.1 = [22 x i8] c"Decay percentile %e\0A\0D\00"
define double @calculateDecayPercentile(i32* %0, i32 %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i64 [ 0, %2 ], [ %31, %3 ]
%5 = phi i32 [ 0, %2 ], [ %30, %3 ]
%6 = getelementptr inbounds i32, i32* %0, i64 %4
%7 = load volatile i32, i32* %6
%8 = xor i32 %7, %1
%9 = and i32 %8, 65535
%10 = icmp ne i32 %9, 0
%11 = zext i1 %10 to i32
%12 = add i32 %5, %11
%13 = load volatile i32, i32* %6
%14 = xor i32 %13, %1
%15 = icmp ugt i32 %14, 65535
%16 = zext i1 %15 to i32
%17 = add i32 %12, %16
%18 = or i64 %4, 1
%19 = getelementptr inbounds i32, i32* %0, i64 %18
%20 = load volatile i32, i32* %19
%21 = xor i32 %20, %1
%22 = and i32 %21, 65535
%23 = icmp ne i32 %22, 0
%24 = zext i1 %23 to i32
%25 = add i32 %17, %24
%26 = load volatile i32, i32* %19
%27 = xor i32 %26, %1
%28 = icmp ugt i32 %27, 65535
%29 = zext i1 %28 to i32
%30 = add i32 %25, %29
%31 = add nuw nsw i64 %4, 2
%32 = icmp eq i64 %31, 65536
br i1 %32, label %33, label %3
33: ; preds = %3
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %30)
%35 = uitofp i32 %30 to double
%36 = fmul double %35, 0x3EE0000000000000
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), double %36)
ret double %36
}