int Simple_ReportScanHit(int left, int right, double score,
                         int (*print_hit)(int, int, double)) {
  static int oldleft = -1;
  static int oldright = -1;
  static double oldscore = -999999.0;
  if (left != oldleft || (left == -1 && right == -1)) {
    if (oldright != -1 && oldleft != -1)
      (*print_hit)(oldleft, oldright, oldscore);
    oldright = right;
    oldleft = left;
    oldscore = score;
  } else if (score > oldscore) {
    oldright = right;
    oldscore = score;
  }
  return 1;
}


x86 assembly (clang, -O0):
<Simple_ReportScanHit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%eax
cmp    0x2f00(%rip),%eax
jne    113a <Simple_ReportScanHit+0x3a>
cmpl   $0xffffffff,-0x4(%rbp)
jne    1192 <Simple_ReportScanHit+0x92>
cmpl   $0xffffffff,-0x8(%rbp)
jne    1192 <Simple_ReportScanHit+0x92>
cmpl   $0xffffffff,0x2ee3(%rip)
je     116e <Simple_ReportScanHit+0x6e>
cmpl   $0xffffffff,0x2ed2(%rip)
je     116e <Simple_ReportScanHit+0x6e>
mov    -0x18(%rbp),%rax
mov    0x2ec2(%rip),%edi
mov    0x2ec0(%rip),%esi
movsd  0x2ebc(%rip),%xmm0
call   *%rax
mov    -0x8(%rbp),%eax
mov    %eax,0x2ead(%rip)
mov    -0x4(%rbp),%eax
mov    %eax,0x2ea0(%rip)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,0x2e9b(%rip)
jmp    11c0 <Simple_ReportScanHit+0xc0>
movsd  -0x10(%rbp),%xmm0
ucomisd 0x2e89(%rip),%xmm0
jbe    11bb <Simple_ReportScanHit+0xbb>
mov    -0x8(%rbp),%eax
mov    %eax,0x2e76(%rip)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,0x2e6d(%rip)
jmp    11c0 <Simple_ReportScanHit+0xc0>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Simple_ReportScanHit>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
mov    0x2f13(%rip),%edi
mov    %esi,%eax
and    %ebp,%eax
cmp    $0xffffffff,%eax
je     112c <Simple_ReportScanHit+0x2c>
cmp    %ebp,%edi
jne    112c <Simple_ReportScanHit+0x2c>
ucomisd 0x2f06(%rip),%xmm0
jbe    1164 <Simple_ReportScanHit+0x64>
mov    %ebx,0x2efa(%rip)
jmp    115c <Simple_ReportScanHit+0x5c>
mov    0x2ef2(%rip),%esi
cmp    $0xffffffff,%esi
je     1150 <Simple_ReportScanHit+0x50>
cmp    $0xffffffff,%edi
je     1150 <Simple_ReportScanHit+0x50>
movsd  %xmm0,(%rsp)
movsd  0x2edf(%rip),%xmm0
call   *%rdx
movsd  (%rsp),%xmm0
mov    %ebx,0x2ece(%rip)
mov    %ebp,0x2ec4(%rip)
movsd  %xmm0,0x2ec4(%rip)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@Simple_ReportScanHit.oldleft = internal global i32 -1
@Simple_ReportScanHit.oldright = internal global i32 -1
@Simple_ReportScanHit.oldscore = internal global double -9.999990e+05
define i32 @Simple_ReportScanHit(i32 %0, i32 %1, double %2, i32 (i32, i32, double)* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca i32 (i32, i32, double)*
store i32 %0, i32* %5
store i32 %1, i32* %6
store double %2, double* %7
store i32 (i32, i32, double)* %3, i32 (i32, i32, double)** %8
%9 = load i32, i32* %5
%10 = load i32, i32* @Simple_ReportScanHit.oldleft
%11 = icmp ne i32 %9, %10
br i1 %11, label %18, label %12
12: ; preds = %4
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %34
15: ; preds = %12
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %34
18: ; preds = %15, %4
%19 = load i32, i32* @Simple_ReportScanHit.oldright
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %30
21: ; preds = %18
%22 = load i32, i32* @Simple_ReportScanHit.oldleft
%23 = icmp ne i32 %22, -1
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = load i32 (i32, i32, double)*, i32 (i32, i32, double)** %8
%26 = load i32, i32* @Simple_ReportScanHit.oldleft
%27 = load i32, i32* @Simple_ReportScanHit.oldright
%28 = load double, double* @Simple_ReportScanHit.oldscore
%29 = call i32 %25(i32 %26, i32 %27, double %28)
br label %30
30: ; preds = %24, %21, %18
%31 = load i32, i32* %6
store i32 %31, i32* @Simple_ReportScanHit.oldright
%32 = load i32, i32* %5
store i32 %32, i32* @Simple_ReportScanHit.oldleft
%33 = load double, double* %7
store double %33, double* @Simple_ReportScanHit.oldscore
br label %42
34: ; preds = %15, %12
%35 = load double, double* %7
%36 = load double, double* @Simple_ReportScanHit.oldscore
%37 = fcmp ogt double %35, %36
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = load i32, i32* %6
store i32 %39, i32* @Simple_ReportScanHit.oldright
%40 = load double, double* %7
store double %40, double* @Simple_ReportScanHit.oldscore
br label %41
41: ; preds = %38, %34
br label %42
42: ; preds = %41, %30
ret i32 1
}

LLVM IR (-O2):
@Simple_ReportScanHit.oldleft = internal unnamed_addr global i32 -1
@Simple_ReportScanHit.oldright = internal unnamed_addr global i32 -1
@Simple_ReportScanHit.oldscore = internal unnamed_addr global double -9.999990e+05
define i32 @Simple_ReportScanHit(i32 %0, i32 %1, double %2, i32 (i32, i32, double)* nocapture %3) {
%5 = load i32, i32* @Simple_ReportScanHit.oldleft
%6 = icmp ne i32 %5, %0
%7 = and i32 %1, %0
%8 = icmp eq i32 %7, -1
%9 = or i1 %8, %6
br i1 %9, label %10, label %19
10: ; preds = %4
%11 = load i32, i32* @Simple_ReportScanHit.oldright
%12 = icmp ne i32 %11, -1
%13 = icmp ne i32 %5, -1
%14 = select i1 %12, i1 %13, i1 false
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load double, double* @Simple_ReportScanHit.oldscore
%17 = tail call i32 %3(i32 %5, i32 %11, double %16)
br label %18
18: ; preds = %15, %10
store i32 %1, i32* @Simple_ReportScanHit.oldright
store i32 %0, i32* @Simple_ReportScanHit.oldleft
br label %23
19: ; preds = %4
%20 = load double, double* @Simple_ReportScanHit.oldscore
%21 = fcmp olt double %20, %2
br i1 %21, label %22, label %24
22: ; preds = %19
store i32 %1, i32* @Simple_ReportScanHit.oldright
br label %23
23: ; preds = %18, %22
store double %2, double* @Simple_ReportScanHit.oldscore
br label %24
24: ; preds = %23, %19
ret i32 1
}